Patch Detail
Show a patch.
GET /api/1.1/patches/26299/?format=api
{ "id": 26299, "url": "https://patchwork.libcamera.org/api/1.1/patches/26299/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26299/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260319080005.162571-1-barnabas.pocze@ideasonboard.com>", "date": "2026-03-19T08:00:05", "name": "[v1] ipa: libipa: quantized: Enable `constexpr` operation", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "ddafd41530ea37de1a7472be83ae628d63321194", "submitter": { "id": 216, "url": "https://patchwork.libcamera.org/api/1.1/people/216/?format=api", "name": "Barnabás Pőcze", "email": "barnabas.pocze@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26299/mbox/", "series": [ { "id": 5831, "url": "https://patchwork.libcamera.org/api/1.1/series/5831/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5831", "date": "2026-03-19T08:00:05", "name": "[v1] ipa: libipa: quantized: Enable `constexpr` operation", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5831/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26299/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26299/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6F41EBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 19 Mar 2026 08:00:10 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9B1B562723;\n\tThu, 19 Mar 2026 09:00:09 +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 7C3AF62635\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2026 09:00:08 +0100 (CET)", "from pb-laptop.local (185.221.143.129.nat.pool.zt.hu\n\t[185.221.143.129])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E80A6838;\n\tThu, 19 Mar 2026 08:58:54 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"I/ieosb+\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1773907135;\n\tbh=K8r/1BVdvKghAP7XuC7OzckRtvFgwxaLpqokIiF9Hnc=;\n\th=From:To:Subject:Date:From;\n\tb=I/ieosb+2gcEICG83jf/xTSRbDkMMuq7SwoUc7CzJH4VzEdTN9Z/jl57veDBA+fHY\n\t/UcAlrOEqCh5yy6tdUE7Q6GLeXZ5ebZVm1C60krFS9lnl62Uft6kIrYI5n2Y3/VTSC\n\tIByawOV/cR+IpgTwvTKsyoewmEKmCFrA1CcslNKo=", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v1] ipa: libipa: quantized: Enable `constexpr` operation", "Date": "Thu, 19 Mar 2026 09:00:05 +0100", "Message-ID": "<20260319080005.162571-1-barnabas.pocze@ideasonboard.com>", "X-Mailer": "git-send-email 2.53.0", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "There is nothing inherently non-constexpr in the `Quantized` type. Whether\nit can work in `constexpr` contexts depends on the traits type. There is\nno reason to explicitly disallow `constexpr` operation. So mark all eligible\nmethods `constexpr`.\n\nIn addition, add some `static_assert()`s to the \"quantized\" test to check\nconstexpr operation.\n\nFor example, `FixedPointQTraits<...>::toFloat()` is `constexpr`, so this\nenables the construction of `{U,}Q<...>` from the underlying quantized\nvalue in `constexpr` contexts, which can be useful for example for\nstoring default values in e.g. `static constexpr` variables.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/libipa/quantized.h | 32 +++++++++++++++++++-------------\n test/ipa/libipa/quantized.cpp | 15 +++++++++++++--\n 2 files changed, 32 insertions(+), 15 deletions(-)", "diff": "diff --git a/src/ipa/libipa/quantized.h b/src/ipa/libipa/quantized.h\nindex 6bd196c7d..8d7b06a2d 100644\n--- a/src/ipa/libipa/quantized.h\n+++ b/src/ipa/libipa/quantized.h\n@@ -24,34 +24,40 @@ struct Quantized {\n \tstatic_assert(std::is_arithmetic_v<QuantizedType>,\n \t\t \"Quantized: QuantizedType must be arithmetic\");\n \n-\tQuantized()\n+\tconstexpr Quantized()\n \t\t: Quantized(0.0f) {}\n-\tQuantized(float x) { *this = x; }\n-\tQuantized(QuantizedType x) { *this = x; }\n \n-\tQuantized &operator=(float x)\n+\tconstexpr Quantized(float x)\n+\t\t: Quantized(Traits::fromFloat(x))\n \t{\n-\t\tquantized_ = Traits::fromFloat(x);\n-\t\tvalue_ = Traits::toFloat(quantized_);\n+\t}\n+\n+\tconstexpr Quantized(QuantizedType x)\n+\t\t: quantized_(x), value_(Traits::toFloat(x))\n+\t{\n+\t}\n+\n+\tconstexpr Quantized &operator=(float x)\n+\t{\n+\t\t*this = Quantized(x);\n \t\treturn *this;\n \t}\n \n-\tQuantized &operator=(QuantizedType x)\n+\tconstexpr Quantized &operator=(QuantizedType x)\n \t{\n-\t\tvalue_ = Traits::toFloat(x);\n-\t\tquantized_ = x;\n+\t\t*this = Quantized(x);\n \t\treturn *this;\n \t}\n \n-\tfloat value() const { return value_; }\n-\tQuantizedType quantized() const { return quantized_; }\n+\tconstexpr float value() const { return value_; }\n+\tconstexpr QuantizedType quantized() const { return quantized_; }\n \n-\tbool operator==(const Quantized &other) const\n+\tconstexpr bool operator==(const Quantized &other) const\n \t{\n \t\treturn quantized_ == other.quantized_;\n \t}\n \n-\tbool operator!=(const Quantized &other) const\n+\tconstexpr bool operator!=(const Quantized &other) const\n \t{\n \t\treturn !(*this == other);\n \t}\ndiff --git a/test/ipa/libipa/quantized.cpp b/test/ipa/libipa/quantized.cpp\nindex f138597f2..18655dac5 100644\n--- a/test/ipa/libipa/quantized.cpp\n+++ b/test/ipa/libipa/quantized.cpp\n@@ -25,7 +25,7 @@ struct BrightnessHueTraits {\n \t\tint quantized = std::lround(v * 128.0f);\n \t\treturn std::clamp<int>(quantized, -128, 127);\n \t}\n-\tstatic float toFloat(QuantizedType v)\n+\tstatic constexpr float toFloat(QuantizedType v)\n \t{\n \t\treturn static_cast<float>(v) / 128.0f;\n \t}\n@@ -40,7 +40,7 @@ struct ContrastSaturationTraits {\n \t\tint quantized = std::lround(v * 128.0f);\n \t\treturn std::clamp<int>(quantized, 0, 255);\n \t}\n-\tstatic float toFloat(QuantizedType v)\n+\tstatic constexpr float toFloat(QuantizedType v)\n \t{\n \t\treturn static_cast<float>(v) / 128.0f;\n \t}\n@@ -138,6 +138,17 @@ protected:\n \t\t\t\treturn TestFail;\n \t\t}\n \n+\t\t/* Test constexpr operation */\n+\t\t{\n+\t\t\tconstexpr BrightnessQ b1(uint8_t(1));\n+\t\t\tconstexpr BrightnessQ b2(uint8_t(2));\n+\n+\t\t\tstatic_assert(b1.quantized() == 1);\n+\t\t\tstatic_assert(b2.quantized() == 2);\n+\t\t\tstatic_assert(b1 != b2);\n+\t\t\tstatic_assert(!(b1 == b2));\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n", "prefixes": [ "v1" ] }