Show a patch.

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

{
    "id": 17655,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17655/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17655/",
    "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": "<20221022062310.2545463-5-paul.elder@ideasonboard.com>",
    "date": "2022-10-22T06:23:03",
    "name": "[libcamera-devel,v2,04/11] utils: libtuning: modules: alsc: Add rkisp1 ALSC module",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "c118863ea81ca4be6419dbc95159d8a50073bd3f",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17655/mbox/",
    "series": [
        {
            "id": 3573,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3573/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3573",
            "date": "2022-10-22T06:22:59",
            "name": "utils: tuning: Add a new tuning infrastructure",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3573/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17655/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17655/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 E35F1C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 22 Oct 2022 06:23:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9145D62ED6;\n\tSat, 22 Oct 2022 08:23:31 +0200 (CEST)",
            "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 2990B62EC8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 22 Oct 2022 08:23:28 +0200 (CEST)",
            "from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp\n\t[175.177.42.159])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B8EC9891;\n\tSat, 22 Oct 2022 08:23:26 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666419811;\n\tbh=fm9gcyQT6tddQvpWlWmvET8AL/c3VhA4sd8JH59SfWg=;\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=2FEIKbgKu1opG0Xdt+sO+OlaXT7R+iyyQL2yzlB7EGSud+0EFCAfreZ6eRaXuqtXL\n\tnvPLvCXxSPopktdpILPmpch43fYEhKuSM/GOBC0K15+WCwQxmJvYeOf3jap5lMXceH\n\tyShmeN1j7IJfHF0FbKxkSjaunJZqbWmxV5F/TmPRzuond+ScVt/rqRE7AN0c/0xdjg\n\t4KbkYzwK/vr2fzKVAovLhDNWiOhCNFSflXnEOx5jcuYpr0NPevWQRSkQzKezKXC3YG\n\ttjMZayrT86GlQC+aRMIS3hLjpyh0EgXGrXtj7dAfDQZvgXGsNlUxmePvNKnPf23Rpm\n\tvv7SgPolnwb8g==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666419807;\n\tbh=fm9gcyQT6tddQvpWlWmvET8AL/c3VhA4sd8JH59SfWg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=cfgjEjSuowzytPnHPecZZZrFahaFTARI41ne2/G6BvRP3gFgsmcxBcsjHnhaxxKjr\n\tyBB7GqKNlRWDpwqp9U2afI25QDYApIGA1MSAGWif0CSWOC1OI1r3qmIBHmgRM78e8F\n\tC+c0x7mYqgA12P+TXXaKp5djlTf4ZhpkFdVlcmj8="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"cfgjEjSu\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 22 Oct 2022 15:23:03 +0900",
        "Message-Id": "<20221022062310.2545463-5-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20221022062310.2545463-1-paul.elder@ideasonboard.com>",
        "References": "<20221022062310.2545463-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 04/11] utils: libtuning: modules: alsc:\n\tAdd rkisp1 ALSC 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 ALSC module for RkISP1.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nNew in v2\n---\n .../tuning/libtuning/modules/alsc/__init__.py |   1 +\n utils/tuning/libtuning/modules/alsc/rkisp1.py | 112 ++++++++++++++++++\n 2 files changed, 113 insertions(+)\n create mode 100644 utils/tuning/libtuning/modules/alsc/rkisp1.py",
    "diff": "diff --git a/utils/tuning/libtuning/modules/alsc/__init__.py b/utils/tuning/libtuning/modules/alsc/__init__.py\nindex ef6300c2..932ce38e 100644\n--- a/utils/tuning/libtuning/modules/alsc/__init__.py\n+++ b/utils/tuning/libtuning/modules/alsc/__init__.py\n@@ -4,3 +4,4 @@\n \n from libtuning.modules.alsc.alsc import ALSC\n from libtuning.modules.alsc.raspberrypi import ALSCRaspberryPi\n+from libtuning.modules.alsc.rkisp1 import ALSCRkISP1\ndiff --git a/utils/tuning/libtuning/modules/alsc/rkisp1.py b/utils/tuning/libtuning/modules/alsc/rkisp1.py\nnew file mode 100644\nindex 00000000..d8f253e6\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/alsc/rkisp1.py\n@@ -0,0 +1,112 @@\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+from .alsc import ALSC\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 ALSCRkISP1(ALSC):\n+    hr_name = 'ALSC (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_alsc(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+        # Should these ratio against the average of both greens or just each\n+        # 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_alsc(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_alsc_images(images):\n+            col, cr, cb, cgr, cgb = self._do_single_alsc(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_alsc(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",
        "v2",
        "04/11"
    ]
}