3 // [HGM] This program converts a WinBoard monochrome .bmp piece-symbol bitmap file
\r
4 // to a .bm C-source file suitable for inclusion in xboard as buit-in bitmap.
\r
5 // You will have to convert the bitmaps one by one, and re-direct the output to the desired file!
\r
7 main(int argc, char **argv)
\r
9 int i, j, k, d, cnt; char c, *p, data[10000], *name; unsigned char h, w;
\r
12 if(argc<2) { printf("usage is: convert <bmp filename>\n"); exit(0); }
\r
13 f = fopen(argv[1], "rb");
\r
14 if(f == NULL) { printf("file %s not found\n", argv[1]); exit(0); }
\r
16 if(fscanf(f, "BM%c", &i) != 1) { printf("%s does not have bitmap format\n"); exit(0); }
\r
17 for(i=0; i<15; i++) fgetc(f); fscanf(f, "%c%c%c%c%c", &h, &i, &i, &i, &w);
\r
18 for(i=0; i<39; i++) fgetc(f);
\r
20 // printf("h=%d, w=%d\n", h, w);
\r
23 for(i=0; i<h; i++) {
\r
24 for(j=0; j<w; j+=32) {
\r
26 for(k=0; k<8; k++) {
\r
27 d = (d>>1) | (c&0x80);
\r
32 for(k=0; k<8; k++) {
\r
33 d = (d>>1) | (c&0x80);
\r
38 for(k=0; k<8; k++) {
\r
39 d = (d>>1) | (c&0x80);
\r
44 for(k=0; k<8; k++) {
\r
45 d = (d>>1) | (c&0x80);
\r
54 for(i=0; argv[1][i]; i++) if(argv[1][i] == '\\') name = argv[1]+i+1;
\r
55 for(i=0; name[i]; i++) if(name[i] == '.') name[i] = 0;
\r
56 printf("#define %s_width %d\n", name, w);
\r
57 printf("#define %s_height %d\n", name, h);
\r
58 printf("static unsigned char %s_bits[] = {\n", name);
\r
60 for(i=h-1; i>=0; i--) {
\r
61 for(j=0; j<w; j+=8) {
\r
62 c = ~data[i*((w+31)/8&~3)+j/8];
\r
63 if(w-j<8) c &= 255>>(8+j-w);
\r
64 // for(k=0; k<8; k++) {
\r
65 // printf("%c", c&1 ? 'X' : '.');
\r
68 if(cnt!=0) printf(",");
\r
69 printf("0x%02x", c&255);
\r
70 if(++cnt % 15 == 0) { printf("\n"); }
\r