2018-03-21 12:20 PM
Hi, I've been working on a UI for past couple weeks,
I've successfully created functionality for drawing bitmaps (with or without alpha), anti-aliased fonts and solid rectangles / lines using Chrom-ART / DMA2D
I am however currently unsure how to do rectangle fills with transparency. I assumed that DMA2D_R2M would accept a ARGB color and layer configurations, however that was not the case.
Can someone explain in rough lines how I can fill a rectangle, that contains an alpha channel, over an existing drawn area?
Thanks
http://preview.ibb.co/htzuzc/IMG_20180321_202jpg
My current bitmap/font character drawing function:
void
LCD
::DMA_DrawBitmap
(void
*pSrc,
void
*pDst,
uint32_t
xSize,
uint32_t
ySize,
uint32_t
ColorMode,
uint32_t
inputAlpha,
uint32_t
inputOffset) {hDma2dHandler
.Init
.Mode
=DMA2D_M2M_BLEND
;
hDma2dHandler
.Init
.ColorMode
=hLtdcHandler
.LayerCfg
[0
].PixelFormat
;
hDma2dHandler
.Init
.OutputOffset
=SCREEN_WIDTH
- xSize;
hDma2dHandler
.LayerCfg
[0
].AlphaMode
=DMA2D_NO_MODIF_ALPHA
;
hDma2dHandler
.LayerCfg
[0
].InputColorMode
=hLtdcHandler
.LayerCfg
[0
].PixelFormat
;
hDma2dHandler
.LayerCfg
[0
].InputAlpha
=0
;
hDma2dHandler
.LayerCfg
[0
].InputOffset
=SCREEN_WIDTH
- xSize;
/* Foreground Configuration */
hDma2dHandler
.LayerCfg
[1
].AlphaMode
=DMA2D_NO_MODIF_ALPHA
;
hDma2dHandler
.LayerCfg
[1
].InputAlpha
= inputAlpha;
hDma2dHandler
.LayerCfg
[1
].InputColorMode
= ColorMode;
hDma2dHandler
.LayerCfg
[1
].InputOffset
= inputOffset;
hDma2dHandler
.Instance
=DMA2D
;
/* DMA2D Initialization */
if
(HAL_DMA2D_Init(&hDma2dHandler
) ==HAL_OK
) {if
(HAL_DMA2D_ConfigLayer(&hDma2dHandler
,
0
) ==HAL_OK
&& HAL_DMA2D_ConfigLayer(&hDma2dHandler
,
1
) ==HAL_OK
) {if
(HAL_DMA2D_BlendingStart(&hDma2dHandler
,
(uint32_t
) pSrc,
(uint32_t
) pDst,
(uint32_t
) pDst,
xSize,
ySize) ==HAL_OK
) { HAL_DMA2D_PollForTransfer(&hDma2dHandler
,
500
);
} } } }And rectangle fill function:
void
LCD
::DMA_FillRect
(void
*pSrc,
void
*pDst,
uint32_t
xSize,
uint32_t
ySize,
uint32_t
ColorMode) {/* Configure the DMA2D Mode, Color Mode and output offset */
hDma2dHandler
.Init
.Mode
=DMA2D_M2M_PFC
;
hDma2dHandler
.Init
.ColorMode
=hLtdcHandler
.LayerCfg
[0
].PixelFormat
;
hDma2dHandler
.Init
.OutputOffset
=SCREEN_WIDTH
- xSize;
/* Foreground Configuration */
hDma2dHandler
.LayerCfg
[1
].AlphaMode
=DMA2D_NO_MODIF_ALPHA
;
hDma2dHandler
.LayerCfg
[1
].InputAlpha
=0xFF
;
hDma2dHandler
.LayerCfg
[1
].InputColorMode
= ColorMode;
hDma2dHandler
.LayerCfg
[1
].InputOffset
=0
;
hDma2dHandler
.Instance
=DMA2D
;
/* DMA2D Initialization */
if
(HAL_DMA2D_Init(&hDma2dHandler
) ==HAL_OK
) {if
(HAL_DMA2D_ConfigLayer(&hDma2dHandler
,
1
) ==HAL_OK
) {if
(HAL_DMA2D_Start(&hDma2dHandler
,
(uint32_t
) pSrc,
(uint32_t
) pDst,
xSize,
ySize) ==HAL_OK
) { HAL_DMA2D_PollForTransfer(&hDma2dHandler
,
500
);
} } } } graphics lcd ui chrom-art dma2d2018-03-26 04:38 AM
Anyone?
2018-03-26 04:42 AM
Hello
Sleziak.Marcin
,R2M with blending is directly not supported. However, you can do these steps:
Best regards,
Tilen
2018-03-26 04:50 AM
Hello
Sleziak.Marcin
,this is the only way. Any operation with transparency is normally done in pixel2pixel conversion between 2 memory addresses (2 layers), thus R2M_Blending mode is not supported and alpha channel is ignored.
Which STM32 do you use in this project?
Best regards,
Tilen
2018-03-26 06:48 AM
Hi
Majerle.Tilen
, thank you for your reply!That's currently the work-around I'm using, however this requires me to have a 3rd buffer allocated just for transparent rectangle fill operations.
Is this something that is technically not possible or just not documented?
Best wishes,
2018-03-26 06:56 AM
All right, that makes sense.
I'll try to optimize my 3rd buffer memory usage by using A4 color mode + a CLUT (If that makes sense?).
I'm using the F746
Best wishes,