Show a patch.

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

{
    "id": 19848,
    "url": "https://patchwork.libcamera.org/api/patches/19848/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19848/",
    "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": "<20240405084050.1919105-3-paul.elder@ideasonboard.com>",
    "date": "2024-04-05T08:40:49",
    "name": "[2/3] ipa: libipa: Add MatrixInterpolator class",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "0bc0600172238b7372bed74a62e62ce0620ac147",
    "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/19848/mbox/",
    "series": [
        {
            "id": 4250,
            "url": "https://patchwork.libcamera.org/api/series/4250/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4250",
            "date": "2024-04-05T08:40:47",
            "name": "ipa: rkisp1: Add crosstalk algorithm",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4250/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19848/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19848/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 DA5EFBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Apr 2024 08:41:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7CC7F6333E;\n\tFri,  5 Apr 2024 10:41:06 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5999B63334\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Apr 2024 10:41:03 +0200 (CEST)",
            "from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp\n\t[175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8FBA122A;\n\tFri,  5 Apr 2024 10:40:23 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"HKqBkw0M\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1712306424;\n\tbh=S2Zw/tr9WLjjidfR5SKOdbcR9ffxg0vS8O9YtknOcl4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=HKqBkw0Mt6lWO9P17dmAPCRtPZuWkKTNLk1c9Z1XCrbV8N+UpJO6lydqqmyhXP6q7\n\ti80KyB9bd+QBRGhGzRSsVKb8T3eLP2GCta46ljHy89OX059TelRbQVGGluO4lNevQ3\n\tPLhwXgLTYrVpaDxUMbl5bo1Wokb8gfJi/K0aOrV0=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>",
        "Subject": "[PATCH 2/3] ipa: libipa: Add MatrixInterpolator class",
        "Date": "Fri,  5 Apr 2024 17:40:49 +0900",
        "Message-Id": "<20240405084050.1919105-3-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20240405084050.1919105-1-paul.elder@ideasonboard.com>",
        "References": "<20240405084050.1919105-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "Add a class to encapsulate the functionality of fetching a matrix based\non an integer key, and interpolating if there is no exact match. This is\nexpected to be used by both color correction matrices / crosstalk\ncorrection as well as lens shading correction.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/libipa/matrix_interpolator.cpp | 54 +++++++++++++++\n src/ipa/libipa/matrix_interpolator.h   | 94 ++++++++++++++++++++++++++\n src/ipa/libipa/meson.build             |  2 +\n 3 files changed, 150 insertions(+)\n create mode 100644 src/ipa/libipa/matrix_interpolator.cpp\n create mode 100644 src/ipa/libipa/matrix_interpolator.h",
    "diff": "diff --git a/src/ipa/libipa/matrix_interpolator.cpp b/src/ipa/libipa/matrix_interpolator.cpp\nnew file mode 100644\nindex 00000000..394633b5\n--- /dev/null\n+++ b/src/ipa/libipa/matrix_interpolator.cpp\n@@ -0,0 +1,54 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2019, Raspberry Pi Ltd\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * matrix_interpolator.cpp - Helper class for interpolating maps of matrices\n+ */\n+#include \"matrix_interpolator.h\"\n+\n+#include <algorithm>\n+#include <string>\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"matrix.h\"\n+\n+/**\n+ * \\file ccm.h\n+ * \\brief Helper class for interpolating maps of matrices\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(MatrixInterpolator)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class MatrixInterpolator\n+ * \\brief Class for storing, retrieving, and interpolating matrices\n+ */\n+\n+/**\n+ * \\fn int MatrixInterpolator<T, R, C>::readYaml(const libcamera::YamlObject &yaml)\n+ * \\brief Initialize an MatrixInterpolator instance from yaml\n+ * \\tparam T Type of data stored in the matrices\n+ * \\tparam R Number of rows of the matrices\n+ * \\tparam C Number of columns of the matrices\n+ * \\param[in] yaml The yaml object that contains the map of unsigned integers to matrices\n+ * \\return Zero on success, negative error code otherwise\n+ */\n+\n+/**\n+ * \\fn Matrix<T> MatrixInterpolator<T, R, C>::get(unsigned int key)\n+ * \\brief Retrieve a matrix from the list of matrices, interpolating if necessary\n+ * \\param[in] key The unsigned integer key of the matrix to retrieve\n+ * \\return The matrix corresponding to the color temperature\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/matrix_interpolator.h b/src/ipa/libipa/matrix_interpolator.h\nnew file mode 100644\nindex 00000000..2cd4ff75\n--- /dev/null\n+++ b/src/ipa/libipa/matrix_interpolator.h\n@@ -0,0 +1,94 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2019, Raspberry Pi Ltd\n+ * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n+ *\n+ * matrix_interpolator.h - Helper class for interpolating maps of matrices\n+ */\n+\n+#pragma once\n+\n+#include <algorithm>\n+#include <map>\n+#include <string>\n+#include <tuple>\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"matrix.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(MatrixInterpolator)\n+\n+namespace ipa {\n+\n+template<typename T, unsigned int R, unsigned int C>\n+class MatrixInterpolator\n+{\n+public:\n+\tMatrixInterpolator(){};\n+\t~MatrixInterpolator(){};\n+\n+\tint readYaml(const libcamera::YamlObject &yaml)\n+\t{\n+\t\tint ret;\n+\n+\t\tif (!yaml.isDictionary()) {\n+\t\t\tLOG(MatrixInterpolator, Error) << \"yaml object must be a dictionary\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tfor (const auto &[ctStr, value] : yaml.asDict()) {\n+\t\t\tunsigned int ct = std::stoul(ctStr);\n+\t\t\tMatrix<T> matrix;\n+\t\t\tif ((ret = matrix.readYaml(R, C, value)) < 0) {\n+\t\t\t\tLOG(MatrixInterpolator, Error) << \"Failed to read matrix\";\n+\t\t\t\treturn ret;\n+\t\t\t}\n+\n+\t\t\tmatrices_[ct] = matrix;\n+\n+\t\t\tLOG(MatrixInterpolator, Debug)\n+\t\t\t\t<< \"Read matrix for key \" << ct << \": \"\n+\t\t\t\t<< matrices_[ct].toString();\n+\t\t}\n+\n+\t\tif (matrices_.size() < 1) {\n+\t\t\tLOG(MatrixInterpolator, Error) << \"Need at least one matrix\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tMatrix<T> get(unsigned int ct)\n+\t{\n+\t\tif (matrices_.size() == 1 ||\n+\t\t    ct <= matrices_.begin()->first)\n+\t\t\treturn matrices_.begin()->second;\n+\n+\t\tif (ct >= matrices_.rbegin()->first)\n+\t\t\treturn matrices_.rbegin()->second;\n+\n+\t\tif (matrices_.count(ct))\n+\t\t\treturn matrices_[ct];\n+\n+\t\t/* The above four guarantee that this will succeed */\n+\t\tauto iter = matrices_.upper_bound(ct);\n+\t\tunsigned int ctUpper = iter->first;\n+\t\tunsigned int ctLower = (--iter)->first;\n+\n+\t\tdouble lambda = (ct - ctLower) / (ctUpper - ctLower);\n+\t\treturn lambda * matrices_[ctUpper] + (1.0 - lambda) * matrices_[ctLower];\n+\t}\n+\n+private:\n+\tstd::map<unsigned int, Matrix<T>> matrices_;\n+};\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 5d5ba5e5..128de712 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -3,6 +3,7 @@\n libipa_headers = files([\n     'algorithm.h',\n     'camera_sensor_helper.h',\n+    'matrix_interpolator.h',\n     'exposure_mode_helper.h',\n     'fc_queue.h',\n     'histogram.h',\n@@ -14,6 +15,7 @@ libipa_headers = files([\n libipa_sources = files([\n     'algorithm.cpp',\n     'camera_sensor_helper.cpp',\n+    'matrix_interpolator.cpp',\n     'exposure_mode_helper.cpp',\n     'fc_queue.cpp',\n     'histogram.cpp',\n",
    "prefixes": [
        "2/3"
    ]
}