[{"id":37680,"web_url":"https://patchwork.libcamera.org/comment/37680/","msgid":"<13b33e30-d96c-4f38-bbc1-02307f8c749a@ideasonboard.com>","date":"2026-01-15T15:49:35","subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","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> Provide use case tests for the Quantized types to ensure construction\n> and usages are consistent and work as expected.\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> - Rename quantized_type to QuantizedType\n> \n> v5:\n> - use static asserts for constructible failure tests\n> - Remove constexpr from lround users (only possible in C++23)\n> - Remove move tests\n> - Fix up inequality test\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   test/ipa/libipa/meson.build   |   1 +\n>   test/ipa/libipa/quantized.cpp | 124 ++++++++++++++++++++++++++++++++++\n>   2 files changed, 125 insertions(+)\n>   create mode 100644 test/ipa/libipa/quantized.cpp\n> \n> diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\n> index 2070bed70222..c3e255871f4f 100644\n> --- a/test/ipa/libipa/meson.build\n> +++ b/test/ipa/libipa/meson.build\n> @@ -5,6 +5,7 @@ libipa_test = [\n>       {'name': 'histogram', 'sources': ['histogram.cpp']},\n>       {'name': 'interpolator', 'sources': ['interpolator.cpp']},\n>       {'name': 'pwl', 'sources': ['pwl.cpp'] },\n> +    {'name': 'quantized', 'sources': ['quantized.cpp']},\n>   ]\n>   \n>   foreach test : libipa_test\n> diff --git a/test/ipa/libipa/quantized.cpp b/test/ipa/libipa/quantized.cpp\n> new file mode 100644\n> index 000000000000..6b6a61311125\n> --- /dev/null\n> +++ b/test/ipa/libipa/quantized.cpp\n> @@ -0,0 +1,124 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2025, Ideas on Board\n> + *\n> + * Dual Type and Quantizer tests\n> + */\n> +\n> +#include \"../src/ipa/libipa/quantized.h\"\n> +\n> +#include <algorithm>\n> +#include <cmath>\n> +#include <iostream>\n> +#include <map>\n> +#include <stdint.h>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +using namespace ipa;\n> +\n> +struct BrightnessHueTraits {\n> +\tusing QuantizedType = int8_t;\n> +\tstatic QuantizedType fromFloat(float v)\n> +\t{\n> +\t\tint quantized = std::lround(v * 128.0f);\n> +\t\treturn static_cast<int8_t>(std::clamp<int>(quantized, -128, 127));\n\nI don't think there is a need for the static cast. (Same later.)\n\n\n> +\t}\n> +\tstatic float toFloat(QuantizedType v)\n> +\t{\n> +\t\treturn static_cast<float>(v) / 128.0f;\n> +\t}\n> +};\n> +\n> +using BrightnessHueQuantizer = Quantized<BrightnessHueTraits>;\n> +\n> +struct ContrastSaturationTraits {\n> +\tusing QuantizedType = uint8_t;\n> +\tstatic QuantizedType fromFloat(float v)\n> +\t{\n> +\t\tint quantized = std::lround(v * 128.0f);\n> +\t\treturn static_cast<uint8_t>(std::clamp<int>(quantized, 0, 255));\n> +\t}\n> +\tstatic float toFloat(QuantizedType v)\n> +\t{\n> +\t\treturn static_cast<float>(v) / 128.0f;\n> +\t}\n> +};\n> +\n> +using ContrastSaturationQuantizer = Quantized<ContrastSaturationTraits>;\n> +\n> +using BrightnessQ = BrightnessHueQuantizer;\n> +using HueQ = BrightnessHueQuantizer;\n> +using ContrastQ = ContrastSaturationQuantizer;\n> +using SaturationQ = ContrastSaturationQuantizer;\n> +\n> +class QuantizedTest : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\t/* Test construction from float */\n> +\t\t{\n> +\t\t\tBrightnessQ b(0.5f);\n> +\t\t\tif (b.quantized() != 64 || std::abs(b.value() - 0.5f) > 0.01f)\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test construction from T */\n> +\t\t{\n> +\t\t\tContrastQ c(uint8_t(128));\n> +\t\t\tif (c.quantized() != 128 || std::abs(c.value() - 1.0f) > 0.01f)\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Only construction from the exact storage type or a float\n> +\t\t * is permitted.\n> +\t\t */\n> +\t\tstatic_assert(!std::is_constructible_v<BrightnessQ, unsigned int>);\n> +\t\tstatic_assert(!std::is_constructible_v<BrightnessQ, uint8_t>);\n> +\t\tstatic_assert(!std::is_constructible_v<BrightnessQ, double>);\n> +\t\tstatic_assert(!std::is_constructible_v<ContrastQ, int>);\n> +\t\tstatic_assert(!std::is_constructible_v<ContrastQ, int8_t>);\n> +\t\tstatic_assert(!std::is_constructible_v<ContrastQ, unsigned int>);\n> +\n> +\t\t/* Test equality */\n> +\t\t{\n> +\t\t\tBrightnessQ b1(0.5f), b2((int8_t)64);\n\n   int8_t(64)\n\nlooks better in my opinion.\n\n\n> +\t\t\tif (!(b1 == b2))\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test inequality */\n> +\t\t{\n> +\t\t\tBrightnessQ b1(0.5f), b2(-0.5f);\n> +\t\t\tif (!(b1 != b2))\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test copying */\n> +\t\t{\n> +\t\t\tBrightnessQ b1(0.25f);\n> +\t\t\tBrightnessQ b2 = b1;\n> +\t\t\tif (!(b1 == b2))\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test assignment */\n> +\t\t{\n> +\t\t\tContrastQ c1(1.5f);\n> +\t\t\tContrastQ c2(0.0f);\n> +\t\t\tc2 = c1;\n> +\t\t\tif (!(c1 == c2))\n> +\t\t\t\treturn TestFail;\n> +\t\t}\n\nAnother test case that I think would be good to have: construction from two\ndifferent float values that map to the same quantized value, but that quantized\nvalue corresponds to a third float value. Then both the quantized and float\nvalues should be tested for equality.\n\n\n\n> +\n> +\t\tstd::cout << \"Quantised tests passed successfully.\" << std::endl;\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(QuantizedTest)","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 E032BBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Jan 2026 15:49:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 24C7261FBC;\n\tThu, 15 Jan 2026 16:49:41 +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 5D7AD61F84\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Jan 2026 16:49:40 +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 714E7316;\n\tThu, 15 Jan 2026 16:49:12 +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=\"W8aiOixt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768492152;\n\tbh=SnPZlxbhH+OgIU+hAdYJgYG3wjmPmBVWu9cKmpAhNrc=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=W8aiOixtl/XzusrWLt/BaDQv+A1Lp2u18ftVM04FQ0JzgOyC6NN+BWgy/37NVoAd6\n\tSTATFM2mgCmJ6lGzwG/29MYxnuvecXV/SZqsd29sNQDS9dhqZDe55wKoxtTUwi2JC1\n\tdGKaU8NmjpjIMCFsme7josEO+oPNQQGbcSwJ+jLM=","Message-ID":"<13b33e30-d96c-4f38-bbc1-02307f8c749a@ideasonboard.com>","Date":"Thu, 15 Jan 2026 16:49:35 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","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-3-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-3-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":37742,"web_url":"https://patchwork.libcamera.org/comment/37742/","msgid":"<176884243738.1693075.8187441240391878792@ping.linuxembedded.co.uk>","date":"2026-01-19T17:07:17","subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","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 15:49:35)\n> 2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n> > Provide use case tests for the Quantized types to ensure construction\n> > and usages are consistent and work as expected.\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> > - Rename quantized_type to QuantizedType\n> > \n> > v5:\n> > - use static asserts for constructible failure tests\n> > - Remove constexpr from lround users (only possible in C++23)\n> > - Remove move tests\n> > - Fix up inequality test\n> > \n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >   test/ipa/libipa/meson.build   |   1 +\n> >   test/ipa/libipa/quantized.cpp | 124 ++++++++++++++++++++++++++++++++++\n> >   2 files changed, 125 insertions(+)\n> >   create mode 100644 test/ipa/libipa/quantized.cpp\n> > \n> > diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\n> > index 2070bed70222..c3e255871f4f 100644\n> > --- a/test/ipa/libipa/meson.build\n> > +++ b/test/ipa/libipa/meson.build\n> > @@ -5,6 +5,7 @@ libipa_test = [\n> >       {'name': 'histogram', 'sources': ['histogram.cpp']},\n> >       {'name': 'interpolator', 'sources': ['interpolator.cpp']},\n> >       {'name': 'pwl', 'sources': ['pwl.cpp'] },\n> > +    {'name': 'quantized', 'sources': ['quantized.cpp']},\n> >   ]\n> >   \n> >   foreach test : libipa_test\n> > diff --git a/test/ipa/libipa/quantized.cpp b/test/ipa/libipa/quantized.cpp\n> > new file mode 100644\n> > index 000000000000..6b6a61311125\n> > --- /dev/null\n> > +++ b/test/ipa/libipa/quantized.cpp\n> > @@ -0,0 +1,124 @@\n> > +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > +/*\n> > + * Copyright (C) 2025, Ideas on Board\n> > + *\n> > + * Dual Type and Quantizer tests\n> > + */\n> > +\n> > +#include \"../src/ipa/libipa/quantized.h\"\n> > +\n> > +#include <algorithm>\n> > +#include <cmath>\n> > +#include <iostream>\n> > +#include <map>\n> > +#include <stdint.h>\n> > +\n> > +#include \"test.h\"\n> > +\n> > +using namespace std;\n> > +using namespace libcamera;\n> > +using namespace ipa;\n> > +\n> > +struct BrightnessHueTraits {\n> > +     using QuantizedType = int8_t;\n> > +     static QuantizedType fromFloat(float v)\n> > +     {\n> > +             int quantized = std::lround(v * 128.0f);\n> > +             return static_cast<int8_t>(std::clamp<int>(quantized, -128, 127));\n> \n> I don't think there is a need for the static cast. (Same later.)\n\nRemoved both.\n\n> > +     }\n> > +     static float toFloat(QuantizedType v)\n> > +     {\n> > +             return static_cast<float>(v) / 128.0f;\n> > +     }\n> > +};\n> > +\n> > +using BrightnessHueQuantizer = Quantized<BrightnessHueTraits>;\n> > +\n> > +struct ContrastSaturationTraits {\n> > +     using QuantizedType = uint8_t;\n> > +     static QuantizedType fromFloat(float v)\n> > +     {\n> > +             int quantized = std::lround(v * 128.0f);\n> > +             return static_cast<uint8_t>(std::clamp<int>(quantized, 0, 255));\n> > +     }\n> > +     static float toFloat(QuantizedType v)\n> > +     {\n> > +             return static_cast<float>(v) / 128.0f;\n> > +     }\n> > +};\n> > +\n> > +using ContrastSaturationQuantizer = Quantized<ContrastSaturationTraits>;\n> > +\n> > +using BrightnessQ = BrightnessHueQuantizer;\n> > +using HueQ = BrightnessHueQuantizer;\n> > +using ContrastQ = ContrastSaturationQuantizer;\n> > +using SaturationQ = ContrastSaturationQuantizer;\n> > +\n> > +class QuantizedTest : public Test\n> > +{\n> > +protected:\n> > +     int run()\n> > +     {\n> > +             /* Test construction from float */\n> > +             {\n> > +                     BrightnessQ b(0.5f);\n> > +                     if (b.quantized() != 64 || std::abs(b.value() - 0.5f) > 0.01f)\n> > +                             return TestFail;\n> > +             }\n> > +\n> > +             /* Test construction from T */\n> > +             {\n> > +                     ContrastQ c(uint8_t(128));\n> > +                     if (c.quantized() != 128 || std::abs(c.value() - 1.0f) > 0.01f)\n> > +                             return TestFail;\n> > +             }\n> > +\n> > +             /*\n> > +              * Only construction from the exact storage type or a float\n> > +              * is permitted.\n> > +              */\n> > +             static_assert(!std::is_constructible_v<BrightnessQ, unsigned int>);\n> > +             static_assert(!std::is_constructible_v<BrightnessQ, uint8_t>);\n> > +             static_assert(!std::is_constructible_v<BrightnessQ, double>);\n> > +             static_assert(!std::is_constructible_v<ContrastQ, int>);\n> > +             static_assert(!std::is_constructible_v<ContrastQ, int8_t>);\n> > +             static_assert(!std::is_constructible_v<ContrastQ, unsigned int>);\n> > +\n> > +             /* Test equality */\n> > +             {\n> > +                     BrightnessQ b1(0.5f), b2((int8_t)64);\n> \n>    int8_t(64)\n> \n> looks better in my opinion.\n\nFixed.\n\n> \n> \n> > +                     if (!(b1 == b2))\n> > +                             return TestFail;\n> > +             }\n> > +\n> > +             /* Test inequality */\n> > +             {\n> > +                     BrightnessQ b1(0.5f), b2(-0.5f);\n> > +                     if (!(b1 != b2))\n> > +                             return TestFail;\n> > +             }\n> > +\n> > +             /* Test copying */\n> > +             {\n> > +                     BrightnessQ b1(0.25f);\n> > +                     BrightnessQ b2 = b1;\n> > +                     if (!(b1 == b2))\n> > +                             return TestFail;\n> > +             }\n> > +\n> > +             /* Test assignment */\n> > +             {\n> > +                     ContrastQ c1(1.5f);\n> > +                     ContrastQ c2(0.0f);\n> > +                     c2 = c1;\n> > +                     if (!(c1 == c2))\n> > +                             return TestFail;\n> > +             }\n> \n> Another test case that I think would be good to have: construction from two\n> different float values that map to the same quantized value, but that quantized\n> value corresponds to a third float value. Then both the quantized and float\n> values should be tested for equality.\n\nIs this what you had in mind?\n\n\t\t/*\n\t\t * Test construction from different floats mapping to same\n\t\t * quantized value\n\t\t */\n\t\t{\n\t\t\t/* Two floats that have the same quantized value. */\n\t\t\tconst float f1 = 1.007f;\n\t\t\tconst float f2 = 1.008f;\n\n\t\t\tContrastQ c1(f1);\n\t\t\tContrastQ c2(f2);\n\n\t\t\tstd::cout << \"  Checking \" << f1 << \" and \" << f2\n\t\t\t\t  << \" both map to \" << c1 << std::endl;\n\t\t\tstd::cout << \"    c1: \" << c1 << std::endl;\n\t\t\tstd::cout << \"    c2: \" << c2 << std::endl;\n\n\t\t\t/* Quantized values must match */\n\t\t\tif (!(c1.quantized() == c2.quantized()))\n\t\t\t\treturn TestFail;\n\n\t\t\t/* Float values must now match */\n\t\t\tif (!(c1.value() == c2.value()))\n\t\t\t\treturn TestFail;\n\n\t\t\tif (!(c1 == c2))\n\t\t\t\treturn TestFail;\n\t\t}\n\n\ntest/ipa/libipa/quantized\n  Checking 1.007 and 1.008 both map to [0x81:1.00781]\n    c1: [0x81:1.00781]\n    c2: [0x81:1.00781]\nQuantised tests passed successfully.\n\n(I'll remove the Checking prints for the patch)\n\n--\nKieran\n\n\n> \n> \n> \n> > +\n> > +             std::cout << \"Quantised tests passed successfully.\" << std::endl;\n> > +\n> > +             return TestPass;\n> > +     }\n> > +};\n> > +\n> > +TEST_REGISTER(QuantizedTest)\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 8F274BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 19 Jan 2026 17:07:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA261606D5;\n\tMon, 19 Jan 2026 18:07:22 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE9C9606D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Jan 2026 18:07:20 +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 E9402C1;\n\tMon, 19 Jan 2026 18:06: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=\"KJS4CDyR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768842410;\n\tbh=kf31xnkErwxZ6q9T01Gxz6uI1Nya0YNi9tD8mXN9AWE=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=KJS4CDyRqRnx7LwMOBlAhQOPaN8lkzpaqLFNVs05KJ9sOPAnbQx3S80vvLZ8hWoFS\n\tZBB0aVypzSt6qhryzCbMwRK9qMCLg12o8jHTeTQkQ2fUGQDLL2Fvknd5poCFHKyvWG\n\tj8XiigaiufpRQmazWA/g7A5zJdG+W1mX5SvtnosI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<13b33e30-d96c-4f38-bbc1-02307f8c749a@ideasonboard.com>","References":"<20260114173918.1744023-1-kieran.bingham@ideasonboard.com>\n\t<20260114173918.1744023-3-kieran.bingham@ideasonboard.com>\n\t<13b33e30-d96c-4f38-bbc1-02307f8c749a@ideasonboard.com>","Subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","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":"Mon, 19 Jan 2026 17:07:17 +0000","Message-ID":"<176884243738.1693075.8187441240391878792@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":37761,"web_url":"https://patchwork.libcamera.org/comment/37761/","msgid":"<6fb3618b-ba86-4ad1-ac4d-c62bb59e48d9@ideasonboard.com>","date":"2026-01-20T13:27:32","subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 01. 19. 18:07 keltezéssel, Kieran Bingham írta:\n> Quoting Barnabás Pőcze (2026-01-15 15:49:35)\n>> 2026. 01. 14. 18:39 keltezéssel, Kieran Bingham írta:\n>>> Provide use case tests for the Quantized types to ensure construction\n>>> and usages are consistent and work as expected.\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>>> - Rename quantized_type to QuantizedType\n>>>\n>>> v5:\n>>> - use static asserts for constructible failure tests\n>>> - Remove constexpr from lround users (only possible in C++23)\n>>> - Remove move tests\n>>> - Fix up inequality test\n>>>\n>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>> ---\n>>>    test/ipa/libipa/meson.build   |   1 +\n>>>    test/ipa/libipa/quantized.cpp | 124 ++++++++++++++++++++++++++++++++++\n>>>    2 files changed, 125 insertions(+)\n>>>    create mode 100644 test/ipa/libipa/quantized.cpp\n>>>\n>>> diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build\n>>> index 2070bed70222..c3e255871f4f 100644\n>>> --- a/test/ipa/libipa/meson.build\n>>> +++ b/test/ipa/libipa/meson.build\n>>> @@ -5,6 +5,7 @@ libipa_test = [\n>>>        {'name': 'histogram', 'sources': ['histogram.cpp']},\n>>>        {'name': 'interpolator', 'sources': ['interpolator.cpp']},\n>>>        {'name': 'pwl', 'sources': ['pwl.cpp'] },\n>>> +    {'name': 'quantized', 'sources': ['quantized.cpp']},\n>>>    ]\n>>>\n>>>    foreach test : libipa_test\n>>> diff --git a/test/ipa/libipa/quantized.cpp b/test/ipa/libipa/quantized.cpp\n>>> new file mode 100644\n>>> index 000000000000..6b6a61311125\n>>> --- /dev/null\n>>> +++ b/test/ipa/libipa/quantized.cpp\n>>> @@ -0,0 +1,124 @@\n>>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n>>> +/*\n>>> + * Copyright (C) 2025, Ideas on Board\n>>> + *\n>>> + * Dual Type and Quantizer tests\n>>> + */\n>>> +\n>>> +#include \"../src/ipa/libipa/quantized.h\"\n>>> +\n>>> +#include <algorithm>\n>>> +#include <cmath>\n>>> +#include <iostream>\n>>> +#include <map>\n>>> +#include <stdint.h>\n>>> +\n>>> +#include \"test.h\"\n>>> +\n>>> +using namespace std;\n>>> +using namespace libcamera;\n>>> +using namespace ipa;\n>>> +\n>>> +struct BrightnessHueTraits {\n>>> +     using QuantizedType = int8_t;\n>>> +     static QuantizedType fromFloat(float v)\n>>> +     {\n>>> +             int quantized = std::lround(v * 128.0f);\n>>> +             return static_cast<int8_t>(std::clamp<int>(quantized, -128, 127));\n>>\n>> I don't think there is a need for the static cast. (Same later.)\n> \n> Removed both.\n> \n>>> +     }\n>>> +     static float toFloat(QuantizedType v)\n>>> +     {\n>>> +             return static_cast<float>(v) / 128.0f;\n>>> +     }\n>>> +};\n>>> +\n>>> +using BrightnessHueQuantizer = Quantized<BrightnessHueTraits>;\n>>> +\n>>> +struct ContrastSaturationTraits {\n>>> +     using QuantizedType = uint8_t;\n>>> +     static QuantizedType fromFloat(float v)\n>>> +     {\n>>> +             int quantized = std::lround(v * 128.0f);\n>>> +             return static_cast<uint8_t>(std::clamp<int>(quantized, 0, 255));\n>>> +     }\n>>> +     static float toFloat(QuantizedType v)\n>>> +     {\n>>> +             return static_cast<float>(v) / 128.0f;\n>>> +     }\n>>> +};\n>>> +\n>>> +using ContrastSaturationQuantizer = Quantized<ContrastSaturationTraits>;\n>>> +\n>>> +using BrightnessQ = BrightnessHueQuantizer;\n>>> +using HueQ = BrightnessHueQuantizer;\n>>> +using ContrastQ = ContrastSaturationQuantizer;\n>>> +using SaturationQ = ContrastSaturationQuantizer;\n>>> +\n>>> +class QuantizedTest : public Test\n>>> +{\n>>> +protected:\n>>> +     int run()\n>>> +     {\n>>> +             /* Test construction from float */\n>>> +             {\n>>> +                     BrightnessQ b(0.5f);\n>>> +                     if (b.quantized() != 64 || std::abs(b.value() - 0.5f) > 0.01f)\n>>> +                             return TestFail;\n>>> +             }\n>>> +\n>>> +             /* Test construction from T */\n>>> +             {\n>>> +                     ContrastQ c(uint8_t(128));\n>>> +                     if (c.quantized() != 128 || std::abs(c.value() - 1.0f) > 0.01f)\n>>> +                             return TestFail;\n>>> +             }\n>>> +\n>>> +             /*\n>>> +              * Only construction from the exact storage type or a float\n>>> +              * is permitted.\n>>> +              */\n>>> +             static_assert(!std::is_constructible_v<BrightnessQ, unsigned int>);\n>>> +             static_assert(!std::is_constructible_v<BrightnessQ, uint8_t>);\n>>> +             static_assert(!std::is_constructible_v<BrightnessQ, double>);\n>>> +             static_assert(!std::is_constructible_v<ContrastQ, int>);\n>>> +             static_assert(!std::is_constructible_v<ContrastQ, int8_t>);\n>>> +             static_assert(!std::is_constructible_v<ContrastQ, unsigned int>);\n>>> +\n>>> +             /* Test equality */\n>>> +             {\n>>> +                     BrightnessQ b1(0.5f), b2((int8_t)64);\n>>\n>>     int8_t(64)\n>>\n>> looks better in my opinion.\n> \n> Fixed.\n> \n>>\n>>\n>>> +                     if (!(b1 == b2))\n>>> +                             return TestFail;\n>>> +             }\n>>> +\n>>> +             /* Test inequality */\n>>> +             {\n>>> +                     BrightnessQ b1(0.5f), b2(-0.5f);\n>>> +                     if (!(b1 != b2))\n>>> +                             return TestFail;\n>>> +             }\n>>> +\n>>> +             /* Test copying */\n>>> +             {\n>>> +                     BrightnessQ b1(0.25f);\n>>> +                     BrightnessQ b2 = b1;\n>>> +                     if (!(b1 == b2))\n>>> +                             return TestFail;\n>>> +             }\n>>> +\n>>> +             /* Test assignment */\n>>> +             {\n>>> +                     ContrastQ c1(1.5f);\n>>> +                     ContrastQ c2(0.0f);\n>>> +                     c2 = c1;\n>>> +                     if (!(c1 == c2))\n>>> +                             return TestFail;\n>>> +             }\n>>\n>> Another test case that I think would be good to have: construction from two\n>> different float values that map to the same quantized value, but that quantized\n>> value corresponds to a third float value. Then both the quantized and float\n>> values should be tested for equality.\n> \n> Is this what you had in mind?\n\nYes, something like this, thanks.\n\n\n> \n> \t\t/*\n> \t\t * Test construction from different floats mapping to same\n> \t\t * quantized value\n> \t\t */\n> \t\t{\n> \t\t\t/* Two floats that have the same quantized value. */\n> \t\t\tconst float f1 = 1.007f;\n> \t\t\tconst float f2 = 1.008f;\n> \n> \t\t\tContrastQ c1(f1);\n> \t\t\tContrastQ c2(f2);\n> \n> \t\t\tstd::cout << \"  Checking \" << f1 << \" and \" << f2\n> \t\t\t\t  << \" both map to \" << c1 << std::endl;\n> \t\t\tstd::cout << \"    c1: \" << c1 << std::endl;\n> \t\t\tstd::cout << \"    c2: \" << c2 << std::endl;\n> \n> \t\t\t/* Quantized values must match */\n> \t\t\tif (!(c1.quantized() == c2.quantized()))\n> \t\t\t\treturn TestFail;\n> \n> \t\t\t/* Float values must now match */\n> \t\t\tif (!(c1.value() == c2.value()))\n> \t\t\t\treturn TestFail;\n> \n> \t\t\tif (!(c1 == c2))\n> \t\t\t\treturn TestFail;\n> \t\t}\n> \n> \n> test/ipa/libipa/quantized\n>    Checking 1.007 and 1.008 both map to [0x81:1.00781]\n>      c1: [0x81:1.00781]\n>      c2: [0x81:1.00781]\n> Quantised tests passed successfully.\n> \n> (I'll remove the Checking prints for the patch)\n> \n> --\n> Kieran\n> \n> \n>>\n>>\n>>\n>>> +\n>>> +             std::cout << \"Quantised tests passed successfully.\" << std::endl;\n>>> +\n>>> +             return TestPass;\n>>> +     }\n>>> +};\n>>> +\n>>> +TEST_REGISTER(QuantizedTest)\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 58DBAC3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Jan 2026 13:27:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1068D61FC9;\n\tTue, 20 Jan 2026 14:27:37 +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 5136D61A35\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Jan 2026 14:27:36 +0100 (CET)","from [192.168.33.23] (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DB1B92147;\n\tTue, 20 Jan 2026 14:27:04 +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=\"jPDnfCbZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768915625;\n\tbh=7S7NxJoh6AkstKzbloQ9yRZvArB4CgEiNruZq6jfiKk=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=jPDnfCbZxVnmVXfB2CkZ1hxJ4x9Ux0tuz4VpUgxH9t7b7Nxoc5TvEJQPdaKiDXO7T\n\tG4pDSZIKlz8zJrb6xG2WoeQFwGKgjtWp8ynYv5f9Pb2iyZyaQ8SdL9viIfyebFcyNf\n\t4tZCC0kEBQwq5YZkAnabJOQqQ4sEzPy/xxgmdPyA=","Message-ID":"<6fb3618b-ba86-4ad1-ac4d-c62bb59e48d9@ideasonboard.com>","Date":"Tue, 20 Jan 2026 14:27:32 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v5 02/16] test: libipa: Add tests for Quantized types","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-3-kieran.bingham@ideasonboard.com>\n\t<13b33e30-d96c-4f38-bbc1-02307f8c749a@ideasonboard.com>\n\t<a-AlYiaCbqPTHp2h_dqlgOQApTodp8RDTy-_qmsz-Uo3yWxGh7LcQ5S7ZSfcWYQ_dp1H8ECzVv-NlcYFnpwYkQ==@protonmail.internalid>\n\t<176884243738.1693075.8187441240391878792@ping.linuxembedded.co.uk>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<176884243738.1693075.8187441240391878792@ping.linuxembedded.co.uk>","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>"}}]