Write bitmap pixel data without Bitmap Converter

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Write bitmap pixel data without Bitmap Converter

      Hello,

      to display bitmaps on a screen I've successfully used the functions GUI_DrawBitmap() with pre-converted *.bmp files into c structures with the ST Bitmap Converter for STM32 GUI applications.

      So the converted bmp files into c structures look like:

      Source Code

      1. extern GUI_CONST_STORAGE GUI_BITMAP bmCustomer_Logo;
      2. static GUI_CONST_STORAGE unsigned char _acCustomer_Logo[] = {
      3. 0xFF,0xFF,0xFF,...
      4. }
      5. GUI_CONST_STORAGE GUI_BITMAP bmCustomer_Logo =
      6. {
      7. 360, // xSize
      8. 120, // ySize
      9. 1080, // BytesPerLine
      10. 24, // BitsPerPixel
      11. (unsigned char *)_acCustomer_Logo, // Pointer to picture data
      12. NULL, // Pointer to palette
      13. GUI_DRAW_BMPA565
      14. };
      Display All

      Now I want to change the pixel data of this structure (_acCustomer_Logo[]) without changing the bitmap dimensions, bits per pixels, etc. reading another file (with the same dimensions and no compression) from a USB/SD card while the application is running (the bitmap will be stored in a different memory area than the application).

      Is there any way / example code to convert directly a bitmap file into the emWin c structures without using the Bitmap converter?
      I've tried to read the individual pixels and manually overwrite the structure but I get corrupted data (dirty pixels), maybe I'm missing something regarding the conversion the bitmap converter is doing.

      Thank you for your support.
      Mark
    • Hi,

      Unfortunately, it is not possible to convert an image on runtime into a c-style image for emWin.

      The format you have chosen is 16bpp with alpha. This means that the pixel data in _acCustomer_Logo are stored as follows:


      AAAA AAAA, BBBB BGGG, GGGR RRRR - 8bit alpha, 5bit blue, 6bit green and 5bit red

      This is not the easiest format if you like to convert your image from sd card into this format.

      Easier it would be by using a more intuitive format like ARGB 32 bit. Of course, this will require some more memory.

      Not sure what your goal is but if you like to change the images on runtime you could convert them into a *.dta file and load them from SD card or USB. The dta format is almost the same a c-bitmap but it gets directly stored in a binary format.

      Attached is a short example on how to use *.dta files. It uses Windows FS API but it should be quite easy to write this for any other FS.

      Regards,
      Sven
      Files