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

This commit is contained in:
Song Ruo Jing
2025-12-01 19:21:49 +08:00
parent 1fcafee01c
commit fe8ace8bef
24 changed files with 274 additions and 332 deletions
+11 -33
View File
@@ -46,16 +46,6 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
}
assert(dma2d_tx_bg_chan && dma2d_tx_fg_chan && dma2d_rx_chan);
color_space_pixel_format_t in_bg_pixel_format = {
.color_type_id = blend_trans_desc->in_bg.blend_cm,
};
color_space_pixel_format_t in_fg_pixel_format = {
.color_type_id = blend_trans_desc->in_fg.blend_cm,
};
color_space_pixel_format_t out_pixel_format = {
.color_type_id = blend_trans_desc->out.blend_cm,
};
// Fill 2D-DMA descriptors
blend_engine->dma_tx_bg_desc->vb_size = blend_trans_desc->in_bg.block_h;
blend_engine->dma_tx_bg_desc->hb_length = blend_trans_desc->in_bg.block_w;
@@ -65,7 +55,7 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
blend_engine->dma_tx_bg_desc->owner = DMA2D_DESCRIPTOR_BUFFER_OWNER_DMA;
blend_engine->dma_tx_bg_desc->va_size = blend_trans_desc->in_bg.pic_h;
blend_engine->dma_tx_bg_desc->ha_length = blend_trans_desc->in_bg.pic_w;
blend_engine->dma_tx_bg_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value(in_bg_pixel_format);
blend_engine->dma_tx_bg_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value((esp_color_fourcc_t)blend_trans_desc->in_bg.blend_cm);
blend_engine->dma_tx_bg_desc->y = blend_trans_desc->in_bg.block_offset_y;
blend_engine->dma_tx_bg_desc->x = blend_trans_desc->in_bg.block_offset_x;
blend_engine->dma_tx_bg_desc->mode = DMA2D_DESCRIPTOR_BLOCK_RW_MODE_SINGLE;
@@ -80,7 +70,7 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
blend_engine->dma_tx_fg_desc->owner = DMA2D_DESCRIPTOR_BUFFER_OWNER_DMA;
blend_engine->dma_tx_fg_desc->va_size = blend_trans_desc->in_fg.pic_h;
blend_engine->dma_tx_fg_desc->ha_length = blend_trans_desc->in_fg.pic_w;
blend_engine->dma_tx_fg_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value(in_fg_pixel_format);
blend_engine->dma_tx_fg_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value((esp_color_fourcc_t)blend_trans_desc->in_fg.blend_cm);
blend_engine->dma_tx_fg_desc->y = blend_trans_desc->in_fg.block_offset_y;
blend_engine->dma_tx_fg_desc->x = blend_trans_desc->in_fg.block_offset_x;
blend_engine->dma_tx_fg_desc->mode = DMA2D_DESCRIPTOR_BLOCK_RW_MODE_SINGLE;
@@ -95,7 +85,7 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
blend_engine->dma_rx_desc->owner = DMA2D_DESCRIPTOR_BUFFER_OWNER_DMA;
blend_engine->dma_rx_desc->va_size = blend_trans_desc->out.pic_h;
blend_engine->dma_rx_desc->ha_length = blend_trans_desc->out.pic_w;
blend_engine->dma_rx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value(out_pixel_format);
blend_engine->dma_rx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value((esp_color_fourcc_t)blend_trans_desc->out.blend_cm);
blend_engine->dma_rx_desc->y = blend_trans_desc->out.block_offset_y;
blend_engine->dma_rx_desc->x = blend_trans_desc->out.block_offset_x;
blend_engine->dma_rx_desc->mode = DMA2D_DESCRIPTOR_BLOCK_RW_MODE_SINGLE;
@@ -140,19 +130,16 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
// Configure PPA Blending engine
ppa_ll_blend_set_rx_bg_color_mode(platform->hal.dev, blend_trans_desc->in_bg.blend_cm);
if (COLOR_SPACE_TYPE((uint32_t)blend_trans_desc->in_bg.blend_cm) == COLOR_SPACE_YUV) {
if (PPA_IS_CM_YUV(blend_trans_desc->in_bg.blend_cm)) {
ppa_ll_blend_set_rx_bg_yuv_range(platform->hal.dev, blend_trans_desc->in_bg.yuv_range);
ppa_ll_blend_set_rx_bg_yuv2rgb_std(platform->hal.dev, blend_trans_desc->in_bg.yuv_std);
}
if ((uint32_t)blend_trans_desc->in_bg.blend_cm == PPA_BLEND_COLOR_MODE_YUV422) {
ppa_ll_blend_set_rx_bg_yuv422_pack_order(platform->hal.dev, blend_trans_desc->in_bg.yuv422_pack_order);
}
ppa_ll_blend_enable_rx_bg_byte_swap(platform->hal.dev, blend_trans_desc->bg_byte_swap);
ppa_ll_blend_enable_rx_bg_rgb_swap(platform->hal.dev, blend_trans_desc->bg_rgb_swap);
ppa_ll_blend_configure_rx_bg_alpha(platform->hal.dev, blend_trans_desc->bg_alpha_update_mode, blend_trans_desc->bg_alpha_value);
ppa_ll_blend_set_rx_fg_color_mode(platform->hal.dev, blend_trans_desc->in_fg.blend_cm);
if (COLOR_SPACE_TYPE((uint32_t)blend_trans_desc->in_fg.blend_cm) == COLOR_SPACE_ALPHA) {
if (PPA_IS_CM_ALPHA(blend_trans_desc->in_fg.blend_cm)) {
ppa_ll_blend_set_rx_fg_fix_rgb(platform->hal.dev, &blend_trans_desc->fg_fix_rgb_val);
}
ppa_ll_blend_enable_rx_fg_byte_swap(platform->hal.dev, blend_trans_desc->fg_byte_swap);
@@ -160,7 +147,7 @@ bool ppa_blend_transaction_on_picked(uint32_t num_chans, const dma2d_trans_chann
ppa_ll_blend_configure_rx_fg_alpha(platform->hal.dev, blend_trans_desc->fg_alpha_update_mode, blend_trans_desc->fg_alpha_value);
ppa_ll_blend_set_tx_color_mode(platform->hal.dev, blend_trans_desc->out.blend_cm);
if (COLOR_SPACE_TYPE((uint32_t)blend_trans_desc->out.blend_cm) == COLOR_SPACE_YUV) {
if (PPA_IS_CM_YUV(blend_trans_desc->out.blend_cm)) {
ppa_ll_blend_set_tx_yuv_range(platform->hal.dev, blend_trans_desc->out.yuv_range);
ppa_ll_blend_set_tx_rgb2yuv_std(platform->hal.dev, blend_trans_desc->out.yuv_std);
}
@@ -201,7 +188,7 @@ esp_err_t ppa_do_blend(ppa_client_handle_t ppa_client, const ppa_blend_oper_conf
config->in_bg.block_h % 2 == 0 && config->in_bg.block_w % 2 == 0 &&
config->in_bg.block_offset_x % 2 == 0 && config->in_bg.block_offset_y % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV420 input does not support odd h/w/offset_x/offset_y");
} else if (config->in_bg.blend_cm == PPA_BLEND_COLOR_MODE_YUV422) {
} else if (PPA_IS_CM_YUV422(config->in_bg.blend_cm)) {
ESP_RETURN_ON_FALSE(config->in_bg.pic_w % 2 == 0 && config->in_bg.block_w % 2 == 0 && config->in_bg.block_offset_x % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV422 input does not support odd w/offset_x");
}
@@ -218,7 +205,7 @@ esp_err_t ppa_do_blend(ppa_client_handle_t ppa_client, const ppa_blend_oper_conf
ESP_RETURN_ON_FALSE(config->out.pic_h % 2 == 0 && config->out.pic_w % 2 == 0 &&
config->out.block_offset_x % 2 == 0 && config->out.block_offset_y % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV420 output does not support odd h/w/offset_x/offset_y");
} else if (config->out.blend_cm == PPA_BLEND_COLOR_MODE_YUV422) {
} else if (PPA_IS_CM_YUV422(config->out.blend_cm)) {
ESP_RETURN_ON_FALSE(config->out.pic_w % 2 == 0 && config->out.block_offset_x % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV422 output does not support odd w/offset_x");
}
@@ -228,10 +215,7 @@ esp_err_t ppa_do_blend(ppa_client_handle_t ppa_client, const ppa_blend_oper_conf
ESP_RETURN_ON_FALSE(config->in_fg.block_w <= (config->in_fg.pic_w - config->in_fg.block_offset_x) &&
config->in_fg.block_h <= (config->in_fg.pic_h - config->in_fg.block_offset_y),
ESP_ERR_INVALID_ARG, TAG, "in_fg.block_w/h + in_fg.block_offset_x/y does not fit in the in pic");
color_space_pixel_format_t out_pixel_format = {
.color_type_id = config->out.blend_cm,
};
uint32_t out_pixel_depth = color_hal_pixel_format_get_bit_depth(out_pixel_format); // bits
uint32_t out_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->out.blend_cm); // bits
uint32_t out_pic_len = config->out.pic_w * config->out.pic_h * out_pixel_depth / 8;
ESP_RETURN_ON_FALSE(out_pic_len <= config->out.buffer_size, ESP_ERR_INVALID_ARG, TAG, "out.pic_w/h mismatch with out.buffer_size");
ESP_RETURN_ON_FALSE(config->in_bg.block_w == config->in_fg.block_w && config->in_bg.block_h == config->in_fg.block_h,
@@ -271,10 +255,7 @@ esp_err_t ppa_do_blend(ppa_client_handle_t ppa_client, const ppa_blend_oper_conf
// Write back and invalidate necessary data (note that the window content is not continuous in the buffer)
// Write back in_bg_buffer, in_fg_buffer extended windows (alignment not necessary on C2M direction)
color_space_pixel_format_t in_bg_pixel_format = {
.color_type_id = config->in_bg.blend_cm,
};
uint32_t in_bg_pixel_depth = color_hal_pixel_format_get_bit_depth(in_bg_pixel_format); // bits
uint32_t in_bg_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->in_bg.blend_cm); // bits
// Usually C2M can let the msync do alignment internally, however, it only do L1-cacheline-size alignment for L1->L2, and then L2-cacheline-size alignment for L2->mem
// While M2C direction manual alignment is L2-cacheline-size alignment for mem->L2->L1
// Mismatching writeback and invalidate data size could cause synchronization error if in_bg/fg_buffer and out_buffer are the same one
@@ -282,10 +263,7 @@ esp_err_t ppa_do_blend(ppa_client_handle_t ppa_client, const ppa_blend_oper_conf
uint32_t in_bg_ext_window_aligned = PPA_ALIGN_DOWN(in_bg_ext_window, buf_alignment_size);
uint32_t in_bg_ext_window_len = config->in_bg.pic_w * config->in_bg.block_h * in_bg_pixel_depth / 8;
esp_cache_msync((void *)in_bg_ext_window_aligned, PPA_ALIGN_UP(in_bg_ext_window_len + (in_bg_ext_window - in_bg_ext_window_aligned), buf_alignment_size), ESP_CACHE_MSYNC_FLAG_DIR_C2M);
color_space_pixel_format_t in_fg_pixel_format = {
.color_type_id = config->in_fg.blend_cm,
};
uint32_t in_fg_pixel_depth = color_hal_pixel_format_get_bit_depth(in_fg_pixel_format); // bits
uint32_t in_fg_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->in_fg.blend_cm); // bits
uint32_t in_fg_ext_window = (uint32_t)config->in_fg.buffer + config->in_fg.block_offset_y * config->in_fg.pic_w * in_fg_pixel_depth / 8;
// Same for fg_buffer msync, do manual alignment
uint32_t in_fg_ext_window_aligned = PPA_ALIGN_DOWN(in_fg_ext_window, buf_alignment_size);
+3 -10
View File
@@ -32,10 +32,6 @@ bool ppa_fill_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channe
assert(dma2d_chans[0].dir == DMA2D_CHANNEL_DIRECTION_RX);
dma2d_channel_handle_t dma2d_rx_chan = dma2d_chans[0].chan;
color_space_pixel_format_t out_pixel_format = {
.color_type_id = fill_trans_desc->out.fill_cm,
};
// Fill 2D-DMA descriptors
blend_engine->dma_rx_desc->vb_size = fill_trans_desc->fill_block_h;
blend_engine->dma_rx_desc->hb_length = fill_trans_desc->fill_block_w;
@@ -45,7 +41,7 @@ bool ppa_fill_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channe
blend_engine->dma_rx_desc->owner = DMA2D_DESCRIPTOR_BUFFER_OWNER_DMA;
blend_engine->dma_rx_desc->va_size = fill_trans_desc->out.pic_h;
blend_engine->dma_rx_desc->ha_length = fill_trans_desc->out.pic_w;
blend_engine->dma_rx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value(out_pixel_format);
blend_engine->dma_rx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value((esp_color_fourcc_t)fill_trans_desc->out.fill_cm);
blend_engine->dma_rx_desc->y = fill_trans_desc->out.block_offset_y;
blend_engine->dma_rx_desc->x = fill_trans_desc->out.block_offset_x;
blend_engine->dma_rx_desc->mode = DMA2D_DESCRIPTOR_BLOCK_RW_MODE_SINGLE;
@@ -104,14 +100,11 @@ esp_err_t ppa_do_fill(ppa_client_handle_t ppa_client, const ppa_fill_oper_config
// config->out.block_offset_x % 2 == 0 && config->out.block_offset_y % 2 == 0,
// ESP_ERR_INVALID_ARG, TAG, "YUV420 output does not support odd h/w/offset_x/offset_y");
// } else
if (config->out.fill_cm == PPA_FILL_COLOR_MODE_YUV422) {
if (config->out.fill_cm == PPA_FILL_COLOR_MODE_YUV422_UYVY) {
ESP_RETURN_ON_FALSE(config->out.pic_w % 2 == 0 && config->out.block_offset_x % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV422 output does not support odd w/offset_x");
}
color_space_pixel_format_t out_pixel_format = {
.color_type_id = config->out.fill_cm,
};
uint32_t out_pixel_depth = color_hal_pixel_format_get_bit_depth(out_pixel_format);
uint32_t out_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->out.fill_cm);
uint32_t out_pic_len = config->out.pic_w * config->out.pic_h * out_pixel_depth / 8;
ESP_RETURN_ON_FALSE(out_pic_len <= config->out.buffer_size, ESP_ERR_INVALID_ARG, TAG, "out.pic_w/h mismatch with out.buffer_size");
ESP_RETURN_ON_FALSE(config->fill_block_w <= (config->out.pic_w - config->out.block_offset_x) &&
+12 -2
View File
@@ -28,13 +28,23 @@ extern "C" {
#define PPA_PM_LOCK_NAME_LEN_MAX 16
#define PPA_CHECK_CM_SUPPORT_BYTE_SWAP(str, color_type_id) \
ESP_RETURN_ON_FALSE(color_type_id == COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888) || color_type_id == COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), \
ESP_RETURN_ON_FALSE((color_type_id == ESP_COLOR_FOURCC_BGRA32) || (color_type_id == ESP_COLOR_FOURCC_RGB16), \
ESP_ERR_INVALID_ARG, TAG, str "_cm does not support byte_swap");
#define PPA_CHECK_CM_SUPPORT_RGB_SWAP(str, color_type_id) \
ESP_RETURN_ON_FALSE(COLOR_SPACE_TYPE(color_type_id) == COLOR_SPACE_ARGB || COLOR_SPACE_TYPE(color_type_id) == COLOR_SPACE_RGB, \
ESP_RETURN_ON_FALSE((color_type_id == ESP_COLOR_FOURCC_BGRA32) || (color_type_id == ESP_COLOR_FOURCC_BGR24) || (color_type_id == ESP_COLOR_FOURCC_RGB16), \
ESP_ERR_INVALID_ARG, TAG, str "_cm does not support rgb_swap");
#define PPA_IS_CM_YUV422(color_type_id) \
(color_type_id == ESP_COLOR_FOURCC_UYVY || color_type_id == ESP_COLOR_FOURCC_VYUY || \
color_type_id == ESP_COLOR_FOURCC_YUYV || color_type_id == ESP_COLOR_FOURCC_YVYU)
#define PPA_IS_CM_YUV(color_type_id) \
(color_type_id == ESP_COLOR_FOURCC_OUYY_EVYY || color_type_id == ESP_COLOR_FOURCC_YUV || PPA_IS_CM_YUV422(color_type_id))
#define PPA_IS_CM_ALPHA(color_type_id) \
(color_type_id == ESP_COLOR_FOURCC_ALPHA8 || color_type_id == ESP_COLOR_FOURCC_ALPHA4)
#define PPA_ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
#define PPA_ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
+9 -25
View File
@@ -41,10 +41,6 @@ bool ppa_srm_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channel
}
assert(dma2d_tx_chan && dma2d_rx_chan);
color_space_pixel_format_t in_pixel_format = {
.color_type_id = srm_trans_desc->in.srm_cm,
};
// Fill 2D-DMA descriptors
srm_engine->dma_tx_desc->vb_size = srm_trans_desc->in.block_h;
srm_engine->dma_tx_desc->hb_length = srm_trans_desc->in.block_w;
@@ -54,7 +50,7 @@ bool ppa_srm_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channel
srm_engine->dma_tx_desc->owner = DMA2D_DESCRIPTOR_BUFFER_OWNER_DMA;
srm_engine->dma_tx_desc->va_size = srm_trans_desc->in.pic_h;
srm_engine->dma_tx_desc->ha_length = srm_trans_desc->in.pic_w;
srm_engine->dma_tx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value(in_pixel_format);
srm_engine->dma_tx_desc->pbyte = dma2d_desc_pixel_format_to_pbyte_value((esp_color_fourcc_t)srm_trans_desc->in.srm_cm);
srm_engine->dma_tx_desc->y = srm_trans_desc->in.block_offset_y;
srm_engine->dma_tx_desc->x = srm_trans_desc->in.block_offset_x;
srm_engine->dma_tx_desc->mode = DMA2D_DESCRIPTOR_BLOCK_RW_MODE_SINGLE;
@@ -136,19 +132,16 @@ bool ppa_srm_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channel
// Configure PPA SRM engine
ppa_ll_srm_set_rx_color_mode(platform->hal.dev, ppa_in_color_mode);
if (COLOR_SPACE_TYPE((uint32_t)ppa_in_color_mode) == COLOR_SPACE_YUV) {
if (PPA_IS_CM_YUV(ppa_in_color_mode)) {
ppa_ll_srm_set_rx_yuv_range(platform->hal.dev, srm_trans_desc->in.yuv_range);
ppa_ll_srm_set_rx_yuv2rgb_std(platform->hal.dev, srm_trans_desc->in.yuv_std);
}
if ((uint32_t)ppa_in_color_mode == COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422)) {
ppa_ll_srm_set_rx_yuv422_pack_order(platform->hal.dev, srm_trans_desc->in.yuv422_pack_order);
}
ppa_ll_srm_enable_rx_byte_swap(platform->hal.dev, srm_trans_desc->byte_swap);
ppa_ll_srm_enable_rx_rgb_swap(platform->hal.dev, srm_trans_desc->rgb_swap);
ppa_ll_srm_configure_rx_alpha(platform->hal.dev, srm_trans_desc->alpha_update_mode, srm_trans_desc->alpha_value);
ppa_ll_srm_set_tx_color_mode(platform->hal.dev, ppa_out_color_mode);
if (COLOR_SPACE_TYPE((uint32_t)ppa_out_color_mode) == COLOR_SPACE_YUV) {
if (PPA_IS_CM_YUV(ppa_out_color_mode)) {
ppa_ll_srm_set_tx_yuv_range(platform->hal.dev, srm_trans_desc->out.yuv_range);
ppa_ll_srm_set_tx_rgb2yuv_std(platform->hal.dev, srm_trans_desc->out.yuv_std);
}
@@ -169,10 +162,7 @@ bool ppa_srm_transaction_on_picked(uint32_t num_chans, const dma2d_trans_channel
h_in_left = (h_in_left == 0) ? h_mb : h_in_left;
uint32_t h_left = h_in_left * srm_trans_desc->scale_y_int + h_in_left * srm_trans_desc->scale_y_frag / PPA_LL_SRM_SCALING_FRAG_MAX;
const uint32_t dma2d_fifo_depth_bits = 12 * 128;
color_space_pixel_format_t out_pixel_format = {
.color_type_id = ppa_out_color_mode,
};
uint32_t out_pixel_depth = color_hal_pixel_format_get_bit_depth(out_pixel_format);
uint32_t out_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)ppa_out_color_mode);
bool bypass_mb_order = false;
if (((w_out > w_divisor) || (srm_trans_desc->in.block_h > h_mb)) && // will be cut into more than one trans unit
((w_left * h_left * out_pixel_depth) < dma2d_fifo_depth_bits)
@@ -207,7 +197,7 @@ esp_err_t ppa_do_scale_rotate_mirror(ppa_client_handle_t ppa_client, const ppa_s
config->in.block_h % 2 == 0 && config->in.block_w % 2 == 0 &&
config->in.block_offset_x % 2 == 0 && config->in.block_offset_y % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV420 input does not support odd h/w/offset_x/offset_y");
} else if (config->in.srm_cm == PPA_SRM_COLOR_MODE_YUV422) {
} else if (PPA_IS_CM_YUV422(config->in.srm_cm)) {
ESP_RETURN_ON_FALSE(config->in.pic_w % 2 == 0 && config->in.block_w % 2 == 0 && config->in.block_offset_x % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV422 input does not support odd w/offset_x");
}
@@ -215,17 +205,14 @@ esp_err_t ppa_do_scale_rotate_mirror(ppa_client_handle_t ppa_client, const ppa_s
ESP_RETURN_ON_FALSE(config->out.pic_h % 2 == 0 && config->out.pic_w % 2 == 0 &&
config->out.block_offset_x % 2 == 0 && config->out.block_offset_y % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV420 output does not support odd h/w/offset_x/offset_y");
} else if (config->out.srm_cm == PPA_SRM_COLOR_MODE_YUV422) {
} else if (PPA_IS_CM_YUV422(config->out.srm_cm)) {
ESP_RETURN_ON_FALSE(config->out.pic_w % 2 == 0 && config->out.block_offset_x % 2 == 0,
ESP_ERR_INVALID_ARG, TAG, "YUV422 output does not support odd w/offset_x");
}
ESP_RETURN_ON_FALSE(config->in.block_w <= (config->in.pic_w - config->in.block_offset_x) &&
config->in.block_h <= (config->in.pic_h - config->in.block_offset_y),
ESP_ERR_INVALID_ARG, TAG, "in.block_w/h + in.block_offset_x/y does not fit in the in pic");
color_space_pixel_format_t out_pixel_format = {
.color_type_id = config->out.srm_cm,
};
uint32_t out_pixel_depth = color_hal_pixel_format_get_bit_depth(out_pixel_format); // bits
uint32_t out_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->out.srm_cm); // bits
uint32_t out_pic_len = config->out.pic_w * config->out.pic_h * out_pixel_depth / 8;
ESP_RETURN_ON_FALSE(out_pic_len <= config->out.buffer_size, ESP_ERR_INVALID_ARG, TAG, "out.pic_w/h mismatch with out.buffer_size");
ESP_RETURN_ON_FALSE(config->scale_x < PPA_LL_SRM_SCALING_INT_MAX && config->scale_x >= (1.0 / PPA_LL_SRM_SCALING_FRAG_MAX) &&
@@ -261,10 +248,7 @@ esp_err_t ppa_do_scale_rotate_mirror(ppa_client_handle_t ppa_client, const ppa_s
// Write back and invalidate necessary data (note that the window content is not continuous in the buffer)
// Write back in_buffer extended window (alignment not necessary on C2M direction)
color_space_pixel_format_t in_pixel_format = {
.color_type_id = config->in.srm_cm,
};
uint32_t in_pixel_depth = color_hal_pixel_format_get_bit_depth(in_pixel_format); // bits
uint32_t in_pixel_depth = color_hal_pixel_format_fourcc_get_bit_depth((esp_color_fourcc_t)config->in.srm_cm); // bits
uint32_t in_ext_window = (uint32_t)config->in.buffer + config->in.block_offset_y * config->in.pic_w * in_pixel_depth / 8;
uint32_t in_ext_window_len = config->in.pic_w * config->in.block_h * in_pixel_depth / 8;
esp_cache_msync((void *)in_ext_window, in_ext_window_len, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED);
@@ -295,7 +279,7 @@ esp_err_t ppa_do_scale_rotate_mirror(ppa_client_handle_t ppa_client, const ppa_s
if (config->out.srm_cm == PPA_SRM_COLOR_MODE_YUV420) {
srm_trans_desc->scale_x_frag = srm_trans_desc->scale_x_frag & ~1;
srm_trans_desc->scale_y_frag = srm_trans_desc->scale_y_frag & ~1;
} else if (config->out.srm_cm == PPA_SRM_COLOR_MODE_YUV422) {
} else if (PPA_IS_CM_YUV422(config->out.srm_cm)) {
srm_trans_desc->scale_x_frag = srm_trans_desc->scale_x_frag & ~1;
}
srm_trans_desc->alpha_value = new_alpha_value;