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