]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/bmp_logo.c
54fdcffbaff40b1a6592e7652e3c953c4a347065
15 typedef unsigned short ushort
;
16 #endif /* __CYGWIN__ */
19 typedef struct bitmap_s
{ /* bitmap description */
22 uint8_t palette
[256*3];
26 #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
29 * Neutralize little endians.
31 uint16_t le_short(uint16_t x
)
34 uint8_t *p
= (uint8_t *)(&x
);
36 val
= (*p
++ & 0xff) << 0;
37 val
|= (*p
& 0xff) << 8;
42 void skip_bytes (FILE *fp
, int n
)
48 int main (int argc
, char *argv
[])
57 fprintf (stderr
, "Usage: %s file\n", argv
[0]);
61 if ((fp
= fopen (argv
[1], "rb")) == NULL
) {
66 if (fgetc (fp
) != 'B' || fgetc (fp
) != 'M') {
67 fprintf (stderr
, "%s is not a bitmap file.\n", argv
[1]);
72 * read width and height of the image, and the number of colors used;
76 fread (&b
->width
, sizeof (uint16_t), 1, fp
);
78 fread (&b
->height
, sizeof (uint16_t), 1, fp
);
80 fread (&n_colors
, sizeof (uint16_t), 1, fp
);
86 b
->width
= le_short(b
->width
);
87 b
->height
= le_short(b
->height
);
88 n_colors
= le_short(n_colors
);
90 /* assume we are working with an 8-bit file */
91 if ((n_colors
== 0) || (n_colors
> 256 - DEFAULT_CMAP_SIZE
)) {
92 /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
93 n_colors
= 256 - DEFAULT_CMAP_SIZE
;
97 " * Automatically generated by \"tools/bmp_logo\"\n"
102 "#ifndef __BMP_LOGO_H__\n"
103 "#define __BMP_LOGO_H__\n\n"
104 "#define BMP_LOGO_WIDTH\t\t%d\n"
105 "#define BMP_LOGO_HEIGHT\t\t%d\n"
106 "#define BMP_LOGO_COLORS\t\t%d\n"
107 "#define BMP_LOGO_OFFSET\t\t%d\n"
109 b
->width
, b
->height
, n_colors
,
112 /* allocate memory */
113 if ((b
->data
= (uint8_t *)malloc(b
->width
* b
->height
)) == NULL
) {
115 printf ("Error allocating memory for file %s.\n", argv
[1]);
119 /* read and print the palette information */
120 printf ("unsigned short bmp_logo_palette[] = {\n");
122 for (i
=0; i
<n_colors
; ++i
) {
123 b
->palette
[(int)(i
*3+2)] = fgetc(fp
);
124 b
->palette
[(int)(i
*3+1)] = fgetc(fp
);
125 b
->palette
[(int)(i
*3+0)] = fgetc(fp
);
131 printf ("0x%02X, 0x%02X, 0x%02X,%s",
132 b
->palette
[(int)(i
*3+0)],
133 b
->palette
[(int)(i
*3+1)],
134 b
->palette
[(int)(i
*3+2)],
135 ((i
%4) == 3) ? "\n" : " "
140 printf ("0x0%X%X%X,%s",
141 (b
->palette
[(int)(i
*3+0)] >> 4) & 0x0F,
142 (b
->palette
[(int)(i
*3+1)] >> 4) & 0x0F,
143 (b
->palette
[(int)(i
*3+2)] >> 4) & 0x0F,
144 ((i
%8) == 7) ? "\n" : " "
149 /* read the bitmap; leave room for default color map */
153 printf ("unsigned char bmp_logo_bitmap[] = {\n");
154 for (i
=(b
->height
-1)*b
->width
; i
>=0; i
-=b
->width
) {
155 for (x
= 0; x
< b
->width
; x
++) {
156 b
->data
[(uint16_t) i
+ x
] = (uint8_t) fgetc (fp
) \
162 for (i
=0; i
<(b
->height
*b
->width
); ++i
) {
167 ((i
%8) == 7) ? '\n' : ' '
172 "#endif /* __BMP_LOGO_H__ */\n"