From 4acc8e35cff7548eba9fb1e4be4052d5340a9254 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Fri, 31 May 2024 12:20:34 +0200 Subject: ipa: rkisp1: Use the extensible parameters format Signed-off-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/dpf.cpp | 98 ++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 31 deletions(-) (limited to 'src/ipa/rkisp1/algorithms/dpf.cpp') diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index abf95728..9f24b13b 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -211,46 +211,82 @@ void Dpf::queueRequest(IPAContext &context, frameContext.dpf.update = update; } +void Dpf::prepareDpf(IPAContext &context, rkisp1_ext_params_dpf_config *dpf) +{ + dpf->header.type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF; + dpf->header.size = sizeof(rkisp1_ext_params_dpf_config); + dpf->header.enable = RKISP1_EXT_PARAMS_BLOCK_ENABLE; + + dpf->dpf_config = config_; + + /* + * The DPF needs to take into account the total amount of + * digital gain, which comes from the AWB and LSC modules. The + * DPF hardware can be programmed with a digital gain value + * manually, but can also use the gains supplied by the AWB and + * LSC modules automatically when they are enabled. Use that + * mode of operation as it simplifies control of the DPF. + */ + const auto &awb = context.configuration.awb; + const auto &lsc = context.configuration.lsc; + auto &mode = dpf->dpf_config.gain.mode; + if (awb.enabled && lsc.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS; + else if (awb.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS; + else if (lsc.enabled) + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS; + else + mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED; +} + +void Dpf::prepareDpfStrength(rkisp1_ext_params_dpf_strength_config *dpfs) +{ + dpfs->header.type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH; + dpfs->header.enable = RKISP1_EXT_PARAMS_BLOCK_ENABLE; + dpfs->header.size = sizeof(rkisp1_ext_params_dpf_strength_config); + + dpfs->dpf_strength_config = strengthConfig_; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ void Dpf::prepare(IPAContext &context, const uint32_t frame, - IPAFrameContext &frameContext, rkisp1_params_cfg *params) + IPAFrameContext &frameContext, rkisp1_ext_params_block_header *hdr) { + struct rkisp1_ext_params_dpf_config *dpf = + reinterpret_cast(hdr); + + /* On first frame program both DPF and strenghts. */ if (frame == 0) { - params->others.dpf_config = config_; - params->others.dpf_strength_config = strengthConfig_; - - const auto &awb = context.configuration.awb; - const auto &lsc = context.configuration.lsc; - auto &mode = params->others.dpf_config.gain.mode; - - /* - * The DPF needs to take into account the total amount of - * digital gain, which comes from the AWB and LSC modules. The - * DPF hardware can be programmed with a digital gain value - * manually, but can also use the gains supplied by the AWB and - * LSC modules automatically when they are enabled. Use that - * mode of operation as it simplifies control of the DPF. - */ - if (awb.enabled && lsc.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS; - else if (awb.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS; - else if (lsc.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS; - else - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED; - - params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_DPF | - RKISP1_CIF_ISP_MODULE_DPF_STRENGTH; + + prepareDpf(context, dpf); + + char *dpf_hdr = reinterpret_cast(hdr); + struct rkisp1_ext_params_dpf_strength_config *dpfs = + reinterpret_cast + (dpf_hdr + sizeof(rkisp1_ext_params_dpf_config)); + + prepareDpfStrength(dpfs); + + return; } - if (frameContext.dpf.update) { - params->module_en_update |= RKISP1_CIF_ISP_MODULE_DPF; - if (frameContext.dpf.denoise) - params->module_ens |= RKISP1_CIF_ISP_MODULE_DPF; + /* If no updates, skip the DPF block completely. */ + if (!frameContext.dpf.update) + return; + + /* Re-enable DPF by re-programming it, or disable it. */ + if (frameContext.dpf.denoise) { + prepareDpf(context, dpf); + + return; } + + dpf->header.type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF; + dpf->header.size = sizeof(rkisp1_ext_params_dpf_config); + dpf->header.enable = RKISP1_EXT_PARAMS_BLOCK_DISABLE; } REGISTER_IPA_ALGORITHM(Dpf, "Dpf") -- cgit v1.2.1