From patchwork Fri Sep 11 15:39:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28232 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 18807C3352 for ; Fri, 11 Sep 2026 15:39:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 831F468678; Fri, 11 Sep 2026 17:39:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="a2cNqwaS"; dkim-atps=neutral Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E41968643 for ; Fri, 11 Sep 2026 17:39:04 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-495437bb891so5211405e9.1 for ; Fri, 11 Sep 2026 08:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789141143; x=1789745943; 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=XNXMcyspmux818VLtqPgFj0iz0r6K4vaSIAs+CfWaBw=; b=a2cNqwaSxs+jbXny3ZLj+mwCtMHg2ZWVO+2RrRq8S2n+HImZObM8rVI8MLIRMaMOKu C+nqmQRicUB/ePVnGUKjPngxQ253Zk7TX0ZaGPTNjyV4w1aoFJWjBx9bzh+mnmB8qCSC JDco3mfsCyVKru9XgOzH0SQ49XwLpRuvE6fE3uYuo0yss5mSiMQ9LLXp59TYIruAqMxy zDNbfzpS5RU9IQB8tMT+JIZF+0a7K0C1PN8CjBhfqYUBhAq8+wryqEQ0qQ7qBbYIlcSU QeNzwzlhjmtuCR+G2aLN5+EN575cwzM/ojqjnweS59eTCZFrJVrginRuu0ja5WyHze/n nTVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789141143; x=1789745943; 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=XNXMcyspmux818VLtqPgFj0iz0r6K4vaSIAs+CfWaBw=; b=CqauTlO+3ayj6BTjSaleyC7InqindTzrHaK0NJwsPv/UHvyi77ff6iQxwcGL8EvFQN GpG09Ckpf5bF+I5gD3cedDQ4PP6FTHbrApb8xPWd1v0wnti6zfBEfo/+IpzenBAgO5f7 Apeg62aRbjqwM1UB5+g7Nl4jpVQAcxfwLI3SZ9/1iZKXA7iCL5HBsPuYa7cLw7mQjeTK 3h7dPKYgIS6vfqd6NRsDlInxS2m3yBrWznk3Ux37/BEcQ5y4jPNkeyhC0PdrMnnxak1c hrXadPRkVtUCNWY8XqZ0A+vJkuYcBHcrVEQVHYV+pUOT+0MRpX/sA6Qnpn7X10lsOxgM Ca1Q== X-Gm-Message-State: AFuF++kG2uqY4abplJWbg3asCbiijzxAc0h8jNIlX+DXYhomGWKlGktr xdxqkZ5N3N9SmeVWxI3IAmxx0hqCsUtzCSGRAUWWQ8su1h4Zm4wahjwCqH6kLHI= X-Gm-Gg: AYBFou1CNMbKO7ZVE+D7nKkMAyedd7S3xvCwtbFbd0MW3dXy7aYpjW/ICE9s4c/hgxl lTAwiUmWS+aHBj2KeyR16sP8bx7BWhZJsMt5enDFKEr52z2uIm5+40B18Q8dQM05kE0Yko4SAwl yLBuWWtPMCiA0Jbb8rt928WuWf55qWwG3MIJyy0ZGsfPcOna+33iGEpuzTi1O1e3LO6CJ5e06TX Jy+HLB8fNCGFOOxWjsRvIZST75S3IK6GZgvFKeUe0w3iOXJxAtTnhe9TWLSF0wrHGppQh6oIbbA HlbXysHnnPBkAs9BDQkVz+fCdtuqhNnhLSONw40TjvqhL3D4DtNmauQpH324UqMIc3+eOJkX6lp tRYDHpX/CBCDeeS1kE8OCz8+JrBjTc4LMntBJDdFejnQaSTStIQvOxoYquJ7m3CfqqvKJf6ujgr 1MEIcw8nYO0LUhdAoJtJNOaXzW5w4ioEi+pBf1BZXSjmR3eN7Iq7C9z/DoAL9kmyeAnMh3kvMaB aFMNmmAyetwZ5G+T9+fHwJwOddtbcDzysnqwBbEV4TViSrIQ3HaYjcrtSgX+VWFmbnZXQ== X-Received: by 2002:a05:600d:4445:10b0:49d:28fc:d6a0 with SMTP id 5b1f17b1804b1-49d28fcd72fmr93444385e9.18.1789141143363; Fri, 11 Sep 2026 08:39:03 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-486eb33ee5csm6851570f8f.20.2026.09.11.08.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 08:39:02 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart , Daniel Scally Subject: [PATCH v4 1/2] ipa: libipa: camera_sensor_helper: Add OV5670 black level Date: Fri, 11 Sep 2026 17:39:17 +0200 Message-ID: <20260911153918.96470-2-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911153918.96470-1-dmanresa@gmail.com> References: <20260910172120.73148-1-dmanresa@gmail.com> <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 --- 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..eeb3277 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() { + /* Default BLC target of 64 at 10bits, confirmed by measurement. */ + blackLevel_ = 4096; gain_ = AnalogueGainLinear{ 1, 0, 0, 128 }; } }; From patchwork Fri Sep 11 15:39:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "D. Manresa" X-Patchwork-Id: 28233 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 DB7D3C3353 for ; Fri, 11 Sep 2026 15:39:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A50C66867B; Fri, 11 Sep 2026 17:39:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pj/efjJt"; dkim-atps=neutral Received: from mail-wr2-x10.google.com (mail-wr2-x10.google.com [IPv6:2a00:1450:4864:30::10]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C531568674 for ; Fri, 11 Sep 2026 17:39:05 +0200 (CEST) Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-4834977ae75so606158f8f.3 for ; Fri, 11 Sep 2026 08:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789141145; x=1789745945; 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=xby0CBtbTkWw5dZFHcUB/DGISVPExz1AZ6fUVMDfY10=; b=pj/efjJtkcYG+Kp73KYOYMGHZEiSpd2DHfsacs8ByFNb9Z6QU7gxXkAUdOh9IimX3e XMDkHB/7hyqtlnpfG8q+nCHsksxRPdstTqeDpPLudo8OD9smU20ouxMflPjpoBddc3+X zX5hiij0bi07cRTtFk3Nyg2qha9WFsOr2VhgCxcd2/R9FT6ychfXLHyg28Jue1tzSnj8 jRGxjKU7noNZaVwHZwxgRbDf625OhknexraTgcI4bCeDTKrpnMvnDhc1WQlx9YbES1tT 4xMgkm6EX4NQgVku0RDvLlIoaei6PuhdEZdKbC2nXRYcCWdvcuYd8ClPmwVvLTIXx1zS oLjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789141145; x=1789745945; 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=xby0CBtbTkWw5dZFHcUB/DGISVPExz1AZ6fUVMDfY10=; b=B8L/Ze0SBMd9x/A6CRPKB7Eo+TJK+JVTOyPqWlLzet/OAvbBAZYMHf4BU18etyDhbh bAz7VUt1TtQADWispAnkoZpdQZgKsxbSHUxXD+CiEo8C44VHWyLZVck7twjeCfgM12qV hy5eRXLUNPs3dljG7eSeCli0qEZTiP3EiT8rWGsjr3Kuy4XOi/zV99K6IuRAapHkBgOA dMNumQBcRoTFL940B7ZZtvuzq6l+J8IsvOh1RplM4NvNbm7k0j82ZXG/eC3dKS4i3/c3 XHXcHNthvMNOToY2F7GMSrt47XGXnfAoDQacuJDtZZnOID29Jd8G1jKWntGY4MEapccV 7S8Q== X-Gm-Message-State: AFuF++mvEKxtB8fLw39j2jQQqwD0jvwlyOd0GVVdgI9JgXnz1wX3aPRc +TyJgbx2OLoH/F05MMI1b2SnhCTXRsXmgIwyWc8xWyg7nPm14iiyugoVLTt/92I= X-Gm-Gg: AYBFou2jpQdYnLzJ/iU7bpuhscT9TL8Uhv7+5iCgam37//a4uRFo7hEajnh3zpuCTwL bOQcH7G86xWHLSxoE1FP04D87SM64J5j+Le+sinmaZabQsTqW4YVtzij5gFf5deyhvpDmBy/XfL kXyRK8E5Lt8DbxpawKMHB8TBpdMivEzMM4o2L4y72RL/NAzB0t9awJuacX4+DjEPoyTr0MsEpKM CW+nPKBv/R8mzFJTZyF4camr+n457apPvLpp/xnpqQ3dAxrH61uFMn88Ev/fj1eoJbu5HFA7I2W 9axR3kixWsApqtjF3MnShpQfHMi81b0D5nAVKFlQW8Mte7WTBPpAes2Sm+wcsrKzqjSjK5lzP1Z IXcsmzbnVPku1Ir1iPYIFJ7arYSKellndKDV/A9FkxXISnzkmrMBTT1FFSEU892KQFNNdmzBI/I BeGKO6HpQD4Cqq8LcRrxSiVrJEGD0SkSTXMUn8lKKX+yN78sRXMhP32K1sQzHCI9RAOcoDAorKJ h7OXX9qb7k4IGicHEocDrT+cmTSST4PjVVidZRdOXmHOUNBwU8F4PlRG/U= X-Received: by 2002:a05:6000:4a01:b0:486:e726:bb30 with SMTP id ffacd0b85a97d-486eb2d722bmr12229939f8f.8.1789141144851; Fri, 11 Sep 2026 08:39:04 -0700 (PDT) Received: from latitude7275 (84.124.213.91.dyn.user.ono.com. [84.124.213.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-486eb33ee5csm6851570f8f.20.2026.09.11.08.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 08:39:03 -0700 (PDT) From: "D. Manresa" To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart , Daniel Scally Subject: [PATCH v4 2/2] ipa: ipu3: blc: Use the black level from the camera sensor helper Date: Fri, 11 Sep 2026 17:39:18 +0200 Message-ID: <20260911153918.96470-3-dmanresa@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911153918.96470-1-dmanresa@gmail.com> References: <20260910172120.73148-1-dmanresa@gmail.com> <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 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 --- src/ipa/ipu3/algorithms/blc.cpp | 53 ++++++++++++++++++++----- src/ipa/ipu3/algorithms/blc.h | 5 +++ src/ipa/libipa/camera_sensor_helper.cpp | 2 +- 3 files changed, 50 insertions(+), 10 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 */ diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index eeb3277..3589b06 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -802,7 +802,7 @@ class CameraSensorHelperOv5670 : public CameraSensorHelper public: CameraSensorHelperOv5670() { - /* Default BLC target of 64 at 10bits, confirmed by measurement. */ + /* From the OEM black level characterisation: 64 at 10bits. */ blackLevel_ = 4096; gain_ = AnalogueGainLinear{ 1, 0, 0, 128 }; }