]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/bmp_logo.c
8 typedef struct bitmap_s
{ /* bitmap description */
11 uint8_t palette
[256*3];
15 #define DEFAULT_CMAP_SIZE 16 /* size of default color map */
17 void usage(const char *prog
)
19 fprintf(stderr
, "Usage: %s [--gen-info|--gen-data] file\n", prog
);
23 * Neutralize little endians.
25 uint16_t le_short(uint16_t x
)
28 uint8_t *p
= (uint8_t *)(&x
);
30 val
= (*p
++ & 0xff) << 0;
31 val
|= (*p
& 0xff) << 8;
36 void skip_bytes (FILE *fp
, int n
)
42 __attribute__ ((__noreturn__
))
43 int error (char * msg
, FILE *fp
)
45 fprintf (stderr
, "ERROR: %s\n", msg
);
52 void gen_info(bitmap_t
*b
, uint16_t n_colors
)
55 " * Automatically generated by \"tools/bmp_logo\"\n"
60 "#ifndef __BMP_LOGO_H__\n"
61 "#define __BMP_LOGO_H__\n\n"
62 "#define BMP_LOGO_WIDTH\t\t%d\n"
63 "#define BMP_LOGO_HEIGHT\t\t%d\n"
64 "#define BMP_LOGO_COLORS\t\t%d\n"
65 "#define BMP_LOGO_OFFSET\t\t%d\n\n"
66 "extern unsigned short bmp_logo_palette[];\n"
67 "extern unsigned char bmp_logo_bitmap[];\n\n"
68 "#endif /* __BMP_LOGO_H__ */\n",
69 b
->width
, b
->height
, n_colors
,
73 int main (int argc
, char *argv
[])
79 uint16_t data_offset
, n_colors
;
86 if (!strcmp(argv
[1], "--gen-info"))
88 else if (!strcmp(argv
[1], "--gen-data"))
95 fp
= fopen(argv
[2], "rb");
101 if (fgetc (fp
) != 'B' || fgetc (fp
) != 'M')
102 error ("Input file is not a bitmap", fp
);
105 * read width and height of the image, and the number of colors used;
109 if (fread (&data_offset
, sizeof (uint16_t), 1, fp
) != 1)
110 error ("Couldn't read bitmap data offset", fp
);
112 if (fread (&b
->width
, sizeof (uint16_t), 1, fp
) != 1)
113 error ("Couldn't read bitmap width", fp
);
115 if (fread (&b
->height
, sizeof (uint16_t), 1, fp
) != 1)
116 error ("Couldn't read bitmap height", fp
);
118 if (fread (&n_colors
, sizeof (uint16_t), 1, fp
) != 1)
119 error ("Couldn't read bitmap colors", fp
);
125 data_offset
= le_short(data_offset
);
126 b
->width
= le_short(b
->width
);
127 b
->height
= le_short(b
->height
);
128 n_colors
= le_short(n_colors
);
130 /* assume we are working with an 8-bit file */
131 if ((n_colors
== 0) || (n_colors
> 256 - DEFAULT_CMAP_SIZE
)) {
132 /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
133 n_colors
= 256 - DEFAULT_CMAP_SIZE
;
136 if (mode
== MODE_GEN_INFO
) {
137 gen_info(b
, n_colors
);
142 " * Automatically generated by \"tools/bmp_logo\"\n"
147 "#ifndef __BMP_LOGO_DATA_H__\n"
148 "#define __BMP_LOGO_DATA_H__\n\n");
150 /* allocate memory */
151 if ((b
->data
= (uint8_t *)malloc(b
->width
* b
->height
)) == NULL
)
152 error ("Error allocating memory for file", fp
);
154 /* read and print the palette information */
155 printf("unsigned short bmp_logo_palette[] = {\n");
157 for (i
=0; i
<n_colors
; ++i
) {
158 b
->palette
[(int)(i
*3+2)] = fgetc(fp
);
159 b
->palette
[(int)(i
*3+1)] = fgetc(fp
);
160 b
->palette
[(int)(i
*3+0)] = fgetc(fp
);
163 printf ("%s0x0%X%X%X,%s",
164 ((i
%8) == 0) ? "\t" : " ",
165 (b
->palette
[(int)(i
*3+0)] >> 4) & 0x0F,
166 (b
->palette
[(int)(i
*3+1)] >> 4) & 0x0F,
167 (b
->palette
[(int)(i
*3+2)] >> 4) & 0x0F,
168 ((i
%8) == 7) ? "\n" : ""
172 /* seek to offset indicated by file header */
173 fseek(fp
, (long)data_offset
, SEEK_SET
);
175 /* read the bitmap; leave room for default color map */
179 printf("unsigned char bmp_logo_bitmap[] = {\n");
180 for (i
=(b
->height
-1)*b
->width
; i
>=0; i
-=b
->width
) {
181 for (x
= 0; x
< b
->width
; x
++) {
182 b
->data
[i
+ x
] = (uint8_t) fgetc(fp
)
187 for (i
=0; i
<(b
->height
*b
->width
); ++i
) {
192 ((i
%8) == 7) ? '\n' : ' '
197 "#endif /* __BMP_LOGO_DATA_H__ */\n"