From patchwork Wed May 6 21:45:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Tia X-Patchwork-Id: 26647 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 D7C80BDCB5 for ; Wed, 6 May 2026 22:19:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 71D8D63022; Thu, 7 May 2026 00:19:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=jetm.me header.i=@jetm.me header.b="PfH3671Q"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="h9C5ivXZ"; dkim-atps=neutral Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D33EA6301A for ; Thu, 7 May 2026 00:19:40 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 06022EC025F; Wed, 6 May 2026 18:19:40 -0400 (EDT) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-02.internal (MEProxy); Wed, 06 May 2026 18:19:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1778105980; x=1778192380; bh=3t9cDvvEgn7bvwE6/1289iqcE8HGnbECmVmQKnVol1s=; b= PfH3671QajS13M3Ot80YX8BNlOJYoYvGw0NJ5lAGuAn0n+998/msfNqLLsxcdvTQ PHpmhGgKWNqA5iT6NbXtRRgKqpamYgNDMYufp/qnHZNcWSyV+SZBp8dJXXSuMe2f v6C6Az8dPiv6NNKNiC59xGNZAJcGY7849Bpf6tS7VGOaWkxYbPyNcfvbJX6je9d2 e6AT5LruQ9I54m/hl05/c9/sX4+m64j6FdVWCgBJ7wS7H/uFIP1GOrP2y8SSk6G7 ACUTc7LAxGuZmKdxPRwbwkM5+IFiJkze1a4tS6cKDR4nBWHZjJsrBcssiCncrLop tRBp8IOrGPwZIiSFoWpvdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778105980; x= 1778192380; bh=3t9cDvvEgn7bvwE6/1289iqcE8HGnbECmVmQKnVol1s=; b=h 9C5ivXZpFxoGyELCSIbIWKxCrC5jOOONH6umjq6JPzLoygZ8upXRGDOyEgd4LlOQ tJbdZJpxv9I2zEdsWQMubRkqkGt7dIvHtv6XHAACeP/mmWHNCmu2Fv7PA2O/othV Hu1wb7fenR6bm0mqUNgluWK+gE+8nX4QtoesFPwrYrjd/iz4BdhZ/AHcr9vPhviv ABAOyw35t3IcFDw24Jojg33mU6ajt3UTXoMeNUGOLf2va0rv86ue05XxIxBQ+w0n PfPhJolNGoRpBq/3Jjwl6FbFcQkihnPH77MsDRU6+amQQQt7JJ9v0SHbvm7qXFuc 1tG3ZqPUUjIR/z31CtO8A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddutdehjeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefotggggffhvfffufevjghfkfesthekre dtredtjeenucfhrhhomheplfgrvhhivghrucfvihgruceofhhlohhsshesjhgvthhmrdhm vgeqnecuggftrfgrthhtvghrnhepfeejfffhffeuvdduhfegleffleduueehudduffekle eikedtvddvgeefgfeukeelnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvg htmhdrmhgvpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgtphht thhopegsrghrnhgrsggrshdrphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpd hrtghpthhtohepkhhivghrrghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdr tghomhdprhgtphhtthhopehlihgstggrmhgvrhgrqdguvghvvghlsehlihhsthhsrdhlih gstggrmhgvrhgrrdhorhhgpdhrtghpthhtohepjhhohhgrnhhnvghsrdhgohgvuggvseho shhsrdhquhgrlhgtohhmmhdrtghomhdprhgtphhtthhopehmiigrmhgriigrlhesrhgvug hhrghtrdgtohhm X-ME-Proxy: Feedback-ID: i9dde48b3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id C51BF1EA006B; Wed, 6 May 2026 18:19:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 From: Javier Tia To: libcamera-devel@lists.libcamera.org Date: Wed, 06 May 2026 15:45:28 -0600 Subject: [PATCH v5 0/3] ipa: simple: Proportional AGC and statistics normalization Cc: mzamazal@redhat.com, barnabas.pocze@ideasonboard.com, kieran.bingham@ideasonboard.com, johannes.goede@oss.qualcomm.com In-Reply-To: <20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me> References: <20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me> Message-ID: <177810597783.688418.1631246733707368646@jetm.me> 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 AGC in the simple pipeline uses a fixed ~10% step per frame regardless of how far the current exposure is from the target. With a hysteresis dead band of only +/-4%, the controller overshoots near the optimal value, causing visible brightness oscillation (flicker). This series replaces the bang-bang controller with a proportional one (patch 1/3), fixes a bit-depth mismatch in the statistics sums used by AWB (patch 2/3), and adds the OV2740 black level calibration needed for correct BLC subtraction (patch 3/3). Tested on OV2740 behind Intel IPU6 ISYS (ThinkPad X1 Carbon Gen 10). A 40-frame capture with all three patches shows smooth monotonic brightness convergence from frame 4 onwards with no oscillation. Changes since v4: - Patch 1/3: Added kExpMaxStep = 0.15 to clamp the proportional step, bounding corrections to +/-15% even when the scene changes dramatically. This addresses Barnabas's question on v4 about large-error behavior. - Patch 2/3: Rebased; diff context updated for the multi-threading refactor in swstats_cpu (6e53e72e), which restructured finishFrame() to aggregate from a stats_ vector before applying the shift. No functional change. Regarding Kieran's question on patch 1/3 (gain model): the proportional step `again * factor` has the same linearity assumption as the old fixed step `again * 11/10`. Both multiply the current register value by a scalar. For devices without a calibrated gain model the register value is already used as a linear proxy in the original code. This change only affects the step magnitude, not the direction logic or gain model assumption. Devices without a gain model should behave the same or better. Regarding Kieran's question on whether 3/3 is needed for the flicker fix: patch 1/3 alone cures the flicker. Patch 3/3 improves AWB color accuracy by providing the correct black level baseline (BLC=16) for channel gain calculation, but it is independent of the oscillation fix. Link to v4: https://lore.kernel.org/libcamera-devel/20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me/ Javier Tia (3): ipa: simple: agc: Replace bang-bang controller with proportional libcamera: software_isp: Normalize statistics sums to 8-bit ipa: libipa: camera_sensor_helper: Add OV2740 black level .../internal/software_isp/swstats_cpu.h | 1 + src/ipa/libipa/camera_sensor_helper.cpp | 2 + src/ipa/simple/algorithms/agc.cpp | 73 +++++++++++++------ src/libcamera/software_isp/swstats_cpu.cpp | 9 +++ 4 files changed, 61 insertions(+), 24 deletions(-)