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