Show a patch.

GET /api/1.1/patches/26268/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 26268,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/26268/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26268/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20260306-agc-proportional-v4-2-e87c7e0d837a@jetm.me>",
    "date": "2026-03-06T18:46:41",
    "name": "[v4,2/3] libcamera: software_isp: Normalize statistics sums to 8-bit",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "15d3a93126e966d30f221d659254a61949de44c9",
    "submitter": {
        "id": 261,
        "url": "https://patchwork.libcamera.org/api/1.1/people/261/?format=api",
        "name": "Javier Tia",
        "email": "floss@jetm.me"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/26268/mbox/",
    "series": [
        {
            "id": 5824,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5824/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5824",
            "date": "2026-03-06T18:46:39",
            "name": "Simple pipeline: proportional AGC, AWB stats fix, OV2740 black level",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/5824/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26268/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26268/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 C9E49BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Mar 2026 18:47:26 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7ED6162633;\n\tFri,  6 Mar 2026 19:47:26 +0100 (CET)",
            "from fout-b3-smtp.messagingengine.com\n\t(fout-b3-smtp.messagingengine.com [202.12.124.146])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 815686261B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2026 19:47:25 +0100 (CET)",
            "from phl-compute-02.internal (phl-compute-02.internal\n\t[10.202.2.42])\n\tby mailfout.stl.internal (Postfix) with ESMTP id 8EC401D00128;\n\tFri,  6 Mar 2026 13:47:24 -0500 (EST)",
            "from phl-imap-07 ([10.202.2.97])\n\tby phl-compute-02.internal (MEProxy); Fri, 06 Mar 2026 13:47:24 -0500",
            "by mailuser.phl.internal (Postfix, from userid 501)\n\tid 4CD991EA006B; Fri,  6 Mar 2026 13:47:24 -0500 (EST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=jetm.me header.i=@jetm.me header.b=\"qOKeJDgj\";\n\tdkim=pass (2048-bit key;\n\tunprotected) header.d=messagingengine.com\n\theader.i=@messagingengine.com header.b=\"bOVksbR2\"; \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=fm3; t=1772822844;\n\tx=1772909244; bh=fFQMfRVX4SXJwh9RbOEBdeIDJ6/usq4wS8mkK6iJZ/4=; b=\n\tqOKeJDgjFyeXmQxKn+HXG57pp9CnvSjhVY7uW9tTsGQPSqRHjY64PvtaLAI9x5Et\n\tMqTpVImSye4CeA1hiJeB7zw1QStbpP4rf/q0kbobrzM6+oORUkaEETGFZRJ1bVfa\n\t76RLcZQfFlJ95gEqGeUSFAEN0fnN/AwvL62VMjU/sReWcDB/j/TCqmR0OxjJUP53\n\tnIi7gxRlO34x4u6CLxLfdyZ0xZE/RY2qdtUEFcxbYY65u8svdPG49rfFypx7CpDU\n\tb3wQQaw1XHRb9lhThEpoc9N14fU5RmSlfP5GUapeSbVWwYty6q8gz0X7J2s7MGng\n\tKfQtLR2raO8HyQOilrGoMA==",
            "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=fm1; t=1772822844; x=\n\t1772909244; bh=fFQMfRVX4SXJwh9RbOEBdeIDJ6/usq4wS8mkK6iJZ/4=; b=b\n\tOVksbR2c2ujL1cim2h1R2XJR2of872s2Qwgt1O3QJYAkba0F20zX07wzidS1mHYK\n\tcBgw/8vfrap8cwU0u1ZWsGk9x+niIle4QIxvwSj1WAtK4IRAjbyveDH9hej/ldNI\n\t38eABC0l/CVqFbnYT+gtKJz7jrC37ZVnyrLBpnaKdR4yA8j1Uj9b6Y1W9GhvmClq\n\tivqXhtLZNjCOGN98HUbl2HL+oTenu+xb+AW+cy+AzXaJbEMPQqvZiRKScnTv8CKp\n\tZrh9uyA9Gh91i6B2DxegCEfBB50/DlOa8sFeuWvtZVc2LHdqQsMSfS1TVznQ1m1+\n\t4HTgf8gprtMa7oJjyOs7w=="
        ],
        "X-ME-Sender": "<xms:PCGraTvhzYDd7nzZrP1mO6kuZMw7wV8TPov4XhzDQvClUeGWeWN1aA>\n\t<xme:PCGrafS79nddV0ttXuzQ_iAzG99q4rYG0lf75MLYXXA3JoZtFiXoID2lXCDOb3TfJ\n\tvUfsmU6Aextma8iTcUKeywr-xW-vlJ2w3vx23GDTBlQ5zWFsBEgf8k>",
        "X-ME-Proxy-Cause": "gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvjedttdegucetufdoteggodetrf\n\tdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu\n\trghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf\n\tgurhepoffhfffugggtgffkvfevofgjfhesthekredtredtjeenucfhrhhomheplfgrvhhi\n\tvghrucfvihgruceofhhlohhsshesjhgvthhmrdhmvgeqnecuggftrfgrthhtvghrnhepve\n\tektdfhffevuddtgfetieevtddvheduhfeggfekveejlefhleefieevueefiefhnecuvehl\n\tuhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepfhhlohhsshesjh\n\tgvthhmrdhmvgdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghp\n\tthhtohepsggrrhhnrggsrghsrdhpohgtiigvsehiuggvrghsohhnsghorghrugdrtghomh\n\tdprhgtphhtthhopehflhhoshhssehjvghtmhdrmhgvpdhrtghpthhtoheplhhisggtrghm\n\tvghrrgdquggvvhgvlheslhhishhtshdrlhhisggtrghmvghrrgdrohhrghdprhgtphhtth\n\thopehmiigrmhgriigrlhesrhgvughhrghtrdgtohhm",
        "X-ME-Proxy": "<xmx:PCGrabWKazZBLl9Iv5ClpgvLC9_--TLvrP7m-Y6ViFXUAlHKXIPx4w>\n\t<xmx:PCGraRa7ZHjmXfpVMGddq_lEu7HVdbaICStGIsUvE_m2cokXpMg1eg>\n\t<xmx:PCGraR2igvw__C285Fv073FTUe8QH4r3CcwgDA0KejFcTk2xM9t5Fw>\n\t<xmx:PCGraThil8j_w_wQQGms94tc5Js3XcOIV8535PKo4EZF0dfwb_VvUQ>\n\t<xmx:PCGrab62sSlDzKutK7bZv3FQuaaM7tr1BpehvO5htY2ItwIoTjdBQG9D>",
        "Feedback-ID": "i9dde48b3:Fastmail",
        "X-Mailer": [
            "MessagingEngine.com Webmail Interface",
            "b4 0.14.3"
        ],
        "From": "Javier Tia <floss@jetm.me>",
        "Date": "Fri, 06 Mar 2026 12:46:41 -0600",
        "Subject": "[PATCH v4 2/3] libcamera: software_isp: Normalize statistics sums\n\tto 8-bit",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "8bit",
        "Message-Id": "<20260306-agc-proportional-v4-2-e87c7e0d837a@jetm.me>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Javier Tia <floss@jetm.me>, Milan Zamazal <mzamazal@redhat.com>,\n\t=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=3262; i=floss@jetm.me;\n\th=from:subject:message-id;\n\tbh=LPdCiSDd3MA8NAdHMsUrfV6hJzO9wW24ssL+LcTrfSg=; \n\tb=owEB7QES/pANAwAKAbXuwwuoZ3cfAcsmYgBpqyEPM0DYOvoMGOjeah2y0sdaHWmcMOG/wzKEq\n\tOmSLOmMOZyJAbMEAAEKAB0WIQSbE7ILzw7eI0VKk8m17sMLqGd3HwUCaashDwAKCRC17sMLqGd3\n\tHyFDDACbwlLXhgrHH3oYsJfyvDmsJhZH9uK8XpvVjFAK7LDYGWHy+2v9Or3k574Cut7XRAmIV3L\n\tdvE8W1DH2nQmIUlFL9xdGzaGbyjtXss2xcpZvw1DL4mT4QYyZxhXVCHWXGfTv98AsgfFIWgLAT3\n\t1m0yd5Y+DDzsvVGafZl2JOMm1Kjzd/RGCN1OTSPdSTUGLLoAg++SfBIpQ6ogMeIfSKcA5kX3nGy\n\tv3sg31YLf5kEZHPPwLHGqFG5fCx//x6qyM9/JrLXDmg0qruRaEm95wAFefMTvgGzU0JFC78HEVZ\n\tsfJl+i6cQpVH8VCY0YTTatqLQ1tJxjjyCTBNMRnX5QSGa/UA4sM6OvBwwl1goolYdJAlpS65331\n\tITMcTliQJJtSxVY5VyAPZH7g5xTV0RldRgCnjYwCOQVIDx20eB7M2Ml3C6Q3YZ5P8Me4z1Dx7No\n\tGZ5wWqvDi2jt0M+Ph1ybCZZxcfSZlCxcw4+13OSm944/EIgq0GXlrxanOuy5rQmKOYjng=",
        "X-Developer-Key": "i=floss@jetm.me; a=openpgp;\n\tfpr=9B13B20BCF0EDE23454A93C9B5EEC30BA867771F",
        "In-Reply-To": "<20260306-agc-proportional-v4-0-e87c7e0d837a@jetm.me>",
        "References": "<20260306-agc-proportional-v4-0-e87c7e0d837a@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 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            | 7 +++++++\n 2 files changed, 8 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h\nindex 64b3e23f..37bfde53 100644\n--- a/include/libcamera/internal/software_isp/swstats_cpu.h\n+++ b/include/libcamera/internal/software_isp/swstats_cpu.h\n@@ -115,6 +115,7 @@ private:\n \n \tunsigned int xShift_;\n \tunsigned int stride_;\n+\tunsigned int sumShift_;\n \n \tSharedMemObject<SwIspStats> sharedStats_;\n \tSwIspStats stats_;\ndiff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\nindex 1cedcfbc..744a7560 100644\n--- a/src/libcamera/software_isp/swstats_cpu.cpp\n+++ b/src/libcamera/software_isp/swstats_cpu.cpp\n@@ -346,6 +346,11 @@ void SwStatsCpu::startFrame(uint32_t frame)\n void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId)\n {\n \tstats_.valid = frame % kStatPerNumFrames == 0;\n+\tif (stats_.valid && sumShift_) {\n+\t\tstats_.sum_.r() >>= sumShift_;\n+\t\tstats_.sum_.g() >>= sumShift_;\n+\t\tstats_.sum_.b() >>= sumShift_;\n+\t}\n \t*sharedStats_ = stats_;\n \tstatsReady.emit(frame, bufferId);\n }\n@@ -402,6 +407,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\n \tif (bayerFormat.packing == BayerFormat::Packing::None &&\n \t    setupStandardBayerOrder(bayerFormat.order) == 0) {\n \t\tprocessFrame_ = &SwStatsCpu::processBayerFrame2;\n+\t\tsumShift_ = bayerFormat.bitDepth - 8;\n \t\tswitch (bayerFormat.bitDepth) {\n \t\tcase 8:\n \t\t\tstats0_ = &SwStatsCpu::statsBGGR8Line0;\n@@ -422,6 +428,7 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)\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": [
        "v4",
        "2/3"
    ]
}