Patch Detail
Show a patch.
GET /api/patches/26649/?format=api
{ "id": 26649, "url": "https://patchwork.libcamera.org/api/patches/26649/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26649/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260506221944.066FD1EA006B@mailuser.phl.internal>", "date": "2026-05-06T21:46:28", "name": "[v5,2/3] libcamera: software_isp: Normalize statistics sums to 8-bit", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "14ac6b111e409b665395fc252fe1c6296d901e20", "submitter": { "id": 261, "url": "https://patchwork.libcamera.org/api/people/261/?format=api", "name": "Javier Tia", "email": "floss@jetm.me" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26649/mbox/", "series": [ { "id": 5913, "url": "https://patchwork.libcamera.org/api/series/5913/?format=api", "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/patches/26649/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26649/checks/", "tags": {}, "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 4B35FC32F7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 6 May 2026 22:19:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EEA1063021;\n\tThu, 7 May 2026 00:19:46 +0200 (CEST)", "from fhigh-a6-smtp.messagingengine.com\n\t(fhigh-a6-smtp.messagingengine.com [103.168.172.157])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C88C66301A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 7 May 2026 00:19:44 +0200 (CEST)", "from phl-compute-02.internal (phl-compute-02.internal\n\t[10.202.2.42])\n\tby mailfhigh.phl.internal (Postfix) with ESMTP id 239EB1400104;\n\tWed, 6 May 2026 18:19:44 -0400 (EDT)", "from phl-imap-07 ([10.202.2.97])\n\tby phl-compute-02.internal (MEProxy); Wed, 06 May 2026 18:19:44 -0400", "by mailuser.phl.internal (Postfix, from userid 501)\n\tid 066FD1EA006B; Wed, 6 May 2026 18:19:44 -0400 (EDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=jetm.me header.i=@jetm.me header.b=\"sCnzFFRr\";\n\tdkim=pass (2048-bit key;\n\tunprotected) header.d=messagingengine.com\n\theader.i=@messagingengine.com header.b=\"DswLGRyn\"; \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=1778105984;\n\tx=1778192384; bh=5MB+QUJnQv7BuMZdc1sbTeJZxf3mGgcxn80Hy32zQLE=; b=\n\tsCnzFFRriEz+CHuS+K/Mh9dlP2X6xTDsORoVa4iu1oau7agLZ9wzP0OARV9lri+o\n\tJEWK0LP5payZCNUQTZlHoNpeSlK7XZTjb2yTD1Kx+X2AGrrnREKx0VzhWXQr0LJ6\n\t38JDzpGT2sSMkKDThINdxATKPOByUhDmcZUc5vGsxnDRgdKa23KbMRBUTGGl94mA\n\tk89z9pTG0pRl+HL/wbIBy6b+fxNDClMeLWWeif7Ua1trsFVsE/S5ZVXMPLmSWxUq\n\t2/cqCms2dWFAJHTfzSjSrpK7UC4APAhr9iyvx7t0V0weI4Cf1EMZ4DOijfzlgkSE\n\te/B8ME0TKH18Hxk+pZOZ+Q==", "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=1778105984; x=\n\t1778192384; bh=5MB+QUJnQv7BuMZdc1sbTeJZxf3mGgcxn80Hy32zQLE=; b=D\n\tswLGRynmyG8uiiiH2WGrbXgXjUhUs6Ho4TgbmCOVZH0TLXqQ3omqpzFgNDTKxXlb\n\tJINmiLDzzfbQhOTQun2KrgV+kNbfWR0+nGMIf3Zo0Qz2iuaXY0w0etPTqBNGdhB3\n\t+hkr+DlaYxWhcDVoHIdXGb1e0jHl5mFz8kNjxrERzCFSJ6RxvminYe8yIeGAjG6G\n\tfyNSJ3bOhwyM0JwFgBqTKpCUiJcmzBIfesvDLkBsESvnEHyA7KFAKnKEkWXGCJd6\n\tsgl1x+xgIvpmdDGUAVy2nj6pI1hFB0qIVIMq4Fgm7ZEaydK9FDcI3NCXFDaX6FhU\n\tpD9dx/89A7EWC2MW0gV0w==" ], "X-ME-Sender": "<xms:gL77aZGNQIIPOu_mveanVXEeRiccE-tZxXoBba_qf5NqrbpYLSoOLw>\n\t<xme:gL77aZJg548q7b42BJwfOoYae4MTqGxuylSJRga3e-h20BDxz8_QLsGYacbxI0j8H\n\tMfvmytrauvRx_5mEIX86oyEdZBKJY8NPHCX31C-mgUlNhehjIVKmrs>", "X-ME-Proxy-Cause": "gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddutdehjeejucetufdoteggodetrf\n\tdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu\n\trghilhhouhhtmecufedttdenucgopfhokfffucdluddtmdenucfjughrpefotggggffhvf\n\tffufevjghfsehtkedttdertdejnecuhfhrohhmpeflrghvihgvrhcuvfhirgcuoehflhho\n\tshhssehjvghtmhdrmhgvqeenucggtffrrghtthgvrhhnpedtudejffejkeekteelueefvd\n\tejvdeuhfefteehkeevtddvleduteekleetvdelhfenucevlhhushhtvghrufhiiigvpedt\n\tnecurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvghtmhdrmhgvpdhnsggprh\n\tgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegsrghrnhgrsggr\n\tshdrphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohepkhhivg\n\thrrghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthho\n\tpehlihgstggrmhgvrhgrqdguvghvvghlsehlihhsthhsrdhlihgstggrmhgvrhgrrdhorh\n\thgpdhrtghpthhtohepmhiirghmrgiirghlsehrvgguhhgrthdrtghomh", "X-ME-Proxy": "<xmx:gL77aatwnFWKDOf6iO4bG2CcECWrTzd_OTWKMCIGFPRp7IFykKqC-g>\n\t<xmx:gL77adSomQF6hGNUYg1_w3jevOmeaoXfaHtJ0Mplhxcyzgqlm_FWeA>\n\t<xmx:gL77aQOQzOQU2WNNu03g-eOXS-GalqBVbyOfYgpVq4vA8rDjf9-lcQ>\n\t<xmx:gL77aSZR1t9_F7FjrIvBLa_aBSONunqwSzf3qJ_wznYc2YqHy_icew>\n\t<xmx:gL77aT7PkfhYp9ruAT197XSeYTA_BRCYDjc8UtsfhGLZ0Be7yx5Aeyn0>", "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:46:28 -0600", "Subject": "[PATCH v5 2/3] libcamera: software_isp: Normalize statistics sums to\n\t8-bit", "Cc": "mzamazal@redhat.com, barnabas.pocze@ideasonboard.com,\n\tkieran.bingham@ideasonboard.com", "In-Reply-To": "<177810597783.688418.1631246733707368646@jetm.me>", "References": "<177810597783.688418.1631246733707368646@jetm.me>", "Message-Id": "<20260506221944.066FD1EA006B@mailuser.phl.internal>", "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 SWSTATS_ACCUMULATE_LINE_STATS() macro divides the luminance value\nfor the histogram to normalize it to 8-bit range, but does not apply\nthe same normalization to the RGB sums. For 10-bit and 12-bit unpacked\nBayer formats this means the sums are accumulated at native bit depth\n(0-1023 or 0-4095 per pixel) while the AWB algorithm subtracts an\n8-bit black level from them, under-correcting by 4x or 16x\nrespectively.\n\nThis mismatch between the AWB's gain calculation (using incorrectly\nBLC-subtracted sums) and the debayer's correct normalized BLC\nsubtraction produces a visible color cast. For example, with the\nOV2740 sensor (10-bit, BLC=16), the under-subtraction skews R/G gain\nby ~9%.\n\nFix this by right-shifting the RGB sums in finishFrame() to normalize\nthem to 8-bit scale, matching the histogram and the 8-bit black level\nused by AWB. A per-format sumShift_ value is set in configure():\n0 for 8-bit and CSI-2 packed formats (already 8-bit), 2 for 10-bit,\nand 4 for 12-bit unpacked formats.\n\nSigned-off-by: Javier Tia <floss@jetm.me>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nTested-by: Milan Zamazal <mzamazal@redhat.com>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nTested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/internal/software_isp/swstats_cpu.h | 1 +\n src/libcamera/software_isp/swstats_cpu.cpp | 9 +++++++++\n 2 files changed, 10 insertions(+)", "diff": "diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nindex 802370bd..2dac6945 100644\n--- a/include/libcamera/internal/software_isp/swstats_cpu.h\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -116,6 +116,7 @@ private:\n \n \tunsigned int xShift_;\n \tunsigned int stride_;\n+\tunsigned int sumShift_;\n \n \tstd::vector<SwIspStats> stats_;\n \tSharedMemObject<SwIspStats> sharedStats_;\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 5366e019..b40d3334 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -362,6 +362,11 @@ void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n \t\t\tfor (unsigned int j = 0; j < SwIspStats::kYHistogramSize; j++)\n \t\t\t\tsharedStats_->yHistogram[j] += s.yHistogram[j];\n \t\t}\n+\t\tif (sumShift_) {\n+\t\t\tsharedStats_->sum_.r() >>= sumShift_;\n+\t\t\tsharedStats_->sum_.g() >>= sumShift_;\n+\t\t\tsharedStats_->sum_.b() >>= sumShift_;\n+\t\t}\n \t}\n \n \tsharedStats_->valid = valid;\n@@ -425,12 +430,15 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg, unsigned int stat\n \t\tswitch (bayerFormat.bitDepth) {\n \t\tcase 8:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n+\t\t\tsumShift_ = 0;\n \t\t\treturn 0;\n \t\tcase 10:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR10Line0;\n+\t\t\tsumShift_ = 2;\n \t\t\treturn 0;\n \t\tcase 12:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR12Line0;\n+\t\t\tsumShift_ = 4;\n \t\t\treturn 0;\n \t\t}\n \t}\n@@ -442,6 +450,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg, unsigned int stat\n \t\t/* Skip every 3th and 4th line, sample every other 2x2 block */\n \t\tySkipMask_ = 0x02;\n \t\txShift_ = 0;\n+\t\tsumShift_ = 0;\n \t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n \n \t\tswitch (bayerFormat.order) {\n", "prefixes": [ "v5", "2/3" ] }