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 <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-11-19 14:22:11 +01:00
parent 3b4414ccaa
commit 7dd713ba2e
3 changed files with 29 additions and 5 deletions

View File

@@ -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")

View File

@@ -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,

View File

@@ -133,6 +133,10 @@ struct IPAActiveState {
double gamma;
} goc;
struct {
double lux;
} lux;
struct {
controls::WdrModeEnum mode;
AgcMeanLuminance::AgcConstraint constraint;