cancel
Showing results for 
Search instead for 
Did you mean: 

How to change LTDC color format from RGB888 to BGR888

AAsad.1
Associate II

Hi,

Is there a way to configure LTDC or touchgfx to use BGR instead of RGB color format, I'm using 24bit LCD interface.

3 REPLIES 3
Foued_KH
ST Employee

Hello @AAsad.1​ ,

The supported color formats for LTDC on STM32 processors are up to 8 Input color formats selectable per layer

– ARGB8888

– RGB888

– RGB565

– ARGB1555

– ARGB4444

– L8 (8-bit Luminance or CLUT)

– AL44 (4-bit alpha + 4-bit luminance)

– AL88 (8-bit alpha + 8-bit luminance)

Therefore, you cannot directly change the LTDC color format to BGR888 in STM32TouchGFX.

If you need to use the BGR888 format, you may need to implement a custom color conversion function to convert your RGB pixel data to BGR format before sending it to the display. This would require modifying the STM32TouchGFX code and implementing the conversion function yourself.

However, I would recommend using one of the supported color formats instead, as this will likely be easier to implement and will be more compatible with STM32 processors.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

AAsad.1
Associate II

Thanks Foued,

How can I do that, can you show me some code or check-boxes that I should set to do that in touchgfx

AAsad.1
Associate II

Why not implement that directly in touchgfx, as I have made a mistake in PCB design and I can not use RGB, I should use BGR, for converting the images I use this python script to swap RGB to BGR, but for text and normal color I should manually input swapped colors, can you ask your touchgfx team to add this simple support to their next relase, Because it's very easier for them, and this way of doing it right now, makes simulation hard for me, because the colors are swapped

import os
import sys
import numpy as np
import cv2
from PIL import Image
 
for filename in os.listdir("."):
    if filename.endswith(".png"):
        # Open the input file
        img = Image.open(filename)
        # Convert the image to a NumPy array
        np_img = np.array(img)
        # Swap the red and blue color channels
        np_img[:, :, [0, 2]] = np_img[:, :, [2, 0]]
        # Convert the NumPy array back to an image
        bgr_img = Image.fromarray(np_img)
        # Save the BGR image to the output file
        # bgr_img.save(filename[:-4] + "_bgr.png")
        bgr_img.save(filename)