{"id":16735,"url":"https://patchwork.libcamera.org/api/1.1/patches/16735/?format=json","web_url":"https://patchwork.libcamera.org/patch/16735/","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":"<20220722151635.239221-3-fsylvestre@baylibre.com>","date":"2022-07-22T15:16:32","name":"[libcamera-devel,v2,2/5] ipa: rkisp1: Add support of Gamma Sensor Linearization control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2dd7bdb30286a27959bddad76fb12c06e6a15da8","submitter":{"id":123,"url":"https://patchwork.libcamera.org/api/1.1/people/123/?format=json","name":"Florian Sylvestre","email":"fsylvestre@baylibre.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16735/mbox/","series":[{"id":3319,"url":"https://patchwork.libcamera.org/api/1.1/series/3319/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3319","date":"2022-07-22T15:16:30","name":"Add GSL, LSC and DPCC tuning support for rkisp1","version":2,"mbox":"https://patchwork.libcamera.org/series/3319/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16735/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16735/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 9AD34BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Jul 2022 15:16:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 370256331A;\n\tFri, 22 Jul 2022 17:16:48 +0200 (CEST)","from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B3A01603F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jul 2022 17:16:45 +0200 (CEST)","by mail-wm1-x32e.google.com with SMTP id\n\tay11-20020a05600c1e0b00b003a3013da120so5376449wmb.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Jul 2022 08:16:45 -0700 (PDT)","from BL087.. ([2a01:e34:eea9:e630:e9da:4076:6aa:6cd2])\n\tby smtp.gmail.com with ESMTPSA id\n\tb1-20020a5d4d81000000b0021e4fd8e10bsm4871557wru.11.2022.07.22.08.16.44\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 22 Jul 2022 08:16:44 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658503008;\n\tbh=e3gnoIE7hd1H2qwFxVryzwpZZW6NgAb9iQnQIzAeH5Q=;\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=QOn6ebpYWsRvPq1kiRQ17mx2qUsLo8JuaF5oW7ytF81PJ9I1/BgrH5xgQ+rwYSO7X\n\tHgXdegHzRFtY0MNhuEzCL4VSQEy8KRzO1raretdlyMRh1hTc7Yux4KACofrxJbQgCO\n\tzKAy5TCzKlba20051fVx0w5VcVQwUzb0RgrYUjTZwwq0OEqYmN4u6WWR7twl6lmF6z\n\tldJzfSNECDtlCTfaFAM73Z4kt/6PjeWPDu3S12IA4BXFFKog6QQjMvIuzU7MSM/0kp\n\tUuzxZit4EHkyMMot5+SYUBU0KP3saUKRwu8yg0ormLrQC1te0JfybDeM61PTdu0Kli\n\tH5d05S2UNpWQw==","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=7No+ATRUBr79WnsG3uZbVTv6ZwY75D8K0UmViluBK9E=;\n\tb=Uerl0jVl0VgGI8u2HFyphtrdm952s7gCLfb6YiKL6L3+4gEmRZ7KwOAZFeEwDBXQbD\n\tbIEgn0vfnllMjE5SvL1LEMybHRqCQBPpzwkfBhaepsDqZehcWPGu51DI0KZe4FMJku2s\n\tdXq+rX3zI4xaxp6j84nH4uMD7zDIIXZXXZaniUduw3ADicjLXIkWHRQKLsUcnkkZjW31\n\tM+L33ydIsizNmR0C81kxw3baiDolV5KdHZEunvJf6/UC7znqErZI6vWijb8RF8YFrK/P\n\tBvEiFXImjTw+VL+eAa3SePax1bOomQrDz8TwwnvKgul90h3D6yb+v/+LuBIs8/pF0mVk\n\t/TXw=="],"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=\"Uerl0jVl\"; \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=7No+ATRUBr79WnsG3uZbVTv6ZwY75D8K0UmViluBK9E=;\n\tb=T9IGtfWU/IA+ZqxS5JDngH7ntc804VcmsZSy77JtR5exgFCMBlH5JFBCHEvNyh8rPi\n\t6hT0stCe6PBXD08l+WO9CirtNFB9CA4747VMKEVB9xDwBvZ6rqXIhIrOjOMp3UiDudDq\n\tnoougw/PfTNKRLHEIs7w/4N6eMY4H5RZCj7+mUmtMnGayxCPov3zFCDfFkWqxCw12nut\n\tTrB5Bj2tfX4XhldOSQ/kkjmLf8pN42bvD9d9TTolkUzkmceXzYl6EAW3bQe/aapswDmW\n\tC/iHAd2xjBT506S7oTvhQ6t+8JKFqxkZCeK4EWM1ucK3OwW261O43ZGNZWxlEJrOlYna\n\tMTxg==","X-Gm-Message-State":"AJIora/15IDCwvX1xiVfkwDb14CuKJOAwejD4d2iuO8Oc8YLb3iU2He5\n\tCXs8I3jRhtOuI9wl+ooZDaBYSKpkSfdL4f8y","X-Google-Smtp-Source":"AGRyM1uThCey8dPEKVOAZ5WGBN1grPll2fcXaDcMnuLXAz0ZlxA120dqIAO1+KipYN7zNzlyurfbOg==","X-Received":"by 2002:a05:600c:4e0d:b0:3a3:bc7:e9ec with SMTP id\n\tb13-20020a05600c4e0d00b003a30bc7e9ecmr13028937wmq.167.1658503005003; \n\tFri, 22 Jul 2022 08:16:45 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 22 Jul 2022 17:16:32 +0200","Message-Id":"<20220722151635.239221-3-fsylvestre@baylibre.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220722151635.239221-1-fsylvestre@baylibre.com>","References":"<20220722151635.239221-1-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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 improves the image dynamic using\na coefficient table in the YAML tuning file.\nThe GammaSensorLinearization algorithm linearizes the sensor output to\ncompensate the sensor non-linearities by applying piecewise linear curves to\nthe red, green and blue channels.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.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 src/ipa/rkisp1/rkisp1.cpp             |   1 +\n 5 files changed, 189 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..1680ddc3\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 curves 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 ...\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 4018265c..1c002939 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -31,6 +31,7 @@\n #include \"algorithms/algorithm.h\"\n #include \"algorithms/awb.h\"\n #include \"algorithms/blc.h\"\n+#include \"algorithms/gsl.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n #include \"ipa_context.h\"\n","prefixes":["libcamera-devel","v2","2/5"]}