~ubuntu-branches/ubuntu/karmic/xboard/karmic

« back to all changes in this revision

Viewing changes to winboard/bitmaps/convert.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-07-05 07:58:26 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090705075826-gj6dcvz5fn0rxc6l
Tags: 4.4.0~alpha6-1ubuntu1
* Merge from debian unstable, remaining changes: LP: #395667
  - Add debian/xboard.xpm and set as icon.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
 
 
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!
 
6
 
 
7
main(int argc, char **argv)
 
8
{
 
9
        int i, j, k, d, cnt; char c, h, w, *p, data[10000], *name;
 
10
        FILE *f;
 
11
 
 
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); }
 
15
 
 
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);
 
19
 
 
20
// printf("h=%d, w=%d\n", h, w);
 
21
 
 
22
        p = data;
 
23
        for(i=0; i<h; i++) {
 
24
                for(j=0; j<w; j+=32) {
 
25
                        c = fgetc(f);
 
26
                        for(k=0; k<8; k++) {
 
27
                                d = (d>>1) | (c&0x80);
 
28
                                c <<= 1;
 
29
                        }
 
30
                        *p++ = d;
 
31
                        c = fgetc(f);
 
32
                        for(k=0; k<8; k++) {
 
33
                                d = (d>>1) | (c&0x80);
 
34
                                c <<= 1;
 
35
                        }
 
36
                        *p++ = d;
 
37
                        c = fgetc(f);
 
38
                        for(k=0; k<8; k++) {
 
39
                                d = (d>>1) | (c&0x80);
 
40
                                c <<= 1;
 
41
                        }
 
42
                        *p++ = d;
 
43
                        c = fgetc(f);
 
44
                        for(k=0; k<8; k++) {
 
45
                                d = (d>>1) | (c&0x80);
 
46
                                c <<= 1;
 
47
                        }
 
48
                        *p++ = d;
 
49
                }
 
50
        }
 
51
 
 
52
        name = argv[1];
 
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);
 
58
        cnt = 0;
 
59
        for(i=h-1; i>=0; i--) {
 
60
                for(j=0; j<w; j+=8) {
 
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' : '.');
 
65
//                              c >>= 1;
 
66
//                      }
 
67
                        if(cnt!=0) printf(",");
 
68
                        printf("0x%02x", c&255);
 
69
                        if(++cnt % 15 == 0) { printf("\n"); }
 
70
                }
 
71
        }
 
72
        printf("\n};\n");
 
73
}