更改应用的像素格式
本文将介绍在创建项目后,如何更改应用的像素格式。 具体地说,本文将举例说明如何通过TouchGFX Generator将24位RGB888应用修改为16位RGB565,还将介绍对TouchGFX项目配置的影响。 更改像素格式的原因可能是:
- 修改了显示屏要求
- 修改了应用要求
- 项目最初创建期间的错误
Further reading
一般而言,更改了应用的像素格式,还需要进行下列更改。
- 板启动搭建:更改LTDC的像素格式。
- HAL开发:修改TouchGFX Generator设置,以反映LTDC设置或帧缓冲在存储器中的位置。
- TouchGFX Designer: Ensure that TouchGFX Designer is using this new converted bit depth and correct format for image assets.
Starting from TouchGFX Designer we can inspect the current configuration for Display and Image and return to these screens later to validate.
板卡调试与启动
如果STM32CubeMX项目中的特定设置可能影响应用需要的像素格式,就像LTDC一样,则开发者需要在此进行适当更改,以使TouchGFX以LTDC期望的格式进行渲染。
Further reading
HAL开发
如果应用的位深随帧缓冲的像素格式而变化(例如,将ARGB2222更改为BRGA2222后仍将得到8位应用),则开发者可能需要修改帧缓冲的存储位置。 在以下情况下:
使用此配置生成代码将生成使用16位TouchGFX LCD
类的TouchGFXConfiguration
。
TouchGFXConfiguration.cpp
static LCD16bpp display;```
如果项目已在TouchGFX Designer中打开,将提示开发者更新,以反映新生成的配置更改。
```json {7-8}
{
"image_configuration": {
"images": {},
"dither_algorithm": "2",
"alpha_dither": "yes",
"layout_rotation": "0",
"opaque_image_format": "RGB565",
"nonopaque_image_format": "ARGB8888",
"section": "ExtFlashSection",
"extra_section": "ExtFlashSection"
},
下表列出了在给定像素格式下对不透明和透明图像格式的影响:
帧缓冲像素格式 | 不透明格式 | 透明格式 |
---|---|---|
Gray2 | Gray2 | Gray2 |
Gray4 | Gray4 | Gray4 |
ABGR2222 | ABGR2222 | ABGR2222 |
ARGB2222 | ARGB2222 | ARGB2222 |
BGRA2222 | BGRA2222 | BGRA2222 |
RGBA2222 | RGBA2222 | RGBA2222 |
RGB565 | RGB565 | ARGB8888 |
RGB888 | RGB888 | ARGB8888 |
TouchGFX Designer
Once the TouchGFX project has been updated based on the new TouchGFX Generator settings defined in STM32CubeMX, developers will find that TouchGFX Designer configuration has changed to match.
在从TouchGFX Designer内部生成代码后,图像资源的代码现已反映了更新后的像素格式:
TouchGFX\generated\images\src\my_image.png
LOCATION_PRAGMA("ExtFlashSection")
KEEP extern const unsigned char my_image[] LOCATION_ATTRIBUTE("ExtFlashSection") = // 320x240 RGB565 pixels.
结论
只需使用TouchGFX Generator即可修改应用的当前像素格式。 对于具有LTDC的MCU,运行TouchGFX的层必须与在TouchGFX Generator(就LTDC而言,仅限于RGB565和RGB888)设置中定义的帧缓冲像素格式相匹配,以确保与TouchGFX Core渲染的格式相一致。
在从STM32CubeMX生成代码后,将更新TouchGFX项目,后续在TouchGFX Designer中生成代码后,图像资源和帧缓冲驱动程序都将具有指定的格式。