From patchwork Mon Sep 30 08:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21423 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 43C03C0F1B for ; Mon, 30 Sep 2024 08:40:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8A5363512; Mon, 30 Sep 2024 10:40:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FD9GLb5n"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FC0D6350F for ; Mon, 30 Sep 2024 10:40:30 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42f5a663ed5so3907685e9.0 for ; Mon, 30 Sep 2024 01:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727685629; x=1728290429; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kEQT44ygkQycnvCLuOXQchB36OoSxbxMmuyht28SyVg=; b=FD9GLb5nsVBRr7kaUT0G1aNQ042Zy7nkU9ENvsrxHJLx8EKtnpfXNMob445wkvAdjx cKqY5uXlZr8Wpa4WWJ5ob5bGIN4IaTVkndoaSnen9cvttf+l0pkC0WSh7irG9uUOsqss 7BhIxKX1uo4C+b6wqrVOkyYhCZMm0nTs7c02LJKnz0AXA8qt0WS4ry1qep41TwahvhI+ lXdihF89nk8NnwD5jo80g/y/s8Wg6lZ7Qtgmb9uG90RydML0mPT8Nome5Cq67HVKrRlo ELFbrBkA5co+inGF0L7FvZxfcFCN1E289QGsYQgiROcJd11spckNZv+Z2a7aPEN5SW0C jW9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727685629; x=1728290429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kEQT44ygkQycnvCLuOXQchB36OoSxbxMmuyht28SyVg=; b=sbgqIxpbYK8f4fhAtKkr6gKKYXBzq8f7xJTYf4ebRw/uuSh8Ikfym2OCxhp98We7fn xXCp0jomrBp85TNL7M6qP49Ua1boMEJ/FMaDE5J0tnnomEsGCpmCdfISeLuh7+73uXg9 +NYE+WW9AfzMHSzFuIaRlbHXCXYBWE0MMAdVBhL+kzyMm39f0om+NPuyWGgdzarlvD0w xMeZKUXwzUoaFkVpQsd3y+DVX75ro3d5OIDu7AkXTu8YesurewSJmbV8dJV6oBP5ZbDf Fm4V67Hs+2HRPNj4wHSYQWARJaLjLi9w7JQLep+MFc6zl17tkbx15D5pU1Y+W7wJmf3q 2Plg== X-Gm-Message-State: AOJu0YyBgGQx2Qu4EUnlZitEDqFQb4PI0fVrR3PKhwJgqdmmLzWXpLw4 1mFUvlniV0LvQaGE/YJVnpklNW3usg0eVo0pF5CS912qMdlnH6cURCVjPyqc0l7YrM/+y6oDPtV D X-Google-Smtp-Source: AGHT+IEnBYNATANGzp8zFK2GZ2WzNEwt4OwoT+kryoSpHGvk2mecLpGVbLd3A9A7YPLe0RQWGUWO8Q== X-Received: by 2002:a05:600c:3b92:b0:42c:d084:ed69 with SMTP id 5b1f17b1804b1-42f584855f3mr36427615e9.4.1727685629212; Mon, 30 Sep 2024 01:40:29 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm8463421f8f.90.2024.09.30.01.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 01:40:28 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH 1/2] ipa: rpi: awb: Add a const for the default colour temperature Date: Mon, 30 Sep 2024 09:40:39 +0100 Message-Id: <20240930084040.2919-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930084040.2919-1-naush@raspberrypi.com> References: <20240930084040.2919-1-naush@raspberrypi.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A default CT of 4500K is used in a couple of places. Add a constexpr value for the default CT value and use it instead. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- src/ipa/rpi/controller/rpi/awb.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index f45525bce2d1..24f296fc66fa 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -20,6 +20,8 @@ using namespace libcamera; LOG_DEFINE_CATEGORY(RPiAwb) +constexpr double DefaultCT = 4500.0; + #define NAME "rpi.awb" /* @@ -214,7 +216,7 @@ void Awb::initialise() syncResults_.gainB = 1.0 / config_.ctB.eval(syncResults_.temperatureK); } else { /* random values just to stop the world blowing up */ - syncResults_.temperatureK = 4500; + syncResults_.temperatureK = DefaultCT; syncResults_.gainR = syncResults_.gainG = syncResults_.gainB = 1.0; } prevSyncResults_ = syncResults_; @@ -716,7 +718,7 @@ void Awb::awbGrey() sumR += *ri, sumB += *bi; double gainR = sumR.G / (sumR.R + 1), gainB = sumB.G / (sumB.B + 1); - asyncResults_.temperatureK = 4500; /* don't know what it is */ + asyncResults_.temperatureK = DefaultCT; /* don't know what it is */ asyncResults_.gainR = gainR; asyncResults_.gainG = 1.0; asyncResults_.gainB = gainB; From patchwork Mon Sep 30 08:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21424 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 5EF7CC0F1B for ; Mon, 30 Sep 2024 08:40:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE66D6351A; Mon, 30 Sep 2024 10:40:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="XB+MR8Ed"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 57BC06350F for ; Mon, 30 Sep 2024 10:40:31 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-37cde5c2700so81600f8f.1 for ; Mon, 30 Sep 2024 01:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727685631; x=1728290431; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eyOiGQZUubNluqCplMlAYaj328dUjPUH55z+f5YjsEQ=; b=XB+MR8Ed3Xcz6t6zLg7RCW0HKKQblNbul7RCWZmYqZhwWiwY8rzQsTfy5Z2j4z6nlc zx4+RIkFfdZlYQyLfF+pcX3ssMLq3J/mpz6LeZE6TWOjGS2stEuXcm8F9DbWsBb060hs GtKUTNkDRA3FxVnO2Tn2MQRHz/XtcLfP4Zl21z7ICnHbHqm2aucUSROAM6cGU1/KK/CB t3cp3/1BaupoOyt5oBBub9h0ZkmPzKVYHQIB1wDXVr+bcoF4nqF3yZ2ROLc6TCBdUwUq lPv6gm7ahA3bpZT7WcphZSoXrHPbJrCujpXDuASk63pBtsFbtNklU3SpuLXyyFTvdiKL zFkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727685631; x=1728290431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eyOiGQZUubNluqCplMlAYaj328dUjPUH55z+f5YjsEQ=; b=BxIH5qbQpMoHUnY/7QOFYAHCsJUxswD3ej9fmjqNnaSFze5C+IfFe/suKeyMEpYcKF kYUL/lryh6QtmtWfG6RPLcBRLNXCdb8pdAubqDFVqxi3gVAB5uNAXO8wx0/LnkGiyoxz QrppJLiPNI+OAteELlo12nDDuJBJW/ZZHGBETudhuVs8jmZ7IBezeyPOOFzPW3qIU106 X0GqDVgnA7GWVHP1luFxBYUyhPuQCLWOqO2LspBPcvdP4gLS0n6bBJ1HqcVQRNFE84jJ YODeIFYn+2TpmiSlC6WQvxTYnHwdYSL1cEhUdMrd+gUnQ2Jykb6w5+owHKMfuuAXcfgE hUPg== X-Gm-Message-State: AOJu0YzRBZ34nCUCJSED6H/Bv65O60rnRQnTYxo6l7K6xmKO2NcYfJjj ej7fp706DlqEtjrOMpnxt2x8OEouz5fMulFrnMMoqGwqPFaplUZ2BaQMp88GJYsc1isaCX3mMne j X-Google-Smtp-Source: AGHT+IEIoI98WwIOR0gNaqH/3H3T+mWuWaocuN0QxHdgVRBmAzemBLgDjSQbbSnk7VK+aIr7iKlbQQ== X-Received: by 2002:a05:6000:1fab:b0:375:bb30:6525 with SMTP id ffacd0b85a97d-37cd5a616edmr3090003f8f.1.1727685630515; Mon, 30 Sep 2024 01:40:30 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm8463421f8f.90.2024.09.30.01.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 01:40:29 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH 2/2] ipa: rpi: awb: Add a bias to the AWB search Date: Mon, 30 Sep 2024 09:40:40 +0100 Message-Id: <20240930084040.2919-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930084040.2919-1-naush@raspberrypi.com> References: <20240930084040.2919-1-naush@raspberrypi.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In the case of an AWB search failure, the current algorithm logic will return a point on the CT curve closest to where the search finisned. This can be quite undesirable. Instead, add some bias params to the AWB algorithm which will direct the search to a set CT value in the case where statistics become unreliable causing the search to fail. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/rpi/controller/rpi/awb.cpp | 17 +++++++++++++++-- src/ipa/rpi/controller/rpi/awb.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index 24f296fc66fa..8f46dae0a961 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -169,6 +169,8 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) whitepointB = params["whitepoint_b"].get(0.0); if (bayes == false) sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */ + biasProportion = params["bias_proportion"].get(0.0); + biasCT = params["bias_ct"].get(DefaultCT); return 0; } @@ -409,7 +411,8 @@ void Awb::asyncFunc() static void generateStats(std::vector &zones, StatisticsPtr &stats, double minPixels, - double minG, Metadata &globalMetadata) + double minG, Metadata &globalMetadata, + double biasProportion, double biasCtR, double biasCtB) { std::scoped_lock l(globalMetadata); @@ -422,6 +425,14 @@ static void generateStats(std::vector &zones, continue; zone.R = region.val.rSum / region.counted; zone.B = region.val.bSum / region.counted; + /* + * Add some bias samples to allow the search to tend to a + * bias CT in failure cases. + */ + const unsigned int proportion = biasProportion * region.counted; + zone.R += proportion * biasCtR; + zone.B += proportion * biasCtB; + zone.G += proportion * 1.0; /* Factor in the ALSC applied colour shading correction if required. */ const AlscStatus *alscStatus = globalMetadata.getLocked("alsc.status"); if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) { @@ -442,7 +453,9 @@ void Awb::prepareStats() * any LSC compensation. We also ignore config_.fast in this version. */ generateStats(zones_, statistics_, config_.minPixels, - config_.minG, getGlobalMetadata()); + config_.minG, getGlobalMetadata(), + config_.biasProportion, config_.ctR.eval(config_.biasCT), + config_.ctB.eval(config_.biasCT)); /* * apply sensitivities, so values appear to come from our "canonical" * sensor. diff --git a/src/ipa/rpi/controller/rpi/awb.h b/src/ipa/rpi/controller/rpi/awb.h index ab30f4fa51c1..5d628b47c8a6 100644 --- a/src/ipa/rpi/controller/rpi/awb.h +++ b/src/ipa/rpi/controller/rpi/awb.h @@ -87,6 +87,10 @@ struct AwbConfig { double whitepointR; double whitepointB; bool bayes; /* use Bayesian algorithm */ + /* proportion of counted samples to add for the search bias */ + double biasProportion; + /* CT target for the search bias */ + double biasCT; }; class Awb : public AwbAlgorithm