Commit 0bbe2005ea208b12a4d96f28bf20c27abec97727

Authored by wdenk
1 parent f6d29959a8
Exists in master and in 55 other branches 8qm-imx_v2020.04_5.4.70_2.3.0, emb_lf_v2022.04, emb_lf_v2023.04, imx_v2015.04_4.1.15_1.0.0_ga, pitx_8mp_lf_v2020.04, smarc-8m-android-10.0.0_2.6.0, smarc-8m-android-11.0.0_2.0.0, smarc-8mp-android-11.0.0_2.0.0, smarc-emmc-imx_v2014.04_3.10.53_1.1.0_ga, smarc-emmc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx-l5.0.0_1.0.0-ga, smarc-imx6_v2018.03_4.14.98_2.0.0_ga, smarc-imx7_v2017.03_4.9.11_1.0.0_ga, smarc-imx7_v2018.03_4.14.98_2.0.0_ga, smarc-imx_v2014.04_3.14.28_1.0.0_ga, smarc-imx_v2015.04_4.1.15_1.0.0_ga, smarc-imx_v2017.03_4.9.11_1.0.0_ga, smarc-imx_v2017.03_4.9.88_2.0.0_ga, smarc-imx_v2017.03_o8.1.0_1.3.0_8m, smarc-imx_v2018.03_4.14.78_1.0.0_ga, smarc-m6.0.1_2.1.0-ga, smarc-n7.1.2_2.0.0-ga, smarc-rel_imx_4.1.15_2.0.0_ga, smarc_8m-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8m-imx_v2019.04_4.19.35_1.1.0, smarc_8m_00d0-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga, smarc_8mm-imx_v2019.04_4.19.35_1.1.0, smarc_8mm-imx_v2020.04_5.4.24_2.1.0, smarc_8mp_lf_v2020.04, smarc_8mq-imx_v2020.04_5.4.24_2.1.0, smarc_8mq_lf_v2020.04, ti-u-boot-2015.07, u-boot-2013.01.y, v2013.10, v2013.10-smarct33, v2013.10-smartmen, v2014.01, v2014.04, v2014.04-smarct33, v2014.04-smarct33-emmc, v2014.04-smartmen, v2014.07, v2014.07-smarct33, v2014.07-smartmen, v2015.07-smarct33, v2015.07-smarct33-emmc, v2015.07-smarct4x, v2016.05-dlt, v2016.05-smarct3x, v2016.05-smarct3x-emmc, v2016.05-smarct4x, v2017.01-smarct3x, v2017.01-smarct3x-emmc, v2017.01-smarct4x

Initial revision

Showing 1 changed file with 177 additions and 0 deletions Side-by-side Diff

  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +
  4 +#if defined(__linux__)
  5 +#include <stdint.h>
  6 +#else
  7 +#ifdef __CYGWIN__
  8 +#include "elf.h"
  9 +#else
  10 +#include <inttypes.h>
  11 +#endif
  12 +#endif
  13 +
  14 +#ifdef __CYGWIN__
  15 +typedef unsigned short ushort;
  16 +#endif /* __CYGWIN__ */
  17 +
  18 +
  19 +typedef struct bitmap_s { /* bitmap description */
  20 + uint16_t width;
  21 + uint16_t height;
  22 + uint8_t palette[256*3];
  23 + uint8_t *data;
  24 +} bitmap_t;
  25 +
  26 +#define DEFAULT_CMAP_SIZE 16 /* size of default color map */
  27 +
  28 +/*
  29 + * Neutralize little endians.
  30 + */
  31 +uint16_t le_short(uint16_t x)
  32 +{
  33 + uint16_t val;
  34 + uint8_t *p = (uint8_t *)(&x);
  35 +
  36 + val = (*p++ & 0xff) << 0;
  37 + val |= (*p & 0xff) << 8;
  38 +
  39 + return val;
  40 +}
  41 +
  42 +void skip_bytes (FILE *fp, int n)
  43 +{
  44 + while (n-- > 0)
  45 + fgetc (fp);
  46 +}
  47 +
  48 +int main (int argc, char *argv[])
  49 +{
  50 + int i, x;
  51 + FILE *fp;
  52 + bitmap_t bmp;
  53 + bitmap_t *b = &bmp;
  54 + uint16_t n_colors;
  55 +
  56 + if (argc < 2) {
  57 + fprintf (stderr, "Usage: %s file\n", argv[0]);
  58 + exit (EXIT_FAILURE);
  59 + }
  60 +
  61 + if ((fp = fopen (argv[1], "rb")) == NULL) {
  62 + perror (argv[1]);
  63 + exit (EXIT_FAILURE);
  64 + }
  65 +
  66 + if (fgetc (fp) != 'B' || fgetc (fp) != 'M') {
  67 + fprintf (stderr, "%s is not a bitmap file.\n", argv[1]);
  68 + exit (EXIT_FAILURE);
  69 + }
  70 +
  71 + /*
  72 + * read width and height of the image, and the number of colors used;
  73 + * ignore the rest
  74 + */
  75 + skip_bytes (fp, 16);
  76 + fread (&b->width, sizeof (uint16_t), 1, fp);
  77 + skip_bytes (fp, 2);
  78 + fread (&b->height, sizeof (uint16_t), 1, fp);
  79 + skip_bytes (fp, 22);
  80 + fread (&n_colors, sizeof (uint16_t), 1, fp);
  81 + skip_bytes (fp, 6);
  82 +
  83 + /*
  84 + * Repair endianess.
  85 + */
  86 + b->width = le_short(b->width);
  87 + b->height = le_short(b->height);
  88 + n_colors = le_short(n_colors);
  89 +
  90 + /* assume we are working with an 8-bit file */
  91 + if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
  92 + /* reserve DEFAULT_CMAP_SIZE color map entries for default map */
  93 + n_colors = 256 - DEFAULT_CMAP_SIZE;
  94 + }
  95 +
  96 + printf ("/*\n"
  97 + " * Automatically generated by \"tools/bmp_logo\"\n"
  98 + " *\n"
  99 + " * DO NOT EDIT\n"
  100 + " *\n"
  101 + " */\n\n\n"
  102 + "#ifndef __BMP_LOGO_H__\n"
  103 + "#define __BMP_LOGO_H__\n\n"
  104 + "#define BMP_LOGO_WIDTH\t\t%d\n"
  105 + "#define BMP_LOGO_HEIGHT\t\t%d\n"
  106 + "#define BMP_LOGO_COLORS\t\t%d\n"
  107 + "#define BMP_LOGO_OFFSET\t\t%d\n"
  108 + "\n",
  109 + b->width, b->height, n_colors,
  110 + DEFAULT_CMAP_SIZE);
  111 +
  112 + /* allocate memory */
  113 + if ((b->data = (uint8_t *)malloc(b->width * b->height)) == NULL) {
  114 + fclose (fp);
  115 + printf ("Error allocating memory for file %s.\n", argv[1]);
  116 + exit (EXIT_FAILURE);
  117 + }
  118 +
  119 + /* read and print the palette information */
  120 + printf ("unsigned short bmp_logo_palette[] = {\n");
  121 +
  122 + for (i=0; i<n_colors; ++i) {
  123 + b->palette[(int)(i*3+2)] = fgetc(fp);
  124 + b->palette[(int)(i*3+1)] = fgetc(fp);
  125 + b->palette[(int)(i*3+0)] = fgetc(fp);
  126 + x=fgetc(fp);
  127 +
  128 +#if 0
  129 + if ((i%4) == 0)
  130 + putchar ('\t');
  131 + printf ("0x%02X, 0x%02X, 0x%02X,%s",
  132 + b->palette[(int)(i*3+0)],
  133 + b->palette[(int)(i*3+1)],
  134 + b->palette[(int)(i*3+2)],
  135 + ((i%4) == 3) ? "\n" : " "
  136 + );
  137 +#else
  138 + if ((i%8) == 0)
  139 + putchar ('\t');
  140 + printf ("0x0%X%X%X,%s",
  141 + (b->palette[(int)(i*3+0)] >> 4) & 0x0F,
  142 + (b->palette[(int)(i*3+1)] >> 4) & 0x0F,
  143 + (b->palette[(int)(i*3+2)] >> 4) & 0x0F,
  144 + ((i%8) == 7) ? "\n" : " "
  145 + );
  146 +#endif
  147 + }
  148 +
  149 + /* read the bitmap; leave room for default color map */
  150 + printf ("\n");
  151 + printf ("};\n");
  152 + printf ("\n");
  153 + printf ("unsigned char bmp_logo_bitmap[] = {\n");
  154 + for (i=(b->height-1)*b->width; i>=0; i-=b->width) {
  155 + for (x = 0; x < b->width; x++) {
  156 + b->data[(uint16_t) i + x] = (uint8_t) fgetc (fp) \
  157 + + DEFAULT_CMAP_SIZE;
  158 + }
  159 + }
  160 + fclose (fp);
  161 +
  162 + for (i=0; i<(b->height*b->width); ++i) {
  163 + if ((i%8) == 0)
  164 + putchar ('\t');
  165 + printf ("0x%02X,%c",
  166 + b->data[i],
  167 + ((i%8) == 7) ? '\n' : ' '
  168 + );
  169 + }
  170 + printf ("\n"
  171 + "};\n\n"
  172 + "#endif /* __BMP_LOGO_H__ */\n"
  173 + );
  174 +
  175 + return (0);
  176 +}