Show a patch.

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

{
    "id": 19973,
    "url": "https://patchwork.libcamera.org/api/patches/19973/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19973/",
    "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-6-mzamazal@redhat.com>",
    "date": "2024-04-30T17:34:30",
    "name": "[v2,5/5] libcamera: software_isp: Pass color lookup tables as floats",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c5ac89091980ed96746e1a0b0fd8cadc241fa894",
    "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/19973/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/19973/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19973/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 386FDC32CA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Apr 2024 17:35:08 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9322F63420;\n\tTue, 30 Apr 2024 19:35:07 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE5EA6341E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Apr 2024 19:35:01 +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-444-6cVfNg0LPFi9wtTvrMF9Jw-1; Tue, 30 Apr 2024 13:34:58 -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 6450D80017B;\n\tTue, 30 Apr 2024 17:34:58 +0000 (UTC)",
            "from nuthatch.redhat.com (unknown [10.45.224.26])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 506901BDB7;\n\tTue, 30 Apr 2024 17:34:57 +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=\"aMgSV3oc\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1714498500;\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=9vOTcsvb0XG7fZp/r6Z5kg0EbCgL2arKuk5L0aAvEys=;\n\tb=aMgSV3ocqXGpwCPv8YCnmAv/G1vd9VuZ79dUJ6n5qWbi0VxQh77D9F83lviLDwC4xr9gio\n\tFscN1uro0UZoZJ0f7OZ4b8l20srQA00uHAaD/xezF2WsIxMPmDtqtW2hVqIu/O6er0lXX+\n\ttMx5pywEsALkiZMBckO62aiJm3jHfSU=",
        "X-MC-Unique": "6cVfNg0LPFi9wtTvrMF9Jw-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 5/5] libcamera: software_isp: Pass color lookup tables as\n\tfloats",
        "Date": "Tue, 30 Apr 2024 19:34:30 +0200",
        "Message-ID": "<20240430173430.200392-6-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 color lookup tables are passed from stats processing to debayering\nfor direct use as 8-bit color output values.  Let's pass the values as\n0.0..1.0 floats to make the gains color bit width independent.\n\nCompletes software ISP TODO #4.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../internal/software_isp/debayer_params.h     |  2 +-\n src/ipa/simple/soft_simple.cpp                 |  4 ++--\n src/libcamera/software_isp/TODO                | 13 -------------\n src/libcamera/software_isp/debayer.cpp         |  6 +++---\n src/libcamera/software_isp/debayer_cpu.cpp     | 18 +++++++++++++++---\n src/libcamera/software_isp/debayer_cpu.h       | 10 +++++++---\n 6 files changed, 28 insertions(+), 25 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h\nindex 6aaa7d4c..a29eb37a 100644\n--- a/include/libcamera/internal/software_isp/debayer_params.h\n+++ b/include/libcamera/internal/software_isp/debayer_params.h\n@@ -18,7 +18,7 @@ namespace libcamera {\n struct DebayerParams {\n \tstatic constexpr unsigned int kRGBLookupSize = 256;\n \n-\tusing ColorLookupTable = std::array<uint8_t, kRGBLookupSize>;\n+\tusing ColorLookupTable = std::array<float, kRGBLookupSize>;\n \n \tColorLookupTable red;\n \tColorLookupTable green;\ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex 0af23ee7..017fd15a 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -86,7 +86,7 @@ private:\n \tBlackLevel blackLevel_;\n \n \tstatic constexpr unsigned int kGammaLookupSize = 1024;\n-\tstd::array<uint8_t, kGammaLookupSize> gammaTable_;\n+\tstd::array<float, kGammaLookupSize> gammaTable_;\n \tint lastBlackLevel_ = -1;\n \n \tint32_t exposureMin_, exposureMax_;\n@@ -283,7 +283,7 @@ void IPASoftSimple::processStats(const ControlList &sensorControls)\n \t\tstd::fill(gammaTable_.begin(), gammaTable_.begin() + blackIndex, 0);\n \t\tconst float divisor = kGammaLookupSize - blackIndex - 1.0;\n \t\tfor (unsigned int i = blackIndex; i < kGammaLookupSize; i++)\n-\t\t\tgammaTable_[i] = UINT8_MAX * powf((i - blackIndex) / divisor, gamma);\n+\t\t\tgammaTable_[i] = powf((i - blackIndex) / divisor, gamma);\n \n \t\tlastBlackLevel_ = blackLevel;\n \t}\ndiff --git a/src/libcamera/software_isp/TODO b/src/libcamera/software_isp/TODO\nindex 4fcee39b..6bdc5905 100644\n--- a/src/libcamera/software_isp/TODO\n+++ b/src/libcamera/software_isp/TODO\n@@ -72,19 +72,6 @@ stats in hardware, such as the i.MX7), but please keep it on your radar.\n \n ---\n \n-4. Hide internal representation of gains from callers\n-\n-> struct DebayerParams {\n-> \tstatic constexpr unsigned int kGain10 = 256;\n-\n-Forcing the caller to deal with the internal representation of gains\n-isn't nice, especially given that it precludes implementing gains of\n-different precisions in different backend. Wouldn't it be better to pass\n-the values as floating point numbers, and convert them to the internal\n-representation in the implementation of process() before using them ?\n-\n----\n-\n 5. Store ISP parameters in per-frame buffers\n \n > /**\ndiff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp\nindex 548c2ccd..acc9cd21 100644\n--- a/src/libcamera/software_isp/debayer.cpp\n+++ b/src/libcamera/software_isp/debayer.cpp\n@@ -30,17 +30,17 @@ namespace libcamera {\n \n /**\n  * \\var DebayerParams::red\n- * \\brief Lookup table for red color, mapping input values to output values\n+ * \\brief Lookup table for red color, mapping input values to 0.0..1.0\n  */\n \n /**\n  * \\var DebayerParams::green\n- * \\brief Lookup table for green color, mapping input values to output values\n+ * \\brief Lookup table for green color, mapping input values to 0.0..1.0\n  */\n \n /**\n  * \\var DebayerParams::blue\n- * \\brief Lookup table for blue color, mapping input values to output values\n+ * \\brief Lookup table for blue color, mapping input values to 0.0..1.0\n  */\n \n /**\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 8b2b2f40..df4c6e88 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -11,6 +11,8 @@\n \n #include \"debayer_cpu.h\"\n \n+#include <stddef.h>\n+#include <stdint.h>\n #include <stdlib.h>\n #include <time.h>\n \n@@ -688,6 +690,14 @@ static inline int64_t timeDiff(timespec &after, timespec &before)\n \t       (int64_t)after.tv_nsec - (int64_t)before.tv_nsec;\n }\n \n+void DebayerCpu::updateColorLookupTable(\n+\tconst DebayerParams::ColorLookupTable &src,\n+\tColorLookupTable &dst)\n+{\n+\tfor (std::size_t i = 0; i < src.size(); i++)\n+\t\tdst[i] = src[i] * UINT8_MAX;\n+}\n+\n void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n {\n \ttimespec frameStartTime;\n@@ -697,9 +707,11 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams\n \t\tclock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);\n \t}\n \n-\tgreen_ = params.green;\n-\tred_ = swapRedBlueGains_ ? params.blue : params.red;\n-\tblue_ = swapRedBlueGains_ ? params.red : params.blue;\n+\tupdateColorLookupTable(params.green, green_);\n+\tupdateColorLookupTable(swapRedBlueGains_ ? params.blue : params.red,\n+\t\t\t       red_);\n+\tupdateColorLookupTable(swapRedBlueGains_ ? params.red : params.blue,\n+\t\t\t       blue_);\n \n \t/* Copy metadata from the input buffer */\n \tFrameMetadata &metadata = output->_d()->metadata();\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 47373426..18808076 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -18,6 +18,7 @@\n #include <libcamera/base/object.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/software_isp/debayer_params.h\"\n \n #include \"debayer.h\"\n #include \"swstats_cpu.h\"\n@@ -125,9 +126,12 @@ private:\n \t/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */\n \tstatic constexpr unsigned int kMaxLineBuffers = 5;\n \n-\tDebayerParams::ColorLookupTable red_;\n-\tDebayerParams::ColorLookupTable green_;\n-\tDebayerParams::ColorLookupTable blue_;\n+\tusing ColorLookupTable = std::array<uint8_t, DebayerParams::kRGBLookupSize>;\n+\tvoid updateColorLookupTable(const DebayerParams::ColorLookupTable &src,\n+\t\t\t\t    ColorLookupTable &dst);\n+\tColorLookupTable red_;\n+\tColorLookupTable green_;\n+\tColorLookupTable blue_;\n \tdebayerFn debayer0_;\n \tdebayerFn debayer1_;\n \tdebayerFn debayer2_;\n",
    "prefixes": [
        "v2",
        "5/5"
    ]
}