From patchwork Tue Aug 13 08:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 20896 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 3F06FC32A9 for ; Tue, 13 Aug 2024 08:45:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4921633C0; Tue, 13 Aug 2024 10:45:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WHSO9KC9"; dkim-atps=neutral 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 AFA57633B5 for ; Tue, 13 Aug 2024 10:45:11 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:7025:8d00:1ffd:751a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4C8A2827; Tue, 13 Aug 2024 10:44:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723538654; bh=/KOBVKAao58HbFs5enY7FFTibZIebIgtD3qfN8Dq52s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHSO9KC9z7Th48Z/Of+bL3/AbCk4kVIDyT8mOZhfPNQjaGeUxf1RksHwgQwv/BIDx hwpfhtImCDCOyR+M/3TfpUsCzyDxU8E5TViGIalYlQSOVfTsdDkAAljLUD7fUqJV71 1PbCE+PETr9sQ7LtwbE47p+cRpn7ktwk/WTCFeBk= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v4 3/6] ipa: rkisp1: awb: Implement ColourTemperature control Date: Tue, 13 Aug 2024 10:44:20 +0200 Message-ID: <20240813084451.44099-4-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813084451.44099-1-stefan.klug@ideasonboard.com> References: <20240813084451.44099-1-stefan.klug@ideasonboard.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" There are many use-cases (tuning-validation, working in static environments) where a manual ColourTemperature control is helpful. Implement that by interpolating and applying the white balance gains from the tuning file according to the requested colour temperature. If colour gains are provided on the same request, they take precedence. As the colour temperature reported in the metadata is always based on the measurements, we don't have to touch that. Note that in the automatic case, the colour gains are still based on the gray world model and the ones from the tuning file get ignored. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder --- src/ipa/rkisp1/algorithms/awb.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index c23f749c192b..d482eda5b541 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -31,6 +31,10 @@ namespace ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Awb) +constexpr int32_t kMinColourTemperature = 2500; +constexpr int32_t kMaxColourTemperature = 10000; +constexpr int32_t kDefaultColourTemperature = 6500; + /* Minimum mean value below which AWB can't operate. */ constexpr double kMeanMinThreshold = 2.0; @@ -42,8 +46,13 @@ Awb::Awb() /** * \copydoc libcamera::ipa::Algorithm::init */ -int Awb::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData) +int Awb::init(IPAContext &context, const YamlObject &tuningData) { + auto &cmap = context.ctrlMap; + cmap[&controls::ColourTemperature] = ControlInfo(kMinColourTemperature, + kMaxColourTemperature, + kDefaultColourTemperature); + MatrixInterpolator gains; int ret = gains.readYaml(tuningData["gains"], "ct", "gains"); if (ret < 0) @@ -113,6 +122,17 @@ void Awb::queueRequest(IPAContext &context, << ", blue: " << awb.gains.manual.blue; } + const auto &colourTemperature = controls.get(controls::ColourTemperature); + if (colourTemperature && !awb.autoEnabled && gains_ && !colourGains) { + Matrix gains = gains_->get(*colourTemperature); + awb.gains.manual.red = gains[0][0]; + awb.gains.manual.blue = gains[1][0]; + + LOG(RkISP1Awb, Debug) + << "Set colour gains to red: " << awb.gains.manual.red + << ", blue: " << awb.gains.manual.blue; + } + frameContext.awb.autoEnabled = awb.autoEnabled; if (!awb.autoEnabled) {