{"id":25015,"url":"https://patchwork.libcamera.org/api/patches/25015/?format=json","web_url":"https://patchwork.libcamera.org/patch/25015/","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":"<20251113122450.287633-2-kieran.bingham@ideasonboard.com>","date":"2025-11-13T12:24:36","name":"[v3,01/14] ipa: libipa: Provide a Quantized data type support","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"2cd182f711c4ff6f40dc2ebe101c83fdc79cd619","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25015/mbox/","series":[{"id":5587,"url":"https://patchwork.libcamera.org/api/series/5587/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5587","date":"2025-11-13T12:24:35","name":"libipa: Introduce a Quantized type","version":3,"mbox":"https://patchwork.libcamera.org/series/5587/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25015/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25015/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 0AF4BC3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 12:24:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A413360A80;\n\tThu, 13 Nov 2025 13:24:58 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7139B60A80\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 13:24:54 +0100 (CET)","from Monstersaurus.infra.iob\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5BDAA6AF;\n\tThu, 13 Nov 2025 13:22:54 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"hIASYZTg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763036574;\n\tbh=i4aQb0iu4kkqT/s8oUxX6tBf1FrPSE/Vs9mocVV9bSw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=hIASYZTg80dGm1MdAnqiL2XJRdKS67x50VCAShPsAILs5MAIADZ4d/AvazJcKtxwx\n\tfOvLg97m5uL3Q51vi6HW8YsY59xEeENAFt8UPcD7JbpBcfEncSZzahHZm+TVaR4Y++\n\tpPrQJX6oNxL+T40UCsjZ2wk2u3KlkYre51MquHsM=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"[PATCH v3 01/14] ipa: libipa: Provide a Quantized data type support","Date":"Thu, 13 Nov 2025 12:24:36 +0000","Message-ID":"<20251113122450.287633-2-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20251113122450.287633-1-kieran.bingham@ideasonboard.com>","References":"<20251113122450.287633-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Frequently when handling data in IPA components we must convert and\nstore user interface values which may be floating point values, and\nperform a specific operation or conversion to quantize this to a\nhardware value.\n\nThis value may be to a fixed point type, or more custom code mappings,\nbut in either case it is important to contain both the required hardware\nvalue, with its effective quantized value.\n\nProvide a new storage type 'Quantized' which can be defined based on a\nset of type specific Traits to perform the conversions between floats\nand the underlying hardware type.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv3:\n - adapt string format to [0xff:1.99] style instead of Q:0xff V:1.99\n - Clean up comments and copyright\n - Remove private initialisers - already handled by constructors\n - Change quantized_type to QuantizedType\n\n src/ipa/libipa/meson.build   |   2 +\n src/ipa/libipa/quantized.cpp | 134 +++++++++++++++++++++++++++++++++++\n src/ipa/libipa/quantized.h   |  78 ++++++++++++++++++++\n 3 files changed, 214 insertions(+)\n create mode 100644 src/ipa/libipa/quantized.cpp\n create mode 100644 src/ipa/libipa/quantized.h","diff":"diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex 660be94054fa..804289778f72 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -17,6 +17,7 @@ libipa_headers = files([\n     'lux.h',\n     'module.h',\n     'pwl.h',\n+    'quantized.h',\n ])\n \n libipa_sources = files([\n@@ -36,6 +37,7 @@ libipa_sources = files([\n     'lux.cpp',\n     'module.cpp',\n     'pwl.cpp',\n+    'quantized.cpp',\n ])\n \n libipa_includes = include_directories('..')\ndiff --git a/src/ipa/libipa/quantized.cpp b/src/ipa/libipa/quantized.cpp\nnew file mode 100644\nindex 000000000000..ef3ae21e9a3b\n--- /dev/null\n+++ b/src/ipa/libipa/quantized.cpp\n@@ -0,0 +1,134 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board Oy\n+ *\n+ * Helper class to manage conversions between floating point types and quantized\n+ * storage and representation of those values.\n+ */\n+\n+#include \"quantized.h\"\n+\n+/**\n+ * \\file quantized.h\n+ * \\brief Quantized storage and Quantizer representations\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+/**\n+ * \\struct libcamera::ipa::Quantized\n+ * \\brief Wrapper that stores a value in both quantized and floating-point form\n+ * \\tparam Traits The traits class defining the quantization behaviour\n+ *\n+ * The Quantized struct template provides a thin wrapper around a quantized\n+ * representation of a floating-point value. It uses a traits type \\a Traits\n+ * to define the conversion policy between the floating-point domain and the\n+ * quantized integer domain.\n+ *\n+ * Each Quantized instance maintains two synchronized members:\n+ *  - the quantized integer representation, and\n+ *  - the corresponding floating-point value.\n+ *\n+ * The traits type defines:\n+ *  - the integer storage type used for quantization,\n+ *  - the static conversion functions \\c fromFloat() and \\c toFloat(), and\n+ *  - optional metadata such as value ranges.\n+ *\n+ * Quantized provides convenient constructors and assignment operators from\n+ * either representation, as well as comparison and string formatting utilities.\n+ */\n+\n+/**\n+ * \\typedef Quantized::TraitsType\n+ * \\brief The traits policy type defining the quantization behaviour\n+ *\n+ * Exposes the associated traits type used by this Quantized instance.\n+ * This allows external code to refer to constants or metadata defined in\n+ * the traits, such as \\c TraitsType::min or \\c TraitsType::max.\n+ */\n+\n+/**\n+ * \\typedef Quantized::QuantizedType\n+ * \\brief The integer type used for the quantized representation\n+ *\n+ * This alias corresponds to \\c TraitsType::QuantizedType, as defined by\n+ * the traits class.\n+ */\n+\n+/**\n+ * \\fn Quantized::Quantized(float x)\n+ * \\brief Construct a Quantized value from a floating-point number\n+ * \\param[in] x The floating-point value to be quantized\n+ *\n+ * Converts the floating-point input \\a x to its quantized integer\n+ * representation using the associated traits policy, and initializes\n+ * both the quantized and floating-point members.\n+ */\n+\n+/**\n+ * \\fn Quantized::Quantized(QuantizedType x)\n+ * \\brief Construct a Quantized value from an existing quantized integer\n+ * \\param[in] x The quantized integer value\n+ *\n+ * Converts the quantized integer \\a x to its corresponding floating-point\n+ * value using the traits policy, and initializes both internal members.\n+ */\n+\n+/**\n+ * \\fn Quantized::operator=(float x)\n+ * \\brief Assign a floating-point value to the Quantized object\n+ * \\param[in] x The floating-point value to assign\n+ * \\return A reference to the updated Quantized object\n+ *\n+ * Converts the floating-point value \\a x to its quantized integer\n+ * representation using the traits policy and updates both members.\n+ */\n+\n+/**\n+ * \\fn Quantized::operator=(QuantizedType x)\n+ * \\brief Assign a quantized integer value to the Quantized object\n+ * \\param[in] x The quantized integer value to assign\n+ * \\return A reference to the updated Quantized object\n+ *\n+ * Converts the quantized integer \\a x to its corresponding floating-point\n+ * value using the traits policy and updates both members.\n+ */\n+\n+/**\n+ * \\fn Quantized::value() const noexcept\n+ * \\brief Retrieve the floating-point representation\n+ * \\return The floating-point value corresponding to the quantized value\n+ */\n+\n+/**\n+ * \\fn Quantized::quantized() const noexcept\n+ * \\brief Retrieve the quantized integer representation\n+ * \\return The quantized integer value\n+ */\n+\n+/**\n+ * \\fn Quantized::toString() const\n+ * \\brief Format the quantized and floating-point values as a string\n+ * \\return A string containing the hexadecimal quantized value and its\n+ *         floating-point equivalent.\n+ */\n+\n+/**\n+ * \\fn Quantized::operator==(const Quantized &other) const noexcept\n+ * \\brief Compare two Quantized objects for equality\n+ * \\param[in] other The other Quantized object to compare against\n+ * \\return True if both objects have the same quantized integer value\n+ */\n+\n+/**\n+ * \\fn Quantized::operator!=(const Quantized &other) const noexcept\n+ * \\brief Compare two Quantized objects for inequality\n+ * \\param[in] other The other Quantized object to compare against\n+ * \\return True if the quantized integer values differ\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/quantized.h b/src/ipa/libipa/quantized.h\nnew file mode 100644\nindex 000000000000..db1c0d72db86\n--- /dev/null\n+++ b/src/ipa/libipa/quantized.h\n@@ -0,0 +1,78 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2025, Ideas On Board Oy\n+ *\n+ * Helper class to manage conversions between floating point types and quantized\n+ * storage and representation of those values.\n+ */\n+\n+#pragma once\n+\n+#include <iomanip>\n+#include <sstream>\n+#include <stdint.h>\n+#include <type_traits>\n+\n+#include <libcamera/base/utils.h>\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+template<typename Traits>\n+struct Quantized {\n+\tusing TraitsType = Traits;\n+\tusing QuantizedType = typename Traits::QuantizedType;\n+\tstatic_assert(std::is_arithmetic_v<QuantizedType>,\n+\t\t      \"Quantized: QuantizedType must be arithmetic\");\n+\n+\tQuantized()\n+\t\t: Quantized(0.0f) {}\n+\tQuantized(float x) { *this = x; }\n+\tQuantized(QuantizedType x) { *this = x; }\n+\n+\tQuantized &operator=(float x)\n+\t{\n+\t\tquantized_ = Traits::fromFloat(x);\n+\t\tvalue_ = Traits::toFloat(quantized_);\n+\t\treturn *this;\n+\t}\n+\n+\tQuantized &operator=(QuantizedType x)\n+\t{\n+\t\tvalue_ = Traits::toFloat(x);\n+\t\tquantized_ = x;\n+\t\treturn *this;\n+\t}\n+\n+\tfloat value() const noexcept { return value_; }\n+\tQuantizedType quantized() const noexcept { return quantized_; }\n+\n+\tstd::string toString() const\n+\t{\n+\t\tstd::ostringstream oss;\n+\n+\t\toss << \"[\" << utils::hex(quantized_)\n+\t\t    << \":\" << value_ << \"]\";\n+\n+\t\treturn oss.str();\n+\t}\n+\n+\tbool operator==(const Quantized &other) const noexcept\n+\t{\n+\t\treturn quantized_ == other.quantized_;\n+\t}\n+\n+\tbool operator!=(const Quantized &other) const noexcept\n+\t{\n+\t\treturn !(*this == other);\n+\t}\n+\n+private:\n+\tQuantizedType quantized_;\n+\tfloat value_;\n+};\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\n","prefixes":["v3","01/14"]}