[{"id":37926,"web_url":"https://patchwork.libcamera.org/comment/37926/","msgid":"<20260124011921.GK215800@killaraus>","date":"2026-01-24T01:19:21","subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Wed, Jan 21, 2026 at 05:37:20PM +0000, Kieran Bingham wrote:\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: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\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 | 135 +++++++++++++++++++++++++++++++++++\n>  src/ipa/libipa/quantized.h   |  75 +++++++++++++++++++\n>  3 files changed, 212 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..06143a97ab3e\n> --- /dev/null\n> +++ b/src/ipa/libipa/quantized.cpp\n> @@ -0,0 +1,135 @@\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::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..0b2f7148c821\n> --- /dev/null\n> +++ b/src/ipa/libipa/quantized.h\n> @@ -0,0 +1,75 @@\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\nAny reason to use a struct and not a class ? We usually use struct only\n(or mostly) for plain old C structures with no member functions.\n\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\nThere's an open question in the v4 thread about whether or not we should\nmake these constructors explicit. Let's continue the discussion there.\n\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\nAs we don't use exceptions, is noexcept useful ?\n\nApart from those comments this looks good.\n\n> +\tQuantizedType quantized() const noexcept { return quantized_; }\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> +\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 CEBE5BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 24 Jan 2026 01:19:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F2E661FC9;\n\tSat, 24 Jan 2026 02:19:26 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B7F1261F84\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 24 Jan 2026 02:19:23 +0100 (CET)","from pendragon.ideasonboard.com\n\t(2001-14ba-703d-e500--2a1.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::2a1])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id DFA46448;\n\tSat, 24 Jan 2026 02:18:49 +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=\"FSyWHFFk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769217530;\n\tbh=tnVWYcaFIcaCWr0k/dNTFCki033lK2CwggP6NtsMB6U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=FSyWHFFkZGsf1WK7N/dlLQldUfX4NacjZKCLC0UsSdNyK56AI60eONifBwF1jmnDN\n\tGR6EnQ5Y8o01kvm26d/8Y7Tg9ZMjGNcnbKZ20XJ4B76It7Y0ofiW8AO4w5kamKq3OW\n\tQK35wux3sZwCXMBIKbrfxsc8F/+hDfotqtvdkwFc=","Date":"Sat, 24 Jan 2026 03:19:21 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>, =?utf-8?q?Barna?=\n\t=?utf-8?b?YsOhcyBQxZFjemU=?= <barnabas.pocze@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","Subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","Message-ID":"<20260124011921.GK215800@killaraus>","References":"<20260121173737.376113-1-kieran.bingham@ideasonboard.com>\n\t<20260121173737.376113-2-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260121173737.376113-2-kieran.bingham@ideasonboard.com>","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":37927,"web_url":"https://patchwork.libcamera.org/comment/37927/","msgid":"<20260124012029.GL215800@killaraus>","date":"2026-01-24T01:20:29","subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Sat, Jan 24, 2026 at 03:19:23AM +0200, Laurent Pinchart wrote:\n> On Wed, Jan 21, 2026 at 05:37:20PM +0000, Kieran Bingham wrote:\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: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\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 | 135 +++++++++++++++++++++++++++++++++++\n> >  src/ipa/libipa/quantized.h   |  75 +++++++++++++++++++\n> >  3 files changed, 212 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..06143a97ab3e\n> > --- /dev/null\n> > +++ b/src/ipa/libipa/quantized.cpp\n> > @@ -0,0 +1,135 @@\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::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..0b2f7148c821\n> > --- /dev/null\n> > +++ b/src/ipa/libipa/quantized.h\n> > @@ -0,0 +1,75 @@\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> \n> Any reason to use a struct and not a class ? We usually use struct only\n> (or mostly) for plain old C structures with no member functions.\n> \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> There's an open question in the v4 thread about whether or not we should\n> make these constructors explicit. Let's continue the discussion there.\n> \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> \n> As we don't use exceptions, is noexcept useful ?\n> \n> Apart from those comments this looks good.\n\nAh I forgot to mention that the operator<<() should not be a friend\nmember function any more now that Barnabás has fixed the ADL issue.\n\n> > +\tQuantizedType quantized() const noexcept { return quantized_; }\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> > +\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 97BC6C3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 24 Jan 2026 01:20:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D99961FC9;\n\tSat, 24 Jan 2026 02:20:33 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1414661F84\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 24 Jan 2026 02:20:31 +0100 (CET)","from pendragon.ideasonboard.com\n\t(2001-14ba-703d-e500--2a1.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::2a1])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 520EA448;\n\tSat, 24 Jan 2026 02:19:57 +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=\"e+NIe6Fi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769217597;\n\tbh=u4Gaqse6q++KtLO2qfVjDsrN+iVXsLM0kmdIfxLq0Qo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=e+NIe6FiiiMw2BNApyqwuAEr3ODVvarjYN8GsPzBjcokoXkNrjrSZcOEgFsQ303sT\n\tpXCArG8N2NIFvPOWLyCvI85EA/2O3tiiApzCN0enakmk8CPagCR0/W6AhVTrTrkKDj\n\tSuT25RYFnVkV0P0rMiEb9c3E2OIfTJlujqJWr8LQ=","Date":"Sat, 24 Jan 2026 03:20:29 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>, =?utf-8?q?Barna?=\n\t=?utf-8?b?YsOhcyBQxZFjemU=?= <barnabas.pocze@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","Subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","Message-ID":"<20260124012029.GL215800@killaraus>","References":"<20260121173737.376113-1-kieran.bingham@ideasonboard.com>\n\t<20260121173737.376113-2-kieran.bingham@ideasonboard.com>\n\t<20260124011921.GK215800@killaraus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260124011921.GK215800@killaraus>","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":37929,"web_url":"https://patchwork.libcamera.org/comment/37929/","msgid":"<176925637399.3894215.663115579821450971@ping.linuxembedded.co.uk>","date":"2026-01-24T12:06:13","subject":"Re: [PATCH v6 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 Laurent Pinchart (2026-01-24 01:20:29)\n> On Sat, Jan 24, 2026 at 03:19:23AM +0200, Laurent Pinchart wrote:\n> > On Wed, Jan 21, 2026 at 05:37:20PM +0000, Kieran Bingham wrote:\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: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\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 | 135 +++++++++++++++++++++++++++++++++++\n> > >  src/ipa/libipa/quantized.h   |  75 +++++++++++++++++++\n> > >  3 files changed, 212 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..06143a97ab3e\n> > > --- /dev/null\n> > > +++ b/src/ipa/libipa/quantized.cpp\n> > > @@ -0,0 +1,135 @@\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::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..0b2f7148c821\n> > > --- /dev/null\n> > > +++ b/src/ipa/libipa/quantized.h\n> > > @@ -0,0 +1,75 @@\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> > \n> > Any reason to use a struct and not a class ? We usually use struct only\n> > (or mostly) for plain old C structures with no member functions.\n> > \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> > There's an open question in the v4 thread about whether or not we should\n> > make these constructors explicit. Let's continue the discussion there.\n\n\nI remember not liking that .. but lets try to close this.\n\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> > \n> > As we don't use exceptions, is noexcept useful ?\n\nAt this stage, this was from a long time ago I don't remember why\nnoexcept is here. Do you want me to just remove it ?\n\n\n> > \n> > Apart from those comments this looks good.\n> \n> Ah I forgot to mention that the operator<<() should not be a friend\n> member function any more now that Barnabás has fixed the ADL issue.\n\nExcept that's not merged yet - I posted somewhere that a patch is\nalready available on top, but this series works and passes CI on master,\nso it has to use the friend for the moment.\n--\nKieran\n\n> \n> > > +   QuantizedType quantized() const noexcept { return quantized_; }\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> > > +private:\n> > > +   QuantizedType quantized_;\n> > > +   float value_;\n> > > +};\n> > > +\n> > > +} /* namespace ipa */\n> > > +\n> > > +} /* namespace libcamera */\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 D0DDFBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 24 Jan 2026 12:06:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0362261FC4;\n\tSat, 24 Jan 2026 13:06:18 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0274461FA0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 24 Jan 2026 13:06:16 +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 C5DB4596;\n\tSat, 24 Jan 2026 13:05:42 +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=\"WwEAcvn+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769256342;\n\tbh=KM1GXbm4HcIS2RWqAXO/YevRGifHBitI2dUASQFi/Gs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=WwEAcvn+JP5abeobFMZQCkqIm945tPAxpMg6Iyt2CqpXdx9jiijim6L9PqPDn8Kwt\n\tBqbQYqsCHDyDlnl0rNapyiPUmFvPQ17Fx+q4aaWD5W8T3NAxrhDq5ZY18el+CougS7\n\tuTzcbIinlK7zy4gjg0olB+d3+Z//qEw3HcFrLEbg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260124012029.GL215800@killaraus>","References":"<20260121173737.376113-1-kieran.bingham@ideasonboard.com>\n\t<20260121173737.376113-2-kieran.bingham@ideasonboard.com>\n\t<20260124011921.GK215800@killaraus>\n\t<20260124012029.GL215800@killaraus>","Subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>, =?utf-8?q?Barna?=\n\t=?utf-8?b?YsOhcyBQxZFjemU=?= <barnabas.pocze@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Sat, 24 Jan 2026 12:06:13 +0000","Message-ID":"<176925637399.3894215.663115579821450971@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>"}},{"id":37930,"web_url":"https://patchwork.libcamera.org/comment/37930/","msgid":"<20260124123640.GN215800@killaraus>","date":"2026-01-24T12:36:40","subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Sat, Jan 24, 2026 at 12:06:13PM +0000, Kieran Bingham wrote:\n> Quoting Laurent Pinchart (2026-01-24 01:20:29)\n> > On Sat, Jan 24, 2026 at 03:19:23AM +0200, Laurent Pinchart wrote:\n> > > On Wed, Jan 21, 2026 at 05:37:20PM +0000, Kieran Bingham wrote:\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: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\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 | 135 +++++++++++++++++++++++++++++++++++\n> > > >  src/ipa/libipa/quantized.h   |  75 +++++++++++++++++++\n> > > >  3 files changed, 212 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..06143a97ab3e\n> > > > --- /dev/null\n> > > > +++ b/src/ipa/libipa/quantized.cpp\n> > > > @@ -0,0 +1,135 @@\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::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..0b2f7148c821\n> > > > --- /dev/null\n> > > > +++ b/src/ipa/libipa/quantized.h\n> > > > @@ -0,0 +1,75 @@\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> > > \n> > > Any reason to use a struct and not a class ? We usually use struct only\n> > > (or mostly) for plain old C structures with no member functions.\n> > > \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> > > There's an open question in the v4 thread about whether or not we should\n> > > make these constructors explicit. Let's continue the discussion there.\n> \n> I remember not liking that .. but lets try to close this.\n> \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> > > \n> > > As we don't use exceptions, is noexcept useful ?\n> \n> At this stage, this was from a long time ago I don't remember why\n> noexcept is here. Do you want me to just remove it ?\n\nI'd drop it yes. If we want noexcept annotations, they should be added\nthrough the whole code base.\n\n> > > Apart from those comments this looks good.\n> > \n> > Ah I forgot to mention that the operator<<() should not be a friend\n> > member function any more now that Barnabás has fixed the ADL issue.\n> \n> Except that's not merged yet - I posted somewhere that a patch is\n> already available on top, but this series works and passes CI on master,\n> so it has to use the friend for the moment.\n\nSure. I think Barnabás' patch is ready to be merged, so this can be\nsolved quickly.\n\n> > > > +   QuantizedType quantized() const noexcept { return quantized_; }\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> > > > +private:\n> > > > +   QuantizedType quantized_;\n> > > > +   float 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 6C6D1C3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 24 Jan 2026 12:36:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AEF5661FA0;\n\tSat, 24 Jan 2026 13:36:44 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 74E0961FA0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 24 Jan 2026 13:36:43 +0100 (CET)","from pendragon.ideasonboard.com\n\t(2001-14ba-703d-e500--ff4.rev.dnainternet.fi\n\t[IPv6:2001:14ba:703d:e500::ff4])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 14F56596;\n\tSat, 24 Jan 2026 13:36:09 +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=\"cut0PPV6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769258169;\n\tbh=w9GYDCrtTGxp1YDXPrQKSfeqr1STyF0R7n4B+QK/cEM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cut0PPV63NEIzzf+yJyteN8yD/fui+3Kb1PUqGbB/FbpuyFUeKfJHmD8VriJkWHL5\n\tQdIKafWpaknUeQfcE6N0QjRPOfeM+gFM3ItvLsQcj+VWK4z+IuNGzAngDXn+4Obwdh\n\t97OTGyg2VinDVMVb5ONXOFOFTpuEPZfyyjsLkMB0=","Date":"Sat, 24 Jan 2026 14:36:40 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>, =?utf-8?q?Barna?=\n\t=?utf-8?b?YsOhcyBQxZFjemU=?= <barnabas.pocze@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>","Subject":"Re: [PATCH v6 01/16] ipa: libipa: Provide a Quantized data type\n\tsupport","Message-ID":"<20260124123640.GN215800@killaraus>","References":"<20260121173737.376113-1-kieran.bingham@ideasonboard.com>\n\t<20260121173737.376113-2-kieran.bingham@ideasonboard.com>\n\t<20260124011921.GK215800@killaraus>\n\t<20260124012029.GL215800@killaraus>\n\t<176925637399.3894215.663115579821450971@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<176925637399.3894215.663115579821450971@ping.linuxembedded.co.uk>","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>"}}]