cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 DMA2D ARGB8888 image load

EasyNet
Associate III

Hello,

I'm facing a issue with DMA2D to blend some images.

From the naming ARGB means that the order of the colors should be Alpha, Red, Green and Blue.
But if I have a PNG file which contains my image with Alpha, how I have to convert to a static image for my MCU to be able to work correctly  with it with DMA2D?

Normally PNG is using RGBA format in big-endian. But if I'm converting this file to ARGB format and try to blend it over another image, it will work?

Also I'm confused with endianess, because I know that ARM normally is using little-endian.

Which is the best approach to load the image?

A struct like this:

typedef struct {
	uint8_t A: 8;
	uint8_t R: 8;
	uint8_t G: 8;
	uint8_t B: 8;
} ARGB_TypeDef;


typedef struct {
	const uint16_t width;
	const uint16_t height;
	ARGB_TypeDef *data;
} FCU_Labels_TypeDef;

Should work with DMA2D which requires uint32_t data for source and destination?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

The DMA2D order that matters is the order within memory and is given by the reference manual:

TDK_0-1767301722278.png

If you were to interpret the same memory as a uint32_t, the order would be 0xBBGGRRAA since the STM32 is little-endian as all modern popular computing systems are.

Bit order within a struct is implementation defined. Yes, the bit field you have defined will work in most cases. But it's not guaranteed.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Super User

The DMA2D order that matters is the order within memory and is given by the reference manual:

TDK_0-1767301722278.png

If you were to interpret the same memory as a uint32_t, the order would be 0xBBGGRRAA since the STM32 is little-endian as all modern popular computing systems are.

Bit order within a struct is implementation defined. Yes, the bit field you have defined will work in most cases. But it's not guaranteed.

If you feel a post has answered your question, please click "Accept as Solution".
EasyNet
Associate III

Thnaks @TDK ,

This is an good start for me. I will try to use a union instead of bit fields, something similat to this:

typedef union {
    struct __attribute__((packed)) {
        uint8_t B;
        uint8_t G;
        uint8_t R;
        uint8_t A;
    } components;
    uint32_t value;
} ARGB8888_TypeDef;

 

I will play a little bit. I will build my own C program on my PC to convert correctly a PNg to ARGB format. Then I will load the static image to MCU, convert to RGB565 and I will try to send it to ST7789 SPI display.

I hope Iwill not face strage issues with ST7789 SPI endianess .