From patchwork Mon Oct 5 15:22:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28402 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 DA45CC3305 for ; Mon, 5 Oct 2026 15:22:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F4E468A7A; Mon, 5 Oct 2026 17:22:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="emhrw45h"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 15B9868A3F for ; Mon, 5 Oct 2026 17:22:35 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-48b9d8055dfso1598485f8f.3 for ; Mon, 05 Oct 2026 08:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791213755; x=1791818555; darn=lists.libcamera.org; h=content-transfer-encoding:content-type: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=Q3NHScSWtUUr7qBbtgxXtfmAAyuDRDzPxoiY0RNx/hU=; b=emhrw45hWaSxCyE9iyZOlMda7Btuoxh9GZCQzPR+3QAYPz9bttl0grnswZiZktWkD1 gfpAAr+PD2Z+m+alCMJRy4TYTIudDJVDx+v86HMQ4FKXCtCxFkEykGxPZx9I8i1LE3ny m3ZExDjfPD+2zgn3rmGsmcvDw9bqNN9bAoM0KP3689t+XF2A5cnNry8MogPhlx37xBqk bOaYd4qpPHJayKn7eeQo8oJTzEMIALFVGGzzFFBog3vY/DVU/Bn+psQmYNDiQSJW64XN 3Qd1MeEJXp3B1jRjcYZKy2uK01uGAhUjNdO2x9HCwSWN2kymJWV98W+Bh8Pf8dg2UfYn Tplg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791213755; x=1791818555; h=content-transfer-encoding:content-type: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=Q3NHScSWtUUr7qBbtgxXtfmAAyuDRDzPxoiY0RNx/hU=; b=kQ1I3feqIv76/EWpx7oTLa0/0zG90rkljoOQSjWCP5HXBOU38k6tA5bixwNyAABA+s /Tk4HQ1su8aDKshLIShYOUMD9/1M/hr8emwHLIfHYRvIhcYu9K+gdeTdr5AoectU8yse U0/+R4G7ZN51BW64AIosZeUsVAvDVv/jf8FkVLI4ivN4Gm8lLFdRPseiZ4IvB0laXe2f qCcbAn5Maj1QQNFZI6NPqfFE6vNbgoA4gtObCHSdvcfy9+4UxG5CRJ7rjvL3BR8V6N6G ZX8zoWZF4mXO3Q0W7HkziUkJyEW7d1xgUkpmCjKvdH0IVKcxtqfBPYz/rN7dCRqaWlMr WlFw== X-Gm-Message-State: AFq9FYK3LvLuYIBH9/Cz9yu/oti5TxPwME8PcQRg3UVo/xxmJu1EvHGY yYA/J3rmLQLKUEF4oY79HGn8jBYiMKWmgAuydSYIYHVRUbvz7vVnVQODnLUC X-Gm-Gg: AYBFou0+gZdpw6UT35X7/fYqm5FvL8d85PCrVRwiDn4L5M+gyciFKq0NGR3GaRSkHkM L7F5TffkcsJ2ArdaQ55q/09hpjA2CQm4nLsNW/q/B040l5wkPFzGpUTyE88ZQf+2JmvzDhIghbY aD2uPO3oLW8MNUd9WP3mXKu074CJvm1kqsXUzNtIJVrmkxAhNdJHza0feB8MjmhULxxvkl0XLv3 A9D3zjbF7sxsuRpvFQkSbX+6gPeDP41VWm6P3mEyh4CBN92zY2YquejPcF5lzAWqMi1LL1Etxof KNfpGLX6Jbc0D6xWrzwYejpCv9uJ51CYHnvc+luFWbQhj3EMtIT2ihT2NKkyY1X0N1lFvxTL4lp /lfv/xn1SXoOtOCWyqONB03A6IU239AOIj+jn0j8E+EEymPD7YuzUcH7EfCsD5mq7wXbxZSZNRb exA+uFBLhL/x4EgCTbzlnc2CyS/Njpe6dHfWRufJcSKn7SXwl/BXiL3iB48tvVX/X9f50NSrQxa ZEaMGr9KjNi6Rpqzg9uxOk5CcNWXpQRca8kkv0GSWuOb/Lw3U33tUM= X-Received: by 2002:a05:6000:230a:b0:48b:848:3a48 with SMTP id ffacd0b85a97d-48c4801ac5emr16011373f8f.46.1791213754313; Mon, 05 Oct 2026 08:22:34 -0700 (PDT) Received: from surface.. (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c622ab7b5sm4707591f8f.37.2026.10.05.08.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2026 08:22:33 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , Laurent Pinchart , Daniel Scally , "D . Manresa" Subject: [PATCH v5 2/2] ipa: ipu3: blc: Use the black level from the camera sensor helper Date: Mon, 5 Oct 2026 17:22:31 +0200 Message-ID: <20261005152231.2024537-2-dmanresa@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261005152231.2024537-1-dmanresa@gmail.com> References: <20260911153918.96470-1-dmanresa@gmail.com> <20261005152231.2024537-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. Take it from the camera sensor helper instead, like the RkISP1 IPA does, falling back to the historical value with a warning when the helper does not provide one. Signed-off-by: D. Manresa --- Written with the assistance of an AI tool (Claude). libcamera has no trailer for this and checkstyle.py rejects unknown trailer keys, so it is noted here rather than in the commit message. v5: move the camera_sensor_helper comment to 1/2, per Barnabás Pőcze's review of v4 2/2. The src/ipa/libipa/camera_sensor_helper.cpp hunk is gone from this patch. No functional change. src/ipa/ipu3/algorithms/blc.cpp | 53 +++++++++++++++++++++++++++------ src/ipa/ipu3/algorithms/blc.h | 5 ++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/ipa/ipu3/algorithms/blc.cpp b/src/ipa/ipu3/algorithms/blc.cpp index 35748fb..65ee822 100644 --- a/src/ipa/ipu3/algorithms/blc.cpp +++ b/src/ipa/ipu3/algorithms/blc.cpp @@ -7,6 +7,10 @@ #include "blc.h" +#include + +#include "libipa/camera_sensor_helper.h" + /** * \file blc.h * \brief IPU3 Black Level Correction control @@ -30,10 +34,45 @@ namespace ipa::ipu3::algorithms { * isn't currently supported. */ +LOG_DEFINE_CATEGORY(IPU3Blc) + +/* Historical value, used when the camera sensor helper has no black level. */ +static constexpr uint16_t kDefaultBlackLevel = 64; + BlackLevelCorrection::BlackLevelCorrection() + : blackLevel_(kDefaultBlackLevel) { } +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int BlackLevelCorrection::init(IPAContext &context, + [[maybe_unused]] const ValueNode &tuningData) +{ + std::optional blackLevel = context.camHelper->blackLevel(); + if (!blackLevel) { + LOG(IPU3Blc, Warning) + << "No black level provided by camera sensor helper" + << ", please fix"; + blackLevel_ = kDefaultBlackLevel; + } else { + /* + * CameraSensorHelper reports the black level as a 16-bit + * value, while experimentation has shown that the ImgU OB grid + * expects it in units of half a 10-bit pixel value: to cancel a + * data pedestal of 16 the ISP has to be configured with 32, and + * to cancel a pedestal of 64 with 128. The 16-bit value is + * therefore shifted right by 5. + */ + blackLevel_ = *blackLevel >> 5; + } + + LOG(IPU3Blc, Debug) << "Black level " << blackLevel_; + + return 0; +} + /** * \brief Fill in the parameter structure, and enable black level correction * \param[in] context The shared IPA context @@ -49,15 +88,11 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] IPAFrameContext &frameContext, ipu3_uapi_params *params) { - /* - * The Optical Black Level correction values - * \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; + /* The Optical Black Level correction values */ + 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..bef756f 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: + uint16_t blackLevel_; }; } /* namespace ipa::ipu3::algorithms */