From patchwork Wed Nov 18 16:47:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29027 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 D67FCC3304 for ; Wed, 18 Nov 2026 16:47:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D33A6A90E; Wed, 18 Nov 2026 17:47:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="Udy4nJUC"; dkim-atps=neutral Received: from mail-106119.protonmail.ch (mail-106119.protonmail.ch [79.135.106.119]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C94076A900 for ; Wed, 18 Nov 2026 17:47:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795020437; x=1795279637; bh=I5vrSgvfA1Y11G8mrYychKaQ86YgeooWfKoRLA3JHJ4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Udy4nJUCtdZjCA9MKmVnIOk9f/CDi+R410IjdJyCVb+92zQrHvBlqaMBwRAvt8t1t XbSGb2EN1l2Wi+y+YCu2u2UbFaC3O54zujVHSWxt4TiyhHrqgKmHBIQvmDPoI6GC73 6/Y8qVH4cLk5R9/f1vKXIG6W0nwxVyQGXAqgKYO00vU7hUTPhMQ86Bg1tjvQz8oQeN pSj7Tf+kEVTIqubS0DuL5RrqX0O5ljTHqrE6gweIU/SEH1Gmdbh61ngnmFqXJX8xP1 RKjGBxaqrCyVaHnRZhxvfXSHPboQ4vzkgsRiNmqPknbsJPn289PAELraAJihKxKHia gSaGrvrnpWeGw== Date: Wed, 18 Nov 2026 16:47:11 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 6/6] ipa: ipu3: blc: Use the black level from the camera sensor helper Message-ID: <20261118164621.15513-7-guyliandejong@proton.me> In-Reply-To: <20261118164621.15513-1-guyliandejong@proton.me> References: <20261118164621.15513-1-guyliandejong@proton.me> Feedback-ID: 112452169:user:proton X-Pm-Message-ID: c89070bdd3a8157f50bb1b3c8f88573f051f3a15 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 BlackLevelCorrection algorithm programs a fixed obgrid value of 64 for all sensors. Use the black level from the camera sensor helper instead, and keep 64 when the helper doesn't provide one. The obgrid units are not documented. Measured on an OV9734 by sweeping the obgrid value on frames with a fixed exposure and gain, at three input levels read from the raw CIO2 stream (16.3, 31.9 and 48.4 on 10 bits), the value that brings the output to black was about 28, 60 and 96. The obgrid scale is thus twice the 10-bit scale, which corresponds to the 16-bit helper value shifted right by 5. For the OV9734, whose black level is 0x10 on 10 bits, this gives 32 instead of 64. With 64, an input 16 levels above the black level comes out at 1.3 instead of 6.9 (on 8 bits, with a linear tone curve), so the shadows are crushed. This also changes the value for the other IPU3 sensors whose helper provides a black level, from 64 to 128 for a black level of 0x40 on 10 bits, which was too low by the same measure. Signed-off-by: GuyliandeJong --- src/ipa/ipu3/algorithms/blc.cpp | 53 +++++++++++++++++++++++++++------ src/ipa/ipu3/algorithms/blc.h | 4 +++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/ipa/ipu3/algorithms/blc.cpp b/src/ipa/ipu3/algorithms/blc.cpp index 35748fb2..491ed199 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,8 +34,44 @@ namespace ipa::ipu3::algorithms { * isn't currently supported. */ +LOG_DEFINE_CATEGORY(IPU3Blc) + +/* + * Black level applied when the camera sensor helper doesn't provide one, in + * the units of the ImgU obgrid parameters. + */ +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, using " + << kDefaultBlackLevel; + return 0; + } + + /* + * The camera sensor helper expresses the black level on 16 bits. The + * obgrid parameters are on 11 bits for the 10-bit raw formats the CIO2 + * produces: measured with an OV9734, the obgrid value that brings a + * raw input level to black is twice that level on 10 bits. + */ + blackLevel_ = static_cast(*blackLevel) >> 5; + + LOG(IPU3Blc, Debug) << "Black level: " << blackLevel_; + + return 0; } /** @@ -49,15 +89,10 @@ 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; + 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 62748045..9c63ee85 100644 --- a/src/ipa/ipu3/algorithms/blc.h +++ b/src/ipa/ipu3/algorithms/blc.h @@ -18,9 +18,13 @@ 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 */