{"id":16709,"url":"https://patchwork.libcamera.org/api/patches/16709/?format=json","web_url":"https://patchwork.libcamera.org/patch/16709/","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":"<20220720154221.50937-5-fsylvestre@baylibre.com>","date":"2022-07-20T15:42:21","name":"[libcamera-devel,v2,4/4] ipa: rkisp1: Add support of ColorProcessing control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b4e8275c9f0db1dfff5f92a0d40486a0297f3250","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/16709/mbox/","series":[{"id":3310,"url":"https://patchwork.libcamera.org/api/series/3310/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3310","date":"2022-07-20T15:42:17","name":"Add Demosaicing and Color Processing control for rkisp1","version":2,"mbox":"https://patchwork.libcamera.org/series/3310/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16709/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16709/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 1BC6CBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Jul 2022 15:42:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AAF1563317;\n\tWed, 20 Jul 2022 17:42:37 +0200 (CEST)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D23063317\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Jul 2022 17:42:35 +0200 (CEST)","by mail-wm1-x32a.google.com with SMTP id\n\tay11-20020a05600c1e0b00b003a3013da120so1601121wmb.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Jul 2022 08:42:35 -0700 (PDT)","from BL087.. ([2a01:e34:eea9:e630:516d:f303:6345:b768])\n\tby smtp.gmail.com with ESMTPSA id\n\td2-20020adffbc2000000b0021e489ec78bsm2159294wrs.21.2022.07.20.08.42.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 20 Jul 2022 08:42:33 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658331757;\n\tbh=2E3bcs1TIXH8g9pWyRgtMsRwI4PM4PjapWAFqJQQXJ8=;\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=4DXzsAqLFjsMe/x3tDo6uNKMDIaZVF7i7MthNh6OM3FNly6JE5JYfif17Pg3UZL5R\n\t8ngUddLOP3FTS0XiKTRT5JFffkWdvViREMjaD9wD99Bq5D7cowuYPkQPvrrEglJtGX\n\tI6rIci0bA/KAwTAkVwrVOZ2XxxTHu/22J/d29R9c+DX7Qftqa+vORCgu1eif3jI+ig\n\t8jSg3JRR3Z02+LYhfkwZh4Zj+WoXd25CPDBOyfKn9rKNmkJIf46jhPbCzV8PVmUvOq\n\t+2/D4jwpqMLHwfcpRlDm+nb91WGnSqMAMdn0cR36dSKzrHWMQ1aUrMjqzKr5UzmpTX\n\t0QcvjBs8HAbRA==","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=jjruhyoiyW+4uTxXzzsM9Z4EbDLtkiXsS5Kv7O13Nwo=;\n\tb=rKbUyXEgHaFqGFKgddCdfTvlM5oJ6C+cDuoQI/JYGxtnOtEubcOZtDK0CYMsT+0EqU\n\tGbydqcRVOvkD5AFA20Y8+zfyHhEHlzQD/MSZjRZAe9YpNQK5W8FeUq6QxS1gkKTbnc4k\n\t0U26E8hzDS6cxWeRcVL+yTnoJrN+yCwGtW+fIfb6hUXK5/xJR1tWxXDMoWYUyDhEpqJM\n\t6AjcU+6MJeFS9rAvBs0X2qeaUbt66ghoUVDcbrIR1OmqO+SsfoEFQzOsprSLFOyyYdk7\n\t9A3y7zHmmXhgaACusofkgvPiqRhFRIYnmRHNs3qqlQOiClDqGboh1qVHmCSGVvO3KAe9\n\tKjqg=="],"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=\"rKbUyXEg\"; \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=jjruhyoiyW+4uTxXzzsM9Z4EbDLtkiXsS5Kv7O13Nwo=;\n\tb=vkJa+bs81hcxl8vsfyxkmjv/pCE/x/eYv4fJcTP2K8S7FQK1o7Bmx8vkOzo3AlFo9n\n\tlNjJ9c0Lg7BTQ6dEzUPU3+fKGw7CXXN0DKAXMlimwk3Eij9D8vSrO9Avs/t0FzaGtWE+\n\tpY5Al9WpjigPAWXDHRsNG+vZUJdO07/Oy7WvDnc66/q5HqhM7WPpuNM78pz5/VHxPndi\n\tLW0wajXdyYntLrdcm8Q/Dxn3w/x8mDKmdCOEM5r8JQMx4W6XcoFdxhixCKpIzi82mM/d\n\teurZi/dOKGj6g/NVYVbgEn+hp+XdgU+o2M/4kZPCRF9EVLpT6V9e2frjvWV4tvdySIGE\n\tka9Q==","X-Gm-Message-State":"AJIora9bZ+0WcjC+8hYjTQFmCDsrl7faCNZSRBfmPiImTRtHCte8Qq/b\n\tm1K3Cn8JSWRdALCL+mSu7fmrypEKxC90awa+","X-Google-Smtp-Source":"AGRyM1syEyX66TiSrEYWI4f1TFUat4B6s1Fc9XEm/W9p0+3mkgGYqTY2pMeE0CGPJzfFmA4SkafkGw==","X-Received":"by 2002:a7b:ce8f:0:b0:3a2:ff2d:915f with SMTP id\n\tq15-20020a7bce8f000000b003a2ff2d915fmr4390047wmj.165.1658331754327; \n\tWed, 20 Jul 2022 08:42:34 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 20 Jul 2022 17:42:21 +0200","Message-Id":"<20220720154221.50937-5-fsylvestre@baylibre.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220720154221.50937-1-fsylvestre@baylibre.com>","References":"<20220720154221.50937-1-fsylvestre@baylibre.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 4/4] ipa: rkisp1: Add support of\n\tColorProcessing 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":"Add ColorProcessing algorithm that is in charge to manage brightness, contrast\nand saturation controls.\nThese controls are currently based on user controls.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/cproc.cpp      | 94 ++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/cproc.h        | 30 ++++++++\n src/ipa/rkisp1/algorithms/meson.build    |  1 +\n src/ipa/rkisp1/data/ov5640.yaml          |  1 +\n src/ipa/rkisp1/ipa_context.h             |  7 ++\n src/ipa/rkisp1/rkisp1.cpp                |  1 +\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 12 +++\n 7 files changed, 146 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/cproc.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/cproc.h","diff":"diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp\nnew file mode 100644\nindex 00000000..7e9e8cf1\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/cproc.cpp\n@@ -0,0 +1,94 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * cproc.cpp - RkISP1 Color Processing control\n+ */\n+\n+#include \"cproc.h\"\n+\n+#include <algorithm>\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/control_ids.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+/**\n+ * \\file cproc.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class ColorProcessing\n+ * \\brief RkISP1 Color Processing control\n+ *\n+ * The ColorProcessing algorithm is responsible for applying brightness,\n+ * contrast and saturation corrections. The values are directly provided\n+ * through requests by the corresponding controls.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1CProc)\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void ColorProcessing::queueRequest([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   [[maybe_unused]] const uint32_t frame,\n+\t\t\t\t   const ControlList &controls)\n+{\n+\tconst auto &brightness = controls.get(controls::Brightness);\n+\tif (brightness) {\n+\t\tcontext.frameContext.cproc.brightness = std::clamp(int(*brightness * 128), -128, 127);\n+\t\tcontext.frameContext.cproc.updateParams = true;\n+\n+\t\tLOG(RkISP1CProc, Debug) << \"Set brightness to \" << *brightness;\n+\t}\n+\n+\tconst auto &contrast = controls.get(controls::Contrast);\n+\tif (contrast) {\n+\t\tcontext.frameContext.cproc.contrast = std::clamp(int(*contrast * 128), 0, 255);\n+\t\tcontext.frameContext.cproc.updateParams = true;\n+\n+\t\tLOG(RkISP1CProc, Debug) << \"Set contrast to \" << *contrast;\n+\t}\n+\n+\tconst auto saturation = controls.get(controls::Saturation);\n+\tif (saturation) {\n+\t\tcontext.frameContext.cproc.saturation = std::clamp(int(*saturation) * 128, 0, 255);\n+\t\tcontext.frameContext.cproc.updateParams = true;\n+\n+\t\tLOG(RkISP1CProc, Debug) << \"Set saturation to \" << *saturation;\n+\t}\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void ColorProcessing::prepare([[maybe_unused]] IPAContext &context,\n+\t\t\t      rkisp1_params_cfg *params)\n+{\n+\t/* Check if the algorithm configuration has been updated. */\n+\tif (!context.frameContext.cproc.updateParams)\n+\t\treturn;\n+\n+\tcontext.frameContext.cproc.updateParams = false;\n+\n+\tparams->others.cproc_config.brightness = context.frameContext.cproc.brightness;\n+\tparams->others.cproc_config.contrast = context.frameContext.cproc.contrast;\n+\tparams->others.cproc_config.sat = context.frameContext.cproc.saturation;\n+\n+\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC;\n+\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC;\n+\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CPROC;\n+}\n+\n+REGISTER_IPA_ALGORITHM(ColorProcessing, \"ColorProcessing\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/cproc.h b/src/ipa/rkisp1/algorithms/cproc.h\nnew file mode 100644\nindex 00000000..4b7e4064\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/cproc.h\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * cproc.h - RkISP1 Color Processing control\n+ */\n+\n+#pragma once\n+\n+#include <sys/types.h>\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class ColorProcessing : public Algorithm\n+{\n+public:\n+\tColorProcessing() = default;\n+\t~ColorProcessing() = default;\n+\n+\tvoid queueRequest(IPAContext &context, const uint32_t frame,\n+\t\t\t  const ControlList &controls) override;\n+\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\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 7e078b0d..0ec17e07 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -4,6 +4,7 @@ rkisp1_ipa_algorithms = files([\n     'agc.cpp',\n     'awb.cpp',\n     'blc.cpp',\n+    'cproc.cpp',\n     'demosaicing.cpp',\n     'dpcc.cpp',\n     'gsl.cpp',\ndiff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml\nindex 4ae0ffc0..331f9d2d 100644\n--- a/src/ipa/rkisp1/data/ov5640.yaml\n+++ b/src/ipa/rkisp1/data/ov5640.yaml\n@@ -10,6 +10,7 @@ algorithms:\n       Gr: 256\n       Gb: 256\n       B:  256\n+  - ColorProcessing:\n   - GammaSensorLinearization:\n       x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]\n       y:\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 241a4d04..e6a61c45 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -62,6 +62,13 @@ struct IPAFrameContext {\n \t\tbool updateParams;\n \t} demosaicing;\n \n+\tstruct {\n+\t\tint8_t brightness;\n+\t\tuint8_t contrast;\n+\t\tuint8_t saturation;\n+\t\tbool updateParams;\n+\t} cproc;\n+\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\ndiff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex aeec8f50..c664642f 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/cproc.h\"\n #include \"algorithms/demosaicing.h\"\n #include \"algorithms/dpcc.h\"\n #include \"algorithms/gsl.h\"\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 4e000d31..de687f4d 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -972,6 +972,18 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \t\t      std::forward_as_tuple(&controls::Sharpness),\n \t\t      std::forward_as_tuple(0.0f, 10.0f, 1.0f));\n \n+\tctrls.emplace(std::piecewise_construct,\n+\t\t      std::forward_as_tuple(&controls::Brightness),\n+\t\t      std::forward_as_tuple(-1.0f, 0.993f));\n+\n+\tctrls.emplace(std::piecewise_construct,\n+\t\t      std::forward_as_tuple(&controls::Contrast),\n+\t\t      std::forward_as_tuple(0.0f, 1.993f));\n+\n+\tctrls.emplace(std::piecewise_construct,\n+\t\t      std::forward_as_tuple(&controls::Saturation),\n+\t\t      std::forward_as_tuple(0.0f, 1.993f));\n+\n \tctrls.emplace(std::piecewise_construct,\n \t\t      std::forward_as_tuple(&controls::draft::NoiseReductionMode),\n \t\t      std::forward_as_tuple(controls::draft::NoiseReductionModeValues));\n","prefixes":["libcamera-devel","v2","4/4"]}