16 typedef struct bitmap_s
{ /* bitmap description */
19 uint8_t palette
[256*3];
25 #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
28 * Neutralize little endians.
30 uint16_t le_short(uint16_t x
)
33 uint8_t *p
= (uint8_t *)(&x
);
35 val
= (*p
++ & 0xff) << 0;
36 val
|= (*p
& 0xff) << 8;
41 uint32_t le_int(uint32_t x
)
44 uint8_t *p
= (uint8_t *)(&x
);
46 val
= (*p
++ & 0xff) << 0;
47 val
= (*p
++ & 0xff) << 8;
48 val
= (*p
++ & 0xff) << 16;
49 val
|= (*p
& 0xff) << 24;
54 void skip_bytes (FILE *fp
, int n
)
60 int main (int argc
, char *argv
[])
66 uint16_t data_offset
, n_colors
;
67 #if defined(CONFIG_LCD)
76 fprintf (stderr
, "Usage: %s file\n", argv
[0]);
80 if ((fp
= fopen (argv
[1], "rb")) == NULL
) {
85 if (fgetc (fp
) != 'B' || fgetc (fp
) != 'M') {
86 fprintf (stderr
, "%s is not a bitmap file.\n", argv
[1]);
91 * read width and height of the image, and the number of colors used;
95 fread (&data_offset
, sizeof (uint16_t), 1, fp
);
97 fread (&b
->width
, sizeof (uint16_t), 1, fp
);
99 fread (&b
->height
, sizeof (uint16_t), 1, fp
);
101 fread (&n_colors
, sizeof (uint16_t), 1, fp
);
107 data_offset
= le_short(data_offset
);
108 b
->width
= le_short(b
->width
);
109 b
->height
= le_short(b
->height
);
110 n_colors
= le_short(n_colors
);
112 /* assume we are working with an 8-bit file */
113 #if defined(CONFIG_LCD)
114 if ( n_colors
> 256 ) {
118 if ((n_colors
== 0) || (n_colors
> 256 - DEFAULT_CMAP_SIZE
)) {
119 /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
120 n_colors
= 256 - DEFAULT_CMAP_SIZE
;
125 " * Automatically generated by \"tools/bmp_logo\"\n"
130 "#ifndef __BMP_LOGO_H__\n"
131 "#define __BMP_LOGO_H__\n\n"
132 "#define BMP_LOGO_WIDTH\t\t%d\n"
133 "#define BMP_LOGO_HEIGHT\t\t%d\n"
134 "#define BMP_LOGO_COLORS\t\t%d\n"
135 "#define BMP_LOGO_OFFSET\t\t%d\n"
137 b
->width
, b
->height
, n_colors
,
140 /* allocate memory */
141 if ((b
->data
= (uint8_t *)malloc(b
->width
* b
->height
)) == NULL
) {
143 printf ("Error allocating memory for file %s.\n", argv
[1]);
147 /* read and print the palette information */
148 printf ("unsigned int bmp_logo_palette[] = {\n");
150 for (i
=0; i
<n_colors
; ++i
) {
151 b
->palette
[(int)(i
*3+2)] = fgetc(fp
);
152 b
->palette
[(int)(i
*3+1)] = fgetc(fp
);
153 b
->palette
[(int)(i
*3+0)] = fgetc(fp
);
156 #if defined(CONFIG_LCD)
161 val
= ((b
->palette
[(int)(i
*3+0)] >> 3) & 0x1F )<< 11 | \
162 ((b
->palette
[(int)(i
*3+1)] >> 2) & 0x3F )<< 5 | \
163 ((b
->palette
[(int)(i
*3+2)] >> 3) & 0x1F );
166 val
= b
->palette
[(int)(i
*3+0)] << 16 | \
167 b
->palette
[(int)(i
*3+1)] << 8 | \
168 b
->palette
[(int)(i
*3+2)] << 0 ;
171 ((i
%8) == 0) ? "\t" : " ",
173 ((i
%8) == 7) ? "\n" : ""
177 printf ("%s0x0%X%X%X,%s",
178 ((i
%8) == 0) ? "\t" : " ",
179 (b
->palette
[(int)(i
*3+0)] >> 4) & 0x0F,
180 (b
->palette
[(int)(i
*3+1)] >> 4) & 0x0F,
181 (b
->palette
[(int)(i
*3+2)] >> 4) & 0x0F,
182 ((i
%8) == 7) ? "\n" : ""
187 /* seek to offset indicated by file header */
188 fseek(fp
, (long)data_offset
, SEEK_SET
);
190 /* read the bitmap; leave room for default color map */
194 printf ("unsigned char bmp_logo_bitmap[] = {\n");
195 for (i
=(b
->height
-1)*b
->width
; i
>=0; i
-=b
->width
) {
196 for (x
= 0; x
< b
->width
; x
++) {
197 #if defined(CONFIG_LCD)
198 b
->data
[ i
+ x
] = (uint8_t) fgetc (fp
) ;
200 b
->data
[(uint16_t) i
+ x
] = (uint8_t) fgetc (fp
) \
207 for (i
=0; i
<(b
->height
*b
->width
); ++i
) {
212 ((i
%8) == 7) ? '\n' : ' '
217 "#endif /* __BMP_LOGO_H__ */\n"