更改應用程式的像素格式
本文將介紹在創建專案後,如何更改應用程式的像素格式。 具體地說,本文將舉例說明如何通過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中打開,將提示開發者更新,以套用新生成的配置更改。
{
"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中生成程式碼後,圖像資產和幀緩衝驅動程式都將具有指定格式。