hdmi: cat66121: set i2s freq 44.1k to fix sound too small on some tv
[firefly-linux-kernel-4.4.55.git] / scripts / pnmtologo.c
old mode 100644 (file)
new mode 100755 (executable)
index 5c11312..92af1e5
@@ -27,7 +27,6 @@ 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 */
@@ -67,6 +66,24 @@ 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;
@@ -79,7 +96,6 @@ 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;
@@ -118,15 +134,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);
@@ -150,18 +166,19 @@ 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] = 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] = (struct color *)malloc(logo_width * sizeof(struct color));
+               if (!logo_data[i])
+               die("%s\n", strerror(errno));
+       }
 
     /* read image data */
     switch (magic) {
@@ -218,48 +235,6 @@ 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)
@@ -273,6 +248,55 @@ 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;
@@ -297,6 +321,7 @@ static void write_logo_mono(void)
        }
     }
 
+
     /* write logo structure and file footer */
     write_footer();
 }
@@ -343,48 +368,78 @@ static void write_logo_vga16(void)
 
 static void write_logo_clut224(void)
 {
-    unsigned int i, j, k;
+       unsigned int i, j, k;
 
-    /* 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];
-           }
+       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 file header */
-    write_header();
+       /* 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);
+               }
 
-    /* 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 < sizeof(clut_name); i++){
+               write_hex(clut_name[i]);
        }
-    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_hex(logo_clutsize);
 
-    /* write logo structure and file footer */
-    write_footer();
+       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);
+       }
+
+       for (i = logo_clutsize; i < (MAX_LINUX_LOGO_COLORS * 3); i++)
+       {
+               write_hex(32);
+       }
+
+       /* write logo structure and file footer */
+       write_footer();
 }
 
 static void write_logo_gray256(void)