From 7dd713ba2e8bd55f958aa7ded6bc44f68e6cb5e1 Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Wed, 19 Nov 2025 14:22:11 +0100 Subject: [PATCH] ipa: rkisp1: lux: Properly handle frame context and active state With the upcoming regulation rework the processing order in the IPA is updated a bit so that process() updates the active state with new measurements and fills the metadata with the data from the corresponding frame context. In prepare() all parameters for one frame are tied together using the most up to date values from active state. Change the lux algorithm to support that order of events. Also prepare for cases where stats can be null which can happen with the upcoming regulation rework. While at it fix a formatting issue reported by checkstyle and drop a unnecessary local variable. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/lux.cpp | 27 ++++++++++++++++++++++----- src/ipa/rkisp1/algorithms/lux.h | 3 +++ src/ipa/rkisp1/ipa_context.h | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp index e8da6981..e9717bb3 100644 --- a/src/ipa/rkisp1/algorithms/lux.cpp +++ b/src/ipa/rkisp1/algorithms/lux.cpp @@ -46,6 +46,16 @@ int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData return lux_.parseTuningData(tuningData); } +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + [[maybe_unused]] RkISP1Params *params) +{ + frameContext.lux.lux = context.activeState.lux.lux; +} + /** * \copydoc libcamera::ipa::Algorithm::process */ @@ -55,8 +65,17 @@ void Lux::process(IPAContext &context, const rkisp1_stat_buffer *stats, ControlList &metadata) { - utils::Duration exposureTime = context.configuration.sensor.lineDuration - * frameContext.sensor.exposure; + /* + * Report the lux level used by algorithms to prepare this frame + * not the lux level *of* this frame. + */ + metadata.set(controls::Lux, frameContext.lux.lux); + + if (!stats) + return; + + utils::Duration exposureTime = context.configuration.sensor.lineDuration * + frameContext.sensor.exposure; double gain = frameContext.sensor.gain; /* \todo Deduplicate the histogram calculation from AGC */ @@ -64,9 +83,7 @@ void Lux::process(IPAContext &context, Histogram yHist({ params->hist.hist_bins, context.hw.numHistogramBins }, [](uint32_t x) { return x >> 4; }); - double lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist); - frameContext.lux.lux = lux; - metadata.set(controls::Lux, lux); + context.activeState.lux.lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist); } REGISTER_IPA_ALGORITHM(Lux, "Lux") diff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h index 8dcadc28..e0239848 100644 --- a/src/ipa/rkisp1/algorithms/lux.h +++ b/src/ipa/rkisp1/algorithms/lux.h @@ -23,6 +23,9 @@ public: Lux(); int init(IPAContext &context, const YamlObject &tuningData) override; + void prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + RkISP1Params *params) override; void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index f85a130d..b257cee5 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -133,6 +133,10 @@ struct IPAActiveState { double gamma; } goc; + struct { + double lux; + } lux; + struct { controls::WdrModeEnum mode; AgcMeanLuminance::AgcConstraint constraint;