From 70e2fd6dff3a4257fb2a94442e62ea0b5b5bd8c1 Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Wed, 8 Mar 2023 15:01:22 +0100 Subject: ipa: rkisp1: lsc: Enable/disable LSC algorithm Implement LSC algorithm enable/disable by parsing the "LensShadingEnable" control in queueRequest(). Start with the LSC algorithm enabled by default and disable it on application request. The 'lsc' filed in the context configuration could also be removed but other algorithms inspect it. Do not remove it for now. Signed-off-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/lsc.cpp | 54 ++++++++++++++++++++++++++++++++++++++- src/ipa/rkisp1/algorithms/lsc.h | 4 +++ src/ipa/rkisp1/ipa_context.h | 5 ++++ src/ipa/rkisp1/rkisp1.cpp | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index a7ccedb1..0c9f6cbd 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "libcamera/internal/yaml_parser.h" #include "linux/rkisp1-config.h" @@ -147,6 +149,8 @@ int LensShadingCorrection::init([[maybe_unused]] IPAContext &context, return -EINVAL; } + context.configuration.lsc.enabled = false; + return 0; } @@ -181,10 +185,20 @@ int LensShadingCorrection::configure(IPAContext &context, yGrad_[i] = std::round(32768 / ySizes_[i]); } - context.configuration.lsc.enabled = true; + /* Enable LSC on first run unless explicitly disabled by application. */ + context.activeState.lsc.enable = true; + context.activeState.lsc.active = false; + return 0; } +void LensShadingCorrection::disableLSC(rkisp1_params_cfg *params) +{ + params->module_en_update |= RKISP1_CIF_ISP_MODULE_LSC; + params->module_ens &= ~RKISP1_CIF_ISP_MODULE_LSC; + params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_LSC; +} + void LensShadingCorrection::setParameters(rkisp1_params_cfg *params) { struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config; @@ -242,6 +256,25 @@ void LensShadingCorrection::interpolateTable(rkisp1_cif_isp_lsc_config &config, } } +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void LensShadingCorrection::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + const ControlList &controls) +{ + auto lsc = &context.activeState.lsc; + + const auto lscEnable = controls.get(controls::LensShadingEnable); + if (lscEnable && *lscEnable != lsc->enable) { + LOG(RkISP1Lsc, Debug) + << (*lscEnable ? "Enabling" : "Disabling") << " LSC"; + + lsc->enable = *lscEnable; + } +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ @@ -250,6 +283,25 @@ void LensShadingCorrection::prepare(IPAContext &context, [[maybe_unused]] IPAFrameContext &frameContext, rkisp1_params_cfg *params) { + auto lsc = &context.activeState.lsc; + + if (lsc->enable != lsc->active) { + /* If LSC has to be disabled, disable it and return here. */ + if (!lsc->enable) { + disableLSC(params); + lsc->active = false; + context.configuration.lsc.enabled = false; + return; + } + + lsc->active = true; + context.configuration.lsc.enabled = true; + } + + /* Nothing more to do here if LSC is not active. */ + if (!lsc->active) + return; + struct rkisp1_cif_isp_lsc_config &config = params->others.lsc_config; /* diff --git a/src/ipa/rkisp1/algorithms/lsc.h b/src/ipa/rkisp1/algorithms/lsc.h index e2a93a56..4708065b 100644 --- a/src/ipa/rkisp1/algorithms/lsc.h +++ b/src/ipa/rkisp1/algorithms/lsc.h @@ -23,6 +23,9 @@ public: int init(IPAContext &context, const YamlObject &tuningData) override; int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override; + void queueRequest(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, rkisp1_params_cfg *params) override; @@ -36,6 +39,7 @@ private: std::vector b; }; + void disableLSC(rkisp1_params_cfg *params); void setParameters(rkisp1_params_cfg *params); void copyTable(rkisp1_cif_isp_lsc_config &config, const Components &set0); void interpolateTable(rkisp1_cif_isp_lsc_config &config, diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index b9b20653..ada99527 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -98,6 +98,11 @@ struct IPAActiveState { uint8_t denoise; uint8_t sharpness; } filter; + + struct { + bool enable; + bool active; + } lsc; }; struct IPAFrameContext : public FrameContext { diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index aa73b7db..da931cf2 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -106,6 +106,7 @@ const ControlInfoMap::Map rkisp1Controls{ { &controls::Saturation, ControlInfo(0.0f, 1.993f, 1.0f) }, { &controls::Sharpness, ControlInfo(0.0f, 10.0f, 1.0f) }, { &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }, + { &controls::LensShadingEnable, ControlInfo(false, true) }, }; } /* namespace */ -- cgit v1.2.1