ethernet: gmac with rgmii interface works
[firefly-linux-kernel-4.4.55.git] / scripts / pnmtologo.c
index 92af1e58584fc414521a74476d7890413f9cd834..68bb4efc5af429a2f5d1ec359a06d3f2e7af8bb4 100644 (file)
@@ -27,6 +27,7 @@ static const char *logoname = "linux_logo";
 static const char *outputname;
 static FILE *out;
 
+
 #define LINUX_LOGO_MONO                1       /* monochrome black/white */
 #define LINUX_LOGO_VGA16       2       /* 16 colors VGA text palette */
 #define LINUX_LOGO_CLUT224     3       /* 224 colors */
@@ -66,24 +67,6 @@ static const struct color clut_vga16[16] = {
     { 0xff, 0xff, 0xff },
 };
 
-unsigned char data_name[] = {
-       0x6C, 0x6F, 0x67,
-       0x6F, 0x5F, 0x52,
-       0x4B, 0x6C, 0x6F,
-       0x67, 0x6F, 0x5F,
-       0x64, 0x61, 0x74,
-       0x61
-};
-
-unsigned char clut_name[] = {
-       0x70, 0x70, 0x6c,
-       0x6C, 0x6F, 0x67,
-       0x6F, 0x5F, 0x52,
-       0x4B, 0x6C, 0x6F,
-       0x67, 0x6F, 0x5F,
-       0x63, 0x6C, 0x75,
-       0x74
-};
 
 static int logo_type = LINUX_LOGO_CLUT224;
 static unsigned int logo_width;
@@ -91,11 +74,13 @@ static unsigned int logo_height;
 static struct color **logo_data;
 static struct color logo_clut[MAX_LINUX_LOGO_COLORS];
 static unsigned int logo_clutsize;
+static int is_plain_pbm = 0;
 
 static void die(const char *fmt, ...)
     __attribute__ ((noreturn)) __attribute ((format (printf, 1, 2)));
 static void usage(void) __attribute ((noreturn));
 
+
 static unsigned int get_number(FILE *fp)
 {
     int c, val;
@@ -119,6 +104,11 @@ static unsigned int get_number(FILE *fp)
     val = 0;
     while (isdigit(c)) {
        val = 10*val+c-'0';
+       /* some PBM are 'broken'; GiMP for example exports a PBM without space
+        * between the digits. This is Ok cause we know a PBM can only have a '1'
+        * or a '0' for the digit. */
+       if (is_plain_pbm)
+               break;
        c = fgetc(fp);
        if (c == EOF)
            die("%s: end of file\n", filename);
@@ -134,15 +124,15 @@ static unsigned int get_number255(FILE *fp, unsigned int maxval)
 
 static void read_image(void)
 {
-       FILE *fp;
-       unsigned int i, j;
-       int magic;
-       unsigned int maxval;
+    FILE *fp;
+    unsigned int i, j;
+    int magic;
+    unsigned int maxval;
 
-       /* open image file */
-       fp = fopen(filename, "r");
-       if (!fp)
-               die("Cannot open file %s: %s\n", filename, strerror(errno));
+    /* open image file */
+    fp = fopen(filename, "r");
+    if (!fp)
+       die("Cannot open file %s: %s\n", filename, strerror(errno));
 
     /* check file type and read file header */
     magic = fgetc(fp);
@@ -166,24 +156,24 @@ static void read_image(void)
        default:
            die("%s is not a PNM file\n", filename);
     }
-       logo_width = get_number(fp);
-       logo_height = get_number(fp);
-
-
-       /* allocate image data */
-       logo_data = (struct color **)malloc(logo_height * sizeof(struct color *));
-       if (!logo_data)
-               die("%s\n", strerror(errno));
-       for (i = 0; i < logo_height; i++) {
-               logo_data[i] = (struct color *)malloc(logo_width * sizeof(struct color));
-               if (!logo_data[i])
-               die("%s\n", strerror(errno));
-       }
+    logo_width = get_number(fp);
+    logo_height = get_number(fp);
+
+    /* allocate image data */
+    logo_data = (struct color **)malloc(logo_height*sizeof(struct color *));
+    if (!logo_data)
+       die("%s\n", strerror(errno));
+    for (i = 0; i < logo_height; i++) {
+       logo_data[i] = malloc(logo_width*sizeof(struct color));
+       if (!logo_data[i])
+           die("%s\n", strerror(errno));
+    }
 
     /* read image data */
     switch (magic) {
        case '1':
            /* Plain PBM */
+           is_plain_pbm = 1;
            for (i = 0; i < logo_height; i++)
                for (j = 0; j < logo_width; j++)
                    logo_data[i][j].red = logo_data[i][j].green =
@@ -235,6 +225,48 @@ static inline int is_equal(struct color c1, struct color c2)
     return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
 }
 
+static void write_header(void)
+{
+    /* open logo file */
+    if (outputname) {
+       out = fopen(outputname, "w");
+       if (!out)
+           die("Cannot create file %s: %s\n", outputname, strerror(errno));
+    } else {
+       out = stdout;
+    }
+
+    fputs("/*\n", out);
+    fputs(" *  DO NOT EDIT THIS FILE!\n", out);
+    fputs(" *\n", out);
+    fprintf(out, " *  It was automatically generated from %s\n", filename);
+    fputs(" *\n", out);
+    fprintf(out, " *  Linux logo %s\n", logoname);
+    fputs(" */\n\n", out);
+    fputs("#include <linux/linux_logo.h>\n\n", out);
+    fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
+           logoname);
+}
+
+static void write_footer(void)
+{
+    fputs("\n};\n\n", out);
+    fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
+    fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
+    fprintf(out, "\t.width\t\t= %d,\n", logo_width);
+    fprintf(out, "\t.height\t\t= %d,\n", logo_height);
+    if (logo_type == LINUX_LOGO_CLUT224) {
+       fprintf(out, "\t.clutsize\t= %d,\n", logo_clutsize);
+       fprintf(out, "\t.clut\t\t= %s_clut,\n", logoname);
+    }
+    fprintf(out, "\t.data\t\t= %s_data\n", logoname);
+    fputs("};\n\n", out);
+
+    /* close logo file */
+    if (outputname)
+       fclose(out);
+}
+
 static int write_hex_cnt;
 
 static void write_hex(unsigned char byte)
@@ -248,55 +280,6 @@ static void write_hex(unsigned char byte)
     write_hex_cnt++;
 }
 
-static void write_header(void)
-{
-       /* open logo file */
-       if (outputname) {
-               out = fopen(outputname, "w");
-               if (!out)
-                       die("Cannot create file %s: %s\n", outputname, strerror(errno));
-       } else {
-               out = stdout;
-       }
-
-       fputs("/*\n", out);
-       fputs(" *  DO NOT EDIT THIS FILE!\n", out);
-       fputs(" *\n", out);
-       fprintf(out, " *  It was automatically generated from %s\n", filename);
-       fputs(" *\n", out);
-       fprintf(out, " *  Linux logo %s\n", logoname);
-       fputs(" */\n\n", out);
-       fputs("#include <linux/linux_logo.h>\n\n", out);
-       fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
-               logoname);
-}
-
-static void write_footer(void)
-{
-       fputs("\n};\n\n", out);
-       fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
-       fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
-
-       if (logo_type == LINUX_LOGO_CLUT224) {
-               fprintf(out, "\t.clut\t\t= &(%s_clut[%ld]),\n", logoname, sizeof(clut_name));
-               fprintf(out, "\t.data\t\t= &(%s_data[%ld])\n", logoname, sizeof(data_name) + 4);
-       } else {
-               fprintf(out, "\t.width\t\t= %d,\n", logo_width);
-               fprintf(out, "\t.height\t\t= %d,\n", logo_height);
-               if (logo_type == LINUX_LOGO_CLUT224) {
-                       fprintf(out, "\t.clutsize\t= %d,\n", logo_clutsize);
-                       fprintf(out, "\t.clut\t\t= %s_clut,\n", logoname);
-               }
-               fprintf(out, "\t.data\t\t= %s_data\n", logoname);
-       }
-
-       fputs("};\n\n", out);
-
-       /* close logo file */
-       if (outputname)
-               fclose(out);
-}
-
 static void write_logo_mono(void)
 {
     unsigned int i, j;
@@ -321,7 +304,6 @@ static void write_logo_mono(void)
        }
     }
 
-
     /* write logo structure and file footer */
     write_footer();
 }
@@ -368,78 +350,48 @@ static void write_logo_vga16(void)
 
 static void write_logo_clut224(void)
 {
-       unsigned int i, j, k;
-
-       logo_clutsize = 0;
-
-       /* validate image */
-       for (i = 0; i < logo_height; i++)
-               for (j = 0; j < logo_width; j++) {
-                       for (k = 0; k < logo_clutsize; k++)
-                               if (is_equal(logo_data[i][j], logo_clut[k]))
-                                       break;
-                       if (k == logo_clutsize) {
-                               if (logo_clutsize == MAX_LINUX_LOGO_COLORS)
-                                       die("Image has more than %d colors\n"
-                                               "Use ppmquant(1) to reduce the number of colors\n",
-                                               MAX_LINUX_LOGO_COLORS);
-                                       logo_clut[logo_clutsize++] = logo_data[i][j];
-                       }
-               }
-
-       write_hex_cnt = 0;
-
-       /* write file header */
-       write_header();
-
-       write_hex((unsigned char)(logo_width >> 8));
-       write_hex((unsigned char)logo_width);
-       write_hex((unsigned char)(logo_height >> 8));
-       write_hex((unsigned char)logo_height);
-
-       for (i = 0; i < sizeof(data_name); i++){
-               write_hex(data_name[i]);
-       }
-       write_hex((unsigned char)(logo_width >> 8));
-       write_hex((unsigned char)logo_width);
-       write_hex((unsigned char)(logo_height >> 8));
-       write_hex((unsigned char)logo_height);
-
-       /* write logo data */
-       for (i = 0; i < logo_height; i++)
-               for (j = 0; j < logo_width; j++) {
-                       for (k = 0; k < logo_clutsize; k++)
-                               if (is_equal(logo_data[i][j], logo_clut[k]))
-                                       break;
-                       write_hex(k+32);
-               }
-
-       fputs("\n};\n\n", out);
-
-       /* write logo clut */
-       fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
-               logoname);
-
-       write_hex_cnt = 0;
+    unsigned int i, j, k;
 
-       for (i = 0; i < sizeof(clut_name); i++){
-               write_hex(clut_name[i]);
+    /* validate image */
+    for (i = 0; i < logo_height; i++)
+       for (j = 0; j < logo_width; j++) {
+           for (k = 0; k < logo_clutsize; k++)
+               if (is_equal(logo_data[i][j], logo_clut[k]))
+                   break;
+           if (k == logo_clutsize) {
+               if (logo_clutsize == MAX_LINUX_LOGO_COLORS)
+                   die("Image has more than %d colors\n"
+                       "Use ppmquant(1) to reduce the number of colors\n",
+                       MAX_LINUX_LOGO_COLORS);
+               logo_clut[logo_clutsize++] = logo_data[i][j];
+           }
        }
-       write_hex(logo_clutsize);
 
-       for (i = 0; i < logo_clutsize; i++) {
-               write_hex(logo_clut[i].red);
-               write_hex(logo_clut[i].green);
-               write_hex(logo_clut[i].blue);
-       }
+    /* write file header */
+    write_header();
 
-       for (i = logo_clutsize; i < (MAX_LINUX_LOGO_COLORS * 3); i++)
-       {
-               write_hex(32);
+    /* write logo data */
+    for (i = 0; i < logo_height; i++)
+       for (j = 0; j < logo_width; j++) {
+           for (k = 0; k < logo_clutsize; k++)
+               if (is_equal(logo_data[i][j], logo_clut[k]))
+                   break;
+           write_hex(k+32);
        }
+    fputs("\n};\n\n", out);
+
+    /* write logo clut */
+    fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
+           logoname);
+    write_hex_cnt = 0;
+    for (i = 0; i < logo_clutsize; i++) {
+       write_hex(logo_clut[i].red);
+       write_hex(logo_clut[i].green);
+       write_hex(logo_clut[i].blue);
+    }
 
-       /* write logo structure and file footer */
-       write_footer();
+    /* write logo structure and file footer */
+    write_footer();
 }
 
 static void write_logo_gray256(void)