Merge branch 'feat/isp_demosaic' into 'master'

isp: demosaic

Closes IDF-10519

See merge request espressif/esp-idf!33111
This commit is contained in:
Armando (Dou Yiwen)
2024-08-29 16:13:27 +08:00
16 changed files with 409 additions and 31 deletions
+86 -1
View File
@@ -1327,6 +1327,91 @@ static inline uint32_t isp_ll_awb_get_accumulated_b_value(isp_dev_t *hw)
return hw->awb0_acc_b.awb0_acc_b;
}
/*---------------------------------------------------------------
Demosaic
---------------------------------------------------------------*/
/**
* @brief Enable / Disable demosaic clock
*
* @param[in] hw Hardware instance address
* @param[in] enable Enable / Disable
*/
static inline void isp_ll_demosaic_clk_enable(isp_dev_t *hw, bool enable)
{
hw->clk_en.clk_demosaic_force_on = enable;
}
/**
* @brief Enable / Disable demosaic
*
* @param[in] hw Hardware instance address
* @param[in] enable Enable / Disable
*/
static inline void isp_ll_demosaic_enable(isp_dev_t *hw, bool enable)
{
hw->cntl.demosaic_en = enable;
}
/**
* @brief Set demosaic low thresh
*
* @param[in] hw Hardware instance address
* @param[in] thresh Thresh
*/
__attribute__((always_inline))
static inline void isp_ll_demosaic_set_grad_ratio(isp_dev_t *hw, isp_demosaic_grad_ratio_t grad_ratio)
{
hw->demosaic_grad_ratio.demosaic_grad_ratio = grad_ratio.val;
}
/**
* @brief Set ISP demosaic padding mode
*
* @param[in] hw Hardware instance address
* @param[in] padding_mode padding mode
*/
__attribute__((always_inline))
static inline void isp_ll_demosaic_set_padding_mode(isp_dev_t *hw, isp_demosaic_edge_padding_mode_t padding_mode)
{
hw->demosaic_matrix_ctrl.demosaic_padding_mode = padding_mode;
}
/**
* @brief Set ISP demosaic padding data
*
* @param[in] hw Hardware instance address
* @param[in] padding_data padding data
*/
__attribute__((always_inline))
static inline void isp_ll_demosaic_set_padding_data(isp_dev_t *hw, uint32_t padding_data)
{
hw->demosaic_matrix_ctrl.demosaic_padding_data = padding_data;
}
/**
* @brief Set ISP demosaic tail start pulse pixel
*
* @param[in] hw Hardware instance address
* @param[in] start_pixel start pixel value
*/
__attribute__((always_inline))
static inline void isp_ll_demosaic_set_padding_line_tail_valid_start_pixel(isp_dev_t *hw, uint32_t start_pixel)
{
hw->demosaic_matrix_ctrl.demosaic_tail_pixen_pulse_tl = start_pixel;
}
/**
* @brief Set ISP demosaic tail pulse end pixel
*
* @param[in] hw Hardware instance address
* @param[in] end_pixel end pixel value
*/
__attribute__((always_inline))
static inline void isp_ll_demosaic_set_padding_line_tail_valid_end_pixel(isp_dev_t *hw, uint32_t end_pixel)
{
hw->demosaic_matrix_ctrl.demosaic_tail_pixen_pulse_th = end_pixel;
}
/*---------------------------------------------------------------
Sharpen
---------------------------------------------------------------*/
@@ -1396,7 +1481,7 @@ static inline void isp_ll_sharp_set_medium_freq_coeff(isp_dev_t *hw, isp_sharpen
* @param[in] coeff coeff
*/
__attribute__((always_inline))
static inline void isp_ll_sharp_set_high_freq_coeff(isp_dev_t *hw, isp_sharpen_h_freq_coeff coeff)
static inline void isp_ll_sharp_set_high_freq_coeff(isp_dev_t *hw, isp_sharpen_h_freq_coeff_t coeff)
{
//val higher than `sharp_threshold_high` will be multiplied by `sharp_amount_high`
hw->sharp_ctrl0.sharp_amount_high = coeff.val;
+27 -1
View File
@@ -33,11 +33,26 @@ typedef struct {
uint8_t padding_line_tail_valid_end_pixel; ///< BF edge padding line tail valid end pixel
} isp_hal_bf_cfg_t;
/**
* @brief Demosaic configurations
*/
typedef struct {
isp_demosaic_grad_ratio_t grad_ratio; /**< Demosaic gradient ratio,
- gradient_x * grad_ratio < gradient_y, use interpolation results in X direction
- gradient_y * grad_ratio < gradient_x, use interpolation results in Y direction
- else use the average results between X and Y
*/
isp_demosaic_edge_padding_mode_t padding_mode; ///< Sharpen edge padding mode
uint8_t padding_data; ///< Sharpen edge padding pixel data
uint8_t padding_line_tail_valid_start_pixel; ///< Sharpen edge padding line tail valid start pixel
uint8_t padding_line_tail_valid_end_pixel; ///< Sharpen edge padding line tail valid end pixel
} isp_hal_demosaic_cfg_t;
/**
* @brief Sharpen configurations
*/
typedef struct {
isp_sharpen_h_freq_coeff h_freq_coeff; ///< High freq pixel sharpeness coeff
isp_sharpen_h_freq_coeff_t h_freq_coeff; ///< High freq pixel sharpeness coeff
isp_sharpen_m_freq_coeff m_freq_coeff; ///< Medium freq pixel sharpeness coeff
uint8_t h_thresh; ///< High threshold, pixel value higher than this threshold will be multiplied by `h_freq_coeff`
uint8_t l_thresh; ///< Low threshold, pixel value higher than this threshold but lower than `h_thresh` will be multiplied by `m_freq_coeff`. Pixel value lower than this threshold will be set to 0
@@ -166,6 +181,17 @@ void isp_hal_bf_config(isp_hal_context_t *hal, isp_hal_bf_cfg_t *config);
*/
bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const float flt_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION]);
/*---------------------------------------------------------------
Demosaic
---------------------------------------------------------------*/
/**
* @brief Configure ISP Demosaic
*
* @param[in] hal Context of the HAL layer
* @param[in] config Demosaic config, set NULL to de-config the ISP Demosaic
*/
void isp_hal_demosaic_config(isp_hal_context_t *hal, isp_hal_demosaic_cfg_t *config);
/*---------------------------------------------------------------
INTR
---------------------------------------------------------------*/
+34 -1
View File
@@ -161,6 +161,39 @@ typedef enum {
#define ISP_CCM_DIMENSION 0 ///< Not support CCM
#endif
/*---------------------------------------------------------------
Demosaic
---------------------------------------------------------------*/
#if SOC_ISP_DEMOSAIC_SUPPORTED
#define ISP_DEMOSAIC_GRAD_RATIO_INT_BITS SOC_ISP_DEMOSAIC_GRAD_RATIO_INT_BITS
#define ISP_DEMOSAIC_GRAD_RATIO_DEC_BITS SOC_ISP_DEMOSAIC_GRAD_RATIO_DEC_BITS
#define ISP_DEMOSAIC_GRAD_RATIO_RES_BITS SOC_ISP_DEMOSAIC_GRAD_RATIO_RES_BITS
#else
#define ISP_DEMOSAIC_GRAD_RATIO_INT_BITS 8
#define ISP_DEMOSAIC_GRAD_RATIO_DEC_BITS 8
#define ISP_DEMOSAIC_GRAD_RATIO_RES_BITS 16
#endif
/**
* @brief Gradient ratio
*/
typedef union {
struct {
uint32_t decimal:ISP_DEMOSAIC_GRAD_RATIO_DEC_BITS; ///< Integer part
uint32_t integer:ISP_DEMOSAIC_GRAD_RATIO_INT_BITS; ///< Decimal part
uint32_t reserved:ISP_DEMOSAIC_GRAD_RATIO_RES_BITS; ///< Reserved
};
uint32_t val; ///< 32-bit gradient ratio value
} isp_demosaic_grad_ratio_t;
/**
* @brief ISP Demosaic edge padding mode
*/
typedef enum {
ISP_DEMOSAIC_EDGE_PADDING_MODE_SRND_DATA, ///< Fill Demosaic edge padding data with surrounding pixel data
ISP_DEMOSAIC_EDGE_PADDING_MODE_CUSTOM_DATA, ///< Fill Demosaic edge padding data with custom pixel data
} isp_demosaic_edge_padding_mode_t;
/*---------------------------------------------------------------
DVP
---------------------------------------------------------------*/
@@ -203,7 +236,7 @@ typedef union {
uint32_t reserved:ISP_SHARPEN_H_FREQ_COEF_RES_BITS; ///< Reserved
};
uint32_t val; ///< 32-bit high freq pixel sharpeness coeff register value
} isp_sharpen_h_freq_coeff;
} isp_sharpen_h_freq_coeff_t;
/**
* @brief Medium freq pixel sharpeness coeff
+22 -1
View File
@@ -168,6 +168,27 @@ bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const
return true;
}
/*---------------------------------------------------------------
Demosaic
---------------------------------------------------------------*/
void isp_hal_demosaic_config(isp_hal_context_t *hal, isp_hal_demosaic_cfg_t *config)
{
if (config) {
isp_ll_demosaic_set_grad_ratio(hal->hw, config->grad_ratio);
isp_ll_demosaic_set_padding_mode(hal->hw, config->padding_mode);
isp_ll_demosaic_set_padding_data(hal->hw, config->padding_data);
isp_ll_demosaic_set_padding_line_tail_valid_start_pixel(hal->hw, config->padding_line_tail_valid_start_pixel);
isp_ll_demosaic_set_padding_line_tail_valid_end_pixel(hal->hw, config->padding_line_tail_valid_end_pixel);
} else {
isp_demosaic_grad_ratio_t grad_ratio = {};
isp_ll_demosaic_set_grad_ratio(hal->hw, grad_ratio);
isp_ll_demosaic_set_padding_mode(hal->hw, 0);
isp_ll_demosaic_set_padding_data(hal->hw, 0);
isp_ll_demosaic_set_padding_line_tail_valid_start_pixel(hal->hw, 0);
isp_ll_demosaic_set_padding_line_tail_valid_end_pixel(hal->hw, 0);
}
}
/*---------------------------------------------------------------
Histogram
---------------------------------------------------------------*/
@@ -202,7 +223,7 @@ void isp_hal_sharpen_config(isp_hal_context_t *hal, isp_hal_sharpen_cfg_t *confi
isp_ll_sharp_set_low_thresh(hal->hw, 0);
isp_ll_sharp_set_high_thresh(hal->hw, 0);
isp_sharpen_m_freq_coeff m_freq = {};
isp_sharpen_h_freq_coeff h_freq = {};
isp_sharpen_h_freq_coeff_t h_freq = {};
isp_ll_sharp_set_medium_freq_coeff(hal->hw, m_freq);
isp_ll_sharp_set_high_freq_coeff(hal->hw, h_freq);
isp_ll_sharp_set_padding_mode(hal->hw, 0);