Fix BSP_LCD_DrawBitmap function to account for padding in bitmap images

This commit is contained in:
L-diy
2023-11-08 16:07:39 +01:00
parent a912f45961
commit f22d7c69f1

View File

@@ -1021,7 +1021,7 @@ void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
*/ */
void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp) 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 index = 0, width = 0, height = 0, bit_pixel = 0, row_size = 0;
uint32_t address; uint32_t address;
uint32_t input_color_mode = 0; uint32_t input_color_mode = 0;
@@ -1039,6 +1039,9 @@ void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
/* Set the address */ /* 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));
/* Calculate the row size in byte */
row_size = ((bit_pixel*width + 31)/32) * 4;
/* Get the layer pixel format */ /* Get the layer pixel format */
if ((bit_pixel/8) == 4) if ((bit_pixel/8) == 4)
@@ -1053,20 +1056,20 @@ void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
{ {
input_color_mode = CM_RGB888; input_color_mode = CM_RGB888;
} }
/* Bypass the bitmap header */ /* Bypass the bitmap header */
pbmp += (index + (width * (height - 1) * (bit_pixel/8))); pbmp += (index + (row_size * (height - 1)));
/* Convert picture to ARGB8888 pixel format */ /* Convert picture to ARGB8888 pixel format */
for(index=0; index < height; index++) for(index=0; index < height; index++)
{ {
/* Pixel format conversion */ /* Pixel format conversion */
LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode); LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode);
/* Increment the source and destination buffers */ /* Increment the source and destination buffers */
address+= (BSP_LCD_GetXSize()*4); address += (BSP_LCD_GetXSize()*4);
pbmp -= width*(bit_pixel/8); pbmp -= row_size;
} }
} }
/** /**