{"id":16853,"url":"https://patchwork.libcamera.org/api/1.1/patches/16853/?format=json","web_url":"https://patchwork.libcamera.org/patch/16853/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220727222149.30627-6-laurent.pinchart@ideasonboard.com>","date":"2022-07-27T22:21:45","name":"[libcamera-devel,v5,5/9] ipa: rkisp1: Add support of Gamma Sensor Linearization control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e8cc6e4387a6b6915c497d6e53ed87d15ba051f2","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16853/mbox/","series":[{"id":3338,"url":"https://patchwork.libcamera.org/api/1.1/series/3338/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3338","date":"2022-07-27T22:21:40","name":"ipa: rkisp1: Add GSL, LSC, DPCC, Filter and CProc algorithms","version":5,"mbox":"https://patchwork.libcamera.org/series/3338/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16853/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16853/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 BCFFBBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jul 2022 22:22:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 47D4E63324;\n\tThu, 28 Jul 2022 00:22:04 +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 3861363310\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jul 2022 00:21:58 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CE7B66D4;\n\tThu, 28 Jul 2022 00:21:57 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658960524;\n\tbh=qLJCS3GRp1FhnUvkCdVtCaNVBkD4PNSkddNBh9YbcGw=;\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=AT1T8Toiv36795wxuI/sILcxR74Q/1vJFXKxUwTSuI8mjX0uEoWDaTCIeUrnX7DD7\n\tIQIYRI8UoFLs8bNJ9OyELgDaWY16wB5iWIb5gSosB2b7Z8bxPpBp39KEJPUUDRuooE\n\tpwTx2BxuTYbJY4pZKjz6vAv9/VrCRIjhbiDqY9xZKc8qqMRZXErPepXCsRy+GDVH37\n\tRfZMcSKk7EUazrpvLaTZ6I5QrOw6FvmDxfrAc/0dQRJ3gxWoU4JhLfsTJ26tyNaN7c\n\tGy68QoaFVoj+k2cCKpDT+BdXws/hJYFqyYcsb3CHh3CX9XclNnsoAXQmaOrG1SZ3Ep\n\tcIkCVXDhj6uvw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658960517;\n\tbh=qLJCS3GRp1FhnUvkCdVtCaNVBkD4PNSkddNBh9YbcGw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ECgHeeJ8j4pekNpL9jzNUdObz3GjTjT59WHKdyRGpeJpIxCmK0XGw3QGxDcw0eSGJ\n\tpGb+LtU2cIV+99NDO6ZSJ9ke1xAulMLGvO39Qqae15Jq4xfz+D/SWtejIv58Z0EDVJ\n\tdwe/JeujnLquze0c9q5tOsLA9S8AU0GBPsl0+lMA="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ECgHeeJ8\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 28 Jul 2022 01:21:45 +0300","Message-Id":"<20220727222149.30627-6-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>","References":"<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 5/9] 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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Florian Sylvestre <fsylvestre@baylibre.com>\n\nThe 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---\nChanges since v4:\n\n- Rebase on std::optional-based version of getList()\n---\n src/ipa/rkisp1/algorithms/gsl.cpp     | 149 ++++++++++++++++++++++++++\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, 190 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 000000000000..2fd1a23d3a9b\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n@@ -0,0 +1,149 @@\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+#include <libcamera/base/utils.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 =\n+\t\ttuningData[\"x-intervals\"].getList<uint16_t>().value_or(utils::defopt);\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>().value_or(utils::defopt);\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>().value_or(utils::defopt);\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>().value_or(utils::defopt);\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 000000000000..db287dc280dc\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 7ec53d89e4de..0597c353a0f7 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 232d8ae8d58b..13f764127702 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","v5","5/9"]}