2017-04-19 12:29 AM
Hi all
Recently, I created a Win32 application to convert a bitmap (.bmp) file into a header file (.h) in order to display it in mySTM32F746G-DISCO discovery board. Everything works fine but the bitmap (24 bit depth) displays differently (see attached photo) compared to the original bitmap.
Does everyone experience the same? The displayed bitmap seems to be skewed and de-colored. I have done again with a 16-bit-depth bitmap but no further advance.
(I reused the BSP example in STM32CubeF7Packets for the test)
Note: this post was migrated and contained many threaded conversations, some content may be missing.Solved! Go to Solution.
2017-04-20 06:38 AM
Thanks, I am not at my lab now. I will try it tomorrow
2017-04-20 07:54 PM
Today I changed from
LTDC_PIXEL_FORMAT_ARGB8888 to
LTDC_PIXEL_FORMAT_RGB888 but it seems worse as shown:
Here is the bitmap display function:
/**
* @brief Draws a bitmap picture loaded in the internal Flash in ARGB888 format (32 bits per pixel). * @param Xpos: Bmp X position in the LCD * @param Ypos: Bmp Y position in the LCD * @param pbmp: Pointer to Bmp picture address in the internal Flash * @retval None */void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp){ uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; uint32_t address; uint32_t input_color_mode = 0; /* Get bitmap data address offset */ index = *(__IO uint16_t *) (pbmp + 10); index |= (*(__IO uint16_t *) (pbmp + 12)) << 16; /* Read bitmap width */ width = *(uint16_t *) (pbmp + 18); width |= (*(uint16_t *) (pbmp + 20)) << 16; /* Read bitmap height */ height = *(uint16_t *) (pbmp + 22); height |= (*(uint16_t *) (pbmp + 24)) << 16; /* Read bit/pixel */ bit_pixel = *(uint16_t *) (pbmp + 28); /* Set the address */ //address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); /* Get the layer pixel format */ if ((bit_pixel/8) == 4) { input_color_mode = CM_ARGB8888; } else if ((bit_pixel/8) == 2) { input_color_mode = CM_RGB565; } else { input_color_mode = CM_RGB888; } /* Bypass the bitmap header */ pbmp += (index + (width * (height - 1) * (bit_pixel/8))); /* Convert picture to ARGB8888 pixel format */ for(index=0; index < height; index++) { /* Pixel format conversion */ LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode); /* Increment the source and destination buffers */ address+= (BSP_LCD_GetXSize()*4); pbmp -= width*(bit_pixel/8); } }2017-04-20 08:50 PM
Haven't played with stm32 gfx hw, however, could it be that for sram frame buffer size saving, the way to render picture is like windows 256 indexed color lookup table (256x8888) 256 colors, 32bit each? One pixel is 8 bit index which will generateb a 32 bit color formatted output?
If this is the case, define the color palette for what wilk show onto the screen and use a pc color tool to use it to convert bitmaps in 8 bit format.
2017-04-21 12:31 AM
Yeah! Finally I have resolved the problem:
The problem is that there are many formats for a .bmp file. The original bitmap is of 24 bit depth so the LCD driver handled it poor. I changed it to 16 bit, it displayed well (no skew anymore) but with just a few color. I used Photoshop to change it to RGB565 and it is OK.
Thank you all for kindly help and suggestion.
2017-11-17 01:27 AM
Hello, i made an open source software to convert any picture (jpg, bmp, png) to a header file (.h) in one clic.
you can download it here :
http://www.electro-info.ovh/bitmap2headerfile
The software is in french but it is not difficult to use it.
2022-12-28 02:45 AM
Thank you so much for sharing this result. I had the exact same problem and could not find the solution anywhere.
For anyone who may encounter the problem on the STM32L562E-DK (which mounts a st7789h2 240x240 TFT LCD):
I solved by saving the BMP in the same format as showed in this post (R5 B6 G5) by using GIMP, loading it to a HEX converter (I've used HxD) and exporting it as a C file, which I've used as header in my project.