From patchwork Mon Oct 5 15:22:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28401 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 22490BDCB2 for ; Mon, 5 Oct 2026 15:22:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D080C68A44; Mon, 5 Oct 2026 17:22:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B9i1zRca"; dkim-atps=neutral Received: from mail-wr2-x0d.google.com (mail-wr2-x0d.google.com [IPv6:2a00:1450:4864:30::d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 86523689D8 for ; Mon, 5 Oct 2026 17:22:34 +0200 (CEST) Received: by mail-wr2-x0d.google.com with SMTP id ffacd0b85a97d-48b9d8056d2so1079811f8f.1 for ; Mon, 05 Oct 2026 08:22:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791213754; x=1791818554; 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=myQJDyhkkGwVsg9Uds8vju/vlm2dGHvTBhvi0Rvie3U=; b=B9i1zRcaHSn7eTUnzSWWoiqhyTKPpdTUhFfiOnMAqnG9ADzT3NfwXjuvUWFdyhexGZ AyDYDaukQer73+pmQoWDofy7UnDgMU61rwwvqqf+yKwQ3l8Acd4GOGaNBR+/uv3NikWM OS2+1PeiJaO6ll5uio+8kdCvN+KgiY8p2oFlq9lElc7DDeARkgv44ItC7Yfzf1UB/6Uq YPH6K0u14rOIADZnlYy/qHEpYxFj4E+tPc9/xOpHp6XAaitLozXbzYPKN1xYG/+9UiTZ xWPWSI80QFTyPLqVTDlt/fODrKXTkGixNfg7HYpbqoMeXqYNof3gvSBRjf0CVIGEHNDq AZUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791213754; x=1791818554; 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=myQJDyhkkGwVsg9Uds8vju/vlm2dGHvTBhvi0Rvie3U=; b=U2Kw06n65n/O/q1IaswgRNBp54mUhdaoFvmIVbwzmO9ZuXyrutBNf/8Yl3b5LBl000 jYYdU9sLO6Y7MSrATLWkv68MF7sL45qFeUARO9MpwUmbQ48EagxuhWiQFGZLTqNbHLVa zmMxBDfiVZSgn3uoMCB+FILKgoy+iuEhLrRBa/zbvlor5eI9rw5fJcfGZxt6tWMlnpbF IpVMlTizs3GfiyYZyJrkm7oyO/pgPppKEjXz2nbnW7VLaMK4eY14ZMsL8pZFK//NLPk0 H5iSYlvV/Dc7DmrdqPX6b6rvzCpOoNrVqoZQSTQU92yBPS8Idra4n/9W43hxUNxlRqJ4 WNcQ== X-Gm-Message-State: AFq9FYLTTR9zmYx1RyZeMw/PccCsSQMwzHObKTA5a8Lf8G8xy/F90FHM dupWuuDizzGYtXLsbvE6LplYL2vFN7cUEDbf0ZOjBXru2fvjFEereFrgjfIn X-Gm-Gg: AYBFou28b7HBbgPsDatNkpx1VbpeOfSkooEE1c/Zoh+ylOFTRQhlLR57rYOE9UaLGPT ysVTHCh4JwjhuhBCoE53JQ0aFkLl6EUEegG4ORtkgqJq0TO197Xd0xjk4k2eviU1S+BtwEptS4s BZqlInDkd2uJvUIeRDE6iZUeGS8t22HoknyL9Xl6XWnE8sHwDR9mhR8eLQUDBB5GzK2IaJ1R4MP zRgX2mdO/oGlvdMk6wI1kzYFTFhvQRjCnBIMe6jeJRiL6+76l2wCMj0QRgFECio/H74dZ60z+bK kWGWcWtvC51uX7oyElr3TjTwiL31XaOtN4OFZTB4S7DZu6sew/pnif+SD17fH3HkgbvYYfJDXgd GjuxOLQMAQgQIsOGTJ3NFwTwOOzCHL3Zm23+PCZuxEMVKH58JnyALgzV+svoWVzE3UCVpCZPXbB Ak5YsnrUtkPp/r/WNjTw6O2Ii9htYBqRu9X/LeplEdtAgoaqY6zWa0N4rcbXyyv0NL5j42kLfUM qCnwbKUUJNrqMPBzHLWqxHSWeiKkFbDWeF96p9cx+xDvg5n8o0jkP4= X-Received: by 2002:a05:6000:240e:b0:48c:455b:6625 with SMTP id ffacd0b85a97d-48c455b66e9mr15713349f8f.19.1791213753332; Mon, 05 Oct 2026 08:22:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2026 08:22:32 -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 1/2] ipa: libipa: camera_sensor_helper: Add OV5670 black level Date: Mon, 5 Oct 2026 17:22:30 +0200 Message-ID: <20261005152231.2024537-1-dmanresa@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911153918.96470-1-dmanresa@gmail.com> References: <20260911153918.96470-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 OV5670 outputs a data pedestal of 64 at 10 bits. The black level characterisation in the OEM tuning data for a Dell Latitude 7275 camera module measures 64.1 to 64.4 at unity gain over six exposure times, and stays within 62.0 to 64.5 up to a gain of 15.9. Provide it in the camera sensor helper so that IPAs can use it instead of hard-coded or tuning-file values. 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. This patch now introduces the comment already in its final wording. No functional change. src/ipa/libipa/camera_sensor_helper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 82bf255..3589b06 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -802,6 +802,8 @@ class CameraSensorHelperOv5670 : public CameraSensorHelper public: CameraSensorHelperOv5670() { + /* From the OEM black level characterisation: 64 at 10bits. */ + blackLevel_ = 4096; gain_ = AnalogueGainLinear{ 1, 0, 0, 128 }; } }; 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 */