[go: up one dir, main page]

Menu

[904618]: / util / cc2raw.c  Maximize  Restore  History

Download this file

69 lines (58 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
static uint8_t BitData[64000];
static uint8_t CompData[64000];
int main(int argc, char** argv)
{
size_t i, j, zCount, k, ooo, z, ll;
size_t sz;
uint8_t b, OldB, CarryB;
FILE* fi = fopen(argv[1], "rb");
FILE* fo = fopen("cdump", "wt");
fseek(fi, 0, SEEK_END);
sz = ftell(fi);
fseek(fi, 0, SEEK_SET);
zCount = 0;
OldB = 0;
CarryB = 0;
for (j = 0, i = 0; i < sz; i++)
{
fread(&b, 1, 1, fi);
if ((k & 1) == 0)
BitData[j] = b;
else
BitData[j++] |= b << 4;
k++;
}
// Compress Data, somewhat (RLE style)
zCount = 0;
OldB = BitData[0];
for (ll = 0, i = 1; i < j; i++)
{
b = BitData[i];
// Does not match?
if (OldB != b)
{
CompData[ll++] = zCount;
CompData[ll++] = b;
OldB = b;
zCount = 0;
}
// Matches
else
{
zCount++;
if (zCount > 250)
fprintf(stderr, "TOO MUCH!\n");
}
}
// Print packed data
for (k = 0; k < ll; k++)
{
fprintf(fo, "%hhu,", CompData[k]);
if (((k + 1) % 30) == 0)
fprintf(fo, "\n");
}
fprintf(stderr, "SIZE: %i\n", (int)ll);
}