From patchwork Thu Jan 9 11:54:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22497 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 3E4E8C32EA for ; Thu, 9 Jan 2025 11:55:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CCB136854E; Thu, 9 Jan 2025 12:55:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ksFaXMYv"; 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 2C0C36854B for ; Thu, 9 Jan 2025 12:55:32 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:93b9:eca8:897d:eae6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 898A65B3; Thu, 9 Jan 2025 12:54:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1736423678; bh=/DuFEHPaZsM3vdI7ESRF992+IXEEYo800VfIGt5f5Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ksFaXMYvqm15PIQLKVNSiSsKkb4Uir5+1Z1Bp2JnPV7RV8v1x6BSc6INn5A56WtFr uvHGa3VpgfI19t0yui2aCWkMkkRIO34Lww6XJPEFdSbZOf4XoEEUVSvYczo+8xdxMT /R4zqrdks5+Eg4hGWOnivd2K0fcIs0tQTB6aV+OM= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 10/11] ipa: rkisp1: Add support for bayes AWB algorithm from libipa Date: Thu, 9 Jan 2025 12:54:01 +0100 Message-ID: <20250109115412.356768-11-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250109115412.356768-1-stefan.klug@ideasonboard.com> References: <20250109115412.356768-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" Now that libipa contains a bayes AWB algorithm, add it as supported algorithm to the rkisp1 ipa. The decision between the grey world algorithm and the bayesian is done based on the "algorithm" property of the "Awb" algorithm in the tuning file. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder --- Todo: The lux level is currently hardcoded to 1000. The result from the lux estimation needs to be used here. --- src/ipa/rkisp1/algorithms/awb.cpp | 44 ++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 42a4784998bc..39a2c0589943 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -16,6 +16,7 @@ #include +#include "libipa/awb_bayes.h" #include "libipa/awb_grey.h" #include "libipa/colours.h" @@ -45,13 +46,23 @@ class RkISP1AwbStats : public AwbStats { public: RkISP1AwbStats(const RGB &rgbMeans) - : rgbMeans_(rgbMeans) {} + : rgbMeans_(rgbMeans) + { + rg_ = rgbMeans_.r() / rgbMeans_.g(); + bg_ = rgbMeans_.b() / rgbMeans_.g(); + } - double computeColourError([[maybe_unused]] const RGB &gains) const override + double computeColourError(const RGB &gains) const override { - LOG(RkISP1Awb, Error) - << "RkISP1AwbStats::computeColourError is not implemented"; - return 0.0; + /* + * Compute the sum of the squared colour error (non-greyness) as it + * appears in the log likelihood equation. + */ + double deltaR = gains.r() * rg_ - 1.0; + double deltaB = gains.b() * bg_ - 1.0; + double delta2 = deltaR * deltaR + deltaB * deltaB; + + return delta2; } RGB getRGBMeans() const override @@ -61,6 +72,8 @@ public: private: RGB rgbMeans_; + double rg_; + double bg_; }; Awb::Awb() @@ -78,13 +91,30 @@ int Awb::init(IPAContext &context, const YamlObject &tuningData) kMaxColourTemperature, kDefaultColourTemperature); - awbAlgo_ = std::make_unique(); + if (!tuningData.contains("algorithm")) + LOG(RkISP1Awb, Info) << "No awb algorithm specified." + << " Default to grey world"; + + auto mode = tuningData["algorithm"].get("grey"); + if (mode == "grey") { + awbAlgo_ = std::make_unique(); + } else if (mode == "bayes") { + awbAlgo_ = std::make_unique(); + } else { + LOG(RkISP1Awb, Error) << "Unknown awb algorithm: " << mode; + return -EINVAL; + } + LOG(RkISP1Awb, Debug) << "Using awb algorithm: " << mode; + int ret = awbAlgo_->init(tuningData); if (ret) { LOG(RkISP1Awb, Error) << "Failed to init awb algorithm"; return ret; } + const auto &src = awbAlgo_->controls(); + cmap.insert(src.begin(), src.end()); + return 0; } @@ -131,6 +161,8 @@ void Awb::queueRequest(IPAContext &context, << (*awbEnable ? "Enabling" : "Disabling") << " AWB"; } + awbAlgo_->handleControls(controls); + frameContext.awb.autoEnabled = awb.autoEnabled; if (awb.autoEnabled)