From patchwork Fri Sep 4 06:28:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28190 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 0FD34C3257 for ; Fri, 4 Sep 2026 06:28:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6774D685FC; Fri, 4 Sep 2026 08:28:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Cf1PAdMV"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 774DC683E4 for ; Fri, 4 Sep 2026 08:28:39 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-482dbe4d247so332129f8f.2 for ; Thu, 03 Sep 2026 23:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788503319; x=1789108119; 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:content-type; bh=Rg4JMzp0rRen5Ckv65Vpc9TlQI1+yzIsrgxNF9kuQv0=; b=Cf1PAdMVpcz7BdOqSclQ6V/VGdB6RkJ4ldoqHNUX2R2rtb7I8KmQvsfks7D5QYdJTY fTI8uPtQiD1/LyzDkabg4JWrW4r3yi/gcpR9IsY1quZvDU8V4J4RnBighwW2mfU6/hlr Nbu+RXa6BTupXPRwzhAc6FgfI8BfuWnZPwYmXUb8qyuyxGCEY+WDg2XzDo0r7VrmDjLk DQsvBPLDkhsjhTOnBhFqUNimklM+3gELaeyXzey/uLUeGAWSEMf8PXClSvr7ier5pKmN B+Z12eloB8uGik/5YEmhxeHJnD86rplVZYO+x7coBQm6YfPiEV+QI+PH06Xpxc1cc3N1 0cFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788503319; x=1789108119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Rg4JMzp0rRen5Ckv65Vpc9TlQI1+yzIsrgxNF9kuQv0=; b=jSzbOYS8KrIoPSYS11VfgyjOWyEq8XPux1HzDObU4HbLzI8+8yMG89gt6MyxJBE3MO jCrIXwSWBpBAPariASbfHs/5dwMRwnD1MLwR8K5dQB/PsjAD5p3SpSOQSH0qaiRRSHub XdexzeTDUC41qT6IqykSQh5Yj/l2pbaKiqC1weXiPIRAG36VInSkFHqppmrg/vhHeRMo RI7+GNQT+OoYeU0SZE//l0cRzqWs5sRCNjgXwdnJbA2blPYJnu13V3aCapylQlwPnVj6 tCbjQcdM9YuBlruG6E3BXyE4Tg1Vkg9lenaAGi7S30AKPAFJ4mFD9XrxFg6yhfHlN/vu a2Xg== X-Gm-Message-State: AFuF++n4C19chCBpmPl6lX1HCynL8c7XbsFWx9VF+CT3KCTUIuPcBKGu Th6K58ZQPlxfiaJ0D/ax0MnZI/KtuZBC+j8qtCtLsMdkyG71PRu0NF7JCF5O1bpJxQ== X-Gm-Gg: AYBFou2ivHAN7sBlaxmiacIB/+4nyys1JaoONjQDwyRoMPhWmn6xmQfhKa/0OPEshgN 73mF/tmcSEBdZMcPO21r2pcwOe2/ZnCwpBeKfaUKfwGa+BdArNBFjWYUIUWunAmA6t+L48Rdgur rbq5lMRC942yFiF/VK4OJd3CTuJljmOK7kHqD6NwkiX5jqrvxkumrvmEskzqgUvQ4W5duaY5hMJ 74kD05TC28BbPWngIq9mRBeGI5vuCP+kwWF8V6iHbOOJufMlWga8BfVzry0NKxxgF2cSgfVYk9J Noeiq7uwq1ePtPU8mSfkpDYO0YoHjwUOI14gGIkIR1R+Oe9m4zgI0igeWPQwYhrj1fClUsPc/CT BIUjnAzSTM6rax8bYbbOoUf+f+OAB2OA05fHWDxSNTIfMCVNLweaImd0TLSO2JY/WbV4Ias33jM hIWzJPims4s24uDlM0kkn20wgWUYVi+P2FwGKluerQv5JYKdH2/MmkUx8vwI+0MKlCmnYgtY6J2 zou74U7Pwyuskhhyse2ZICM+nGvNvu9KtoFuQupOqDoN1TI X-Received: by 2002:a05:600c:6306:b0:49c:f5c0:aa76 with SMTP id 5b1f17b1804b1-49cf81e366amr68425315e9.5.1788503318828; Thu, 03 Sep 2026 23:28:38 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5f9114sm125681225e9.5.2026.09.03.23.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 23:28:38 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: "D. Manresa" Subject: [PATCH 1/3] ipa: ipu3: agc: Fix swapped green and blue gains in luminance estimate Date: Fri, 4 Sep 2026 08:28:38 +0200 Message-ID: <20260904062840.46739-2-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904062840.46739-1-dmanresa@gmail.com> References: <20260904062840.46739-1-dmanresa@gmail.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" The AWB gains passed to the AGC traits are built as { red, blue, green }, but the RGB vector expects { red, green, blue }. The luminance estimate therefore weights the blue statistics with the green gain and the green statistics with the blue gain, which biases the exposure whenever the two gains differ (on an OV5670 they are 1.0 and ~1.8). Pass the gains in RGB order. Signed-off-by: D. Manresa Reviewed-by: Daniel Scally --- src/ipa/ipu3/algorithms/agc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 57cfb32..dd4f1ab 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -224,8 +224,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, rgbTriples_, {{ context.activeState.awb.gains.red, - context.activeState.awb.gains.blue, context.activeState.awb.gains.green, + context.activeState.awb.gains.blue, }}, bdsGrid_, }, From patchwork Fri Sep 4 06:28:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28191 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 E7597C3257 for ; Fri, 4 Sep 2026 06:28:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26A33685F8; Fri, 4 Sep 2026 08:28:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="M6op6erg"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D3CBC685E2 for ; Fri, 4 Sep 2026 08:28:40 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-49b392ccaacso9981375e9.2 for ; Thu, 03 Sep 2026 23:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788503320; x=1789108120; 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:content-type; bh=zBwVM6jXgTpWe7fJBlMfvM38mylUgKIGI6iFGQ4ZW9w=; b=M6op6erg6BXwilSsP0l4VYfFyf9Q7tsPcq7AMO+zKMmMM4HaryvhuQz8Mf6Y1OBuaw s2XxZ8z1vTse8h3PwuTzaTW/fiZVaPVYefN8UpGT4zZCzz/wwM3JAt8jtLfOpum8LNyp 2GZRTFH7b0hN1m55RZcK2wDBeRVWmi9NieI2oInGESK5/we0kun+iDIhPXz51Xy1GDNi WYCmIBfaiSuF77iM/2bLmuMCi/2EVtVExTS3Tv8/iW6D2Gu+ggvvJaVoCkzAGsAZYCwY Ij8rLmCauk8XeZyYWe7uOSsEaxZC4I7anF9AaiRJxQBb/5hs59Y04QSy4Y7iFOHsv04l P55w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788503320; x=1789108120; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zBwVM6jXgTpWe7fJBlMfvM38mylUgKIGI6iFGQ4ZW9w=; b=C6H6Su2/JMzCBmBbHZE/7uDk/XnaG3KWVnCk6+94yR9gprGx3yafreHAjs4YoywV9X mYmky+Utsg3Ya+4e66q8UdEbpnkMYfZKvaZ0Bm7PoiGe0FuFV3L0whv4W/SLgnETWO5V ayNrVzZ3kW3ZRDuujhyU5f9QidP0T8m+0q/BFE9Ylnimg6f1qnqO5pS8cO5MOAJ9CdfS /Mb223jyVHww1RG1SNmOkmsU/AfDjA1/uQqnum/IKsU0HKAv/a3Lk/PnKhX436fC2DTI Yuw4DFpsHyY4i+S2T7chYvjjdLl6kc/H5E+zqdk5O1uV3euZq//Ew9QLA/nLCbb3RTS/ Tssw== X-Gm-Message-State: AFuF++nIdVag7xzyqhoKugn4e3XF/kcEpuQwrJpPPm94rM3L5Z/Bzhza N90ZTutPMtOiHZ8kOh6j6EIEaoR0kd4tEEOA7xvsB4+NeiCBChPj4zlHDlVppAeRgw== X-Gm-Gg: AYBFou0LmAUYCfIi5KMstxF6UJHQaZG+5D19PtRB9ab4IUfmIqefTYJKS+Z7kkGvttJ /lbmF9WnIapQt+t0VcRSx69cJO+b6vFzp+E0KwnlrVezmVAOpGbuhFiYx8TfZKP1xeAICqDJwOn 9aoPx7Hl9r5tJWcttABWevMMsi2h+oq73421BXB5kDWzGPZ4X9BtzlHkK+vIyROFrSqYQayfw6m cbo1fpPgBzMq4bw/G73Q1mnxf1Y0OtaV5GQC8dx7nmRtL8twHSphbfW9Z5yHO/lExuza5dDy9gf KLqGUA6D3VbahuX10TxqjoC4gSo0CEuAYcKO+nGL+Je4IpdBmxGy2o1yFPKuYvGoMsRoDBPR4sF ogZ+gIY0ye0qNTikplW3sV4Spfff2mk7WnVdWedp+avyP+XBFQ3KW2DjQPe6Ejkd3f2fV4yJqm2 gWCCzfaBtJkVXaBsypDbfpsznRIBD8zghu3YyhNGFoZg/6BYmUVE4Xbot8nYJn7Lm72neWK88i2 9/VyBLsvJOUCsI2kavtyHZzraSfcLArhqpjqGCCVfYiOzJ4w2x4K1NP6OLr X-Received: by 2002:a05:600d:113:b0:49c:d618:e341 with SMTP id 5b1f17b1804b1-49cf827b19cmr20090865e9.14.1788503319761; Thu, 03 Sep 2026 23:28:39 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5f9114sm125681225e9.5.2026.09.03.23.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 23:28:39 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: "D. Manresa" Subject: [PATCH 2/3] ipa: ipu3: blc: Make the black level configurable Date: Fri, 4 Sep 2026 08:28:39 +0200 Message-ID: <20260904062840.46739-3-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904062840.46739-1-dmanresa@gmail.com> References: <20260904062840.46739-1-dmanresa@gmail.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" The black level correction algorithm hard-codes an optical black level of 64 for the four Bayer channels. Measurements on a Dell Latitude 7275 (OV5670, 10-bit black level 64) show that the ImgU obgrid unit is half a 10-bit LSB: with 64 the AWB statistics and the image keep a residual pedestal of about 9/255 (colour ratios of dark neutral zones drift towards 1.0, and a dark frame reads 7-8), which the colour gains then amplify into a blue or cyan cast. With 128 the pedestal is gone, and with 192 dark zones clip to zero. Add an optional 'blackLevel' tuning parameter, keeping 64 as the default so that existing tuning files behave as before. Signed-off-by: D. Manresa --- src/ipa/ipu3/algorithms/blc.cpp | 42 +++++++++++++++++++++++++++++---- src/ipa/ipu3/algorithms/blc.h | 5 ++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/ipa/ipu3/algorithms/blc.cpp b/src/ipa/ipu3/algorithms/blc.cpp index 35748fb..7d04702 100644 --- a/src/ipa/ipu3/algorithms/blc.cpp +++ b/src/ipa/ipu3/algorithms/blc.cpp @@ -7,6 +7,10 @@ #include "blc.h" +#include + +#include "libcamera/internal/value_node.h" + /** * \file blc.h * \brief IPU3 Black Level Correction control @@ -30,8 +34,38 @@ namespace ipa::ipu3::algorithms { * isn't currently supported. */ +LOG_DEFINE_CATEGORY(IPU3Blc) + +/* + * Default optical black level. This matches the OV5670 sensor black level + * when interpreted as the ImgU obgrid unit (see init()). + */ +static constexpr int16_t kDefaultBlackLevel = 64; + BlackLevelCorrection::BlackLevelCorrection() + : blackLevel_(kDefaultBlackLevel) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + * + * The optional \a blackLevel tuning parameter sets the optical black level + * subtracted by the ImgU for the four Bayer channels. The ImgU obgrid unit + * has been measured to be half a 10-bit LSB: with a value of 64 an OV5670 + * (black level 64 in 10-bit) keeps a residual pedestal of ~9/255 in the + * AWB statistics and in the image, which the colour gains then amplify; + * with 128 the pedestal disappears. The default is kept at 64 for + * compatibility with existing tuning files. + */ +int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context, + const ValueNode &tuningData) { + blackLevel_ = tuningData["blackLevel"].get().value_or(kDefaultBlackLevel); + + LOG(IPU3Blc, Debug) << "Black level " << blackLevel_; + + return 0; } /** @@ -54,10 +88,10 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, * \todo The correction values should come from sensor specific * tuning processes. This is a first rough approximation. */ - params->obgrid_param.gr = 64; - params->obgrid_param.r = 64; - params->obgrid_param.b = 64; - params->obgrid_param.gb = 64; + params->obgrid_param.gr = blackLevel_; + params->obgrid_param.r = blackLevel_; + params->obgrid_param.b = blackLevel_; + params->obgrid_param.gb = blackLevel_; /* Enable the custom black level correction processing */ params->use.obgrid = 1; diff --git a/src/ipa/ipu3/algorithms/blc.h b/src/ipa/ipu3/algorithms/blc.h index 6274804..58cdd92 100644 --- a/src/ipa/ipu3/algorithms/blc.h +++ b/src/ipa/ipu3/algorithms/blc.h @@ -18,9 +18,14 @@ class BlackLevelCorrection : public Algorithm public: BlackLevelCorrection(); + int init(IPAContext &context, const ValueNode &tuningData) override; + void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; + +private: + int16_t blackLevel_; }; } /* namespace ipa::ipu3::algorithms */ From patchwork Fri Sep 4 06:28:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28192 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 D29A6C334D for ; Fri, 4 Sep 2026 06:28:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E7B168602; Fri, 4 Sep 2026 08:28:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aIW0BDzk"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 56A34685FB for ; Fri, 4 Sep 2026 08:28:41 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-49a97714f5dso5060815e9.0 for ; Thu, 03 Sep 2026 23:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788503321; x=1789108121; 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:content-type; bh=vbuBEL+Sm45XiPnBHi31ELtmCqDk9FNm6xvNeLZclvk=; b=aIW0BDzkJmFrXnviQvmtv2/n6GCHFgrUe6WPqDgQVDnQJ/U++7FBYQItflbSYLBUMl 1hhMBHRtZSm0/ymyD6MlYM3UCNC/N4nc7f2NJ5BUO4m6jfSwHhM35+LZvG1EP1XAp+eU UNEyPtYi76GjWHdj8SRGed20CbTqUnHKvN9aYNQke7suqpoGEvmKKN2jXdIptTpuO0aF l175D/AlC7KYrY75jULuMt9ARfkiAiavLy2z97daf6cWqvdReVYf6X7u34crG1G6r4LQ mtsDak9liHUS/O3WDzFRnNx2r+lla2NM9Lj4XimruEJQuMbjnHuIskUDIPj73ANICgzb WIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788503321; x=1789108121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vbuBEL+Sm45XiPnBHi31ELtmCqDk9FNm6xvNeLZclvk=; b=BbzbfxlqLBB0xatGGm6aB+DWQlrciskAUBttij/dCn3C+KIv68+YXvNaoS2DAyP9w2 csenzXv6ZtPmt2SXPvsRmLncx/Vbnj1cbP31jt3Ke5m+vncX9DLXxkEumO6FSbmuKD3K UtrCj8FrP9Zrb5GpVlkfWmzpACeN9vQjhtZ+ksSH7bR2OuOr6yXJNEQkT4irouUd3qIb iC3wAgeZwJfyKs/pOdSFrSr82ANjoXNP81VdkL016z70rHlKojJdaLwgVZVue75zys4a kzGu5+sWGBfSgztPApq0qFo7bXA5E8LQss8F5GCNpi6R1TQ+ycx8P72w1Gh3EzQkjE2H 3DbQ== X-Gm-Message-State: AFuF++nVUHSkfb5yNdfFq/hXgfRlWiIIVp2Cf5jOTkzw9ofIizdAqdIr ewSGrS6Ro9OvKNfNoBc5U1tnWL6r3dnFQW+k3KdJv+PqJ5ZeOjXyBhJYl7+FeLHCiA== X-Gm-Gg: AYBFou0COoXyFydMqZpZWRM9ZaYXZuFnD8k4FB2UqeNav3SZnh9l15ExOQhYRBj6ezx 930KxuwFXgot8jzYsfNHNrnidqPt6ubydjFYCUR+RylR/K5lI/4M3GkzSoCEi4pl4ObyKZ1qlAU v8R9VRERjbSb19Ktea2Gqokkee0nOCqVIhjNU06D2St8cdg3nyYVEkn9THn7L5t1Iw3zPdydhnp dp4azMzFjW9EngFwKnP1465fNkDSrFzU+j/3KKuGxKWsv6AqQzPOhZsvKH1HnxoM4AdYfPaMyVv 2/MswXCNn2WNGM4L7k5q5ZkPVoep40+CNWknaHIk5eml76waRJurDzi68sOwHY9S4jWv1Ybu0bO CCZpS501xZaDCOLjtGRL7hUuFSQ7PSugHtuPPVe5eo9oWG10XJUkKlwoumaqn5u8zWeQcYwFjcp pDAWbIZkXT/VF4iHopaMINDTbrpAaSJcGtBdA+Qzxdz3CIeEiD22HpdPomIPRdaImNSnchhgQmT 5c6i3s5amrUfkOkyFXaYHBQWSucsAQhhbJ9UKwE3GxMo1f5 X-Received: by 2002:a05:600c:a087:b0:49c:fa20:cc07 with SMTP id 5b1f17b1804b1-49cfa20ccc6mr16723225e9.30.1788503320510; Thu, 03 Sep 2026 23:28:40 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5f9114sm125681225e9.5.2026.09.03.23.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 23:28:40 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: "D. Manresa" Subject: [PATCH 3/3] ipa: ipu3: tone_mapping: Make the gamma configurable Date: Fri, 4 Sep 2026 08:28:40 +0200 Message-ID: <20260904062840.46739-4-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904062840.46739-1-dmanresa@gmail.com> References: <20260904062840.46739-1-dmanresa@gmail.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" The tone mapping algorithm hard-codes a gamma of 1.1, which produces an almost linear output and dark mid-tones for a display-referred consumer. Add an optional 'gamma' tuning parameter, keeping 1.1 as the default. While at it, document an observation made on a Dell Latitude 7275 with the IPU3 firmware currently distributed for Linux: in the video pipe the LUT contents are ignored and a fixed curve is applied whenever the gamma block is programmed (gammas of 0.5, 1.1 and 3.0 produce identical output), while leaving the block unprogrammed results in a linear ramp. Signed-off-by: D. Manresa --- src/ipa/ipu3/algorithms/tone_mapping.cpp | 37 +++++++++++++++++++++++- src/ipa/ipu3/algorithms/tone_mapping.h | 3 ++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/tone_mapping.cpp b/src/ipa/ipu3/algorithms/tone_mapping.cpp index 160338c..160b015 100644 --- a/src/ipa/ipu3/algorithms/tone_mapping.cpp +++ b/src/ipa/ipu3/algorithms/tone_mapping.cpp @@ -7,9 +7,14 @@ #include "tone_mapping.h" +#include #include #include +#include + +#include "libcamera/internal/value_node.h" + /** * \file tone_mapping.h */ @@ -26,9 +31,39 @@ namespace ipa::ipu3::algorithms { * generated based on a gamma parameter. */ +LOG_DEFINE_CATEGORY(IPU3ToneMapping) + +/* Historical default, kept for existing tuning files. */ +static constexpr double kDefaultGamma = 1.1; + ToneMapping::ToneMapping() - : gamma_(1.0) + : gamma_(1.0), tunedGamma_(kDefaultGamma) +{ +} + +/** + * \copydoc libcamera::ipa::Algorithm::init + * + * The optional \a gamma tuning parameter sets the exponent of the encoding + * curve programmed in the ImgU gamma correction LUT, output = input^(1/gamma). + * The default is 1.1. + * + * Note that on the IPU3 firmware currently distributed for Linux + * (irci_irci_ecr-master_20161208_0213_20170112_1500) the video pipe applies + * a fixed curve when the gamma block is programmed and ignores the LUT + * contents: values of 0.5, 1.1 and 3.0 produce identical output, while not + * programming the block yields a linear ramp. The parameter is still useful + * to document the intent and for firmware that honours the LUT. + */ +int ToneMapping::init([[maybe_unused]] IPAContext &context, + const ValueNode &tuningData) { + tunedGamma_ = std::clamp(tuningData["gamma"].get().value_or(kDefaultGamma), + 0.5, 4.0); + + LOG(IPU3ToneMapping, Debug) << "Gamma " << tunedGamma_; + + return 0; } /** diff --git a/src/ipa/ipu3/algorithms/tone_mapping.h b/src/ipa/ipu3/algorithms/tone_mapping.h index b2b3801..6c12867 100644 --- a/src/ipa/ipu3/algorithms/tone_mapping.h +++ b/src/ipa/ipu3/algorithms/tone_mapping.h @@ -18,6 +18,8 @@ class ToneMapping : public Algorithm public: ToneMapping(); + int init(IPAContext &context, const ValueNode &tuningData) override; + int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override; @@ -28,6 +30,7 @@ public: private: double gamma_; + double tunedGamma_; }; } /* namespace ipa::ipu3::algorithms */