libcamera: ipa: simple: Initialise the general correction matrix

The combined matrix must be reset to the initial value before each frame
is prepared.  This must be done outside algorithms because any of the
algorithms may be disabled while the matrix must be always initialised.

Let's initialise the combined matrix to the identity matrix (which keeps
the pixel values unchanged) in software ISP just before calling
`prepare' on the algorithms.

Matrix updates can no longer be skipped in ccm.cpp, otherwise the CCM
won't be applied if there is no temperature or saturation change.  We
explicitly track whether the CCM has been set up completely rather than
relying on the frame number, to avoid missing the initialisation in case
the first frame is skipped due to some error.

Reviewed-by: Robert Mader <robert.mader@collabora.com>
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Milan Zamazal
2026-01-28 12:43:53 +01:00
committed by Kieran Bingham
parent 5f3cdafe0f
commit 82ed6c19c2
4 changed files with 17 additions and 18 deletions

View File

@@ -83,7 +83,7 @@ void Ccm::applySaturation(Matrix<float, 3, 3> &ccm, float saturation)
ccm = ycbcr2rgb * saturationMatrix * rgb2ycbcr * ccm;
}
void Ccm::prepare(IPAContext &context, const uint32_t frame,
void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)
{
auto &saturation = context.activeState.knobs.saturation;
@@ -91,24 +91,21 @@ void Ccm::prepare(IPAContext &context, const uint32_t frame,
const unsigned int ct = context.activeState.awb.temperatureK;
/* Change CCM only on saturation or bigger temperature changes. */
if (frame > 0 &&
utils::abs_diff(ct, lastCt_) < kTemperatureThreshold &&
saturation == lastSaturation_) {
frameContext.ccm = context.activeState.ccm;
return;
if (!currentCcm_ ||
utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold ||
saturation != lastSaturation_) {
currentCcm_ = ccm_.getInterpolated(ct);
if (saturation)
applySaturation(currentCcm_.value(), saturation.value());
lastCt_ = ct;
lastSaturation_ = saturation;
context.activeState.matrixChanged = true;
}
lastCt_ = ct;
lastSaturation_ = saturation;
Matrix<float, 3, 3> ccm = ccm_.getInterpolated(ct);
if (saturation)
applySaturation(ccm, saturation.value());
context.activeState.combinedMatrix = ccm;
context.activeState.ccm = ccm;
context.activeState.combinedMatrix =
currentCcm_.value() * context.activeState.combinedMatrix;
frameContext.saturation = saturation;
context.activeState.matrixChanged = true;
frameContext.ccm = ccm;
frameContext.ccm = currentCcm_.value();
}
void Ccm::process([[maybe_unused]] IPAContext &context,