summaryrefslogtreecommitdiff
path: root/src/ipa/rkisp1/algorithms/awb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipa/rkisp1/algorithms/awb.cpp')
-rw-r--r--src/ipa/rkisp1/algorithms/awb.cpp116
1 files changed, 65 insertions, 51 deletions
diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
index a01fe5d9..b6ca27ba 100644
--- a/src/ipa/rkisp1/algorithms/awb.cpp
+++ b/src/ipa/rkisp1/algorithms/awb.cpp
@@ -104,45 +104,34 @@ void Awb::queueRequest(IPAContext &context,
}
}
-/**
- * \copydoc libcamera::ipa::Algorithm::prepare
- */
-void Awb::prepare(IPAContext &context, const uint32_t frame,
- IPAFrameContext &frameContext, rkisp1_params_cfg *params)
+void Awb::prepareAwbGains(IPAFrameContext &frameContext,
+ rkisp1_ext_params_awb_gain_config *awbg)
{
- /*
- * This is the latest time we can read the active state. This is the
- * most up-to-date automatic values we can read.
- */
- if (frameContext.awb.autoEnabled) {
- frameContext.awb.gains.red = context.activeState.awb.gains.automatic.red;
- frameContext.awb.gains.green = context.activeState.awb.gains.automatic.green;
- frameContext.awb.gains.blue = context.activeState.awb.gains.automatic.blue;
- }
-
- params->others.awb_gain_config.gain_green_b = 256 * frameContext.awb.gains.green;
- params->others.awb_gain_config.gain_blue = 256 * frameContext.awb.gains.blue;
- params->others.awb_gain_config.gain_red = 256 * frameContext.awb.gains.red;
- params->others.awb_gain_config.gain_green_r = 256 * frameContext.awb.gains.green;
-
- /* Update the gains. */
- params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AWB_GAIN;
-
- /* If we have already set the AWB measurement parameters, return. */
- if (frame > 0)
- return;
+ awbg->header.type = RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAINS;
+ awbg->header.size = sizeof(rkisp1_ext_params_awb_gain_config);
+ awbg->header.enable = RKISP1_EXT_PARAMS_BLOCK_ENABLE;
+
+ awbg->awb_config.gain_green_b = 256 * frameContext.awb.gains.green;
+ awbg->awb_config.gain_blue = 256 * frameContext.awb.gains.blue;
+ awbg->awb_config.gain_red = 256 * frameContext.awb.gains.red;
+ awbg->awb_config.gain_green_r = 256 * frameContext.awb.gains.green;
+}
- rkisp1_cif_isp_awb_meas_config &awb_config = params->meas.awb_meas_config;
+void Awb::prepareAwbMeas(IPAContext &context,
+ rkisp1_ext_params_awb_meas_config *awbm)
+{
+ awbm->header.type = RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS;
+ awbm->header.size = sizeof(rkisp1_ext_params_awb_meas_config);
+ awbm->header.enable = RKISP1_EXT_PARAMS_BLOCK_ENABLE;
- /* Configure the measure window for AWB. */
- awb_config.awb_wnd = context.configuration.awb.measureWindow;
+ awbm->awb_meas_config.awb_wnd = context.configuration.awb.measureWindow;
/* Number of frames to use to estimate the means (0 means 1 frame). */
- awb_config.frames = 0;
+ awbm->awb_meas_config.frames = 0;
/* Select RGB or YCbCr means measurement. */
if (rgbMode_) {
- awb_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_RGB;
+ awbm->awb_meas_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_RGB;
/*
* For RGB-based measurements, pixels are selected with maximum
@@ -150,19 +139,19 @@ void Awb::prepare(IPAContext &context, const uint32_t frame,
* awb_ref_cr, awb_min_y and awb_ref_cb respectively. The other
* values are not used, set them to 0.
*/
- awb_config.awb_ref_cr = 250;
- awb_config.min_y = 250;
- awb_config.awb_ref_cb = 250;
+ awbm->awb_meas_config.awb_ref_cr = 250;
+ awbm->awb_meas_config.min_y = 250;
+ awbm->awb_meas_config.awb_ref_cb = 250;
- awb_config.max_y = 0;
- awb_config.min_c = 0;
- awb_config.max_csum = 0;
+ awbm->awb_meas_config.max_y = 0;
+ awbm->awb_meas_config.min_c = 0;
+ awbm->awb_meas_config.max_csum = 0;
} else {
- awb_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_YCBCR;
+ awbm->awb_meas_config.awb_mode = RKISP1_CIF_ISP_AWB_MODE_YCBCR;
/* Set the reference Cr and Cb (AWB target) to white. */
- awb_config.awb_ref_cb = 128;
- awb_config.awb_ref_cr = 128;
+ awbm->awb_meas_config.awb_ref_cb = 128;
+ awbm->awb_meas_config.awb_ref_cr = 128;
/*
* Filter out pixels based on luminance and chrominance values.
@@ -170,20 +159,45 @@ void Awb::prepare(IPAContext &context, const uint32_t frame,
* range, while the acceptable chroma values are specified with
* a minimum of 16 and a maximum Cb+Cr sum of 250.
*/
- awb_config.min_y = 16;
- awb_config.max_y = 250;
- awb_config.min_c = 16;
- awb_config.max_csum = 250;
+ awbm->awb_meas_config.min_y = 16;
+ awbm->awb_meas_config.max_y = 250;
+ awbm->awb_meas_config.min_c = 16;
+ awbm->awb_meas_config.max_csum = 250;
}
+}
- /* Enable the AWB gains. */
- params->module_en_update |= RKISP1_CIF_ISP_MODULE_AWB_GAIN;
- params->module_ens |= RKISP1_CIF_ISP_MODULE_AWB_GAIN;
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void Awb::prepare(IPAContext &context, const uint32_t frame,
+ IPAFrameContext &frameContext, rkisp1_ext_params_block_header *hdr)
+{
+ /*
+ * This is the latest time we can read the active state. This is the
+ * most up-to-date automatic values we can read.
+ */
+ if (frameContext.awb.autoEnabled) {
+ frameContext.awb.gains.red = context.activeState.awb.gains.automatic.red;
+ frameContext.awb.gains.green = context.activeState.awb.gains.automatic.green;
+ frameContext.awb.gains.blue = context.activeState.awb.gains.automatic.blue;
+ }
+
+ struct rkisp1_ext_params_awb_gain_config *awbg =
+ reinterpret_cast<rkisp1_ext_params_awb_gain_config *>(hdr);
+
+ prepareAwbGains(frameContext, awbg);
+
+ /* If we have already set the AWB measurement parameters, return. */
+ if (frame > 0)
+ return;
+
+ /* Configure the measure window for AWB. */
+ char *awb_hdr = reinterpret_cast<char *>(hdr);
+ struct rkisp1_ext_params_awb_meas_config *awbm =
+ reinterpret_cast<rkisp1_ext_params_awb_meas_config *>
+ (awb_hdr + sizeof(rkisp1_ext_params_awb_gain_config));
- /* Update the AWB measurement parameters and enable the AWB module. */
- params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_AWB;
- params->module_en_update |= RKISP1_CIF_ISP_MODULE_AWB;
- params->module_ens |= RKISP1_CIF_ISP_MODULE_AWB;
+ prepareAwbMeas(context, awbm);
}
uint32_t Awb::estimateCCT(double red, double green, double blue)