diff --git a/components/esp_driver_isp/include/driver/isp_core.h b/components/esp_driver_isp/include/driver/isp_core.h index ce261a5b69..a028b31989 100644 --- a/components/esp_driver_isp/include/driver/isp_core.h +++ b/components/esp_driver_isp/include/driver/isp_core.h @@ -24,6 +24,8 @@ typedef struct { isp_input_data_source_t input_data_source; ///< Input data source isp_color_t input_data_color_type; ///< Input color type isp_color_t output_data_color_type; ///< Output color type + isp_color_range_t yuv_range; ///< When the `output_data_color_type` is any YUV color space, this field is to describe its color range + isp_yuv_conv_std_t yuv_std; ///< This field is to describe YUV<->RGB conversion standard bool has_line_start_packet; ///< Enable line start packet bool has_line_end_packet; ///< Enable line end packet uint32_t h_res; ///< Input horizontal resolution, i.e. the number of pixels in a line diff --git a/components/esp_driver_isp/src/isp_core.c b/components/esp_driver_isp/src/isp_core.c index dbf333af9a..64b54520ea 100644 --- a/components/esp_driver_isp/src/isp_core.c +++ b/components/esp_driver_isp/src/isp_core.c @@ -136,6 +136,10 @@ esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_ isp_ll_enable_line_end_packet_exist(proc->hal.hw, proc_config->has_line_end_packet); isp_ll_set_intput_data_h_pixel_num(proc->hal.hw, proc_config->h_res); isp_ll_set_intput_data_v_row_num(proc->hal.hw, proc_config->v_res); + isp_ll_yuv_set_std(proc->hal.hw, proc_config->yuv_std); + if (out_color_format.color_space == COLOR_SPACE_YUV) { + isp_ll_yuv_set_range(proc->hal.hw, proc_config->yuv_range); + } proc->in_color_format = in_color_format; proc->out_color_format = out_color_format; diff --git a/components/hal/esp32p4/include/hal/isp_ll.h b/components/hal/esp32p4/include/hal/isp_ll.h index 39758c6843..d0c0c16801 100644 --- a/components/hal/esp32p4/include/hal/isp_ll.h +++ b/components/hal/esp32p4/include/hal/isp_ll.h @@ -1486,6 +1486,63 @@ static inline uint8_t isp_ll_sharp_get_high_freq_pixel_max(isp_dev_t *hw) return hw->sharp_ctrl1.sharp_gradient_max; } +/*--------------------------------------------------------------- + RGB/YUV +---------------------------------------------------------------*/ +/** + * @brief Enable / Disable rgb2yuv clock + * + * @param[in] hw Hardware instance address + * @param[in] enable 0: hw control; 1: always on + */ +static inline void isp_ll_rgb2yuv_clk_enable(isp_dev_t *hw, bool enable) +{ + hw->clk_en.clk_rgb2yuv_force_on = enable; +} + +/** + * @brief Enable / Disable yuv2rgb clock + * + * @param[in] hw Hardware instance address + * @param[in] enable 0: hw control; 1: always on + */ +static inline void isp_ll_yuv2rgb_clk_enable(isp_dev_t *hw, bool enable) +{ + hw->clk_en.clk_yuv2rgb_force_on = enable; +} + +/** + * @brief Set YUV range + * + * @param[in] hw Hardware instance address + * @param[in] range see `isp_color_range_t` + */ +static inline void isp_ll_yuv_set_range(isp_dev_t *hw, isp_color_range_t range) +{ + switch (range) { + case ISP_COLOR_RANGE_LIMIT: + hw->yuv_format.yuv_range = 1; + break; + case ISP_COLOR_RANGE_FULL: + hw->yuv_format.yuv_range = 0; + break; + default: + // Unsupported color range + abort(); + } +} + +/** + * @brief Set YUV standard + * + * @param[in] hw Hardware instance address + * @param[in] std see `isp_yuv_conv_std_t` + */ +static inline void isp_ll_yuv_set_std(isp_dev_t *hw, isp_yuv_conv_std_t std) +{ + hw->yuv_format.yuv_mode = std; +} + #ifdef __cplusplus } #endif diff --git a/components/hal/include/hal/isp_types.h b/components/hal/include/hal/isp_types.h index ea6ff38a6a..06ee9a4ec4 100644 --- a/components/hal/include/hal/isp_types.h +++ b/components/hal/include/hal/isp_types.h @@ -63,6 +63,22 @@ typedef enum { ISP_COLOR_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), ///< YUV420 } isp_color_t; +/** + * @brief ISP color range + */ +typedef enum { + ISP_COLOR_RANGE_LIMIT = COLOR_RANGE_LIMIT, /*!< Limited color range */ + ISP_COLOR_RANGE_FULL = COLOR_RANGE_FULL, /*!< Full color range */ +} isp_color_range_t; + +/** + * @brief The standard used for conversion between RGB and YUV + */ +typedef enum { + ISP_YUV_CONV_STD_BT601 = COLOR_CONV_STD_RGB_YUV_BT601, /*!< YUV<->RGB conversion standard: BT.601 */ + ISP_YUV_CONV_STD_BT709 = COLOR_CONV_STD_RGB_YUV_BT709, /*!< YUV<->RGB conversion standard: BT.709 */ +} isp_yuv_conv_std_t; + /*--------------------------------------------------------------- AE ---------------------------------------------------------------*/