Show a patch.

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

{
    "id": 19969,
    "url": "https://patchwork.libcamera.org/api/patches/19969/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19969/",
    "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": "<20240430173430.200392-3-mzamazal@redhat.com>",
    "date": "2024-04-30T17:34:27",
    "name": "[v2,2/5] libcamera: software_isp: Honor black level in AWB",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "2b896ebe7d3c796e82badda432fc5dff3a09330d",
    "submitter": {
        "id": 177,
        "url": "https://patchwork.libcamera.org/api/people/177/?format=api",
        "name": "Milan Zamazal",
        "email": "mzamazal@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19969/mbox/",
    "series": [
        {
            "id": 4280,
            "url": "https://patchwork.libcamera.org/api/series/4280/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4280",
            "date": "2024-04-30T17:34:25",
            "name": "Software ISP levels cleanup",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4280/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19969/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19969/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 6C0A3C3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Apr 2024 17:34:59 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 153C16341B;\n\tTue, 30 Apr 2024 19:34:59 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E6B1A63415\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Apr 2024 19:34:56 +0200 (CEST)",
            "from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n\t[66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-501-anaKCHfEPquiJm3a0QuSgw-1; Tue, 30 Apr 2024 13:34:54 -0400",
            "from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10ED5182717E;\n\tTue, 30 Apr 2024 17:34:54 +0000 (UTC)",
            "from nuthatch.redhat.com (unknown [10.45.224.26])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 07EC51BDB2;\n\tTue, 30 Apr 2024 17:34:52 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"bgzswFVK\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1714498496;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=C7GP/0/DF8Lmd5f5yLEVjIMYHES4hilTXexSX60y46o=;\n\tb=bgzswFVK2jx8vdmggtDoPU9vAWVCQMMy5t0kHVZhxfT+ggNRZeN+kCJGTUOOdKIG3KkWUe\n\tvYm/xeH8B78FqbrU3vkodythvkXqiAG7eL/hLw2E0pfe7VUFZ0XW4ZCaWChUsUZNNzly2M\n\tdCryESGazQYD/lgrcVyFyS+gY0lekBI=",
        "X-MC-Unique": "anaKCHfEPquiJm3a0QuSgw-1",
        "From": "Milan Zamazal <mzamazal@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Milan Zamazal <mzamazal@redhat.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH v2 2/5] libcamera: software_isp: Honor black level in AWB",
        "Date": "Tue, 30 Apr 2024 19:34:27 +0200",
        "Message-ID": "<20240430173430.200392-3-mzamazal@redhat.com>",
        "In-Reply-To": "<20240430173430.200392-1-mzamazal@redhat.com>",
        "References": "<20240430173430.200392-1-mzamazal@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.5",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "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 white balance computation didn't consider black level.  This is\nwrong because then the computed ratios are off when they are computed\nfrom the whole brightness range rather than the sensor range.\n\nThis patch adjusts white balance computation for the black level.  There\nis no need to change white balance application in debayering as this is\nalready applied after black level correction.\n\nExposure computation already subtracts black level, no changes are\nneeded there.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/ipa/simple/soft_simple.cpp | 36 ++++++++++++++++++++++------------\n 1 file changed, 23 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex b9fb58b5..f595abc2 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -5,6 +5,8 @@\n  * soft_simple.cpp - Simple Software Image Processing Algorithm module\n  */\n \n+#include <numeric>\n+#include <stdint.h>\n #include <sys/mman.h>\n \n #include <linux/v4l2-controls.h>\n@@ -240,28 +242,36 @@ void IPASoftSimple::stop()\n \n void IPASoftSimple::processStats(const ControlList &sensorControls)\n {\n+\tSwIspStats::Histogram histogram = stats_->yHistogram;\n+\tif (ignoreUpdates_ > 0)\n+\t\tblackLevel_.update(histogram);\n+\tconst uint8_t blackLevel = blackLevel_.get();\n+\tparams_->blackLevel = blackLevel;\n+\n \t/*\n \t * Calculate red and blue gains for AWB.\n \t * Clamp max gain at 4.0, this also avoids 0 division.\n+\t * Black level must be subtracted to get the correct AWB ratios,\n+\t * from the sensor range.\n \t */\n-\tif (stats_->sumR_ <= stats_->sumG_ / 4)\n-\t\tparams_->gainR = 1024;\n-\telse\n-\t\tparams_->gainR = 256 * stats_->sumG_ / stats_->sumR_;\n-\n-\tif (stats_->sumB_ <= stats_->sumG_ / 4)\n-\t\tparams_->gainB = 1024;\n-\telse\n-\t\tparams_->gainB = 256 * stats_->sumG_ / stats_->sumB_;\n+\tconst uint64_t nPixels = std::accumulate(\n+\t\thistogram.begin(), histogram.end(), 0);\n+\tauto subtractBlackLevel = [blackLevel, nPixels](\n+\t\t\t\t\t  uint64_t sum, uint64_t div)\n+\t\t-> uint64_t {\n+\t\treturn sum - blackLevel * nPixels / div;\n+\t};\n+\tconst uint64_t sumR = subtractBlackLevel(stats_->sumR_, 4);\n+\tconst uint64_t sumG = subtractBlackLevel(stats_->sumG_, 2);\n+\tconst uint64_t sumB = subtractBlackLevel(stats_->sumB_, 4);\n+\n+\tparams_->gainR = sumR <= sumG / 4 ? 1024 : 256 * sumG / sumR;\n+\tparams_->gainB = sumB <= sumG / 4 ? 1024 : 256 * sumG / sumB;\n \n \t/* Green gain and gamma values are fixed */\n \tparams_->gainG = 256;\n \tparams_->gamma = 0.5;\n \n-\tif (ignoreUpdates_ > 0)\n-\t\tblackLevel_.update(stats_->yHistogram);\n-\tparams_->blackLevel = blackLevel_.get();\n-\n \tsetIspParams.emit();\n \n \t/* \\todo Switch to the libipa/algorithm.h API someday. */\n",
    "prefixes": [
        "v2",
        "2/5"
    ]
}