3 // [HGM] This program converts the WinBoard monochrome .bmp piece-symbol bitmap files
\r
4 // to .xpm C-source files suitable for inclusion in xboard as buit-in pixmap.
\r
5 // It tries all bitmaps in bulk. Run it once in an empty subdirectory 'pixmaps'of the
\r
6 // root directory of the source tree, and it will fill it with pixmaps.
\r
7 // It overwrites any pixmaps of the same name that already exist. So if you want to
\r
8 // keep the pixmaps you already have, move them elsewhere, run convert, and move them back.
\r
11 int sizeList[] = { 21, 25, 29, 33, 37, 40, 45, 49, 54, 58, 64, 72, 80, 87, 95, 108, 116, 129 };
\r
12 char *(pieceList[]) = {"p", "n", "b", "r", "q", "f", "e", "as", "c", "w", "m",
\r
13 "o", "h", "a", "dk", "g", "d", "v", "l", "s", "u", "k",
\r
14 "wp", "wl", "wn", "ws", "cv", NULL };
\r
15 char kindList[] = "sow";
\r
17 void Load(FILE *f, char data[130][130], char*name)
\r
19 int i, j, k; char h, w, c;
\r
21 if(fscanf(f, "BM%c", &i) != 1) { printf("%s does not have bitmap format\n", name); exit(0); }
\r
22 for(i=0; i<15; i++) fgetc(f); fscanf(f, "%c%c%c%c%c", &h, &i, &i, &i, &w);
\r
23 for(i=0; i<39; i++) fgetc(f); // no checking is done to see if the format is as we expect!!!
\r
25 // printf("h=%d, w=%d\n", h, w);
\r
26 for(i=0; i<h; i++) {
\r
27 for(j=0; j<w; j+=32) {
\r
29 for(k=0; k<8; k++) {
\r
30 data[i][j+k] = c&0x80; c <<= 1;
\r
33 for(k=0; k<8; k++) {
\r
34 data[i][j+k+8] = c&0x80; c <<= 1;
\r
37 for(k=0; k<8; k++) {
\r
38 data[i][j+k+16] = c&0x80; c <<= 1;
\r
41 for(k=0; k<8; k++) {
\r
42 data[i][j+k+24] = c&0x80; c <<= 1;
\r
50 void Paint(char dest[130][130], char src[130][130], int size, char c)
\r
51 { // copy monochrome pixmap to destination as if (transparent, c)
\r
54 for(i=0; i<size; i++) for(j=0; j<size; j++) if(!src[i][j]) dest[i][j] = c;
\r
57 void Save(FILE *f, char *name, char data[130][130], int size, char *col, int depth)
\r
58 { // write out data in source format for d x d pixmap with specified square color
\r
61 fprintf(f, "/* XPM */\n");
\r
62 fprintf(f, "static char *%s[] = {\n", name);
\r
63 fprintf(f, "/* columns rows colors chars-per-pixel */\n");
\r
64 fprintf(f, "\"%d %d %d 1\",\n", size, size, depth);
\r
65 fprintf(f, "\" c black s dark_piece\",\n");
\r
66 fprintf(f, "\". %s\",\n", col);
\r
67 if(depth==3) fprintf(f, "\"X c white s light_piece\",\n");
\r
68 fprintf(f, "/* pixels */\n");
\r
69 for(i=size-1; i>=0; i--) {
\r
70 fprintf(f, "\"%s\"%s\n", data[i], i==0 ? "" : ",");
\r
78 char data[130][130], oData[130][130], sData[130][130], wData[130][130];
\r
80 main(int argc, char **argv)
\r
82 int i, j, k, d, cnt, p, s, t; char c, h, w, *name, buf[80];
\r
85 for(s=0; s<18; s++) for(p=0; pieceList[p] != NULL; p++) {
\r
87 // Load the 3 kinds of Windows monochrome bitmaps (outline, solid, white fill)
\r
89 sprintf(buf, "../winboard/bitmaps/%s%d%c.bmp", pieceList[p], sizeList[s], 'o');
\r
90 printf("try %s\n", buf);
\r
91 f = fopen(buf, "rb");
\r
92 if(f == NULL) continue;
\r
93 Load(f, oData, buf);
\r
95 sprintf(buf, "../winboard/bitmaps/%s%d%c.bmp", pieceList[p], sizeList[s], 's');
\r
96 f = fopen(buf, "rb");
\r
97 if(f == NULL) continue;
\r
98 Load(f, sData, buf);
\r
100 sprintf(buf, "../winboard/bitmaps/%s%d%c.bmp", pieceList[p], sizeList[s], 'w');
\r
101 if(pieceList[p][0]=='w')
\r
102 sprintf(buf, "../winboard/bitmaps/%s%d%c.bmp", "w", sizeList[s], 'w');
\r
103 f = fopen(buf, "rb");
\r
104 if(f == NULL) continue;
\r
105 Load(f, wData, buf);
\r
107 printf("%s loaded\n", buf);
\r
108 // construct pixmaps as character arrays
\r
110 for(i=0; i<d; i++) { for(j=0; j<d; j++) data[i][j] = '.'; data[i][d] = 0; } // fill square
\r
112 Paint(data, sData, d, ' '); // overay with solid piece bitmap
\r
114 sprintf(buf, "%s%s%d.xpm", pieceList[p], "dd", d);
\r
115 sprintf(name, "%s%s%d", pieceList[p], "dd", d);
\r
116 f = fopen(buf, "w");
\r
117 Save(f, name, data, d, "c green s dark_square", 2);
\r
119 sprintf(buf, "%s%s%d.xpm", pieceList[p], "dl", d);
\r
120 sprintf(name, "%s%s%d", pieceList[p], "dl", d);
\r
121 f = fopen(buf, "w");
\r
122 Save(f, name, data, d, "c gray s light_square", 2); // silly duplication; pixmap is te same, but other color
\r
124 // now the light piece
\r
125 for(i=0; i<d; i++) { for(j=0; j<d; j++) data[i][j] = '.'; data[i][d] = 0; } // fill square
\r
127 Paint(data, wData, d, 'X'); // overay with white-filler piece bitmap
\r
128 Paint(data, oData, d, ' '); // overay with outline piece bitmaps
\r
130 sprintf(buf, "%s%s%d.xpm", pieceList[p], "ld", d);
\r
131 sprintf(name, "%s%s%d", pieceList[p], "ld", d);
\r
132 f = fopen(buf, "w");
\r
133 Save(f, name, data, d, "c green s dark_square", 3);
\r
135 sprintf(buf, "%s%s%d.xpm", pieceList[p], "ll", d);
\r
136 sprintf(name, "%s%s%d", pieceList[p], "ll", d);
\r
137 f = fopen(buf, "w");
\r
138 Save(f, name, data, d, "c gray s light_square", 3);
\r
140 printf("%s saved\n", buf);
\r