libcamera: software_isp: Initialize exposure+gain before agc calculations

On my setup, since commit fb8ad13d ("libcamera: software_isp: Move exposure+gain
to an algorithm module"), at start camera output stays very dark for dozen
of seconds, and then later slowly gets to normal. This is because existing
sensor exposure+gain settings are not used at start. We save initial
values in frameContext but in the agc algorithm we use IPA context.

Fix the problem by using in frameContext sensor values, since we already
use those in blc algorithm and change exposure type to int32_t to
unnecessary castings.

Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Tested-by: Robert Mader <robert.mader@collabora.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stanislaw Gruszka 2024-10-29 12:25:00 +01:00 committed by Kieran Bingham
parent 8e0e6886f7
commit bb1aa92eb9
5 changed files with 9 additions and 9 deletions

View file

@ -39,7 +39,7 @@ Agc::Agc()
{ {
} }
void Agc::updateExposure(IPAContext &context, double exposureMSV) void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, double exposureMSV)
{ {
/* /*
* kExpDenominator of 10 gives ~10% increment/decrement; * kExpDenominator of 10 gives ~10% increment/decrement;
@ -50,8 +50,8 @@ void Agc::updateExposure(IPAContext &context, double exposureMSV)
static constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1; static constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1;
double next; double next;
int32_t &exposure = context.activeState.agc.exposure; int32_t &exposure = frameContext.sensor.exposure;
double &again = context.activeState.agc.again; double &again = frameContext.sensor.gain;
if (exposureMSV < kExposureOptimal - kExposureSatisfactory) { if (exposureMSV < kExposureOptimal - kExposureSatisfactory) {
next = exposure * kExpNumeratorUp / kExpDenominator; next = exposure * kExpNumeratorUp / kExpDenominator;
@ -129,7 +129,7 @@ void Agc::process(IPAContext &context,
} }
float exposureMSV = (denom == 0 ? 0 : static_cast<float>(num) / denom); float exposureMSV = (denom == 0 ? 0 : static_cast<float>(num) / denom);
updateExposure(context, exposureMSV); updateExposure(context, frameContext, exposureMSV);
} }
REGISTER_IPA_ALGORITHM(Agc, "Agc") REGISTER_IPA_ALGORITHM(Agc, "Agc")

View file

@ -25,7 +25,7 @@ public:
ControlList &metadata) override; ControlList &metadata) override;
private: private:
void updateExposure(IPAContext &context, double exposureMSV); void updateExposure(IPAContext &context, IPAFrameContext &frameContext, double exposureMSV);
}; };
} /* namespace ipa::soft::algorithms */ } /* namespace ipa::soft::algorithms */

View file

@ -27,7 +27,7 @@ public:
ControlList &metadata) override; ControlList &metadata) override;
private: private:
uint32_t exposure_; int32_t exposure_;
double gain_; double gain_;
}; };

View file

@ -53,7 +53,7 @@ struct IPAActiveState {
struct IPAFrameContext : public FrameContext { struct IPAFrameContext : public FrameContext {
struct { struct {
uint32_t exposure; int32_t exposure;
double gain; double gain;
} sensor; } sensor;
}; };

View file

@ -310,8 +310,8 @@ void IPASoftSimple::processStats(const uint32_t frame,
ControlList ctrls(sensorInfoMap_); ControlList ctrls(sensorInfoMap_);
auto &againNew = context_.activeState.agc.again; auto &againNew = frameContext.sensor.gain;
ctrls.set(V4L2_CID_EXPOSURE, context_.activeState.agc.exposure); ctrls.set(V4L2_CID_EXPOSURE, frameContext.sensor.exposure);
ctrls.set(V4L2_CID_ANALOGUE_GAIN, ctrls.set(V4L2_CID_ANALOGUE_GAIN,
static_cast<int32_t>(camHelper_ ? camHelper_->gainCode(againNew) : againNew)); static_cast<int32_t>(camHelper_ ? camHelper_->gainCode(againNew) : againNew));