From 4c131dfa5cebd96f413cfe490a899ba10796e95f Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Fri, 18 Oct 2024 18:06:31 +0200 Subject: ipa: rkisp1: algorithms: awb: Check for correct stats type Sometimes the ISP produces statistics only with a subset of statistic types being valid. It doesn't happen normally, but was observed in the wild. Check for the RKISP1_CIF_ISP_STAT_AWB bit to prevent using invalid or outdated data. As it doesn't happen regularly add an error message to get notified when it happens. For simpler code structure, the ColourTemperature metadata entry gets written unconditionally and overwritten later if needed. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/awb.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 955a9ff4..b3c00bef 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -215,6 +215,12 @@ void Awb::process(IPAContext &context, static_cast(frameContext.awb.gains.red), static_cast(frameContext.awb.gains.blue) }); + metadata.set(controls::ColourTemperature, activeState.awb.temperatureK); + + if (!stats || !(stats->meas_type & RKISP1_CIF_ISP_STAT_AWB)) { + LOG(RkISP1Awb, Error) << "AWB data is missing in statistics"; + return; + } if (rgbMode_) { greenMean = awb->awb_mean[0].mean_y_or_g; @@ -270,10 +276,8 @@ void Awb::process(IPAContext &context, * meaningfully calculate gains. Freeze the algorithm in that case. */ if (redMean < kMeanMinThreshold && greenMean < kMeanMinThreshold && - blueMean < kMeanMinThreshold) { - metadata.set(controls::ColourTemperature, activeState.awb.temperatureK); + blueMean < kMeanMinThreshold) return; - } activeState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean); -- cgit v1.2.1