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 }; }