{"id":16326,"url":"https://patchwork.libcamera.org/api/patches/16326/?format=json","web_url":"https://patchwork.libcamera.org/patch/16326/","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":"<20220622151918.451635-3-fsylvestre@baylibre.com>","date":"2022-06-22T15:19:15","name":"[libcamera-devel,2/5] ipa: rkisp1: Add support of Gamma Sensor Linearization control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"92ca86151087f6795b9259d7d0771d99b8cabdb7","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/16326/mbox/","series":[{"id":3208,"url":"https://patchwork.libcamera.org/api/series/3208/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3208","date":"2022-06-22T15:19:13","name":"Add GSL, LSC and DPCC tuning support for rkisp1","version":1,"mbox":"https://patchwork.libcamera.org/series/3208/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16326/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16326/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 371A8BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jun 2022 15:19:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DE3176563F;\n\tWed, 22 Jun 2022 17:19:27 +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 0D9C2633A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 17:19:23 +0200 (CEST)","by mail-wr1-x435.google.com with SMTP id m1so16130810wrb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 08:19:23 -0700 (PDT)","from BL087.. ([2a01:e34:eea9:e630:4175:47f:ec:c265])\n\tby smtp.gmail.com with ESMTPSA id\n\tbi11-20020a05600c3d8b00b0039c362311d2sm1745388wmb.9.2022.06.22.08.19.22\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Jun 2022 08:19:22 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655911167;\n\tbh=24RVhavebKniWYuCdDXVg65LTNOBDF3d6tMEDxsO1hw=;\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=ob/NwN6TPsrvrqTBaVDWhaZW5/J+JUkZXFpkxnINdO9dMRo/uGCMSbMggw7AEZ/0f\n\tkbC86F1KlXZohew//u8leb1LInUMARllxhzjgDy4ZFjWq3QqDzrXxBmJZtqgtb9K3E\n\tm+aWZaaG1d5N4SHQIDiqOvgvqIN3ev7KiYa4NZHPEm2vdy6rkelaGY1DhyCsplbvqC\n\tXgvmCZZv/O7dT+1EKWM7xIYUU6r+qf8epQqxbLHmLX4LMISAoCXH5bUMeyKsQyJmnu\n\tPMIrKOMvwsMC/3nE2QFcLl/7tegSdrFk4tHlS2Tffno873mdndJUxw7KvT+CXVRcuI\n\tcmZXeOzwkOEAQ==","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=yNaK4lL7ptTiR8Dc2zGHrSfnzbtoITkNc2JISFFG+I0=;\n\tb=eWz5w/Zx8Ef7ubtowMrAYF5nXHtEHej0dMEUZkq+2uoMZHJ73AQa/QYzrGoy+BPlko\n\tCh53Aimu8AOwjD/SJlZ04TYlLFPH4hdAO+ML2tt5NJaWFYPXfAb3Bp7bimSUuZJTpLUh\n\tGbyTyCu1tP9ua5uGSUTbvdwiMmi/pExtYmJgG9tx+S7ItDVeooK79PL2v40Rbsi3Fa6m\n\tTlxiNbWqwPFuOTnMF80q7LKHt4eBdY0JLHdj4IoDxetKGY9cYC9gKcFGe4wc/iAndl9o\n\tPY+qp/XToktluncuTl4XYVLZkMIMcxTg0YpTCFjz44NfZnjRjlggG561lGE/r86Q5C+5\n\t0zrg=="],"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=\"eWz5w/Zx\"; \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=yNaK4lL7ptTiR8Dc2zGHrSfnzbtoITkNc2JISFFG+I0=;\n\tb=fcY+kDbE8aKs3JCecqUsBXCpTXbgdWtJNqkVGtbDN1zZQtacDm1rtJaUn/i8fQsSVV\n\tNeJSnCaJAwdUSaE3cJnZnAcC9AmJKoieH3GOV/vFNHdKkTiLa7MhPkC64a5xfjAacI80\n\tOq0e2xg6Sh+U71v6I8jCwZhIn3Kto/nGILsaJ7GzHRFGN79KAdZSuYjDgZdgQqQGvz5o\n\tOxfQbGGBcVxbR101h9GCXgt9yA8uWHn/1x8Li5gMYZothebhYzef7gNMKiKQOKqYtxH4\n\tAZc+3pFQuS9KIbab1zmvO0FEt85ys5zfD2dwVl16EYiasjd1a/nN7niTiDfxLF7yK19A\n\tHJkg==","X-Gm-Message-State":"AJIora8v0fScXq64o3dXlkPLpTPvtaHv3W8KZgOnDQJns8eTTTvDmazq\n\tGIvhH9gamqZ4jeZeuOFCnr5aFbaCKcEzaw==","X-Google-Smtp-Source":"AGRyM1tlWOuObTr2c113LLcl3nEm31+XxNg0kSEVZeYmsyAEa4ImjQ9opF2oHImwYEH56bHrr8QLLw==","X-Received":"by 2002:adf:ea43:0:b0:21b:9243:be8c with SMTP id\n\tj3-20020adfea43000000b0021b9243be8cmr3761987wrn.650.1655911162976; \n\tWed, 22 Jun 2022 08:19:22 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 22 Jun 2022 17:19:15 +0200","Message-Id":"<20220622151918.451635-3-fsylvestre@baylibre.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220622151918.451635-1-fsylvestre@baylibre.com>","References":"<20220622151918.451635-1-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 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.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\n---\n src/ipa/rkisp1/algorithms/gsl.cpp     | 142 ++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/gsl.h       |  38 +++++++\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, 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..7ff3d360\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/gsl.cpp\n@@ -0,0 +1,142 @@\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+#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 improves the image dynamic using a coefficient table in the\n+ * Yaml tuning file, the table contains:\n+ *  - 'x-intervals': These values corresponds to GAMMA_DX_n values (from\n+ *    GAMMA_DX_0 to GAMMA_DX_16 fields in RKISP1_CIF_ISP_GAMMA_DX_LO and\n+ *    RKISP1_CIF_ISP_GAMMA_DX_HI rkisp1 registers).\n+ *    Note: rkisp1 use each value to compute a X interval equal to 2^(value+4)\n+ *  - 'y' values for each component (red, green , blue) on 12 bits resolution.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Gsl)\n+\n+#define DEGAMMA_X_INTERVALS 16\n+\n+GammaSensorLinearization::GammaSensorLinearization()\n+\t: tuningParameters_(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() != DEGAMMA_X_INTERVALS) {\n+\t\tLOG(RkISP1Gsl, Error)\n+\t\t\t<< \"Issue while parsing 'x'\"\n+\t\t\t<< \"in tuning file (list size:\"\n+\t\t\t<< xIntervals_.size() << \"/\"\n+\t\t\t<< DEGAMMA_X_INTERVALS << \")\";\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 (int i = 0; i < DEGAMMA_X_INTERVALS; ++i) {\n+\t\tgammaDx_[i / 8] |= (xIntervals_[i] & 0x07) << ((i % 8) * 4);\n+\t}\n+\n+\tconst YamlObject &yObject = tuningData[\"y\"];\n+\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<< \"Issue while parsing 'y:red'\"\n+\t\t\t<< \"in tuning file (list size: \"\n+\t\t\t<< curveYr_.size() << \"/\"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_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<< \"Issue while parsing 'y:green'\"\n+\t\t\t<< \"in tuning file (list size: \"\n+\t\t\t<< curveYg_.size() << \"/\"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_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<< \"Issue while parsing 'y:blue'\"\n+\t\t\t<< \"in tuning file (list size: \"\n+\t\t\t<< curveYb_.size() << \"/\"\n+\t\t\t<< RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE << \")\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\ttuningParameters_ = 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 (!tuningParameters_)\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)\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..df16a89b\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/gsl.h\n@@ -0,0 +1,38 @@\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 <linux/rkisp1-config.h>\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+struct IPACameraSensorInfo;\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 tuningParameters_;\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..6cb84ed9 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, 4096 ]\n+        green: [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ]\n+        blue:  [ 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096 ]\n ...\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex d052954e..622a0d61 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","2/5"]}