Show a patch.

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

{
    "id": 17657,
    "url": "https://patchwork.libcamera.org/api/patches/17657/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17657/",
    "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": "<20221022062310.2545463-7-paul.elder@ideasonboard.com>",
    "date": "2022-10-22T06:23:05",
    "name": "[libcamera-devel,v2,06/11] utils: libtuning: generators: Add raspberrypi output",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "4f63607bde1fd6ef09c7c1239de89520c8a21e23",
    "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/17657/mbox/",
    "series": [
        {
            "id": 3573,
            "url": "https://patchwork.libcamera.org/api/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/17657/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17657/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 D7313C3285\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 22 Oct 2022 06:23:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 485EE62ED3;\n\tSat, 22 Oct 2022 08:23:33 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C7FFF62ED8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 22 Oct 2022 08:23:31 +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 5FCCA106;\n\tSat, 22 Oct 2022 08:23:30 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1666419813;\n\tbh=3xIfSIABCUMi62Db0ja6vOFz0lsqnAZdPwKUMdqnYfE=;\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=nAJGRvRUgr4tJJ0TJKraiwC4CUs4GZ4sS8lZ1aG2Cys5CjVH20an/aL88rUFgORqn\n\tUN5I5UPlDuq487H4xz401kr02VPFKTJPemrpJQG8yEL8DZkUhljnU2/P/bVL+XwjCr\n\t9a5BLQ/qUkE2fXk1torACEr9sXUszkQ8AcEAfMTurATMAgsrhm1JM7VCchJ3vaN0ip\n\tJnH0TAUCVBUysLH/Q7M0O57n+k0Bckfg2jvBFePmLbnKYF/cNnOx1bCQ40vL+as/it\n\tpQ35aSPXduzEci91MFeYTEyq4B31BDWGG5kQ/vt7IKW8KVEG/zbkJpIC7Z+BaEoHdl\n\tPC+D8bgSHAICA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1666419811;\n\tbh=3xIfSIABCUMi62Db0ja6vOFz0lsqnAZdPwKUMdqnYfE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=e0clPbUltD7JV91AXXOsYbx6gsDbC2zN8yWl6j2beMR8nbVEcVp7tEshTIH+Wmbh1\n\ty0obWL/s1bwrv54GWkY9ht+gQqjwzDhPmAZCBaXWzgqqTuvwm4rZyt4X+tSdLbLVZF\n\tTniCiefzz58bLm0OVsiMUNNgacTkzobfAJkAwWsM="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"e0clPbUl\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 22 Oct 2022 15:23:05 +0900",
        "Message-Id": "<20221022062310.2545463-7-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 06/11] utils: libtuning: generators:\n\tAdd raspberrypi output",
        "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 a generator to libtuning for writing tuning output to a json file\nformatted the same way that raspberrypi's ctt formats them.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v2:\n- add SPDX and copyright\n- fix style\n- move the 'rpi.' prefix of module names in the tuning output from here\n  to into the Modules' out_name field\n---\n utils/tuning/libtuning/generators/__init__.py |   5 +\n .../generators/raspberrypi_output.py          | 115 ++++++++++++++++++\n 2 files changed, 120 insertions(+)\n create mode 100644 utils/tuning/libtuning/generators/raspberrypi_output.py",
    "diff": "diff --git a/utils/tuning/libtuning/generators/__init__.py b/utils/tuning/libtuning/generators/__init__.py\nindex e69de29b..937aff30 100644\n--- a/utils/tuning/libtuning/generators/__init__.py\n+++ b/utils/tuning/libtuning/generators/__init__.py\n@@ -0,0 +1,5 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2022, Paul Elder <paul.elder@ideasonboard.com>\n+\n+from libtuning.generators.raspberrypi_output import RaspberryPiOutput\ndiff --git a/utils/tuning/libtuning/generators/raspberrypi_output.py b/utils/tuning/libtuning/generators/raspberrypi_output.py\nnew file mode 100644\nindex 00000000..e06aeddf\n--- /dev/null\n+++ b/utils/tuning/libtuning/generators/raspberrypi_output.py\n@@ -0,0 +1,115 @@\n+# SPDX-License-Identifier: BSD-2-Clause\n+#\n+# Copyright 2022 Raspberry Pi Ltd\n+#\n+# Script to pretty print a Raspberry Pi tuning config JSON structure in\n+# version 2.0 and later formats.\n+# (Copied from ctt_pretty_print_json.py)\n+\n+from .generator import Generator\n+\n+import json\n+from pathlib import Path\n+import textwrap\n+\n+\n+class RaspberryPiOutput(Generator):\n+    def __init__(self):\n+        super().__init__()\n+\n+    def _write(self, output_file: Path, output_dict: dict, output_order: list):\n+        # Write json dictionary to file using ctt's version 2 format\n+        out_json = {\n+            \"version\": 2.0,\n+            'target': 'bcm2835',\n+            \"algorithms\": [{f'{module.out_name}': output_dict[module]} for module in output_order]\n+        }\n+\n+        with open(output_file, 'w') as f:\n+            f.write(pretty_print(out_json))\n+\n+\n+class Encoder(json.JSONEncoder):\n+\n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+        self.indentation_level = 0\n+        self.hard_break = 120\n+        self.custom_elems = {\n+            'table': 16,\n+            'luminance_lut': 16,\n+            'ct_curve': 3,\n+            'ccm': 3,\n+            'gamma_curve': 2,\n+            'y_target': 2,\n+            'prior': 2\n+        }\n+\n+    def encode(self, o, node_key=None):\n+        if isinstance(o, (list, tuple)):\n+            # Check if we are a flat list of numbers.\n+            if not any(isinstance(el, (list, tuple, dict)) for el in o):\n+                s = ', '.join(json.dumps(el) for el in o)\n+                if node_key in self.custom_elems.keys():\n+                    # Special case handling to specify number of elements in a row for tables, ccm, etc.\n+                    self.indentation_level += 1\n+                    sl = s.split(', ')\n+                    num = self.custom_elems[node_key]\n+                    chunk = [self.indent_str + ', '.join(sl[x:x + num]) for x in range(0, len(sl), num)]\n+                    t = ',\\n'.join(chunk)\n+                    self.indentation_level -= 1\n+                    output = f'\\n{self.indent_str}[\\n{t}\\n{self.indent_str}]'\n+                elif len(s) > self.hard_break - len(self.indent_str):\n+                    # Break a long list with wraps.\n+                    self.indentation_level += 1\n+                    t = textwrap.fill(s, self.hard_break, break_long_words=False,\n+                                      initial_indent=self.indent_str, subsequent_indent=self.indent_str)\n+                    self.indentation_level -= 1\n+                    output = f'\\n{self.indent_str}[\\n{t}\\n{self.indent_str}]'\n+                else:\n+                    # Smaller lists can remain on a single line.\n+                    output = f' [ {s} ]'\n+                return output\n+            else:\n+                # Sub-structures in the list case.\n+                self.indentation_level += 1\n+                output = [self.indent_str + self.encode(el) for el in o]\n+                self.indentation_level -= 1\n+                output = ',\\n'.join(output)\n+                return f' [\\n{output}\\n{self.indent_str}]'\n+\n+        elif isinstance(o, dict):\n+            self.indentation_level += 1\n+            output = []\n+            for k, v in o.items():\n+                if isinstance(v, dict) and len(v) == 0:\n+                    # Empty config block special case.\n+                    output.append(self.indent_str + f'{json.dumps(k)}: {{ }}')\n+                else:\n+                    # Only linebreak if the next node is a config block.\n+                    sep = f'\\n{self.indent_str}' if isinstance(v, dict) else ''\n+                    output.append(self.indent_str + f'{json.dumps(k)}:{sep}{self.encode(v, k)}')\n+            output = ',\\n'.join(output)\n+            self.indentation_level -= 1\n+            return f'{{\\n{output}\\n{self.indent_str}}}'\n+\n+        else:\n+            return ' ' + json.dumps(o)\n+\n+    @property\n+    def indent_str(self) -> str:\n+        return ' ' * self.indentation_level * self.indent\n+\n+    def iterencode(self, o, **kwargs):\n+        return self.encode(o)\n+\n+\n+def pretty_print(in_json: dict) -> str:\n+\n+    if 'version' not in in_json or \\\n+       'target' not in in_json or \\\n+       'algorithms' not in in_json or \\\n+       in_json['version'] < 2.0:\n+        raise RuntimeError('Incompatible JSON dictionary has been provided')\n+\n+    return json.dumps(in_json, cls=Encoder, indent=4, sort_keys=False)\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "06/11"
    ]
}