Mirai's Miscellaneous Misadventures
M50 / core / packbits.c
1
2
3
4#include <mimimi.h>
5
6void mimimi_unpack_bits(int size, unsigned char *unpacked, unsigned char *packed)
7{
8 int i, j, k, n;
9
10 i = 0;
11 j = 0;
12
13 while (j < size)
14 {
15 n = packed[i++];
16 if (n == 128) continue;
17 if (n > 128) n -= 256;
18
19 if (n > 0)
20 {
21 for (k = 0 ; k <= n ; k++)
22 unpacked[j++] = packed[i++];
23 }
24 else
25 {
26 for (k = 0 ; k <= -n ; k++)
27 unpacked[j++] = packed[i];
28 i++;
29 }
30 }
31}