Show a patch.

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

{
    "id": 17777,
    "url": "https://patchwork.libcamera.org/api/patches/17777/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17777/",
    "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": "<20221110173154.488445-7-paul.elder@ideasonboard.com>",
    "date": "2022-11-10T17:31:48",
    "name": "[libcamera-devel,v3,06/12] utils: libtuning: modules: alsc: Add rkisp1 LSC module",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "817663e66940932c304a18120d6b64d17c58f191",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17777/mbox/",
    "series": [
        {
            "id": 3603,
            "url": "https://patchwork.libcamera.org/api/series/3603/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3603",
            "date": "2022-11-10T17:31:42",
            "name": "utils: tuning: Add a new tuning infrastructure",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3603/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17777/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17777/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 19A3EBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Nov 2022 17:32:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CE3C56308B;\n\tThu, 10 Nov 2022 18:32:30 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 933C463095\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Nov 2022 18:32:28 +0100 (CET)",
            "from pyrite.tail37cf.ts.net (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DE0DD32A;\n\tThu, 10 Nov 2022 18:32:26 +0100 (CET)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1668101550;\n\tbh=BjCaB0QldZmxZ0Fh5H/UuRQuK71C907T+uet7dBiI9Q=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=n68QArsVOqV99NNvh6Q2LqugMwulTp5A52qctGITWRY8wawrmDINUH5jopda2aBrN\n\tbcOUNZuIIeb4+aM5YHJdoD4+8F8PARgSYj/9QMUZWbelxTbnci/Yxa4EKiGpaIeCBb\n\tpuaDijvN1OTqMc08IkG2R00gvBjZ1rAx2lM/n5oPKeBK+xEJNXirtuG/oxtECb2+A8\n\terPBrz7WVD1P3+lfdTP3XJ5PVv16A2GjPCtk679XYwp37vvDSuQ/QLcuhi/ziBC3jz\n\tlIm8KYFlp2klGcXnplFYjkLyMsAIEw2OilVcBtNXR2zOQGft9RisEpzjsEOQ+LTXu7\n\tFTeYTNpOG673A==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1668101548;\n\tbh=BjCaB0QldZmxZ0Fh5H/UuRQuK71C907T+uet7dBiI9Q=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Jxl3adbd8NZ9ojOATATL22tGSrpjzQqDcmd5ErQbVOjVPlkXbJ26CB4dPhhLzvzRO\n\tEHyo7ioU1DMHC/e7Rp9m9gAXbZyJSJ66b7ex0cIe3A6WsRz1kDBJuOBUpGPmIHUrTY\n\tMXKODKh96TbS9cjUxFh4pW/PIcET0sH56cx6Tpso="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Jxl3adbd\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 11 Nov 2022 02:31:48 +0900",
        "Message-Id": "<20221110173154.488445-7-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20221110173154.488445-1-paul.elder@ideasonboard.com>",
        "References": "<20221110173154.488445-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 06/12] utils: libtuning: modules: alsc:\n\tAdd rkisp1 LSC module",
        "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>",
        "From": "Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Paul Elder <paul.elder@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add an LSC module for RkISP1.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v3:\n- rename ALSC to LSC\n- add file description\n\nNew in v2\n---\n .../tuning/libtuning/modules/lsc/__init__.py  |   1 +\n utils/tuning/libtuning/modules/lsc/rkisp1.py  | 114 ++++++++++++++++++\n 2 files changed, 115 insertions(+)\n create mode 100644 utils/tuning/libtuning/modules/lsc/rkisp1.py",
    "diff": "diff --git a/utils/tuning/libtuning/modules/lsc/__init__.py b/utils/tuning/libtuning/modules/lsc/__init__.py\nindex 7cdecdb8..0ba4411b 100644\n--- a/utils/tuning/libtuning/modules/lsc/__init__.py\n+++ b/utils/tuning/libtuning/modules/lsc/__init__.py\n@@ -4,3 +4,4 @@\n \n from libtuning.modules.lsc.lsc import LSC\n from libtuning.modules.lsc.raspberrypi import ALSCRaspberryPi\n+from libtuning.modules.lsc.rkisp1 import LSCRkISP1\ndiff --git a/utils/tuning/libtuning/modules/lsc/rkisp1.py b/utils/tuning/libtuning/modules/lsc/rkisp1.py\nnew file mode 100644\nindex 00000000..150d6001\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/lsc/rkisp1.py\n@@ -0,0 +1,114 @@\n+# SPDX-License-Identifier: BSD-2-Clause\n+#\n+# Copyright (C) 2019, Raspberry Pi Ltd\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# rkisp1.py - LSC module for tuning rkisp1\n+\n+from .lsc import LSC\n+\n+import libtuning as lt\n+import libtuning.utils as utils\n+\n+from numbers import Number\n+import numpy as np\n+\n+\n+class LSCRkISP1(LSC):\n+    hr_name = 'LSC (RkISP1)'\n+    out_name = 'LensShadingCorrection'\n+    # \\todo Not sure if this is useful. Probably will remove later.\n+    compatible = ['rkisp1']\n+\n+    def __init__(self, *args, **kwargs):\n+        super().__init__(**kwargs)\n+\n+    # We don't actually need anything from the config file\n+    def validate_config(self, config: dict) -> bool:\n+        return True\n+\n+    # @return Image color temperature, flattened array of red calibration table\n+    #         (containing {sector size} elements), flattened array of blue\n+    #         calibration table, flattened array of (red's) green calibration\n+    #         table, flattened array of (blue's) green calibration table\n+\n+    def _do_single_lsc(self, image: lt.Image):\n+        cgr, gr = self._lsc_single_channel(image.channels[lt.Color.GR], image)\n+        cgb, gb = self._lsc_single_channel(image.channels[lt.Color.GB], image)\n+\n+        # \\todo Should these ratio against the average of both greens or just\n+        # each green like we've done here?\n+        cr, _ = self._lsc_single_channel(image.channels[lt.Color.R], image, gr)\n+        cb, _ = self._lsc_single_channel(image.channels[lt.Color.B], image, gb)\n+\n+        return image.color, cr.flatten(), cb.flatten(), cgr.flatten(), cgb.flatten()\n+\n+    # @return List of dictionaries of color temperature, red table, red's green\n+    #         table, blue's green table, and blue table\n+\n+    def _do_all_lsc(self, images: list) -> list:\n+        output_list = []\n+        output_map_func = lt.gradient.Linear().map\n+        output_map_domain = (1, 3.999)\n+        output_map_range = (1024, 4095)\n+\n+        # List of colour temperatures\n+        list_col = []\n+        # Associated calibration tables\n+        list_cr = []\n+        list_cb = []\n+        list_cgr = []\n+        list_cgb = []\n+        for image in self._enumerate_lsc_images(images):\n+            col, cr, cb, cgr, cgb = self._do_single_lsc(image)\n+            list_col.append(col)\n+            list_cr.append(cr)\n+            list_cb.append(cb)\n+            list_cgr.append(cgr)\n+            list_cgb.append(cgb)\n+\n+        # Convert to numpy array for data manipulation\n+        list_col = np.array(list_col)\n+        list_cr = np.array(list_cr)\n+        list_cb = np.array(list_cb)\n+        list_cgr = np.array(list_cgr)\n+        list_cgb = np.array(list_cgb)\n+\n+        for color_temperature in sorted(set(list_col)):\n+            # Average tables for the same colour temperature\n+            indices = np.where(list_col == color_temperature)\n+            color_temperature = int(color_temperature)\n+\n+            tables = []\n+            for lis in [list_cr, list_cgr, list_cgb, list_cb]:\n+                table = np.mean(lis[indices], axis=0)\n+                table = output_map_func(output_map_domain, output_map_range, table)\n+                table = np.round(table).astype('int32').tolist()\n+                tables.append(table)\n+\n+            entry = {\n+                'ct': color_temperature,\n+                'r': tables[0],\n+                'gr': tables[1],\n+                'gb': tables[2],\n+                'b': tables[3],\n+            }\n+\n+            output_list.append(entry)\n+\n+        return output_list\n+\n+    def process(self, args, config: dict, images: list, outputs: dict) -> dict:\n+        output = {}\n+\n+        # \\todo This should actually come from self.sector_{x,y}_gradient\n+        size_gradient = lt.gradient.Linear(lt.Remainder.Float)\n+        output['x-size'] = size_gradient.distribute(0.5, 8)\n+        output['y-size'] = size_gradient.distribute(0.5, 8)\n+\n+        output['sets'] = self._do_all_lsc(images)\n+\n+        # \\todo Validate images from greyscale camera and force grescale mode\n+        # \\todo Debug functionality\n+\n+        return output\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "06/12"
    ]
}