]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/bmp_logo.c
3 typedef struct bitmap_s
{ /* bitmap description */
6 uint8_t palette
[256*3];
10 #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
13 * Neutralize little endians.
15 uint16_t le_short(uint16_t x
)
18 uint8_t *p
= (uint8_t *)(&x
);
20 val
= (*p
++ & 0xff) << 0;
21 val
|= (*p
& 0xff) << 8;
26 void skip_bytes (FILE *fp
, int n
)
32 __attribute__ ((__noreturn__
))
33 int error (char * msg
, FILE *fp
)
35 fprintf (stderr
, "ERROR: %s\n", msg
);
42 int main (int argc
, char *argv
[])
48 uint16_t data_offset
, n_colors
;
51 fprintf (stderr
, "Usage: %s file\n", argv
[0]);
55 if ((fp
= fopen (argv
[1], "rb")) == NULL
) {
60 if (fgetc (fp
) != 'B' || fgetc (fp
) != 'M')
61 error ("Input file is not a bitmap", fp
);
64 * read width and height of the image, and the number of colors used;
68 if (fread (&data_offset
, sizeof (uint16_t), 1, fp
) != 1)
69 error ("Couldn't read bitmap data offset", fp
);
71 if (fread (&b
->width
, sizeof (uint16_t), 1, fp
) != 1)
72 error ("Couldn't read bitmap width", fp
);
74 if (fread (&b
->height
, sizeof (uint16_t), 1, fp
) != 1)
75 error ("Couldn't read bitmap height", fp
);
77 if (fread (&n_colors
, sizeof (uint16_t), 1, fp
) != 1)
78 error ("Couldn't read bitmap colors", fp
);
84 data_offset
= le_short(data_offset
);
85 b
->width
= le_short(b
->width
);
86 b
->height
= le_short(b
->height
);
87 n_colors
= le_short(n_colors
);
89 /* assume we are working with an 8-bit file */
90 if ((n_colors
== 0) || (n_colors
> 256 - DEFAULT_CMAP_SIZE
)) {
91 /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
92 n_colors
= 256 - DEFAULT_CMAP_SIZE
;
96 " * Automatically generated by \"tools/bmp_logo\"\n"
101 "#ifndef __BMP_LOGO_H__\n"
102 "#define __BMP_LOGO_H__\n\n"
103 "#define BMP_LOGO_WIDTH\t\t%d\n"
104 "#define BMP_LOGO_HEIGHT\t\t%d\n"
105 "#define BMP_LOGO_COLORS\t\t%d\n"
106 "#define BMP_LOGO_OFFSET\t\t%d\n"
108 b
->width
, b
->height
, n_colors
,
111 /* allocate memory */
112 if ((b
->data
= (uint8_t *)malloc(b
->width
* b
->height
)) == NULL
)
113 error ("Error allocating memory for file", fp
);
115 /* read and print the palette information */
116 printf ("unsigned short bmp_logo_palette[] = {\n");
118 for (i
=0; i
<n_colors
; ++i
) {
119 b
->palette
[(int)(i
*3+2)] = fgetc(fp
);
120 b
->palette
[(int)(i
*3+1)] = fgetc(fp
);
121 b
->palette
[(int)(i
*3+0)] = fgetc(fp
);
124 printf ("%s0x0%X%X%X,%s",
125 ((i
%8) == 0) ? "\t" : " ",
126 (b
->palette
[(int)(i
*3+0)] >> 4) & 0x0F,
127 (b
->palette
[(int)(i
*3+1)] >> 4) & 0x0F,
128 (b
->palette
[(int)(i
*3+2)] >> 4) & 0x0F,
129 ((i
%8) == 7) ? "\n" : ""
133 /* seek to offset indicated by file header */
134 fseek(fp
, (long)data_offset
, SEEK_SET
);
136 /* read the bitmap; leave room for default color map */
140 printf ("unsigned char bmp_logo_bitmap[] = {\n");
141 for (i
=(b
->height
-1)*b
->width
; i
>=0; i
-=b
->width
) {
142 for (x
= 0; x
< b
->width
; x
++) {
143 b
->data
[(uint16_t) i
+ x
] = (uint8_t) fgetc (fp
) \
149 for (i
=0; i
<(b
->height
*b
->width
); ++i
) {
154 ((i
%8) == 7) ? '\n' : ' '
159 "#endif /* __BMP_LOGO_H__ */\n"