14 typedef struct bitmap_s { /* bitmap description */
17 uint8_t palette[256*3];
21 #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
24 * Neutralize little endians.
26 uint16_t le_short(uint16_t x)
29 uint8_t *p = (uint8_t *)(&x);
31 val = (*p++ & 0xff) << 0;
32 val |= (*p & 0xff) << 8;
37 void skip_bytes (FILE *fp, int n)
43 int main (int argc, char *argv[])
52 fprintf (stderr, "Usage: %s file\n", argv[0]);
56 if ((fp = fopen (argv[1], "rb")) == NULL) {
61 if (fgetc (fp) != 'B' || fgetc (fp) != 'M') {
62 fprintf (stderr, "%s is not a bitmap file.\n", argv[1]);
67 * read width and height of the image, and the number of colors used;
71 fread (&b->width, sizeof (uint16_t), 1, fp);
73 fread (&b->height, sizeof (uint16_t), 1, fp);
75 fread (&n_colors, sizeof (uint16_t), 1, fp);
81 b->width = le_short(b->width);
82 b->height = le_short(b->height);
83 n_colors = le_short(n_colors);
85 /* assume we are working with an 8-bit file */
86 if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
87 /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
88 n_colors = 256 - DEFAULT_CMAP_SIZE;
92 " * Automatically generated by \"tools/bmp_logo\"\n"
97 "#ifndef __BMP_LOGO_H__\n"
98 "#define __BMP_LOGO_H__\n\n"
99 "#define BMP_LOGO_WIDTH\t\t%d\n"
100 "#define BMP_LOGO_HEIGHT\t\t%d\n"
101 "#define BMP_LOGO_COLORS\t\t%d\n"
102 "#define BMP_LOGO_OFFSET\t\t%d\n"
104 b->width, b->height, n_colors,
107 /* allocate memory */
108 if ((b->data = (uint8_t *)malloc(b->width * b->height)) == NULL) {
110 printf ("Error allocating memory for file %s.\n", argv[1]);
114 /* read and print the palette information */
115 printf ("unsigned short bmp_logo_palette[] = {\n");
117 for (i=0; i<n_colors; ++i) {
118 b->palette[(int)(i*3+2)] = fgetc(fp);
119 b->palette[(int)(i*3+1)] = fgetc(fp);
120 b->palette[(int)(i*3+0)] = fgetc(fp);
126 printf ("0x%02X, 0x%02X, 0x%02X,%s",
127 b->palette[(int)(i*3+0)],
128 b->palette[(int)(i*3+1)],
129 b->palette[(int)(i*3+2)],
130 ((i%4) == 3) ? "\n" : " "
135 printf ("0x0%X%X%X,%s",
136 (b->palette[(int)(i*3+0)] >> 4) & 0x0F,
137 (b->palette[(int)(i*3+1)] >> 4) & 0x0F,
138 (b->palette[(int)(i*3+2)] >> 4) & 0x0F,
139 ((i%8) == 7) ? "\n" : " "
144 /* read the bitmap; leave room for default color map */
148 printf ("unsigned char bmp_logo_bitmap[] = {\n");
149 for (i=(b->height-1)*b->width; i>=0; i-=b->width) {
150 for (x = 0; x < b->width; x++) {
151 b->data[(uint16_t) i + x] = (uint8_t) fgetc (fp) \
157 for (i=0; i<(b->height*b->width); ++i) {
162 ((i%8) == 7) ? '\n' : ' '
167 "#endif /* __BMP_LOGO_H__ */\n"