Patch Detail
Show a patch.
GET /api/patches/26157/?format=api
{ "id": 26157, "url": "https://patchwork.libcamera.org/api/patches/26157/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26157/", "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": "<20260213-kbingham-quantizers-v7-13-1626b9aaabf1@ideasonboard.com>", "date": "2026-02-13T16:57:52", "name": "[v7,13/15] ipa: mali-c55: agc: Quantise the ISP Digital Gain", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "3ca9133bc788c93170233cd2869c2d470afd0ea1", "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/26157/mbox/", "series": [ { "id": 5789, "url": "https://patchwork.libcamera.org/api/series/5789/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5789", "date": "2026-02-13T16:57:39", "name": "libipa: Introduce a Quantized type", "version": 7, "mbox": "https://patchwork.libcamera.org/series/5789/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26157/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26157/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 6D23DC32FA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 13 Feb 2026 16:58:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B1C762221;\n\tFri, 13 Feb 2026 17:58:21 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C2C3621F1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Feb 2026 17:58:07 +0100 (CET)", "from ping.linuxembedded.co.uk\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 635AE26D7;\n\tFri, 13 Feb 2026 17:57:18 +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=\"Tst59HIj\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1771001838;\n\tbh=8pnKPaQgprr54IjxwE3cUFfx28bFhtFtdAoUq0nAiso=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=Tst59HIjgSkYmpl7NuvBkdfX9iv0PUdmKLycLpZkPauMXh/9Wksovw0A818yVBll9\n\tg7X5HC83wIDOO8QnLoYwBvfXrislwaZ43wAndAFgx7lg9BHq7QOSiShoZHD4Cc+S2J\n\tAYnjpS6si0Te85gXLYjPrDxLDcfn4y7bag3BxMWk=", "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "Date": "Fri, 13 Feb 2026 16:57:52 +0000", "Subject": "[PATCH v7 13/15] ipa: mali-c55: agc: Quantise the ISP Digital Gain", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20260213-kbingham-quantizers-v7-13-1626b9aaabf1@ideasonboard.com>", "References": "<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>", "In-Reply-To": "<20260213-kbingham-quantizers-v7-0-1626b9aaabf1@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Kieran Bingham <kieran.bingham@ideasonboard.com>, \n\tIsaac Scott <isaac.scott@ideasonboard.com>", "X-Mailer": "b4 0.14.3", "X-Developer-Signature": "v=1; a=ed25519-sha256; t=1771001883; l=4635;\n\ti=kieran.bingham@ideasonboard.com; s=20260207;\n\th=from:subject:message-id; \n\tbh=8pnKPaQgprr54IjxwE3cUFfx28bFhtFtdAoUq0nAiso=;\n\tb=d3jXw3gBKC4aGmaC5d2rQNkn5XllsGI7WvVDfcYOfmQFRaxgAcYKt/2fdJLiL/CNEeUHXZk3N\n\tH/+KayrqP1rAK0ohHh6WWHJqLmXglPb4ni7QbxqrBsOd7C2ZBn91jm4", "X-Developer-Key": "i=kieran.bingham@ideasonboard.com; a=ed25519;\n\tpk=FVXKN7YuwHc6UtbRUeTMAmranfsQomA+vnilfglWdaY=", "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": "The Mali-C55 ISP has a digital gain block which allows setting gain in Q5.8\nformat, a range of 0.0 to (very nearly) 32.0.\n\nConvert usage to the new UQ<5, 8> FixedPoint Quantised type which will\nsupport the conversion, clamping and quantisation so that the metadata\nand debug prints can now report the effective gain applied instead of\nthe potentially inaccurate float.\n\nAs the UQ<5, 8> type already clamps values, remove the explicit\nclamping. This removes the clamping to a minimum of 1.0 gain, so we\nrely on calculateNewEv to provide a valid gain.\n\nReviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nv5:\n - Use UQ<5, 8> type directly.\n - Use operator<< to report the UQ<5, 8> value.\n---\n src/ipa/mali-c55/algorithms/agc.cpp | 18 +++++++++---------\n src/ipa/mali-c55/ipa_context.h | 6 +++---\n 2 files changed, 12 insertions(+), 12 deletions(-)", "diff": "diff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp\nindex 014fd12452ac..075717f44ea6 100644\n--- a/src/ipa/mali-c55/algorithms/agc.cpp\n+++ b/src/ipa/mali-c55/algorithms/agc.cpp\n@@ -38,8 +38,8 @@ static constexpr unsigned int kNumHistogramBins = 256;\n * format, a range of 0.0 to (very nearly) 32.0. We clamp from 1.0 to the actual\n * max value which is 8191 * 2^-8.\n */\n-static constexpr double kMinDigitalGain = 1.0;\n-static constexpr double kMaxDigitalGain = 31.99609375;\n+static constexpr float kMinDigitalGain = 1.0;\n+static constexpr float kMaxDigitalGain = UQ<5, 8>::TraitsType::max;\n \n uint32_t AgcStatistics::decodeBinValue(uint16_t binVal)\n {\n@@ -245,7 +245,7 @@ void Agc::fillGainParamBlock(IPAContext &context, IPAFrameContext &frameContext,\n \t\t\t MaliC55Params *params)\n {\n \tIPAActiveState &activeState = context.activeState;\n-\tdouble gain;\n+\tUQ<5, 8> gain;\n \n \tif (activeState.agc.autoEnabled)\n \t\tgain = activeState.agc.automatic.ispGain;\n@@ -253,7 +253,7 @@ void Agc::fillGainParamBlock(IPAContext &context, IPAFrameContext &frameContext,\n \t\tgain = activeState.agc.manual.ispGain;\n \n \tauto block = params->block<MaliC55Blocks::Dgain>();\n-\tblock->gain = floatingToFixedPoint<5, 8, uint16_t, double>(gain);\n+\tblock->gain = gain.quantized();\n \n \tframeContext.agc.ispGain = gain;\n }\n@@ -358,7 +358,7 @@ void Agc::process(IPAContext &context,\n \t */\n \tuint32_t exposure = frameContext.agc.exposure;\n \tdouble analogueGain = frameContext.agc.sensorGain;\n-\tdouble digitalGain = frameContext.agc.ispGain;\n+\tdouble digitalGain = frameContext.agc.ispGain.value();\n \tdouble totalGain = analogueGain * digitalGain;\n \tutils::Duration currentShutter = exposure * configuration.sensor.lineDuration;\n \tutils::Duration effectiveExposureValue = currentShutter * totalGain;\n@@ -370,19 +370,19 @@ void Agc::process(IPAContext &context,\n \t\t\t activeState.agc.exposureMode, statistics_.yHist,\n \t\t\t effectiveExposureValue);\n \n-\tdGain = std::clamp(dGain, kMinDigitalGain, kMaxDigitalGain);\n+\tUQ<5, 8> dGainQ = static_cast<float>(dGain);\n \n \tLOG(MaliC55Agc, Debug)\n \t\t<< \"Divided up shutter, analogue gain and digital gain are \"\n-\t\t<< shutterTime << \", \" << aGain << \" and \" << dGain;\n+\t\t<< shutterTime << \", \" << aGain << \" and \" << dGainQ;\n \n \tactiveState.agc.automatic.exposure = shutterTime / configuration.sensor.lineDuration;\n \tactiveState.agc.automatic.sensorGain = aGain;\n-\tactiveState.agc.automatic.ispGain = dGain;\n+\tactiveState.agc.automatic.ispGain = dGainQ;\n \n \tmetadata.set(controls::ExposureTime, currentShutter.get<std::micro>());\n \tmetadata.set(controls::AnalogueGain, frameContext.agc.sensorGain);\n-\tmetadata.set(controls::DigitalGain, frameContext.agc.ispGain);\n+\tmetadata.set(controls::DigitalGain, frameContext.agc.ispGain.value());\n \tmetadata.set(controls::ColourTemperature, context.activeState.agc.temperatureK);\n }\n \ndiff --git a/src/ipa/mali-c55/ipa_context.h b/src/ipa/mali-c55/ipa_context.h\nindex 08f78e4f74ce..ac4b83773803 100644\n--- a/src/ipa/mali-c55/ipa_context.h\n+++ b/src/ipa/mali-c55/ipa_context.h\n@@ -41,12 +41,12 @@ struct IPAActiveState {\n \t\tstruct {\n \t\t\tuint32_t exposure;\n \t\t\tdouble sensorGain;\n-\t\t\tdouble ispGain;\n+\t\t\tUQ<5, 8> ispGain;\n \t\t} automatic;\n \t\tstruct {\n \t\t\tuint32_t exposure;\n \t\t\tdouble sensorGain;\n-\t\t\tdouble ispGain;\n+\t\t\tUQ<5, 8> ispGain;\n \t\t} manual;\n \t\tbool autoEnabled;\n \t\tuint32_t constraintMode;\n@@ -64,7 +64,7 @@ struct IPAFrameContext : public FrameContext {\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble sensorGain;\n-\t\tdouble ispGain;\n+\t\tUQ<5, 8> ispGain;\n \t} agc;\n \n \tstruct {\n", "prefixes": [ "v7", "13/15" ] }