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;