{"id":16797,"url":"https://patchwork.libcamera.org/api/patches/16797/?format=json","web_url":"https://patchwork.libcamera.org/patch/16797/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20220726143635.518227-3-fsylvestre@baylibre.com>","date":"2022-07-26T14:36:32","name":"[libcamera-devel,v3,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/people/123/?format=json","name":"Florian Sylvestre","email":"fsylvestre@baylibre.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16797/mbox/","series":[{"id":3328,"url":"https://patchwork.libcamera.org/api/series/3328/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3328","date":"2022-07-26T14:36:30","name":"Add GSL, LSC and DPCC tuning support for rkisp1","version":3,"mbox":"https://patchwork.libcamera.org/series/3328/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16797/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16797/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 16371C3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 26 Jul 2022 14:36:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BE1596331C;\n\tTue, 26 Jul 2022 16:36:46 +0200 (CEST)","from mail-wr1-x435.google.com (mail-wr1-x435.google.com\n\t[IPv6:2a00:1450:4864:20::435])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E241260487\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jul 2022 16:36:42 +0200 (CEST)","by mail-wr1-x435.google.com with SMTP id d8so20348743wrp.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jul 2022 07:36:42 -0700 (PDT)","from BL087.. ([2a01:e34:eea9:e630:c7b2:2183:8a06:b4dc])\n\tby smtp.gmail.com with ESMTPSA id\n\tm184-20020a1c26c1000000b003a04722d745sm22447386wmm.23.2022.07.26.07.36.40\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 26 Jul 2022 07:36:41 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658846206;\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=pU9jOOpNieJ5nbdiA5xjtjyzunceYQhf9uSHoel1DHyF7riJ7bbLM7bO4a/L7jXEx\n\toES/oOa+3l2P6rCl8NOhcLmFeHC8xoh6YokDIHpqiazGeHZyQcltSNLId+a7HfYIW3\n\twpU2IGToW7dwqwALy9eWMs0/3xZLHw9gP9C74DDUGD1r6/Nlr9vR188dyiwDx97sPY\n\tdD55J93XYYOsqMFalPueVpmofDjRZUsusR8362ywCPQQI2MTg5TRy+lw5kBFn6Fxv9\n\tYTLh440AqOAOA6fBUgV0K97F7g3TxQQcjzdSBuu1o4bREhSnVxf2Os9EK7+ZcAR52v\n\tx3gWfnoE1MqXg==","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=jso4YM/CuNYBVijqIRQ3Dj+xRjQdplVKgob1ILHdkv7vVWgQBqBP0jXLi08eglQqx3\n\tsySmeKhrbagYaQDKzEb7CifuLC0zTnzveVLqCAqFcQH3xdzeBXfojkNVUksJIZA6qHhb\n\t7omj4d3cwTMueBqQTPaz3Aw3DqqIsG/7S0+62M912ww4lEFOF69HlhA0XQYWeV+uhVgf\n\t3oMr0K8726xSM4FuVRZ3SK2wzNaRFN9IH36FLIB/ENgIQGenUVQ2xXfnN1Xsek8Al084\n\tOxoptOpi2FkVf/cc4GmPdPeSbIwmPvmwm3ZO4m/DjQ+wwZCpBFMEBQPPnhFlJmeT+njl\n\toqBQ=="],"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=\"jso4YM/C\"; \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=hYwz7jO34Ji2V57hFICpJM/pqzrEAKSLvSdyJWJIGcZ6cFBIYttw4OIzZwdSw08gjL\n\to9RQI2O1twsRjcW7vUDqyvFSdR4AVoFXX+cnvlrScoRJs0a6QNLq+6E+jdpShVZhBUbY\n\tQKXVpL9eTsFUA944Ewzbzj3JZEvJcfQ4qmBWYLUTQTLUExEsxJM5d2fhVr+VaKsuL6/N\n\tEvqg7x5+kpZ+vUixxKZmorIqRYWf33RZ8PrXw4p//fmm7OuqIUyXMbzQZdyBFYsQeOqT\n\tW7i6eU8w4uqYJnVqbz2a/Arx6QRE03EkpnFI69bRB2HGvHsvX9UZBOQEZAnjrhbqoUey\n\tOT7Q==","X-Gm-Message-State":"AJIora/6BVI8gOomSZHtZm3+Z0KC0GuVmOCh3k+bZzejaOKf6hdTSiQX\n\tiiTcupcv+5tUW7pvxC8QagHVf5Pxq/t37br9","X-Google-Smtp-Source":"AGRyM1txVUJsYiamVK9Pd1Ek+j5gUscBmfy0Kpzq6Lt0rL7LFDVDQ5aoyFgFVKi3HGh2E4D92dAOfQ==","X-Received":"by 2002:adf:ed41:0:b0:210:20a5:26c2 with SMTP id\n\tu1-20020adfed41000000b0021020a526c2mr10684042wro.603.1658846202084; \n\tTue, 26 Jul 2022 07:36:42 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 26 Jul 2022 16:36:32 +0200","Message-Id":"<20220726143635.518227-3-fsylvestre@baylibre.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220726143635.518227-1-fsylvestre@baylibre.com>","References":"<20220726143635.518227-1-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 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","v3","2/5"]}