{"id":26647,"url":"https://patchwork.libcamera.org/api/covers/26647/?format=json","web_url":"https://patchwork.libcamera.org/cover/26647/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<177810597783.688418.1631246733707368646@jetm.me>","date":"2026-05-06T21:45:28","name":"[v5,0/3] ipa: simple: Proportional AGC and statistics normalization","submitter":{"id":261,"url":"https://patchwork.libcamera.org/api/people/261/?format=json","name":"Javier Tia","email":"floss@jetm.me"},"mbox":"https://patchwork.libcamera.org/cover/26647/mbox/","series":[{"id":5913,"url":"https://patchwork.libcamera.org/api/series/5913/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5913","date":"2026-05-06T21:45:28","name":"ipa: simple: Proportional AGC and statistics normalization","version":5,"mbox":"https://patchwork.libcamera.org/series/5913/mbox/"}],"comments":"https://patchwork.libcamera.org/api/covers/26647/comments/","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D7C80BDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 May 2026 22:19:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71D8D63022;\n\tThu,  7 May 2026 00:19:43 +0200 (CEST)","from fout-a5-smtp.messagingengine.com\n\t(fout-a5-smtp.messagingengine.com [103.168.172.148])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D33EA6301A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 May 2026 00:19:40 +0200 (CEST)","from phl-compute-02.internal (phl-compute-02.internal\n\t[10.202.2.42])\n\tby mailfout.phl.internal (Postfix) with ESMTP id 06022EC025F;\n\tWed,  6 May 2026 18:19:40 -0400 (EDT)","from phl-imap-07 ([10.202.2.97])\n\tby phl-compute-02.internal (MEProxy); Wed, 06 May 2026 18:19:40 -0400","by mailuser.phl.internal (Postfix, from userid 501)\n\tid C51BF1EA006B; Wed,  6 May 2026 18:19:39 -0400 (EDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=jetm.me header.i=@jetm.me header.b=\"PfH3671Q\";\n\tdkim=pass (2048-bit key;\n\tunprotected) header.d=messagingengine.com\n\theader.i=@messagingengine.com header.b=\"h9C5ivXZ\"; \n\tdkim-atps=neutral","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc\n\t:content-transfer-encoding:content-type:content-type:date:date\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to; s=fm2; t=1778105980;\n\tx=1778192380; bh=3t9cDvvEgn7bvwE6/1289iqcE8HGnbECmVmQKnVol1s=; b=\n\tPfH3671QajS13M3Ot80YX8BNlOJYoYvGw0NJ5lAGuAn0n+998/msfNqLLsxcdvTQ\n\tPHpmhGgKWNqA5iT6NbXtRRgKqpamYgNDMYufp/qnHZNcWSyV+SZBp8dJXXSuMe2f\n\tv6C6Az8dPiv6NNKNiC59xGNZAJcGY7849Bpf6tS7VGOaWkxYbPyNcfvbJX6je9d2\n\te6AT5LruQ9I54m/hl05/c9/sX4+m64j6FdVWCgBJ7wS7H/uFIP1GOrP2y8SSk6G7\n\tACUTc7LAxGuZmKdxPRwbwkM5+IFiJkze1a4tS6cKDR4nBWHZjJsrBcssiCncrLop\n\ttRBp8IOrGPwZIiSFoWpvdg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=\n\tmessagingengine.com; h=cc:cc:content-transfer-encoding\n\t:content-type:content-type:date:date:feedback-id:feedback-id\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to:x-me-proxy\n\t:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778105980; x=\n\t1778192380; bh=3t9cDvvEgn7bvwE6/1289iqcE8HGnbECmVmQKnVol1s=; b=h\n\t9C5ivXZpFxoGyELCSIbIWKxCrC5jOOONH6umjq6JPzLoygZ8upXRGDOyEgd4LlOQ\n\ttJbdZJpxv9I2zEdsWQMubRkqkGt7dIvHtv6XHAACeP/mmWHNCmu2Fv7PA2O/othV\n\tHu1wb7fenR6bm0mqUNgluWK+gE+8nX4QtoesFPwrYrjd/iz4BdhZ/AHcr9vPhviv\n\tABAOyw35t3IcFDw24Jojg33mU6ajt3UTXoMeNUGOLf2va0rv86ue05XxIxBQ+w0n\n\tPfPhJolNGoRpBq/3Jjwl6FbFcQkihnPH77MsDRU6+amQQQt7JJ9v0SHbvm7qXFuc\n\t1tG3ZqPUUjIR/z31CtO8A=="],"X-ME-Sender":"<xms:e777aSvwMNJGnIAvaxjc_lwiaHrxQaJMwIivMQi1OOjRO0yTFwNh9g>\n\t<xme:e777aSS4zwNK3ruH0ygqgUqd1cEt00OZV__2Iv4O6GIukzu5AD1vONgeEgKz5Emha\n\tQEFiBTcP-VSBtK5_AjN_i5G9jh46ufNZwZK5IiS8JAQGWhSn-ayDZn4>","X-ME-Proxy-Cause":"gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddutdehjeejucetufdoteggodetrf\n\tdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu\n\trghilhhouhhtmecufedttdenucenucfjughrpefotggggffhvfffufevjghfkfesthekre\n\tdtredtjeenucfhrhhomheplfgrvhhivghrucfvihgruceofhhlohhsshesjhgvthhmrdhm\n\tvgeqnecuggftrfgrthhtvghrnhepfeejfffhffeuvdduhfegleffleduueehudduffekle\n\teikedtvddvgeefgfeukeelnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhu\n\tshhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvg\n\thtmhdrmhgvpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgtphht\n\tthhopegsrghrnhgrsggrshdrphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpd\n\thrtghpthhtohepkhhivghrrghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdr\n\ttghomhdprhgtphhtthhopehlihgstggrmhgvrhgrqdguvghvvghlsehlihhsthhsrdhlih\n\tgstggrmhgvrhgrrdhorhhgpdhrtghpthhtohepjhhohhgrnhhnvghsrdhgohgvuggvseho\n\tshhsrdhquhgrlhgtohhmmhdrtghomhdprhgtphhtthhopehmiigrmhgriigrlhesrhgvug\n\thhrghtrdgtohhm","X-ME-Proxy":"<xmx:e777ac5SDL3_xaNkP9SEJuhSRnjPa8Y7-XtPJaKQ7gRHNETvD9kHYA>\n\t<xmx:e777aW2viI7mpigPrcRWnL7ewsPfMjNVpSiM9_21jHqY9sgbhghr4g>\n\t<xmx:e777aXDngxJkzuSUiQS5RnVRSmP6GpSAG3W83Z8LaxvBmmClSO2LZg>\n\t<xmx:e777aRNsydY4p02OpkPnrS7uMRiZ5W8m_O2k-qpUcgVgjvNA8dQ3SQ>\n\t<xmx:fL77abpOfqGFC1OkN2KuxNCqsi7TRjYeINIcZSU6pc4wX5fNatWZxgFV>","Feedback-ID":"i9dde48b3:Fastmail","X-Mailer":"MessagingEngine.com Webmail Interface","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","From":"Javier Tia <floss@jetm.me>","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\n\tnormalization","Cc":"mzamazal@redhat.com, barnabas.pocze@ideasonboard.com,\n\tkieran.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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The AGC in the simple pipeline uses a fixed ~10% step per frame regardless\nof how far the current exposure is from the target. With a hysteresis dead\nband of only +/-4%, the controller overshoots near the optimal value,\ncausing visible brightness oscillation (flicker).\n\nThis series replaces the bang-bang controller with a proportional one\n(patch 1/3), fixes a bit-depth mismatch in the statistics sums used by\nAWB (patch 2/3), and adds the OV2740 black level calibration needed for\ncorrect BLC subtraction (patch 3/3).\n\nTested on OV2740 behind Intel IPU6 ISYS (ThinkPad X1 Carbon Gen 10).\nA 40-frame capture with all three patches shows smooth monotonic brightness\nconvergence from frame 4 onwards with no oscillation.\n\nChanges since v4:\n- Patch 1/3: Added kExpMaxStep = 0.15 to clamp the proportional step,\n  bounding corrections to +/-15% even when the scene changes dramatically.\n  This addresses Barnabas's question on v4 about large-error behavior.\n- Patch 2/3: Rebased; diff context updated for the multi-threading refactor\n  in swstats_cpu (6e53e72e), which restructured finishFrame() to aggregate\n  from a stats_ vector before applying the shift. No functional change.\n\nRegarding Kieran's question on patch 1/3 (gain model): the proportional\nstep `again * factor` has the same linearity assumption as the old fixed\nstep `again * 11/10`. Both multiply the current register value by a\nscalar. For devices without a calibrated gain model the register value\nis already used as a linear proxy in the original code. This change only\naffects the step magnitude, not the direction logic or gain model\nassumption. Devices without a gain model should behave the same or better.\n\nRegarding Kieran's question on whether 3/3 is needed for the flicker fix:\npatch 1/3 alone cures the flicker. Patch 3/3 improves AWB color accuracy\nby providing the correct black level baseline (BLC=16) for channel gain\ncalculation, but it is independent of the oscillation fix.\n\nLink to v4: https://lore.kernel.org/libcamera-devel/20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me/\n\nJavier Tia (3):\n  ipa: simple: agc: Replace bang-bang controller with proportional\n  libcamera: software_isp: Normalize statistics sums to 8-bit\n  ipa: libipa: camera_sensor_helper: Add OV2740 black level\n\n .../internal/software_isp/swstats_cpu.h       |  1 +\n src/ipa/libipa/camera_sensor_helper.cpp       |  2 +\n src/ipa/simple/algorithms/agc.cpp             | 73 +++++++++++++------\n src/libcamera/software_isp/swstats_cpu.cpp    |  9 +++\n 4 files changed, 61 insertions(+), 24 deletions(-)"}