cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429I-Discovery & BSP: problem with LCD and transparency

RAltm
Senior

Hi,

I'm struggling with the BSP LCD functions. The goal is to display an image which has transparent background. I'm working on STM32F429I-Discovery board, using BSP LCD drivers.

Since the BSP_LCD_DrawBitmap() function seems to expect a real BMP file, which doesn't contain alpha channel information, I want to create my own function for drawing the picture.

Currently I'm only displaying a text to verify that the LCD functions are working in general which seems to be fine.

For the transparency check, I made a small test loop. Here, a vertical line is displayed pixel by pixel with black color and the alpha channel is incremented for each pixel:

for(int y = 0; y < 256; y++)
	BSP_LCD_DrawPixel(10, y, y << 24);

Now, what I expect is that the line will be transparent at the beginning and becoming opaque at the end. But it is drawn fully opaque. I don't know what I'm doing wrong.

My main code (without the above mentioned loop):

/* Initialize the LCD Layers */
BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER);
BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER + BUFFER_OFFSET);
//TEST
BSP_LCD_SelectLayer(0);
 
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
 
/* Clear the LCD */
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_Clear(LCD_COLOR_BLUE);
 
/* Set the LCD Text Color */
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
 
/* Display LCD messages */
BSP_LCD_DisplayStringAt(0, 10, (uint8_t*)"Welcome", CENTER_MODE);

This works, the text is displayed on blue background with white color.

Here's my setup for the LTDC layers:

  pLayerCfg.WindowX0 = 0;
  pLayerCfg.WindowX1 = 239;
  pLayerCfg.WindowY0 = 0;
  pLayerCfg.WindowY1 = 319;
  pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
  pLayerCfg.Alpha = 255;
  pLayerCfg.Alpha0 = 0;
  pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  pLayerCfg.FBStartAdress = 0xD0000000;
  pLayerCfg.ImageWidth = 240;
  pLayerCfg.ImageHeight = 320;
  pLayerCfg.Backcolor.Blue = 0;
  pLayerCfg.Backcolor.Green = 0;
  pLayerCfg.Backcolor.Red = 0;
  if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
  {
    Error_Handler();
  }
  pLayerCfg1.WindowX0 = 0;
  pLayerCfg1.WindowX1 = 239;
  pLayerCfg1.WindowY0 = 0;
  pLayerCfg1.WindowY1 = 319;
  pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
  pLayerCfg1.Alpha = 255;
  pLayerCfg1.Alpha0 = 0;
  pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  pLayerCfg1.FBStartAdress = 0xD0050000;
  pLayerCfg1.ImageWidth = 240;
  pLayerCfg1.ImageHeight = 320;
  pLayerCfg1.Backcolor.Blue = 0;
  pLayerCfg1.Backcolor.Green = 0;
  pLayerCfg1.Backcolor.Red = 0;
  if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg1, 1) != HAL_OK)
  {
    Error_Handler();
  }

And the DMA2D setup:

  hdma2d.Instance = DMA2D;
  hdma2d.Init.Mode = DMA2D_M2M;
  hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
  hdma2d.Init.OutputOffset = 0;
  hdma2d.LayerCfg[1].InputOffset = 0;
  hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
  hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  hdma2d.LayerCfg[1].InputAlpha = 0;

From what I can see in the BSP LCD drivers, the DMA2D is dynamically configured at run-time.

I played around with the alpha values for the layers as well as inserting a call to BSP_LCD_SetTransparency() function with different values before drawing the line. But it affected either the whole layer (obviously) or nothing.

So, here are my questions:

1) Is my layer setup correct?

2) do I have to setup something else to enable alpha channel handling?

3) do I have to draw the line/image on layer 2 (with different setup)?

4) not directly related to the problem: which graphic solution would you recommend, e.g. EmWin, TouchGFX, etc.

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief III

1) maybe yes maybe not based on design. Normal use isnt manage graphics in two layers RAM. For example TouchGFX can manage only one layer and alpha is based sw not hw. Two layers is in basic used as bottom is ROM FLASH static or switched images and over it top layer dynamic RAM alpha hw graphics indicators usw.

2) setup seems good , but BSP and your test isnt prepared maybe. Your test miss when you place black pixels on black background with any alfa is always black...

3) you can draw what you need , but you own functions instead basic BSP or check what BSP realy doo.

4) TouchGFX

View solution in original post

7 REPLIES 7
MM..1
Chief III

1) maybe yes maybe not based on design. Normal use isnt manage graphics in two layers RAM. For example TouchGFX can manage only one layer and alpha is based sw not hw. Two layers is in basic used as bottom is ROM FLASH static or switched images and over it top layer dynamic RAM alpha hw graphics indicators usw.

2) setup seems good , but BSP and your test isnt prepared maybe. Your test miss when you place black pixels on black background with any alfa is always black...

3) you can draw what you need , but you own functions instead basic BSP or check what BSP realy doo.

4) TouchGFX

RAltm
Senior

Hello MM,

thank you for your answer.

2) setup seems good , but BSP and your test isnt prepared maybe. Your test miss when you place black pixels on black background with any alfa is always black...

That was it - I missed that the LTDC background color is set to black. I changed the line color to white, now the line is drawn black to white. So, I have to change background color to white and then it should be possible to show the picture with transparent background.:thumbs_up:

Regarding layer usage, it seems it's always application dependend. I found some document which state that it's also usual to draw on one (hidden) layer while the other one is shown and then swap the layers.

A bunch of own functions isn't neccessary for this application, but I'll check other graphic packages - thank you for your recommendation of TouchGFX.

Regards

Thank for best and one example of custom 1280x480 LTDC layer 0 image in flash, 1024x320 layer 1 320kB TouchGFX framebuffer with alpha 150.

0693W00000AMRWmQAP.jpg

Hello MM,

thank you for the example picture. Looks great. For the current application I don't need much more than what I've already achieved with BSP drivers, but for the next project I'll try it with TouchGFX.

Regards

RAltm
Senior

Hello MM,

another question regarding the BSP drivers and transparency came up. I want to fade in the text and the picture. But the layer transparency functions don't seem to have any effect. So, I wonder if my assumption is correct: if I draw something on a layer and then call BSP_LCD_SetTransparency() for the corresponding layer with an value of e.g. 0, shouldn't that layer get fully transparent? Or is this function meant for anything drawn after calling this function? I tried that, too, but also with no effect.

Even calling BSP_LCD_SetLayerVisible(0, DISABLE) has no effect. What am I missing?

Regards

When your layers is ARGB8888 then global layer alphas is ignored and every pixel have own alpha. I mean you need change your methods or config, plus im not expert to BSP. For alpha understanding learn about

  pLayerCfg.Alpha = 255;
  pLayerCfg.Alpha0 = 0;
  pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;

specialy LTDC_BLENDING_FACTORxx

RAltm
Senior

Hello MM,

thank you for your answer.

When your layers is ARGB8888 then global layer alphas is ignored and every pixel have own alpha.

Then this is the problem - I thought it would be layer alpha x pixel alpha. The blending factor indicates this, according to the definition of 'PAxCA':

#define LTDC_BLENDING_FACTOR1_CA          0x00000400U   /*!< Blending factor : Cte Alpha */
#define LTDC_BLENDING_FACTOR1_PAxCA       0x00000600U   /*!< Blending factor : Cte Alpha x Pixel Alpha*/

But, if the layer is not ARGB8888, what's the sense of PAxCA? On the other side, PAxCA only makes sense with ARGB8888 (or any other format supporting alpha). Strange...

So, if the layer alpha is ignored, I've to modify the image display function...

Regards