[{"id":37683,"web_url":"https://patchwork.libcamera.org/comment/37683/","msgid":"<4c47ec0d-2469-486b-9bf4-ce819c2c9a85@ideasonboard.com>","date":"2026-01-15T16:29:02","subject":"Re: [PATCH v5 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n> Frequently when handling data in IPA components we must convert and\n> store user interface values which may be floating point values, and\n> perform a specific operation or conversion to quantize this to a\n> hardware value.\n> \n> This value may be to a fixed point type, or more custom code mappings,\n> but in either case it is important to contain both the required hardware\n> value, with its effective quantized value.\n> \n> Provide a new storage type 'Quantized' which can be defined based on a\n> set of type specific Traits to perform the conversions between floats\n> and the underlying hardware type.\n> \n> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> v3:\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> v5:\n> - introduce operator<<(std::ostream &out, const Quantized<Traits> &q)\n> - Remove unused iomanip and stdint.h from includes\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   src/ipa/libipa/meson.build   |   2 +\n>   src/ipa/libipa/quantized.cpp | 142 +++++++++++++++++++++++++++++++++++\n>   src/ipa/libipa/quantized.h   |  83 ++++++++++++++++++++\n>   3 files changed, 227 insertions(+)\n>   create mode 100644 src/ipa/libipa/quantized.cpp\n>   create mode 100644 src/ipa/libipa/quantized.h\n> \n> diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n> index 7202df869c2f..963c5ee73063 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>       'v4l2_params.h',\n>   ])\n>   \n> @@ -37,6 +38,7 @@ libipa_sources = files([\n>       'lux.cpp',\n>       'module.cpp',\n>       'pwl.cpp',\n> +    'quantized.cpp',\n>       'v4l2_params.cpp',\n>   ])\n>   \n> diff --git a/src/ipa/libipa/quantized.cpp b/src/ipa/libipa/quantized.cpp\n> new file mode 100644\n> index 000000000000..115739e71654\n> --- /dev/null\n> +++ b/src/ipa/libipa/quantized.cpp\n> @@ -0,0 +1,142 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2025, Ideas On Board Oy\n\n2026 ?\n\n\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\nI think maybe it's worth highlighting with `\\note` that both members are\nupdated, and that likely `value() != x` after the assignment.\n\n\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> +/**\n> + * \\fn std::ostream &Quantized::operator<<(std::ostream &out, const Quantized<Traits> &q)\n> + * \\brief Insert a text representation of a Quantized into an output stream\n> + * \\param[in] out The output stream\n> + * \\param[in] q The Quantized\n> + * \\return The output stream \\a out\n> + */\n> +\n> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/libipa/quantized.h b/src/ipa/libipa/quantized.h\n> new file mode 100644\n> index 000000000000..045ccb755a85\n> --- /dev/null\n> +++ b/src/ipa/libipa/quantized.h\n> @@ -0,0 +1,83 @@\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 <sstream>\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::stringstream ss;\n> +\t\tss << *this;\n> +\n> +\t\treturn ss.str();\n> +\t}\n\nThis doesn't seem to be used (outside of the tests), so I think I'd probably\nremove it so that people won't use it with `<<` accidentally.\n\n\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> +\tfriend std::ostream &operator<<(std::ostream &out,\n> +\t\t\t\t\tconst Quantized<Traits> &q)\n> +\t{\n> +\t\tout << \"[\" << utils::hex(q.quantized())\n> +\t\t    << \":\" << q.value() << \"]\";\n> +\n> +\t\treturn out;\n> +\t}\n\nI have fixed the reason why this couldn't be declared outside the type:\nhttps://patchwork.libcamera.org/project/libcamera/list/?series=5709\n\nBut I think it's fine to leave it in the class as well.\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n> +\n> +private:\n> +\tQuantizedType quantized_;\n> +\tfloat value_;\n> +};\n> +\n> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */","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 1D225C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Jan 2026 16:29:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C79FC61FC0;\n\tThu, 15 Jan 2026 17:29:07 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 05BA961F84\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Jan 2026 17:29:06 +0100 (CET)","from [192.168.33.20] (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A9B12229;\n\tThu, 15 Jan 2026 17:28:37 +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=\"Vd4R41Yj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768494518;\n\tbh=U04vKAOLL1yCwYEtj+zqgVu8LljfEq5EfpSQOjRdsag=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=Vd4R41YjD0LEkldFz8x2yMe0Jwyl7g0fH4mBO7dOWqDP6o/alM/hx4e8q3r7LmTtk\n\tUqS58TyL/bT+psqOkJYQDOr/vKkjyEDCrFyfSBpmfwMRbxnHbu7bi2kJoy+IvtbbgG\n\t0krbM71Ej6ECVlIrZCIKntsSBiFKVphOHq58frN0=","Message-ID":"<4c47ec0d-2469-486b-9bf4-ce819c2c9a85@ideasonboard.com>","Date":"Thu, 15 Jan 2026 17:29:02 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v5 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Cc":"Isaac Scott <isaac.scott@ideasonboard.com>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>\n\t<20260114173918.1744023-2-kieran.bingham@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260114173918.1744023-2-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":37690,"web_url":"https://patchwork.libcamera.org/comment/37690/","msgid":"<176856466924.3486172.8441572695382387238@ping.linuxembedded.co.uk>","date":"2026-01-16T11:57:49","subject":"Re: [PATCH v5 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2026-01-15 16:29:02)\n> 2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n> > Frequently when handling data in IPA components we must convert and\n> > store user interface values which may be floating point values, and\n> > perform a specific operation or conversion to quantize this to a\n> > hardware value.\n> > \n> > This value may be to a fixed point type, or more custom code mappings,\n> > but in either case it is important to contain both the required hardware\n> > value, with its effective quantized value.\n> > \n> > Provide a new storage type 'Quantized' which can be defined based on a\n> > set of type specific Traits to perform the conversions between floats\n> > and the underlying hardware type.\n> > \n> > Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > \n> > ---\n> > v3:\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> > v5:\n> > - introduce operator<<(std::ostream &out, const Quantized<Traits> &q)\n> > - Remove unused iomanip and stdint.h from includes\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >   src/ipa/libipa/meson.build   |   2 +\n> >   src/ipa/libipa/quantized.cpp | 142 +++++++++++++++++++++++++++++++++++\n> >   src/ipa/libipa/quantized.h   |  83 ++++++++++++++++++++\n> >   3 files changed, 227 insertions(+)\n> >   create mode 100644 src/ipa/libipa/quantized.cpp\n> >   create mode 100644 src/ipa/libipa/quantized.h\n> > \n> > diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n> > index 7202df869c2f..963c5ee73063 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> >       'v4l2_params.h',\n> >   ])\n> >   \n> > @@ -37,6 +38,7 @@ libipa_sources = files([\n> >       'lux.cpp',\n> >       'module.cpp',\n> >       'pwl.cpp',\n> > +    'quantized.cpp',\n> >       'v4l2_params.cpp',\n> >   ])\n> >   \n> > diff --git a/src/ipa/libipa/quantized.cpp b/src/ipa/libipa/quantized.cpp\n> > new file mode 100644\n> > index 000000000000..115739e71654\n> > --- /dev/null\n> > +++ b/src/ipa/libipa/quantized.cpp\n> > @@ -0,0 +1,142 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2025, Ideas On Board Oy\n> \n> 2026 ?\n\nI think copyright normally starts when it's authored/first published,\nwhich was 2025 so I won't bother updating this one in particular.\n\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> I think maybe it's worth highlighting with `\\note` that both members are\n> updated, and that likely `value() != x` after the assignment.\n\nOh yes - that's a good one. I'll add that.\n\n> \n> \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> > +/**\n> > + * \\fn std::ostream &Quantized::operator<<(std::ostream &out, const Quantized<Traits> &q)\n> > + * \\brief Insert a text representation of a Quantized into an output stream\n> > + * \\param[in] out The output stream\n> > + * \\param[in] q The Quantized\n> > + * \\return The output stream \\a out\n> > + */\n> > +\n> > +} /* namespace ipa */\n> > +\n> > +} /* namespace libcamera */\n> > diff --git a/src/ipa/libipa/quantized.h b/src/ipa/libipa/quantized.h\n> > new file mode 100644\n> > index 000000000000..045ccb755a85\n> > --- /dev/null\n> > +++ b/src/ipa/libipa/quantized.h\n> > @@ -0,0 +1,83 @@\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 <sstream>\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> > +     using TraitsType = Traits;\n> > +     using QuantizedType = typename Traits::QuantizedType;\n> > +     static_assert(std::is_arithmetic_v<QuantizedType>,\n> > +                   \"Quantized: QuantizedType must be arithmetic\");\n> > +\n> > +     Quantized()\n> > +             : Quantized(0.0f) {}\n> > +     Quantized(float x) { *this = x; }\n> > +     Quantized(QuantizedType x) { *this = x; }\n> > +\n> > +     Quantized &operator=(float x)\n> > +     {\n> > +             quantized_ = Traits::fromFloat(x);\n> > +             value_ = Traits::toFloat(quantized_);\n> > +             return *this;\n> > +     }\n> > +\n> > +     Quantized &operator=(QuantizedType x)\n> > +     {\n> > +             value_ = Traits::toFloat(x);\n> > +             quantized_ = x;\n> > +             return *this;\n> > +     }\n> > +\n> > +     float value() const noexcept { return value_; }\n> > +     QuantizedType quantized() const noexcept { return quantized_; }\n> > +\n> > +     std::string toString() const\n> > +     {\n> > +             std::stringstream ss;\n> > +             ss << *this;\n> > +\n> > +             return ss.str();\n> > +     }\n> \n> This doesn't seem to be used (outside of the tests), so I think I'd probably\n> remove it so that people won't use it with `<<` accidentally.\n\nAck! I like less code.\n\n> > +     bool operator==(const Quantized &other) const noexcept\n> > +     {\n> > +             return quantized_ == other.quantized_;\n> > +     }\n> > +\n> > +     bool operator!=(const Quantized &other) const noexcept\n> > +     {\n> > +             return !(*this == other);\n> > +     }\n> > +\n> > +     friend std::ostream &operator<<(std::ostream &out,\n> > +                                     const Quantized<Traits> &q)\n> > +     {\n> > +             out << \"[\" << utils::hex(q.quantized())\n> > +                 << \":\" << q.value() << \"]\";\n> > +\n> > +             return out;\n> > +     }\n> \n> I have fixed the reason why this couldn't be declared outside the type:\n> https://patchwork.libcamera.org/project/libcamera/list/?series=5709\n\nThat is awesome. I spent hours on that last year and just got myself in\na confused mess! I couldn't see the wood for the trees for sure!\n\nThank you!\n\n\n> But I think it's fine to leave it in the class as well.\n\nI've made this work now - so I almost want to leave it - but also - I\nwent through so much pain trying to get it like all the other\nimplementations ... I also sort of want to see that through - so I might\ntry on top of your patches as we're already spinning a v6 here.\n\nIf it's 'easy' now - I'll convert over. If it's hard - I'll keep what\nworks ;-)\n\n> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> \n\nThanks again.\n\nKieran\n\n> \n> > +\n> > +private:\n> > +     QuantizedType quantized_;\n> > +     float value_;\n> > +};\n> > +\n> > +} /* namespace ipa */\n> > +\n> > +} /* namespace libcamera */\n>","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 82B6CBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jan 2026 11:57:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD26F61FC3;\n\tFri, 16 Jan 2026 12:57:53 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3DBBE615B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jan 2026 12:57:52 +0100 (CET)","from pendragon.ideasonboard.com\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 03C9E4B3;\n\tFri, 16 Jan 2026 12:57:23 +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=\"sj0ec+9v\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768564644;\n\tbh=CDfEnrDS9OQWbD3G/nQ6OaOPEBMkU0dwHarFpSpFX7E=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=sj0ec+9v7BIGVOVzl54xC/X5MGXOwuF6UYwQqNmJs+ax4IptX/UkQohhuOe6WpLdi\n\t9uz6bmBWigr9ky1lcsq3tgFGvK60zgwM3zTk0Z+3qAoSoyQK93kZglwca2Rj8JueRI\n\tMloaAOJ58ndsel93NAZE2Ye79JIdlwKrZJgdlOUY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<4c47ec0d-2469-486b-9bf4-ce819c2c9a85@ideasonboard.com>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>\n\t<20260114173918.1744023-2-kieran.bingham@ideasonboard.com>\n\t<4c47ec0d-2469-486b-9bf4-ce819c2c9a85@ideasonboard.com>","Subject":"Re: [PATCH v5 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Isaac Scott <isaac.scott@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Date":"Fri, 16 Jan 2026 11:57:49 +0000","Message-ID":"<176856466924.3486172.8441572695382387238@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]