libcamera: software_isp: Reset stored exposure in black level

Automatic black level setting in software ISP updates the determined
black level value when exposure or gain change.  It stores the last
exposure and gain values to detect the change.

BlackLevel::configure() resets the stored black level value but not the
exposure and gain values.  This can prevent updating the black value and
cause bad image output, e.g. after suspending and resuming a camera, if
exposure and gain remain unchanged.

Let's store exposure and gain in IPAActiveState.  Although the values
are not supposed to be used outside BlackLevel class, storing them in
the context has the advantage of their automatic reset together with the
other context contents and having them in `blc' struct indicates their
relationship to the black value computation.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=259
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Tested-by: Robert Mader <robert.mader@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Milan Zamazal 2025-03-19 10:55:33 +01:00 committed by Laurent Pinchart
parent 485a807dcb
commit ceea066fa2
3 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
/* /*
* Copyright (C) 2024, Red Hat Inc. * Copyright (C) 2024-2025, Red Hat Inc.
* *
* Black level handling * Black level handling
*/ */
@ -63,8 +63,8 @@ void BlackLevel::process(IPAContext &context,
if (context.configuration.black.level.has_value()) if (context.configuration.black.level.has_value())
return; return;
if (frameContext.sensor.exposure == exposure_ && if (frameContext.sensor.exposure == context.activeState.blc.lastExposure &&
frameContext.sensor.gain == gain_) { frameContext.sensor.gain == context.activeState.blc.lastGain) {
return; return;
} }
@ -88,8 +88,8 @@ void BlackLevel::process(IPAContext &context,
seen += histogram[i]; seen += histogram[i];
if (seen >= pixelThreshold) { if (seen >= pixelThreshold) {
context.activeState.blc.level = i * histogramRatio; context.activeState.blc.level = i * histogramRatio;
exposure_ = frameContext.sensor.exposure; context.activeState.blc.lastExposure = frameContext.sensor.exposure;
gain_ = frameContext.sensor.gain; context.activeState.blc.lastGain = frameContext.sensor.gain;
LOG(IPASoftBL, Debug) LOG(IPASoftBL, Debug)
<< "Auto-set black level: " << "Auto-set black level: "
<< i << "/" << SwIspStats::kYHistogramSize << i << "/" << SwIspStats::kYHistogramSize

View file

@ -30,8 +30,6 @@ public:
ControlList &metadata) override; ControlList &metadata) override;
private: private:
int32_t exposure_;
double gain_;
std::optional<uint8_t> definedLevel_; std::optional<uint8_t> definedLevel_;
}; };

View file

@ -39,6 +39,8 @@ struct IPASessionConfiguration {
struct IPAActiveState { struct IPAActiveState {
struct { struct {
uint8_t level; uint8_t level;
int32_t lastExposure;
double lastGain;
} blc; } blc;
struct { struct {