From patchwork Thu Sep 8 01:41:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17340 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EA956C3272 for ; Thu, 8 Sep 2022 01:43:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A3D4362113; Thu, 8 Sep 2022 03:43:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662601383; bh=FPQ0oy+GR46vpCePLbhpjzaqSYBF4YKVAzLdR6O5vcA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rctIiXFSwaOrFbOSjblLonQvvj4xw8pkqsJkSVJYLg7GOBB6+vo5DdCAApyAED+F7 CP8A6nE/Yd+U+UrfIvDNLaYShLJN0A95Ng/npkkg3ipvHz9SJAZUkG1R0nc9mcKKGx 3FPqcBlYWcroQpnNsy83sRSSNSIs+9axZtuebOKmFgEltRVyUJbYe5Maxe9Zfv11xK M20YIHqjf7SYJJN68WnvmqVY3CoN9YPZ8nJ5e2QtuIdTQDdo2qm3DfV+eVw7zvR7ze qYwrTPXMnod7HXPYNzbHddwhH8KVUzQfx+GDp/8SuLRuOM49ai0FK7k/htyVOhEAVU 81H22TeltA1uQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E85562101 for ; Thu, 8 Sep 2022 03:43:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CU0RXV67"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EB2A76CC for ; Thu, 8 Sep 2022 03:43:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662601381; bh=FPQ0oy+GR46vpCePLbhpjzaqSYBF4YKVAzLdR6O5vcA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CU0RXV67jyAwHZBzCrBB+/K/rECokn55n0uqW/7cVtwwH28lwyGzuRmV9Lz6lQC4P 26SuzaAW8Ggu5QowqQ1PsVyV1cpDGr8n0vne92bnogmUgV/ziM87C9SFQ9gsxoyx3d 5rW/0vyHGNfadAcnAQix8rrZTOt61KjVwrD4qaMA= To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Sep 2022 04:41:59 +0300 Message-Id: <20220908014200.28728-32-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> References: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 31/32] ipa: rkisp1: awb: Freeze AWB when means are too small X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the RGB means are too small, gains and color temperature can't be meaningfully calculated. Freeze the AWB in that case, using the previously calculated values. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/awb.cpp | 17 ++++++++++++++++- src/ipa/rkisp1/ipa_context.cpp | 3 +++ src/ipa/rkisp1/ipa_context.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 5f2535688c93..404ad66e6953 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -31,6 +31,9 @@ namespace ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Awb) +/* Minimum mean value below which AWB can't operate. */ +constexpr double kMeanMinThreshold = 2.0; + Awb::Awb() : rgbMode_(false) { @@ -263,7 +266,17 @@ void Awb::process(IPAContext &context, greenMean /= frameContext.awb.gains.green; blueMean /= frameContext.awb.gains.blue; - frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean); + /* + * If the means are too small we don't have enough information to + * meaningfully calculate gains. Freeze the algorithm in that case. + */ + if (redMean < kMeanMinThreshold && greenMean < kMeanMinThreshold && + blueMean < kMeanMinThreshold) { + frameContext.awb.temperatureK = activeState.awb.temperatureK; + return; + } + + activeState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean); /* * Estimate the red and blue gains to apply in a grey world. The green @@ -290,6 +303,8 @@ void Awb::process(IPAContext &context, activeState.awb.gains.automatic.blue = blueGain; activeState.awb.gains.automatic.green = 1.0; + frameContext.awb.temperatureK = activeState.awb.temperatureK; + LOG(RkISP1Awb, Debug) << std::showpoint << "Means [" << redMean << ", " << greenMean << ", " << blueMean << "], gains [" << activeState.awb.gains.automatic.red << ", " diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp index 335cb32c538d..9cac05bec79b 100644 --- a/src/ipa/rkisp1/ipa_context.cpp +++ b/src/ipa/rkisp1/ipa_context.cpp @@ -156,6 +156,9 @@ namespace libcamera::ipa::rkisp1 { * \var IPAActiveState::awb.gains.automatic.blue * \brief Automatic white balance gain for B channel * + * \var IPAActiveState::awb.temperatureK + * \brief Estimated color temperature + * * \var IPAActiveState::awb.autoEnabled * \brief Whether the Auto White Balance algorithm is enabled */ diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 53787320e565..d0bc9090a8f1 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -68,6 +68,7 @@ struct IPAActiveState { } automatic; } gains; + unsigned int temperatureK; bool autoEnabled; } awb;