Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Convert a logo in ASCII PNM format to C source suitable for inclusion in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  the Linux kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  (C) Copyright 2001-2003 by Geert Uytterhoeven <geert@linux-m68k.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  License. See the file COPYING in the main directory of the Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  distribution for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const char *programname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const char *logoname = "linux_logo";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const char *outputname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static FILE *out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define LINUX_LOGO_MONO		1	/* monochrome black/white */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define LINUX_LOGO_VGA16	2	/* 16 colors VGA text palette */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define LINUX_LOGO_CLUT224	3	/* 224 colors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define LINUX_LOGO_GRAY256	4	/* 256 levels grayscale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static const char *logo_types[LINUX_LOGO_GRAY256+1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)     [LINUX_LOGO_MONO] = "LINUX_LOGO_MONO",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)     [LINUX_LOGO_VGA16] = "LINUX_LOGO_VGA16",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)     [LINUX_LOGO_CLUT224] = "LINUX_LOGO_CLUT224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)     [LINUX_LOGO_GRAY256] = "LINUX_LOGO_GRAY256"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define MAX_LINUX_LOGO_COLORS	224
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) struct color {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)     unsigned char red;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)     unsigned char green;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)     unsigned char blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static const struct color clut_vga16[16] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)     { 0x00, 0x00, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)     { 0x00, 0x00, 0xaa },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)     { 0x00, 0xaa, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)     { 0x00, 0xaa, 0xaa },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)     { 0xaa, 0x00, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)     { 0xaa, 0x00, 0xaa },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)     { 0xaa, 0x55, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)     { 0xaa, 0xaa, 0xaa },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)     { 0x55, 0x55, 0x55 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)     { 0x55, 0x55, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)     { 0x55, 0xff, 0x55 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)     { 0x55, 0xff, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)     { 0xff, 0x55, 0x55 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)     { 0xff, 0x55, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)     { 0xff, 0xff, 0x55 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)     { 0xff, 0xff, 0xff },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int logo_type = LINUX_LOGO_CLUT224;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static unsigned int logo_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static unsigned int logo_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static struct color **logo_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static struct color logo_clut[MAX_LINUX_LOGO_COLORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static unsigned int logo_clutsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static int is_plain_pbm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void die(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)     __attribute__ ((noreturn)) __attribute ((format (printf, 1, 2)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static void usage(void) __attribute ((noreturn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static unsigned int get_number(FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)     int c, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)     /* Skip leading whitespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)     do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	c = fgetc(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (c == EOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	    die("%s: end of file\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (c == '#') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	    /* Ignore comments 'till end of line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	    do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		c = fgetc(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (c == EOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		    die("%s: end of file\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	    } while (c != '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)     } while (isspace(c));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)     /* Parse decimal number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)     val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)     while (isdigit(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	val = 10*val+c-'0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* some PBM are 'broken'; GiMP for example exports a PBM without space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * between the digits. This is Ok cause we know a PBM can only have a '1'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * or a '0' for the digit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (is_plain_pbm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	c = fgetc(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (c == EOF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	    die("%s: end of file\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)     return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static unsigned int get_number255(FILE *fp, unsigned int maxval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)     unsigned int val = get_number(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)     return (255*val+maxval/2)/maxval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static void read_image(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)     FILE *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)     unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)     int magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)     unsigned int maxval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)     /* open image file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)     fp = fopen(filename, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)     if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	die("Cannot open file %s: %s\n", filename, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)     /* check file type and read file header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)     magic = fgetc(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)     if (magic != 'P')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	die("%s is not a PNM file\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)     magic = fgetc(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)     switch (magic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case '1':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	case '2':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case '3':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    /* Plain PBM/PGM/PPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	case '4':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case '5':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case '6':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	    /* Binary PBM/PGM/PPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	    die("%s: Binary PNM is not supported\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		"Use pnmnoraw(1) to convert it to ASCII PNM\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	    die("%s is not a PNM file\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)     logo_width = get_number(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)     logo_height = get_number(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)     /* allocate image data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)     logo_data = (struct color **)malloc(logo_height*sizeof(struct color *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)     if (!logo_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	die("%s\n", strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)     for (i = 0; i < logo_height; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	logo_data[i] = malloc(logo_width*sizeof(struct color));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!logo_data[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	    die("%s\n", strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)     /* read image data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)     switch (magic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	case '1':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	    /* Plain PBM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	    is_plain_pbm = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	    for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		for (j = 0; j < logo_width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		    logo_data[i][j].red = logo_data[i][j].green =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			logo_data[i][j].blue = 255*(1-get_number(fp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	case '2':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	    /* Plain PGM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	    maxval = get_number(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	    for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		for (j = 0; j < logo_width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		    logo_data[i][j].red = logo_data[i][j].green =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			logo_data[i][j].blue = get_number255(fp, maxval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	case '3':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	    /* Plain PPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	    maxval = get_number(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	    for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		for (j = 0; j < logo_width; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		    logo_data[i][j].red = get_number255(fp, maxval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		    logo_data[i][j].green = get_number255(fp, maxval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		    logo_data[i][j].blue = get_number255(fp, maxval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)     /* close file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)     fclose(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline int is_black(struct color c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)     return c.red == 0 && c.green == 0 && c.blue == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline int is_white(struct color c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)     return c.red == 255 && c.green == 255 && c.blue == 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static inline int is_gray(struct color c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)     return c.red == c.green && c.red == c.blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static inline int is_equal(struct color c1, struct color c2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)     return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void write_header(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)     /* open logo file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)     if (outputname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	out = fopen(outputname, "w");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	    die("Cannot create file %s: %s\n", outputname, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	out = stdout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)     fputs("/*\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)     fputs(" *  DO NOT EDIT THIS FILE!\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)     fputs(" *\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)     fprintf(out, " *  It was automatically generated from %s\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)     fputs(" *\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)     fprintf(out, " *  Linux logo %s\n", logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)     fputs(" */\n\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)     fputs("#include <linux/linux_logo.h>\n\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)     fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	    logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void write_footer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)     fputs("\n};\n\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)     fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)     fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)     fprintf(out, "\t.width\t\t= %d,\n", logo_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)     fprintf(out, "\t.height\t\t= %d,\n", logo_height);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)     if (logo_type == LINUX_LOGO_CLUT224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	fprintf(out, "\t.clutsize\t= %d,\n", logo_clutsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	fprintf(out, "\t.clut\t\t= %s_clut,\n", logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)     fprintf(out, "\t.data\t\t= %s_data\n", logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)     fputs("};\n\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)     /* close logo file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)     if (outputname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	fclose(out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int write_hex_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static void write_hex(unsigned char byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)     if (write_hex_cnt % 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	fprintf(out, ", 0x%02x", byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)     else if (write_hex_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	fprintf(out, ",\n\t0x%02x", byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	fprintf(out, "\t0x%02x", byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)     write_hex_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static void write_logo_mono(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)     unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)     unsigned char val, bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)     /* validate image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	for (j = 0; j < logo_width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	    if (!is_black(logo_data[i][j]) && !is_white(logo_data[i][j]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		die("Image must be monochrome\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)     /* write file header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)     write_header();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)     /* write logo data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)     for (i = 0; i < logo_height; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	for (j = 0; j < logo_width;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	    for (val = 0, bit = 0x80; bit && j < logo_width; j++, bit >>= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		if (logo_data[i][j].red)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		    val |= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	    write_hex(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)     /* write logo structure and file footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)     write_footer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void write_logo_vga16(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)     unsigned int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)     unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)     /* validate image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	for (j = 0; j < logo_width; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	    for (k = 0; k < 16; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		if (is_equal(logo_data[i][j], clut_vga16[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	    if (k == 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		die("Image must use the 16 console colors only\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		    "Use ppmquant(1) -map clut_vga16.ppm to reduce the number "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		    "of colors\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)     /* write file header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)     write_header();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)     /* write logo data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	for (j = 0; j < logo_width; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	    for (k = 0; k < 16; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (is_equal(logo_data[i][j], clut_vga16[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	    val = k<<4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	    if (++j < logo_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		for (k = 0; k < 16; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		    if (is_equal(logo_data[i][j], clut_vga16[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		val |= k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	    write_hex(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)     /* write logo structure and file footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)     write_footer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static void write_logo_clut224(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)     unsigned int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)     /* validate image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	for (j = 0; j < logo_width; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	    for (k = 0; k < logo_clutsize; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		if (is_equal(logo_data[i][j], logo_clut[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	    if (k == logo_clutsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if (logo_clutsize == MAX_LINUX_LOGO_COLORS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		    die("Image has more than %d colors\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			"Use ppmquant(1) to reduce the number of colors\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			MAX_LINUX_LOGO_COLORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		logo_clut[logo_clutsize++] = logo_data[i][j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)     /* write file header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)     write_header();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)     /* write logo data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	for (j = 0; j < logo_width; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	    for (k = 0; k < logo_clutsize; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		if (is_equal(logo_data[i][j], logo_clut[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	    write_hex(k+32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)     fputs("\n};\n\n", out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)     /* write logo clut */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)     fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	    logoname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)     write_hex_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)     for (i = 0; i < logo_clutsize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	write_hex(logo_clut[i].red);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	write_hex(logo_clut[i].green);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	write_hex(logo_clut[i].blue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)     /* write logo structure and file footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)     write_footer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static void write_logo_gray256(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)     unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)     /* validate image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	for (j = 0; j < logo_width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	    if (!is_gray(logo_data[i][j]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		die("Image must be grayscale\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)     /* write file header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)     write_header();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)     /* write logo data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)     for (i = 0; i < logo_height; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	for (j = 0; j < logo_width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	    write_hex(logo_data[i][j].red);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)     /* write logo structure and file footer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)     write_footer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void die(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)     va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)     va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)     vfprintf(stderr, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)     va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)     exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static void usage(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)     die("\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	"Usage: %s [options] <filename>\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	"\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	"Valid options:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	"    -h          : display this usage information\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	"    -n <name>   : specify logo name (default: linux_logo)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	"    -o <output> : output to file <output> instead of stdout\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	"    -t <type>   : specify logo type, one of\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	"                      mono    : monochrome black/white\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	"                      vga16   : 16 colors VGA text palette\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	"                      clut224 : 224 colors (default)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	"                      gray256 : 256 levels grayscale\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	"\n", programname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int main(int argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)     int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)     programname = argv[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)     opterr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)     while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	opt = getopt(argc, argv, "hn:o:t:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (opt == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	    case 'h':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	    case 'n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		logoname = optarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	    case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		outputname = optarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	    case 't':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		if (!strcmp(optarg, "mono"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		    logo_type = LINUX_LOGO_MONO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		else if (!strcmp(optarg, "vga16"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		    logo_type = LINUX_LOGO_VGA16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		else if (!strcmp(optarg, "clut224"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		    logo_type = LINUX_LOGO_CLUT224;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		else if (!strcmp(optarg, "gray256"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		    logo_type = LINUX_LOGO_GRAY256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		    usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	    default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)     if (optind != argc-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)     filename = argv[optind];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)     read_image();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)     switch (logo_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	case LINUX_LOGO_MONO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	    write_logo_mono();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	case LINUX_LOGO_VGA16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	    write_logo_vga16();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	case LINUX_LOGO_CLUT224:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	    write_logo_clut224();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	case LINUX_LOGO_GRAY256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	    write_logo_gray256();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)     exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }