refactor(ppa): use fourcc for dma2d and ppa color formats

This commit is contained in:
Song Ruo Jing
2025-11-17 21:27:08 +08:00
parent 1fcafee01c
commit fe8ace8bef
24 changed files with 274 additions and 332 deletions

View File

@@ -30,7 +30,7 @@ uint32_t color_hal_pixel_format_get_bit_depth(color_space_pixel_format_t color_t
*
* @return Number of bits per pixel
*/
uint32_t color_hal_pixel_format_fourcc_get_bit_depth(uint32_t four_character_code);
uint32_t color_hal_pixel_format_fourcc_get_bit_depth(esp_color_fourcc_t four_character_code);
#ifdef __cplusplus
}

View File

@@ -16,26 +16,42 @@ extern "C" {
Four Character Code
---------------------------------------------------------------*/
/**
* @brief Four Character Code type definition
*/
typedef uint32_t esp_color_fourcc_t;
#define ESP_COLOR_FOURCC(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
/**
* RGB24
* BGRA32
* Memory Layout:
* | bit7 - bit0 |
* Byte 2: | B7 - B0 |
* Byte 3: | A7 - A0 |
* Byte 2: | R7 - R0 |
* Byte 1: | G7 - G0 |
* Byte 0: | R7 - R0 |
* Byte 0: | B7 - B0 |
*/
#define ESP_COLOR_FOURCC_RGB24 ESP_COLOR_FOURCC('R', 'G', 'B', '3') /* 24 bpp RGB-8-8-8 */
#define ESP_COLOR_FOURCC_BGRA32 ESP_COLOR_FOURCC('B', 'A', '2', '4') /* 32 bpp BGRA-8-8-8-8 */
/**
* RGB565_BE
* BGR24
* Memory Layout:
* | bit7 - bit0 |
* Byte 2: | R7 - R0 |
* Byte 1: | G7 - G0 |
* Byte 0: | B7 - B0 |
*/
#define ESP_COLOR_FOURCC_BGR24 ESP_COLOR_FOURCC('B', 'G', 'R', '3') /* 24 bpp BGR-8-8-8 */
/**
* RGB565
* Memory Layout:
* | bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 |
* Byte 1: | G2 G1 G0 | B4 B3 B2 B1 B0 |
* Byte 0: | R4 R3 R2 R1 R0 | G5 G4 G3 |
* Byte 1: | R4 R3 R2 R1 R0 | G5 G4 G3 |
* Byte 0: | G2 G1 G0 | B4 B3 B2 B1 B0 |
*/
#define ESP_COLOR_FOURCC_RGB16_BE ESP_COLOR_FOURCC('R', 'G', 'B', 'B') /* 16 bpp RGB-5-6-5, big endian */
#define ESP_COLOR_FOURCC_RGB16 ESP_COLOR_FOURCC('R', 'G', 'B', 'L') /* 16 bpp RGB-5-6-5, little endian */
/**
* Grey8
@@ -45,6 +61,22 @@ extern "C" {
*/
#define ESP_COLOR_FOURCC_GREY ESP_COLOR_FOURCC('G', 'R', 'E', 'Y') /* 8 bpp Greyscale */
/**
* ALPHA4 (Alpha 4 bits)
* Memory Layout:
* Addr0 Addr1 Addr2 Addr3
* A0A1 A2A3 A4A5 A6A7
*/
#define ESP_COLOR_FOURCC_ALPHA4 ESP_COLOR_FOURCC('A', 'L', 'P', '4') /* 4 bpp, an 4-bit alpha-only format */
/**
* ALPHA8 (Alpha 8 bits)
* Memory Layout:
* Addr0 Addr1 Addr2 Addr3
* A0 A1 A2 A3
*/
#define ESP_COLOR_FOURCC_ALPHA8 ESP_COLOR_FOURCC('A', 'L', 'P', '8') /* 8 bpp, an 8-bit alpha-only format */
/**
* YUV444
* Memory Layout:
@@ -75,9 +107,9 @@ extern "C" {
/**
* UYVY422
* Memory Layout:
* +--+--+--+--+ +--+--+--+--+
* |U0|Y0|V0|Y1| |U2|Y2|V2|Y3|
* +--+--+--+--+ +--+--+--+--+
* +--+--+--+--+ +--+--+--+--+
* (lowest byte) |U0|Y0|V0|Y1| |U2|Y2|V2|Y3|
* +--+--+--+--+ +--+--+--+--+
*/
#define ESP_COLOR_FOURCC_UYVY ESP_COLOR_FOURCC('U', 'Y', 'V', 'Y') /* 16 bpp, UYVY 4:2:2 */
@@ -222,16 +254,6 @@ typedef enum {
COLOR_COMPONENT_INVALID, /*!< Invalid color component */
} color_component_t;
/**
* @brief The order of the components per pack in the YUV422 format
*/
typedef enum {
COLOR_YUV422_PACK_ORDER_YUYV, /*!< YUYV */
COLOR_YUV422_PACK_ORDER_YVYU, /*!< YVYU */
COLOR_YUV422_PACK_ORDER_UYVY, /*!< UYVY */
COLOR_YUV422_PACK_ORDER_VYUY, /*!< VYUY */
} color_yuv422_pack_order_t;
///< The following values are deprecated, please use the FOURCC values instead, IDF-14284
/*---------------------------------------------------------------
@@ -339,7 +361,6 @@ typedef union {
uint32_t color_type_id; ///< Unique type of a certain color pixel format
} color_space_pixel_format_t;
#ifdef __cplusplus
}
#endif

View File

@@ -76,31 +76,9 @@ typedef dma2d_descriptor_align8_t dma2d_descriptor_t;
#define DMA2D_DESCRIPTOR_PBYTE_4B0_PER_PIXEL (5) /*!< 2D-DMA descriptor pbyte value when 4 bytes/pixel */
// Helper function to convert pixel format to 2D-DMA descriptor pbyte value
static inline uint32_t dma2d_desc_pixel_format_to_pbyte_value(color_space_pixel_format_t pixel_format)
static inline uint32_t dma2d_desc_pixel_format_to_pbyte_value(esp_color_fourcc_t pixel_format)
{
switch (color_hal_pixel_format_get_bit_depth(pixel_format)) {
case 4:
return DMA2D_DESCRIPTOR_PBYTE_0B5_PER_PIXEL;
case 8:
return DMA2D_DESCRIPTOR_PBYTE_1B0_PER_PIXEL;
case 12:
return DMA2D_DESCRIPTOR_PBYTE_1B5_PER_PIXEL;
case 16:
return DMA2D_DESCRIPTOR_PBYTE_2B0_PER_PIXEL;
case 24:
return DMA2D_DESCRIPTOR_PBYTE_3B0_PER_PIXEL;
case 32:
return DMA2D_DESCRIPTOR_PBYTE_4B0_PER_PIXEL;
default:
// Unsupported bit depth
abort();
}
}
// Helper function to convert pixel format to 2D-DMA descriptor pbyte value
static inline uint32_t dma2d_desc_pixel_format_to_pbyte_value_fourcc(uint32_t four_character_code)
{
switch (color_hal_pixel_format_fourcc_get_bit_depth(four_character_code)) {
switch (color_hal_pixel_format_fourcc_get_bit_depth(pixel_format)) {
case 4:
return DMA2D_DESCRIPTOR_PBYTE_0B5_PER_PIXEL;
case 8:

View File

@@ -36,44 +36,50 @@ typedef enum {
* @brief Enumeration of PPA Scaling-Rotating-Mirroring available color mode
*/
typedef enum {
PPA_SRM_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA SRM color mode: ARGB8888 */
PPA_SRM_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA SRM color mode: RGB888 */
PPA_SRM_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA SRM color mode: RGB565 */
PPA_SRM_COLOR_MODE_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), /*!< PPA SRM color mode: YUV420 */
PPA_SRM_COLOR_MODE_YUV444 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV444), /*!< PPA SRM color mode: YUV444 (limited range only and can only be the input color mode)*/
PPA_SRM_COLOR_MODE_ARGB8888 = ESP_COLOR_FOURCC_BGRA32, /*!< PPA SRM color mode: ARGB8888 */
PPA_SRM_COLOR_MODE_RGB888 = ESP_COLOR_FOURCC_BGR24, /*!< PPA SRM color mode: RGB888 */
PPA_SRM_COLOR_MODE_RGB565 = ESP_COLOR_FOURCC_RGB16, /*!< PPA SRM color mode: RGB565 */
PPA_SRM_COLOR_MODE_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, /*!< PPA SRM color mode: YUV420 */
PPA_SRM_COLOR_MODE_YUV444 = ESP_COLOR_FOURCC_YUV, /*!< PPA SRM color mode: YUV444 (limited range only and can only be the input color mode) */
// YUV444 not supported by PPA hardware, but we can use 2D-DMA to do conversion before sending into the PPA module
// If in_pic is YUV444, then TX DMA channel could do DMA2D_CSC_TX_YUV444_TO_RGB888_601/709, so PPA in_color_mode is RGB888
PPA_SRM_COLOR_MODE_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), /*!< PPA SRM color mode: YUV422 (input data pack order all supported, but output data format is fixed to YVYU) */
PPA_SRM_COLOR_MODE_GRAY8 = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY8), /*!< PPA SRM color mode: GRAY8 */
PPA_SRM_COLOR_MODE_YUV422_UYVY = ESP_COLOR_FOURCC_UYVY, /*!< PPA SRM color mode: YUV422 */
PPA_SRM_COLOR_MODE_YUV422_VYUY = ESP_COLOR_FOURCC_VYUY, /*!< PPA SRM color mode: YUV422, only available on input */
PPA_SRM_COLOR_MODE_YUV422_YUYV = ESP_COLOR_FOURCC_YUYV, /*!< PPA SRM color mode: YUV422, only available on input */
PPA_SRM_COLOR_MODE_YUV422_YVYU = ESP_COLOR_FOURCC_YVYU, /*!< PPA SRM color mode: YUV422, only available on input */
PPA_SRM_COLOR_MODE_GRAY8 = ESP_COLOR_FOURCC_GREY, /*!< PPA SRM color mode: GRAY8 */
} ppa_srm_color_mode_t;
/**
* @brief Enumeration of PPA blend available color mode
*/
typedef enum {
PPA_BLEND_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA blend color mode: ARGB8888 */
PPA_BLEND_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA blend color mode: RGB888 */
PPA_BLEND_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA blend color mode: RGB565 */
PPA_BLEND_COLOR_MODE_A8 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A8), /*!< PPA blend color mode: A8, only available on blend foreground input */
PPA_BLEND_COLOR_MODE_A4 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A4), /*!< PPA blend color mode: A4, only available on blend foreground input */
PPA_BLEND_COLOR_MODE_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), /*!< PPA blend color mode: YUV420, only available on blend background input or on output */
PPA_BLEND_COLOR_MODE_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), /*!< PPA blend color mode: YUV422, only available on blend background input (all pack order supported) or on output (fixed to YVYU) */
PPA_BLEND_COLOR_MODE_GRAY8 = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY8), /*!< PPA blend color mode: GRAY8, only available on blend background input or on output */
PPA_BLEND_COLOR_MODE_ARGB8888 = ESP_COLOR_FOURCC_BGRA32, /*!< PPA blend color mode: ARGB8888 */
PPA_BLEND_COLOR_MODE_RGB888 = ESP_COLOR_FOURCC_BGR24, /*!< PPA blend color mode: RGB888 */
PPA_BLEND_COLOR_MODE_RGB565 = ESP_COLOR_FOURCC_RGB16, /*!< PPA blend color mode: RGB565 */
PPA_BLEND_COLOR_MODE_A8 = ESP_COLOR_FOURCC_ALPHA8, /*!< PPA blend color mode: A8, only available on blend foreground input */
PPA_BLEND_COLOR_MODE_A4 = ESP_COLOR_FOURCC_ALPHA4, /*!< PPA blend color mode: A4, only available on blend foreground input */
PPA_BLEND_COLOR_MODE_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, /*!< PPA blend color mode: YUV420, only available on blend background input or on output */
PPA_BLEND_COLOR_MODE_YUV422_UYVY = ESP_COLOR_FOURCC_UYVY, /*!< PPA blend color mode: YUV422, only available on blend background input or on output */
PPA_BLEND_COLOR_MODE_YUV422_VYUY = ESP_COLOR_FOURCC_VYUY, /*!< PPA blend color mode: YUV422, only available on blend background input */
PPA_BLEND_COLOR_MODE_YUV422_YUYV = ESP_COLOR_FOURCC_YUYV, /*!< PPA blend color mode: YUV422, only available on blend background input */
PPA_BLEND_COLOR_MODE_YUV422_YVYU = ESP_COLOR_FOURCC_YVYU, /*!< PPA blend color mode: YUV422, only available on blend background input */
PPA_BLEND_COLOR_MODE_GRAY8 = ESP_COLOR_FOURCC_GREY, /*!< PPA blend color mode: GRAY8, only available on blend background input or on output */
// TODO: Support CLUT to support L4/L8 color mode
// PPA_BLEND_COLOR_MODE_L8 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L8), /*!< PPA blend color mode: L8, only available on blend input */
// PPA_BLEND_COLOR_MODE_L4 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L4), /*!< PPA blend color mode: L4, only available on blend input */
// PPA_BLEND_COLOR_MODE_L8, /*!< PPA blend color mode: L8, only available on blend input */
// PPA_BLEND_COLOR_MODE_L4, /*!< PPA blend color mode: L4, only available on blend input */
} ppa_blend_color_mode_t;
/**
* @brief Enumeration of PPA fill available color mode
*/
typedef enum {
PPA_FILL_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA fill color mode: ARGB8888 */
PPA_FILL_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA fill color mode: RGB888 */
PPA_FILL_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA fill color mode: RGB565 */
// PPA_FILL_COLOR_MODE_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), /*!< PPA fill color mode: YUV420 */ // Non-typical YUV420, U and V components have to be the same value
PPA_FILL_COLOR_MODE_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), /*!< PPA fill color mode: YUV422 (w/ YVYU pack order) */
PPA_FILL_COLOR_MODE_GRAY8 = COLOR_TYPE_ID(COLOR_SPACE_GRAY, COLOR_PIXEL_GRAY8), /*!< PPA fill color mode: GRAY8 */
PPA_FILL_COLOR_MODE_ARGB8888 = ESP_COLOR_FOURCC_BGRA32, /*!< PPA fill color mode: ARGB8888 */
PPA_FILL_COLOR_MODE_RGB888 = ESP_COLOR_FOURCC_BGR24, /*!< PPA fill color mode: RGB888 */
PPA_FILL_COLOR_MODE_RGB565 = ESP_COLOR_FOURCC_RGB16, /*!< PPA fill color mode: RGB565 */
// PPA_FILL_COLOR_MODE_YUV420, /*!< PPA fill color mode: YUV420 */ // Non-typical YUV420, U and V components have to be the same value
PPA_FILL_COLOR_MODE_YUV422_UYVY = ESP_COLOR_FOURCC_UYVY, /*!< PPA fill color mode: YUV422 (w/ UYVY pack order) */
PPA_FILL_COLOR_MODE_GRAY8 = ESP_COLOR_FOURCC_GREY, /*!< PPA fill color mode: GRAY8 */
} ppa_fill_color_mode_t;
/**