Show a patch.

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

{
    "id": 16833,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16833/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16833/",
    "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": "<20220727084052.590421-3-fsylvestre@baylibre.com>",
    "date": "2022-07-27T08:40:49",
    "name": "[libcamera-devel,v4,2/5] ipa: rkisp1: Add support of Gamma Sensor Linearization control",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b948536f5fdca8155884a8d863c1f527c7b1b907",
    "submitter": {
        "id": 123,
        "url": "https://patchwork.libcamera.org/api/1.1/people/123/?format=api",
        "name": "Florian Sylvestre",
        "email": "fsylvestre@baylibre.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16833/mbox/",
    "series": [
        {
            "id": 3334,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3334/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3334",
            "date": "2022-07-27T08:40:47",
            "name": "Add GSL, LSC and DPCC tuning support for rkisp1",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3334/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16833/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16833/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 BD256BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jul 2022 08:41:03 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B6B763312;\n\tWed, 27 Jul 2022 10:41:03 +0200 (CEST)",
            "from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D9AC63312\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Jul 2022 10:41:00 +0200 (CEST)",
            "by mail-wr1-x433.google.com with SMTP id h8so23179896wrw.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Jul 2022 01:41:00 -0700 (PDT)",
            "from BL087.. ([2a01:e34:eea9:e630:5810:316e:87c:fc17])\n\tby smtp.gmail.com with ESMTPSA id\n\t16-20020a05600c241000b003a2f6367049sm1464275wmp.48.2022.07.27.01.40.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 27 Jul 2022 01:40:59 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658911263;\n\tbh=L8zcJvYk5eCtVtABJBzMpd6199t9z/gw39saggoKRy8=;\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=HQTCuqcg2HGxRp9i7JvU3heIXp6cbc/SGPJNNa6PxUfVfoIJbxMuKDgXwUMEzTnWk\n\t47zbyQ5ivTuXKjHAqwzCVTs9yGR7rulwzKM319+0GVSMqYQAJQmEhygPSkseKXnuX0\n\txwIPFrNTFa5JUSt4nmtqaSPWjPzn9BBGjITtgoUSfEdUfmvaHzJq/sew696eGL5xC1\n\tfNsNcuBJHbWIzjEJ3NwH4nT6YJxpmYuarcB5XIkVqRbVIpuS3dH14/jdPxxF6yT9kk\n\tnMFn+EBKUO3EHeNK9vhr8MXLU5yM8DPrur7WVRteaLM5S9i/Z2+EOfBr+UCpEomKBB\n\tNV2rvTUjn8+dw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20210112.gappssmtp.com; s=20210112;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=QGUnf825e0hZiXwvZbecuTHzWDnko3nc68Y60Kvh/aw=;\n\tb=V6V1eVYy29vPoWaX4Zn0RNFvTsByxzVyBQ1cGrPWMIYuszNE9fP0dBy1rZae8+MzIz\n\tNc3raSYzxa7nDmCXeWzT/Hml5tAtfQ97fGlNEuXtcngZEmB+u/nFH9UuZEZa9/p9Js4K\n\ttu3TfjpWmi1ACcZ+xNQPD/Iwz8PHSnyunzJ/sSYeotUETR10QT7y4S7DjQnJTg2RXJhy\n\tBcFpsYPeu8kQhYM4LDhhA8/B5AvpYVsNTaaciBRG6rOvthMc6v7Q5LB4zo1KtTPKm1B6\n\tULGFYXkzkiSIslGDrvObChZoiSAzmuuxzWiTAC/KS+DT3hyPTT2bBRltHKKaRF7B0/Qq\n\t9A0Q=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20210112.gappssmtp.com\n\theader.i=@baylibre-com.20210112.gappssmtp.com header.b=\"V6V1eVYy\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=QGUnf825e0hZiXwvZbecuTHzWDnko3nc68Y60Kvh/aw=;\n\tb=0OfKqZeV4aGQzqt6dtRxo/5Eix2SCKXtcXAqg2XTkIvTLGOK5IaA3wj4yA9nbu7zjC\n\tS8tx2d2cysZcUPC0yUGzG6dNjaGdEs6sOk7aFcFPam3bml02xOBYbnv2U2yCNONMUwcL\n\tKNgQV0vWtBXqH/POq2+xHl2cFAB9eouasn5G36GWzKm/9m88vusIu448UoUnGNknfMEn\n\t5UjEDf2p+FY6reOHabAbv2/tdmwWjaGsbBzTKFoeFc6kUs6r2WPw5fhcP4jsQD/b67H4\n\thiJcD7ZFXoR+N4hl3EwK/Hh5pr8oTOTqSyKU3ldo1ek7gHyXw4diZUft80OBPz38X9EL\n\tTAwg==",
        "X-Gm-Message-State": "AJIora/x9+f1c4xZK0xNqzoWW/OiIFX/WvCPg2yY9gfYN+EabNTux7oz\n\tHi0qXgwMVlWirDaSw/wkXrksPC890xdH5QIs",
        "X-Google-Smtp-Source": "AGRyM1vrvq13nbAiOcmFiWwE8LBG1YHKU5uFNtOVgWudRbyb0zXPBkdaJa0t322p2aOBZJXo6sy7HA==",
        "X-Received": "by 2002:a05:6000:989:b0:21e:7178:1f99 with SMTP id\n\tby9-20020a056000098900b0021e71781f99mr11920925wrb.581.1658911259728; \n\tWed, 27 Jul 2022 01:40:59 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 27 Jul 2022 10:40:49 +0200",
        "Message-Id": "<20220727084052.590421-3-fsylvestre@baylibre.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220727084052.590421-1-fsylvestre@baylibre.com>",
        "References": "<20220727084052.590421-1-fsylvestre@baylibre.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 2/5] ipa: rkisp1: Add support of Gamma\n\tSensor Linearization control",
        "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": "Florian Sylvestre via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Florian Sylvestre <fsylvestre@baylibre.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The GammaSensorLinearization algorithm linearizes the sensor output to\ncompensate the sensor non-linearities by applying piecewise linear functions to\nthe red, green and blue channels.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/gsl.cpp     | 147 ++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/gsl.h       |  34 ++++++\n src/ipa/rkisp1/algorithms/meson.build |   1 +\n src/ipa/rkisp1/data/ov5640.yaml       |   6 ++\n 4 files changed, 188 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/gsl.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/gsl.h",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/gsl.cpp b/src/ipa/rkisp1/algorithms/gsl.cpp\nnew file mode 100644\nindex 00000000..09588464\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n@@ -0,0 +1,147 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * gsl.cpp - RkISP1 Gamma Sensor Linearization control\n+ */\n+\n+#include \"gsl.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"linux/rkisp1-config.h\"\n+\n+/**\n+ * \\file gsl.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class GammaSensorLinearization\n+ * \\brief RkISP1 Gamma Sensor Linearization control\n+ *\n+ * This algorithm linearizes the sensor output to compensate the sensor\n+ * non-linearities by applying piecewise linear functions to the red, green and\n+ * blue channels.\n+ *\n+ * The curves are specified in the tuning data and defined using 17 points.\n+ *\n+ * - The X coordinates are expressed using 16 intervals, with the first point\n+ *   at X coordinate 0. Each interval is expressed as a 2-bit value DX (from\n+ *   GAMMA_DX_1 to GAMMA_DX_16), stored in the RKISP1_CIF_ISP_GAMMA_DX_LO and\n+ *   RKISP1_CIF_ISP_GAMMA_DX_HI registers. The real interval is equal to\n+ *   \\f$2^{dx+4}\\f$. X coordinates are shared between the red, green and blue\n+ *   curves.\n+ *\n+ * - The Y coordinates are specified as 17 values separately for the\n+ *   red, green and blue channels, with a 12-bit resolution. Each value must be\n+ *   in the [-2048, 2047] range compared to the previous value.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Gsl)\n+\n+static constexpr unsigned int kDegammaXIntervals = 16;\n+\n+GammaSensorLinearization::GammaSensorLinearization()\n+\t: initialized_(false)\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int GammaSensorLinearization::init([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   const YamlObject &tuningData)\n+{\n+\tstd::vector<uint16_t> xIntervals = tuningData[\"x-intervals\"].getList<uint16_t>();\n+\tif (xIntervals.size() != kDegammaXIntervals) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Invalid 'x' coordinates: expected \"\n+\t\t\t<< kDegammaXIntervals << \" elements, got \"\n+\t\t\t<< xIntervals.size();\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Compute gammaDx_ intervals from xIntervals values */\n+\tgammaDx_[0] = 0;\n+\tgammaDx_[1] = 0;\n+\tfor (unsigned int i = 0; i < kDegammaXIntervals; ++i)\n+\t\tgammaDx_[i / 8] |= (xIntervals[i] & 0x07) << ((i % 8) * 4);\n+\n+\tconst YamlObject &yObject = tuningData[\"y\"];\n+\tif (!yObject.isDictionary()) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Issue while parsing 'y' in tuning file: \"\n+\t\t\t<< \"entry must be a dictionary\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tcurveYr_ = yObject[\"red\"].getList<uint16_t>();\n+\tif (curveYr_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Invalid 'y:red' coordinates: expected \"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n+\t\t\t<< \" elements, got \" << curveYr_.size();\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tcurveYg_ = yObject[\"green\"].getList<uint16_t>();\n+\tif (curveYg_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Invalid 'y:green' coordinates: expected \"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n+\t\t\t<< \" elements, got \" << curveYg_.size();\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tcurveYb_ = yObject[\"blue\"].getList<uint16_t>();\n+\tif (curveYb_.size() != RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Invalid 'y:blue' coordinates: expected \"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE\n+\t\t\t<< \" elements, got \" << curveYb_.size();\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tinitialized_ = true;\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void GammaSensorLinearization::prepare(IPAContext &context,\n+\t\t\t\t       rkisp1_params_cfg *params)\n+{\n+\tif (context.frameContext.frameCount > 0)\n+\t\treturn;\n+\n+\tif (!initialized_)\n+\t\treturn;\n+\n+\tparams->others.sdg_config.xa_pnts.gamma_dx0 = gammaDx_[0];\n+\tparams->others.sdg_config.xa_pnts.gamma_dx1 = gammaDx_[1];\n+\n+\tstd::copy(curveYr_.begin(), curveYr_.end(),\n+\t\t  params->others.sdg_config.curve_r.gamma_y);\n+\tstd::copy(curveYg_.begin(), curveYg_.end(),\n+\t\t  params->others.sdg_config.curve_g.gamma_y);\n+\tstd::copy(curveYb_.begin(), curveYb_.end(),\n+\t\t  params->others.sdg_config.curve_b.gamma_y);\n+\n+\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_SDG;\n+\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_SDG;\n+\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_SDG;\n+}\n+\n+REGISTER_IPA_ALGORITHM(GammaSensorLinearization, \"GammaSensorLinearization\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/gsl.h b/src/ipa/rkisp1/algorithms/gsl.h\nnew file mode 100644\nindex 00000000..db287dc2\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/gsl.h\n@@ -0,0 +1,34 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * gsl.h - RkISP1 Gamma Sensor Linearization control\n+ */\n+\n+#pragma once\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class GammaSensorLinearization : public Algorithm\n+{\n+public:\n+\tGammaSensorLinearization();\n+\t~GammaSensorLinearization() = default;\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\n+\n+private:\n+\tbool initialized_;\n+\tuint32_t gammaDx_[2];\n+\tstd::vector<uint16_t> curveYr_;\n+\tstd::vector<uint16_t> curveYg_;\n+\tstd::vector<uint16_t> curveYb_;\n+};\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nindex 7ec53d89..0597c353 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -4,4 +4,5 @@ rkisp1_ipa_algorithms = files([\n     'agc.cpp',\n     'awb.cpp',\n     'blc.cpp',\n+    'gsl.cpp',\n ])\ndiff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml\nindex 232d8ae8..13f76412 100644\n--- a/src/ipa/rkisp1/data/ov5640.yaml\n+++ b/src/ipa/rkisp1/data/ov5640.yaml\n@@ -10,4 +10,10 @@ algorithms:\n       Gr: 256\n       Gb: 256\n       B:  256\n+  - GammaSensorLinearization:\n+      x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]\n+      y:\n+        red:   [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n+        green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n+        blue:  [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4095 ]\n ...\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "2/5"
    ]
}