From patchwork Wed Nov 18 16:46:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29022 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 62DFBC3304 for ; Wed, 18 Nov 2026 16:46:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 073776A90B; Wed, 18 Nov 2026 17:46:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="KvLkU2Ed"; dkim-atps=neutral Received: from mail-43103.protonmail.ch (mail-43103.protonmail.ch [185.70.43.103]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C891D6A8F2 for ; Wed, 18 Nov 2026 17:46:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795020401; x=1795279601; bh=DW23DH4z+kQwIlw+fwd7nWOxo3OFDMRRfF+A/2wK4wk=; 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=KvLkU2Ed2CpqQJ4kwSQ4TpeKvWlRjwoZBajTw6HnOW4/DK37wQDZcrg1NklQ0/PUs c0MolcUOImXMxfZ5JrgPzKrLwIvXqw8439d4eVfCBnrEHeWW6YsQmsV7rLpGa1QtpQ +OUU+G5+/8Wzs3bA7pj9Lui2IP++3i0HUgoW9/suOsIPhd7NWG8KHxOiWpAFCQoMg/ I21c18ky79m0zNngR5HhsRX2ALv6oDKAaZ6gm13HxykPBvebEqvaua1f+cRpvrakoI duhCy5gz/jvBr70MSxyYUKm5a3lkc+LhdPoa+c8ZrQRxn9wakyQKBfvXltOgJPR9IQ B89tshC4loipw== Date: Wed, 18 Nov 2026 16:46:37 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 1/6] ipa: ipu3: lsc: Fill all rows of the shading table Message-ID: <20261118164621.15513-2-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: 6156dd3262afd7c826345753136e420263104eb2 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 shading LUT is split in sets of grid_height_per_slice rows of numHCells_ cells each. The number of sets to fill is computed from the number of horizontal cells instead of the number of vertical cells, so when the grid has more rows than columns, the last rows are never written and get no shading correction. This happens with the OV9734 (1296x734), where the grid is 41x46 cells with 3 rows per set: 16 sets are needed, but only 14 are filled, and the bottom 4 rows of the image are left uncorrected. Compute the number of sets from the number of vertical cells. Fixes: 279d355ef8f7 ("ipa: ipu3: Add Lens Shading Correction algorithm") Signed-off-by: GuyliandeJong --- src/ipa/ipu3/algorithms/lsc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/lsc.cpp b/src/ipa/ipu3/algorithms/lsc.cpp index 77e637fd..729a23ff 100644 --- a/src/ipa/ipu3/algorithms/lsc.cpp +++ b/src/ipa/ipu3/algorithms/lsc.cpp @@ -256,7 +256,7 @@ void Lsc::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const u unsigned int totalCells = numHCells_ * numVCells_; unsigned int cellsPerSet = numHCells_ * config->grid.grid_height_per_slice; - unsigned int numSets = (numHCells_ + config->grid.grid_height_per_slice - 1) / + unsigned int numSets = (numVCells_ + config->grid.grid_height_per_slice - 1) / config->grid.grid_height_per_slice; unsigned int i = 0; From patchwork Wed Nov 18 16:46:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29023 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 156B7C3304 for ; Wed, 18 Nov 2026 16:46:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B54096A900; Wed, 18 Nov 2026 17:46:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="l28wJf2Z"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 714A66A8FA for ; Wed, 18 Nov 2026 17:46:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795020408; x=1795279608; bh=ACGa6Ev5jWO/JMLfyPtURwObeFZB+7HOZcYiddwFyfo=; 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=l28wJf2ZTaOLNJ6A8l+Zx5CGiUFYQ82Ip1E32jzp7+YGJORcUdl5shrejnQdA1ZaG Ursoaq4zUKi0hpjPF6nMbXhU5jjDwN4R9Gxi2efmqMLkHcNE6WA62HIEVJq/ZYNfJ1 CmWFhd8e6Wfu5S9+F8go2mHaV1sqIEsjN6QLojewUYeBxJ14VuCNzZQQkZoEmyaTIU 7X7PUK7C2TC+CfwoMsJm5HyyVWHYZYKnp5GDByS1qpk5Sqh7C4BvR5ef8iZdX8uRPp XFSfDngJM3PGlALhB0Gv9693xG9aOULxPr7JR7tWSE9+4nsWYK9BRUSzZ2ycSsMKjK E60w2p5GQ4KRw== Date: Wed, 18 Nov 2026 16:46:43 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 2/6] ipa: ipu3: lsc: Subtract the base gain from the shading LUT values Message-ID: <20261118164621.15513-3-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: fdd4d345eb1d1569915877a65cf73b7ea074da14 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 ImgU adds a base gain of 1.0 to the shading LUT values, as the comment in prepare() already assumes. The gains produced by LscAlgorithm are total gains in UQ<2, 10> format, where 1024 is a gain of 1.0, and are written to the LUT as is. Every gain is thus applied with an extra 1.0: a table of unity gains doubles the image brightness instead of leaving it unchanged, and the relative correction towards the corners is weakened. Measured on an OV9734 with a fixed exposure and a polynomial table of unity gains, enabling shading correction made the image about 1.7 times brighter. With this change it leaves the image unchanged, and a radial table leaves the centre of the image unchanged while brightening the corners. Subtract the base gain of 1.0 when filling the LUT, clamping gains lower than 1.0 as the hardware can't apply them. Fixes: 279d355ef8f7 ("ipa: ipu3: Add Lens Shading Correction algorithm") Signed-off-by: GuyliandeJong --- src/ipa/ipu3/algorithms/lsc.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ipa/ipu3/algorithms/lsc.cpp b/src/ipa/ipu3/algorithms/lsc.cpp index 729a23ff..1991d6ee 100644 --- a/src/ipa/ipu3/algorithms/lsc.cpp +++ b/src/ipa/ipu3/algorithms/lsc.cpp @@ -32,6 +32,9 @@ static constexpr unsigned int kMaxNumHCells = 73; static constexpr unsigned int kMaxNumVCells = 56; static constexpr int kColourTemperatureQuantization = 10; +/* Gain of 1.0 in the UQ<2, 10> format of the LscAlgorithm gains */ +static constexpr uint16_t kUnityGain = 1 << 10; + /** * \copydoc libcamera::ipa::Algorithm::init */ @@ -238,6 +241,11 @@ void Lsc::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const u * And that a base gain of 1.0 is added to those configured values. As a * gain of more than 5.0 is fairly unlikely, let's fix gain_factor to 0 * for now and revisit if needed. + * + * Measurements on an OV9734 match this: a LUT value of 0 leaves the + * image unchanged, and 1024 doubles it. As LscAlgorithm produces the + * total gain, the base gain of 1.0 is subtracted when filling the LUT + * below. Gains lower than 1.0 can't be represented and are clamped. */ config->general.gain_factor = 0; @@ -260,12 +268,16 @@ void Lsc::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] const u config->grid.grid_height_per_slice; unsigned int i = 0; + const auto lutValue = [](uint16_t gain) -> uint16_t { + return gain > kUnityGain ? gain - kUnityGain : 0; + }; + for (unsigned int s = 0; s < numSets; s++) { for (unsigned int c = 0; c < cellsPerSet && i < totalCells; c++, i++) { - lut->sets[s].r_and_gr[c].r = set.at("r")[i]; - lut->sets[s].r_and_gr[c].gr = set.at("gr")[i]; - lut->sets[s].gb_and_b[c].gb = set.at("gb")[i]; - lut->sets[s].gb_and_b[c].b = set.at("b")[i]; + lut->sets[s].r_and_gr[c].r = lutValue(set.at("r")[i]); + lut->sets[s].r_and_gr[c].gr = lutValue(set.at("gr")[i]); + lut->sets[s].gb_and_b[c].gb = lutValue(set.at("gb")[i]); + lut->sets[s].gb_and_b[c].b = lutValue(set.at("b")[i]); } } From patchwork Wed Nov 18 16:46:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29024 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 C8411C3304 for ; Wed, 18 Nov 2026 16:46:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 782F26A900; Wed, 18 Nov 2026 17:46:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="DDIGgsqc"; dkim-atps=neutral Received: from mail-43102.protonmail.ch (mail-43102.protonmail.ch [185.70.43.102]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EA556A8FA for ; Wed, 18 Nov 2026 17:46:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795020413; x=1795279613; bh=LWlYmnBoboC4FiBpGPYgmPX2THORFoozu0bMkcfpG2c=; 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=DDIGgsqc79LC2X4hMHty3+5xTcy/zIgig4wgCLFxs/yN9q7S/bX1IYvW/l6JVuv1V +7MpuHgCa7+SK5xBrYWmv5HhqnwqqcV+YzRfTxJLUVjLZrpzV71ZzSFprHCtNCjlYc pVUziDNVAmWdLOVGKVbmHXmn7WlqdvyeBWMuZvoNipBSzRZtTqWURpTit0TzKCLow9 U9JStMcQdE6DGiryRnSPQvKESTLH138xd28o3dgXsd10RA13+6JW8Pxqx/50Qqbhbs 2VLErnWSdE+L621Ci9aeUjMz+nOTRCIld6WlNoT5N0IbUin50MSq0FmTkyt3ATP0cK COSkIJKASqZdg== Date: Wed, 18 Nov 2026 16:46:50 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 3/6] libcamera: pipeline: ipu3: Report the first ImgU frame as an error Message-ID: <20261118164621.15513-4-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: 3c95d0038028f86e50a16c4b4d7e845147c2c481 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" After the output size of the ImgU changes, the first frame it produces is processed with parameters left over from the previous configuration and contains horizontal bars of random colours. Applications show this frame, for instance as a flash of pink and blue bars when a video call preview opens. On an OV9734, alternating between 1280x704, 640x360 and 1024x576 with v4l2-ctl through the V4L2 compatibility layer, the first frame after each size change has a strong colour cast (an average V offset of +24 to -41 against 0 to 3 for the following frames), and the following frames are correct. Report the ImgU output buffers of the first request as FrameError, so that applications drop them. The V4L2 compatibility layer passes this on as V4L2_BUF_FLAG_ERROR. Signed-off-by: GuyliandeJong --- src/libcamera/pipeline/ipu3/ipu3.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 46af776e..c951b49c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1270,6 +1270,16 @@ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer) Request *request = info->request; + /* + * The ImgU processes the first frame after starting with parameters + * left over from the previous configuration. After a change of the + * output size, this produces horizontal bars of random colours. Report + * the first frame as an error so that applications drop it. + */ + if (request->sequence() == 0 && + buffer->metadata().status == FrameMetadata::FrameSuccess) + buffer->_d()->metadata().status = FrameMetadata::FrameError; + pipe()->completeBuffer(request, buffer); request->_d()->metadata().set(controls::draft::PipelineDepth, 3); From patchwork Wed Nov 18 16:46:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29025 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 72E5FC3304 for ; Wed, 18 Nov 2026 16:47:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 225606A8FE; Wed, 18 Nov 2026 17:47:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="zdXzrKSo"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 963906A8FE for ; Wed, 18 Nov 2026 17:47:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=2wu4aqv7ozej7bfzjsu6nskhei.protonmail2; t=1795020423; x=1795279623; bh=qB+naVC0UAJMNggIFtM2xDRQP0oEroimoMbk2KUo3+8=; 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=zdXzrKSoM6dlYCtPn0OjlJNCbNY+xAHGT9fhHpglthymcoCXrnCemo+c1jS/M2RxD LOaDYx/Ix8gIRf+4+HENMZ3Ktp/Wt64qqFg+YkQxBRcIK1gIADuh8NjyOBxu8OQoCV QBrgd/Ohsm8hOQ5dcDaQVM0yOfKWonrU0w7lrKHxOi9hPOuwUjah634Vg49cPjI1r9 Kay/bqw/lVRNcR4wi4x37m8Vmm9s+8qWxt4VA3sT01NjplJWbZOvdb6sNL+lFR/KO0 yD624UaAPO4CCGk+5hz+/WopVLKY9mxuSf0BaTrspMPWoLcW04jAWqKRHt04rpQwKF U1mdJy32fK/dg== Date: Wed, 18 Nov 2026 16:46:57 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 4/6] ipa: ipu3: awb: Report statistics without enough zones as invalid Message-ID: <20261118164621.15513-5-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: e508942b00f7636841479a04fa84edd1af684c78 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" When too few statistics zones are usable, for instance in a very dark frame, calculateRgbMeans() returns a default constructed Ipu3AwbStats with zero RGB means. Ipu3AwbStats::valid() always returns true, so AwbAlgorithm processes these zero means as real data: the estimated colour temperature drops to 0K and the gains are computed from zero means. On an OV9734 this happens for one dark frame at stream start. The reported colour temperature drops from about 3200K to 0K, and the CCM and the gains of the following frames are computed from it. Track whether the statistics hold RGB means, and report them as invalid otherwise, so that AwbAlgorithm skips the frame as the IPU3 AWB did before it was ported to AwbAlgorithm. Fixes: b95dd9d14963 ("ipa: ipu3: awb: Port to the new libipa AwbAlgorithm") Signed-off-by: GuyliandeJong --- src/ipa/ipu3/algorithms/awb.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 84d9f62e..57fd0beb 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -42,7 +42,7 @@ public: * \param rgbMeans A vector of doubles representing the RGB mean values */ Ipu3AwbStats(const RGB &rgbMeans) - : rgbMeans_(rgbMeans) + : rgbMeans_(rgbMeans), valid_(true) { rg_ = rgbMeans_.r() / rgbMeans_.g(); bg_ = rgbMeans_.b() / rgbMeans_.g(); @@ -54,8 +54,9 @@ public: private: RGB rgbMeans_; - double rg_; - double bg_; + double rg_ = 0.0; + double bg_ = 0.0; + bool valid_ = false; }; double Ipu3AwbStats::computeColourError(const RGB &gains) const @@ -78,10 +79,11 @@ bool Ipu3AwbStats::valid() const * whether there's enough information in the statistics for a frame to * be useful. The IPU3 implementation already drops any statistics zone * with an average value below a threshold though so we don't need to do - * it in libipa. Report all stats as valid. + * it in libipa. The statistics are only invalid when too few zones + * are left to compute RGB means. */ - return true; + return valid_; } RGB Ipu3AwbStats::rgbMeans() const From patchwork Wed Nov 18 16:47:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: GuyliandeJong X-Patchwork-Id: 29026 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 196E9C3304 for ; Wed, 18 Nov 2026 16:47:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C165E6A912; Wed, 18 Nov 2026 17:47:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=proton.me header.i=@proton.me header.b="fOnMtRpn"; dkim-atps=neutral Received: from mail-24416.protonmail.ch (mail-24416.protonmail.ch [109.224.244.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B5BC6A900 for ; Wed, 18 Nov 2026 17:47:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795020428; x=1795279628; bh=kPaHdNMPNF6wh6zn7dTO/fTDikW3573LXIk6vBZEs/I=; 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=fOnMtRpngzkkLkpMHqz7ZyLMUNMHBPK+8VEsQ21vf9QUmClJYAgRxW3DX0gs+wkbX QEB/ZFNFLru9cu7Rvznt6rJBOoz2wtWkZMijIRkcjLptA7gun3lrCPpZljEIvy0wP8 W4fApPb0yVjEc25Vu5enzlOOGzESSMNvYz1MFkDCaY8j9op0IQqpfMf7E5C8WrfUeg ipWo/6uTW1vldNv9Ym8XL1yQPTNIuLPhX/+Y0CBM1aSJgvXcAhKbfYS/Mm4S2MTuu7 fwS5iqYOGXM3JOanEYBJCs0JP45jlFQGrD51IkvKtCmkzB3sHNIUSSvqp2ESWfci7Z GIfzeGaCkoiKQ== Date: Wed, 18 Nov 2026 16:47:03 +0000 To: libcamera-devel@lists.libcamera.org From: GuyliandeJong Cc: Daniel Scally , Barnabas Pocze , Afonso Figuinha Subject: [PATCH 5/6] ipa: ipu3: Add a tuning file for the OV9734 Message-ID: <20261118164621.15513-6-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: 655fb292366cfa8753870246998ba0e2313199bc 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 OV9734, used as the front camera of the Surface Laptop 1 and 2, has strong lens shading: the relative illumination drops to about 0.38 at three quarters of the image radius and to about 0.25 in the corners, and the red channel falls off faster than the others. The uncalibrated tuning file has no Lsc entry, so none of this is corrected. Add a tuning file with a polynomial Lsc table, and keep the other algorithms at their defaults as in uncalibrated.yaml. The polynomials were measured on a Surface Laptop 2 from raw CIO2 frames of a diffuser over the lens, under room lighting of about 3200K. The log of each frame was fitted with a radial polynomial plus a plane, to separate the lens shading from gradients in the lighting. Two captures with the light coming from different directions gave the same radial falloff (a gain of 1.56 and 1.66 at half the radius, 2.64 for both at three quarters). With this file, the processed image of the flat field is uniform to within 3%, against a corner to centre ratio of 0.64 without it. The corner gains of up to 4.6 are clamped to the 4.0 maximum of the LUT format, which only affects the outermost corners. Signed-off-by: GuyliandeJong --- src/ipa/ipu3/data/meson.build | 1 + src/ipa/ipu3/data/ov9734.yaml | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/ipa/ipu3/data/ov9734.yaml diff --git a/src/ipa/ipu3/data/meson.build b/src/ipa/ipu3/data/meson.build index 0f7cd5c6..9fb0cfdb 100644 --- a/src/ipa/ipu3/data/meson.build +++ b/src/ipa/ipu3/data/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 conf_files = files([ + 'ov9734.yaml', 'uncalibrated.yaml', ]) diff --git a/src/ipa/ipu3/data/ov9734.yaml b/src/ipa/ipu3/data/ov9734.yaml new file mode 100644 index 00000000..d031ec3f --- /dev/null +++ b/src/ipa/ipu3/data/ov9734.yaml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.1 +--- +version: 1 +algorithms: + - Af: + - Agc: + - Awb: + - BlackLevelCorrection: + - Ccm: + - Lsc: + # Measured from raw flat fields (diffuser over the lens) on a Surface + # Laptop 2, under room lighting of about 3200K. + type: polynomial + sets: + - ct: 3200 + r: { cx: 0.5, cy: 0.5, k0: 2.1956, k1: 1.7585, k2: 2.9072, k3: -3.2151, k4: 0.0 } + gr: { cx: 0.5, cy: 0.5, k0: 2.0225, k1: 1.5855, k2: 0.9147, k3: -1.6029, k4: 0.0 } + gb: { cx: 0.5, cy: 0.5, k0: 2.0237, k1: 1.5748, k2: 1.0013, k3: -1.6269, k4: 0.0 } + b: { cx: 0.5, cy: 0.5, k0: 1.8914, k1: 1.7020, k2: 1.6762, k3: -2.6457, k4: 0.0 } + - ToneMapping: +... 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 */