This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Bitmap image conversion

Ciao,
would it be possible to have more information about the bitmap converter used to generate C files in MCBSTM32C LCD_blinky example?
Thank you, ciao
Bruno

  • Hi Bruno,

    GIMP can export C-Source files of an image which contains the raw image data. This is what you
    are interested in. Therefore open your image in GIMP and export the image as C-Source file.
    Enter a prefixed name, check "Use macros instead of stuct", and "Save as RGB565 (16-bit)" and hit "Export". Now a C File is created which look like

    /* GIMP RGB C-Source image dump */
    
    #define GIMP_IMAGE_WIDTH (140)
    #define GIMP_IMAGE_HEIGHT (185)
    #define GIMP_IMAGE_BYTES_PER_PIXEL (3) /* 3:RGB, 4:RGBA */
    #define GIMP_IMAGE_PIXEL_DATA ((unsigned char*) GIMP_IMAGE_pixel_data)
    static const unsigned char GIMP_IMAGE_pixel_data[140 * 185 * 3 + 1] = (...)
    

    Since the data are "static" you can't refer it as "extern" but you can #include the .c file
    where you require it in your code directly or modify the file manually.

    The C-Source file which you have exported with GIMP only contains the raw RGB data (no BMP
    header you need to offset!) but the order is a little bit different to BMP files. The BMP
    specification says:


    Normally pixels are stored "upside-down" with respect to normal image raster scan order,
    starting in the lower left corner, going from left to right, and then row by row from the bottom to the top of the image.

    The C-Source file is upper-left to lower-right. Here the correct GLCD_Bitmap() function which
    works correctly with the GIMP C-Source files:

    void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char
    *bitmap) {
      int i, j;
      unsigned short *bitmap_ptr = (unsigned short *)bitmap;
    
      GLCD_SetWindow (x, y, w, h);
    
      wr_cmd(0x22);
      wr_dat_start();
      for (i = 0; i < (h-1)*w; i += w) {
        for (j = 0; j < w; j++) {
          wr_dat_only (bitmap_ptr[i+j]);
        }
      }
      wr_dat_stop();
    }
    

    Sow you can use the image in your code like

    #include "your_image.c"
    ...
    GLCD_Bitmap(10, 30, 140, 185, (unsigned char *)&your_prefix_pixel_data);
    ...
    

    (for sure, you can use the macros in your_image.c to define width and height as well as the
    image name!)

    The image will be shown at pos 10,30 with 140x185, your_prefix_pixel_data is the name of the
    array stored in your_image.c which is the exported GIMP C-Source file.

    That should be all!

    To be honest, I don't know why Keil include the complete BMP file (incl. file header) since this is not required and only increase the required space for the image. The raw image data are enough.

    Hope this will help you too!

    Best regards,
    Alexander Zaech