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 */