Mercurial > otakunoraifu
comparison window/runlengh.cc @ 0:223b71206888
Initial import
author | thib |
---|---|
date | Fri, 01 Aug 2008 16:32:45 +0000 |
parents | |
children | 6d1a5b7f0838 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:223b71206888 |
---|---|
1 #include<stdio.h> | |
2 | |
3 int main(int argc, char** argv) { | |
4 if (argc != 2) return 0; | |
5 FILE* f = fopen(argv[1],"rb"); | |
6 if (f==0) return 0; | |
7 int i,j; | |
8 fseek(f,0,2); | |
9 int sz=ftell(f); | |
10 fseek(f,0,0); | |
11 char* buf=new char[sz]; | |
12 char* out = new char[sz]; | |
13 fread(buf,sz,1,f); | |
14 fclose(f); | |
15 int oc=0; | |
16 for (i=0; i<sz; i++) { | |
17 int d = buf[i]; | |
18 int c = d & 0xff; | |
19 switch(c) { | |
20 case 0x61: c=1; break; | |
21 case 0xa2: c=2; break; | |
22 case 0xc1: c=3; break; | |
23 case 0xdf: c=4; break; | |
24 case 0xde: c=5; break; | |
25 case 0xff: c=6; break; | |
26 } | |
27 for (j=i; j<sz; j++) | |
28 if (buf[j] != d) break; | |
29 int cnt = j-i; | |
30 if (cnt < 16) { | |
31 out[oc++] = c | 0x08 | (cnt<<4); | |
32 } else if (cnt < 256){ | |
33 out[oc++] = c; | |
34 out[oc++] = cnt; | |
35 } else fprintf(stderr,"cnt %d\n",cnt); | |
36 if (j == sz) break; | |
37 i = j-1; | |
38 } | |
39 printf("int button1_cnt = %d;\nchar button1[%d] = {\n\t",oc,oc+1); | |
40 for (i=0; i<oc; i++) { | |
41 printf("0x%02x,",int(out[i])&0xff); | |
42 if ( (i&15) == 15) printf("\n\t"); | |
43 } | |
44 printf("\n\t0xff};\n"); | |
45 return 0; | |
46 } | |
47 /* 2834bytes*/ |