Show a patch.

GET /api/patches/25922/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 25922,
    "url": "https://patchwork.libcamera.org/api/patches/25922/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/25922/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20260121173737.376113-16-kieran.bingham@ideasonboard.com>",
    "date": "2026-01-21T17:37:34",
    "name": "[v6,15/16] ipa: libipa: fixedpoint: Move float conversion inline",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "1213b1b65caa1144a406feb27229ac28857cb30e",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/25922/mbox/",
    "series": [
        {
            "id": 5730,
            "url": "https://patchwork.libcamera.org/api/series/5730/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5730",
            "date": "2026-01-21T17:37:19",
            "name": "libipa: Introduce a Quantized type",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/5730/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/25922/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/25922/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 ECD3AC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Jan 2026 17:38:03 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9FB2F61FF3;\n\tWed, 21 Jan 2026 18:38:03 +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 2643E61FDE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Jan 2026 18:37:46 +0100 (CET)",
            "from Monstersaurus.hippo-penny.ts.net\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 249D72964;\n\tWed, 21 Jan 2026 18:37:14 +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=\"pfpcFz1L\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769017034;\n\tbh=mw5dwkvdolJ00OupXTt49y7R7orpSZGl18WSyWE6pk8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=pfpcFz1LkWlogaQZaYskVe4LvZgWpRcWhPvglqGmZ5rT1dKQi0wvRgqilsAv5WJNG\n\twRSWqtNyFZxp9nGRF2jzafBjLTCfgHCtisnFG2uXS37WZCVs0GSKTWwQ4MIZghcGAh\n\t7rYoSVODiON5GkUQvOtOZZQACf4ZmORaHgHUxems=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tIsaac Scott <isaac.scott@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Subject": "[PATCH v6 15/16] ipa: libipa: fixedpoint: Move float conversion\n\tinline",
        "Date": "Wed, 21 Jan 2026 17:37:34 +0000",
        "Message-ID": "<20260121173737.376113-16-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.52.0",
        "In-Reply-To": "<20260121173737.376113-1-kieran.bingham@ideasonboard.com>",
        "References": "<20260121173737.376113-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "With all users of the floatingToFixedPoint and fixedToFloatingPoint\ncalls converted to use the FixedPoint Quantized types, remove the calls\nand documentation and move the implementation inline in the\nFixedPointTraits implementation.\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv5:\n - Reflow text when moved\n\nv6:\n- Use UT{1} << F instead of 1 << F\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/libipa/fixedpoint.cpp | 22 ----------\n src/ipa/libipa/fixedpoint.h   | 77 +++++++++++------------------------\n 2 files changed, 24 insertions(+), 75 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/fixedpoint.cpp b/src/ipa/libipa/fixedpoint.cpp\nindex c9d04e31e4df..b9ac7b78749c 100644\n--- a/src/ipa/libipa/fixedpoint.cpp\n+++ b/src/ipa/libipa/fixedpoint.cpp\n@@ -15,28 +15,6 @@ namespace libcamera {\n \n namespace ipa {\n \n-/**\n- * \\fn R floatingToFixedPoint(T number)\n- * \\brief Convert a floating point number to a fixed-point representation\n- * \\tparam I Bit width of the integer part of the fixed-point\n- * \\tparam F Bit width of the fractional part of the fixed-point\n- * \\tparam R Return type of the fixed-point representation\n- * \\tparam T Input type of the floating point representation\n- * \\param number The floating point number to convert to fixed point\n- * \\return The converted value\n- */\n-\n-/**\n- * \\fn R fixedToFloatingPoint(T number)\n- * \\brief Convert a fixed-point number to a floating point representation\n- * \\tparam I Bit width of the integer part of the fixed-point\n- * \\tparam F Bit width of the fractional part of the fixed-point\n- * \\tparam R Return type of the floating point representation\n- * \\tparam T Input type of the fixed-point representation\n- * \\param number The fixed point number to convert to floating point\n- * \\return The converted value\n- */\n-\n /**\n  * \\struct libcamera::ipa::FixedPointQTraits\n  * \\brief Traits type implementing fixed-point quantisation conversions\ndiff --git a/src/ipa/libipa/fixedpoint.h b/src/ipa/libipa/fixedpoint.h\nindex 33d1f4af4792..1a871bc554ef 100644\n--- a/src/ipa/libipa/fixedpoint.h\n+++ b/src/ipa/libipa/fixedpoint.h\n@@ -16,55 +16,6 @@ namespace libcamera {\n \n namespace ipa {\n \n-#ifndef __DOXYGEN__\n-template<unsigned int I, unsigned int F, typename R, typename T,\n-\t std::enable_if_t<std::is_integral_v<R> &&\n-\t\t\t  std::is_floating_point_v<T>> * = nullptr>\n-#else\n-template<unsigned int I, unsigned int F, typename R, typename T>\n-#endif\n-constexpr R floatingToFixedPoint(T number)\n-{\n-\tstatic_assert(sizeof(int) >= sizeof(R));\n-\tstatic_assert(I + F <= sizeof(R) * 8);\n-\n-\t/*\n-\t * The intermediate cast to int is needed on arm platforms to properly\n-\t * cast negative values. See\n-\t * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/\n-\t */\n-\tR mask = (1 << (F + I)) - 1;\n-\tR frac = static_cast<R>(static_cast<int>(std::round(number * (1 << F)))) & mask;\n-\n-\treturn frac;\n-}\n-\n-#ifndef __DOXYGEN__\n-template<unsigned int I, unsigned int F, typename R, typename T,\n-\t std::enable_if_t<std::is_floating_point_v<R> &&\n-\t\t\t  std::is_integral_v<T>> * = nullptr>\n-#else\n-template<unsigned int I, unsigned int F, typename R, typename T>\n-#endif\n-constexpr R fixedToFloatingPoint(T number)\n-{\n-\tstatic_assert(sizeof(int) >= sizeof(T));\n-\tstatic_assert(I + F <= sizeof(T) * 8);\n-\n-\tif constexpr (std::is_unsigned_v<T>)\n-\t\treturn static_cast<R>(number) / static_cast<R>(T{1} << F);\n-\n-\t/*\n-\t * Recreate the upper bits in case of a negative number by shifting the sign\n-\t * bit from the fixed point to the first bit of the unsigned and then right shifting\n-\t * by the same amount which keeps the sign bit in place.\n-\t * This can be optimized by the compiler quite well.\n-\t */\n-\tint remaining_bits = sizeof(int) * 8 - (I + F);\n-\tint t = static_cast<int>(static_cast<unsigned>(number) << remaining_bits) >> remaining_bits;\n-\treturn static_cast<R>(t) / static_cast<R>(1 << F);\n-}\n-\n template<unsigned int I, unsigned int F, typename T>\n struct FixedPointQTraits {\n private:\n@@ -97,11 +48,25 @@ public:\n \n \tstatic constexpr float toFloat(QuantizedType q)\n \t{\n-\t\treturn fixedToFloatingPoint<I, F, float, QuantizedType>(q);\n+\t\tif constexpr (std::is_unsigned_v<T>)\n+\t\t\treturn static_cast<float>(q) / static_cast<float>(UT{1} << F);\n+\n+\t\t/*\n+\t\t * Recreate the upper bits in case of a negative number by\n+\t\t * shifting the sign bit from the fixed point to the first bit\n+\t\t * of the unsigned and then right shifting by the same amount\n+\t\t * which keeps the sign bit in place. This can be optimized by\n+\t\t * the compiler quite well.\n+\t\t */\n+\t\tstatic_assert(sizeof(int) >= sizeof(T));\n+\n+\t\tint remaining_bits = sizeof(int) * 8 - (I + F);\n+\t\tint t = static_cast<int>(static_cast<unsigned>(q) << remaining_bits) >> remaining_bits;\n+\t\treturn static_cast<float>(t) / static_cast<float>(UT{1} << F);\n \t}\n \n-\tstatic constexpr float min = fixedToFloatingPoint<I, F, float>(qMin);\n-\tstatic constexpr float max = fixedToFloatingPoint<I, F, float>(qMax);\n+\tstatic constexpr float min = toFloat(qMin);\n+\tstatic constexpr float max = toFloat(qMax);\n \n \tstatic_assert(min < max, \"FixedPointQTraits: Minimum must be less than maximum\");\n \n@@ -109,7 +74,13 @@ public:\n \tstatic QuantizedType fromFloat(float v)\n \t{\n \t\tv = std::clamp(v, min, max);\n-\t\treturn floatingToFixedPoint<I, F, QuantizedType, float>(v);\n+\n+\t\t/*\n+\t\t * The intermediate cast to int is needed on arm platforms to\n+\t\t * properly cast negative values. See\n+\t\t * https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/\n+\t\t */\n+\t\treturn static_cast<T>(static_cast<int>(std::round(v * (1 << F)))) & bitMask;\n \t}\n };\n \n",
    "prefixes": [
        "v6",
        "15/16"
    ]
}