24 static const char *programname;
26 static const char *logoname =
"linux_logo";
27 static const char *outputname;
31 #define LINUX_LOGO_MONO 1
32 #define LINUX_LOGO_VGA16 2
33 #define LINUX_LOGO_CLUT224 3
34 #define LINUX_LOGO_GRAY256 4
43 #define MAX_LINUX_LOGO_COLORS 224
51 static const struct color clut_vga16[16] = {
72 static unsigned int logo_width;
73 static unsigned int logo_height;
74 static struct color **logo_data;
76 static unsigned int logo_clutsize;
78 static void die(
const char *
fmt, ...)
83 static
unsigned int get_number(FILE *
fp)
113 static unsigned int get_number255(FILE *fp,
unsigned int maxval)
115 unsigned int val = get_number(fp);
116 return (255*val+maxval/2)/maxval;
119 static void read_image(
void)
147 die(
"%s: Binary PNM is not supported\n"
148 "Use pnmnoraw(1) to convert it to ASCII PNM\n",
filename);
153 logo_width = get_number(fp);
154 logo_height = get_number(fp);
160 for (i = 0; i < logo_height; i++) {
170 for (i = 0; i < logo_height; i++)
171 for (j = 0; j < logo_width; j++)
172 logo_data[i][j].
red = logo_data[i][j].
green =
173 logo_data[i][j].
blue = 255*(1-get_number(fp));
178 maxval = get_number(fp);
179 for (i = 0; i < logo_height; i++)
180 for (j = 0; j < logo_width; j++)
181 logo_data[i][j].
red = logo_data[i][j].
green =
182 logo_data[i][j].
blue = get_number255(fp, maxval);
187 maxval = get_number(fp);
188 for (i = 0; i < logo_height; i++)
189 for (j = 0; j < logo_width; j++) {
190 logo_data[
i][
j].
red = get_number255(fp, maxval);
191 logo_data[
i][
j].
green = get_number255(fp, maxval);
192 logo_data[
i][
j].
blue = get_number255(fp, maxval);
201 static inline int is_black(
struct color c)
206 static inline int is_white(
struct color c)
211 static inline int is_gray(
struct color c)
216 static inline int is_equal(
struct color c1,
struct color c2)
221 static void write_header(
void)
225 out = fopen(outputname,
"w");
227 die(
"Cannot create file %s: %s\n", outputname,
strerror(errno));
233 fputs(
" * DO NOT EDIT THIS FILE!\n",
out);
238 fputs(
" */\n\n",
out);
239 fputs(
"#include <linux/linux_logo.h>\n\n",
out);
240 fprintf(
out,
"static unsigned char %s_data[] __initdata = {\n",
244 static void write_footer(
void)
246 fputs(
"\n};\n\n",
out);
247 fprintf(
out,
"const struct linux_logo %s __initconst = {\n", logoname);
248 fprintf(
out,
"\t.type\t\t= %s,\n", logo_types[logo_type]);
249 fprintf(
out,
"\t.width\t\t= %d,\n", logo_width);
250 fprintf(
out,
"\t.height\t\t= %d,\n", logo_height);
252 fprintf(
out,
"\t.clutsize\t= %d,\n", logo_clutsize);
253 fprintf(
out,
"\t.clut\t\t= %s_clut,\n", logoname);
255 fprintf(
out,
"\t.data\t\t= %s_data\n", logoname);
256 fputs(
"};\n\n",
out);
263 static int write_hex_cnt;
265 static void write_hex(
unsigned char byte)
267 if (write_hex_cnt % 12)
269 else if (write_hex_cnt)
276 static void write_logo_mono(
void)
282 for (i = 0; i < logo_height; i++)
283 for (j = 0; j < logo_width; j++)
284 if (!is_black(logo_data[i][j]) && !is_white(logo_data[i][j]))
285 die(
"Image must be monochrome\n");
291 for (i = 0; i < logo_height; i++) {
292 for (j = 0; j < logo_width;) {
293 for (val = 0, bit = 0x80; bit && j < logo_width; j++, bit >>= 1)
294 if (logo_data[i][j].
red)
304 static void write_logo_vga16(
void)
306 unsigned int i,
j,
k;
310 for (i = 0; i < logo_height; i++)
311 for (j = 0; j < logo_width; j++) {
312 for (k = 0; k < 16; k++)
313 if (is_equal(logo_data[i][j], clut_vga16[k]))
316 die(
"Image must use the 16 console colors only\n"
317 "Use ppmquant(1) -map clut_vga16.ppm to reduce the number "
325 for (i = 0; i < logo_height; i++)
326 for (j = 0; j < logo_width; j++) {
327 for (k = 0; k < 16; k++)
328 if (is_equal(logo_data[i][j], clut_vga16[k]))
331 if (++j < logo_width) {
332 for (k = 0; k < 16; k++)
333 if (is_equal(logo_data[i][j], clut_vga16[k]))
344 static void write_logo_clut224(
void)
346 unsigned int i,
j,
k;
349 for (i = 0; i < logo_height; i++)
350 for (j = 0; j < logo_width; j++) {
351 for (k = 0; k < logo_clutsize; k++)
352 if (is_equal(logo_data[i][j], logo_clut[k]))
354 if (k == logo_clutsize) {
356 die(
"Image has more than %d colors\n"
357 "Use ppmquant(1) to reduce the number of colors\n",
359 logo_clut[logo_clutsize++] = logo_data[
i][
j];
367 for (i = 0; i < logo_height; i++)
368 for (j = 0; j < logo_width; j++) {
369 for (k = 0; k < logo_clutsize; k++)
370 if (is_equal(logo_data[i][j], logo_clut[k]))
374 fputs(
"\n};\n\n",
out);
377 fprintf(
out,
"static unsigned char %s_clut[] __initdata = {\n",
380 for (i = 0; i < logo_clutsize; i++) {
381 write_hex(logo_clut[i].
red);
382 write_hex(logo_clut[i].
green);
383 write_hex(logo_clut[i].
blue);
390 static void write_logo_gray256(
void)
395 for (i = 0; i < logo_height; i++)
396 for (j = 0; j < logo_width; j++)
397 if (!is_gray(logo_data[i][j]))
398 die(
"Image must be grayscale\n");
404 for (i = 0; i < logo_height; i++)
405 for (j = 0; j < logo_width; j++)
406 write_hex(logo_data[i][j].
red);
412 static void die(
const char *fmt, ...)
423 static void usage(
void)
426 "Usage: %s [options] <filename>\n"
429 " -h : display this usage information\n"
430 " -n <name> : specify logo name (default: linux_logo)\n"
431 " -o <output> : output to file <output> instead of stdout\n"
432 " -t <type> : specify logo type, one of\n"
433 " mono : monochrome black/white\n"
434 " vga16 : 16 colors VGA text palette\n"
435 " clut224 : 224 colors (default)\n"
436 " gray256 : 256 levels grayscale\n"
444 programname = argv[0];
448 opt = getopt(argc, argv,
"hn:o:t:");
466 if (!
strcmp(optarg,
"mono"))
468 else if (!
strcmp(optarg,
"vga16"))
470 else if (!
strcmp(optarg,
"clut224"))
472 else if (!
strcmp(optarg,
"gray256"))
483 if (optind != argc-1)
499 write_logo_clut224();
503 write_logo_gray256();