annotate window/runlengh.cc @ 18:4d7486cb20a9

Sync with upstream
author thib
date Tue, 16 Sep 2008 15:30:03 +0000
parents 223b71206888
children 6d1a5b7f0838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 #include<stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
2
223b71206888 Initial import
thib
parents:
diff changeset
3 int main(int argc, char** argv) {
223b71206888 Initial import
thib
parents:
diff changeset
4 if (argc != 2) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
5 FILE* f = fopen(argv[1],"rb");
223b71206888 Initial import
thib
parents:
diff changeset
6 if (f==0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
7 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
8 fseek(f,0,2);
223b71206888 Initial import
thib
parents:
diff changeset
9 int sz=ftell(f);
223b71206888 Initial import
thib
parents:
diff changeset
10 fseek(f,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
11 char* buf=new char[sz];
223b71206888 Initial import
thib
parents:
diff changeset
12 char* out = new char[sz];
223b71206888 Initial import
thib
parents:
diff changeset
13 fread(buf,sz,1,f);
223b71206888 Initial import
thib
parents:
diff changeset
14 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
15 int oc=0;
223b71206888 Initial import
thib
parents:
diff changeset
16 for (i=0; i<sz; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
17 int d = buf[i];
223b71206888 Initial import
thib
parents:
diff changeset
18 int c = d & 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
19 switch(c) {
223b71206888 Initial import
thib
parents:
diff changeset
20 case 0x61: c=1; break;
223b71206888 Initial import
thib
parents:
diff changeset
21 case 0xa2: c=2; break;
223b71206888 Initial import
thib
parents:
diff changeset
22 case 0xc1: c=3; break;
223b71206888 Initial import
thib
parents:
diff changeset
23 case 0xdf: c=4; break;
223b71206888 Initial import
thib
parents:
diff changeset
24 case 0xde: c=5; break;
223b71206888 Initial import
thib
parents:
diff changeset
25 case 0xff: c=6; break;
223b71206888 Initial import
thib
parents:
diff changeset
26 }
223b71206888 Initial import
thib
parents:
diff changeset
27 for (j=i; j<sz; j++)
223b71206888 Initial import
thib
parents:
diff changeset
28 if (buf[j] != d) break;
223b71206888 Initial import
thib
parents:
diff changeset
29 int cnt = j-i;
223b71206888 Initial import
thib
parents:
diff changeset
30 if (cnt < 16) {
223b71206888 Initial import
thib
parents:
diff changeset
31 out[oc++] = c | 0x08 | (cnt<<4);
223b71206888 Initial import
thib
parents:
diff changeset
32 } else if (cnt < 256){
223b71206888 Initial import
thib
parents:
diff changeset
33 out[oc++] = c;
223b71206888 Initial import
thib
parents:
diff changeset
34 out[oc++] = cnt;
223b71206888 Initial import
thib
parents:
diff changeset
35 } else fprintf(stderr,"cnt %d\n",cnt);
223b71206888 Initial import
thib
parents:
diff changeset
36 if (j == sz) break;
223b71206888 Initial import
thib
parents:
diff changeset
37 i = j-1;
223b71206888 Initial import
thib
parents:
diff changeset
38 }
223b71206888 Initial import
thib
parents:
diff changeset
39 printf("int button1_cnt = %d;\nchar button1[%d] = {\n\t",oc,oc+1);
223b71206888 Initial import
thib
parents:
diff changeset
40 for (i=0; i<oc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
41 printf("0x%02x,",int(out[i])&0xff);
223b71206888 Initial import
thib
parents:
diff changeset
42 if ( (i&15) == 15) printf("\n\t");
223b71206888 Initial import
thib
parents:
diff changeset
43 }
223b71206888 Initial import
thib
parents:
diff changeset
44 printf("\n\t0xff};\n");
223b71206888 Initial import
thib
parents:
diff changeset
45 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
46 }
223b71206888 Initial import
thib
parents:
diff changeset
47 /* 2834bytes*/