{"id":21848,"url":"https://patchwork.libcamera.org/api/1.1/patches/21848/?format=json","web_url":"https://patchwork.libcamera.org/patch/21848/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241107114819.57599-2-dan.scally@ideasonboard.com>","date":"2024-11-07T11:48:09","name":"[v3,01/11] ipa: helpers: Add Unsigned Q(m, n) helpers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"155d3a6a3e6a659b5b5f9241bcb544c346d25e7a","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/1.1/people/156/?format=json","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21848/mbox/","series":[{"id":4777,"url":"https://patchwork.libcamera.org/api/1.1/series/4777/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4777","date":"2024-11-07T11:48:08","name":"Add Mali-C55 IPA Module and Algorithms","version":3,"mbox":"https://patchwork.libcamera.org/series/4777/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21848/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21848/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 71098C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  7 Nov 2024 11:48:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CBA3B6547F;\n\tThu,  7 Nov 2024 12:48:31 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 847DF653F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 Nov 2024 12:48:27 +0100 (CET)","from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C691499F;\n\tThu,  7 Nov 2024 12:48:17 +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=\"sTMxNPfj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1730980098;\n\tbh=1/zdVU+wNFShOtkldi4YY/AGhOETMeIlUIgRx67CmL8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=sTMxNPfjKrwlyKT19R+8vd7saPPC4EueKpqjkwGinNsHJXT10yfqJsm3aWJyWPA6p\n\tLWzZxJADe+ePYWiuTK53oVil6atvfeW6W75kDJ6DATPhrJ8ZoleD6/wawSjS3xgHaw\n\tNMnIpYkCk4JUcEYr6INi8lecmGfq3WABcDAdGJ/U=","From":"Daniel Scally <dan.scally@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Anthony.McGivern@arm.com,\n\tDaniel Scally <dan.scally@ideasonboard.com>","Subject":"[PATCH v3 01/11] ipa: helpers: Add Unsigned Q(m, n) helpers","Date":"Thu,  7 Nov 2024 11:48:09 +0000","Message-Id":"<20241107114819.57599-2-dan.scally@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20241107114819.57599-1-dan.scally@ideasonboard.com>","References":"<20241107114819.57599-1-dan.scally@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":"Add functions to convert a double to or from an unsigned Q(m,n)\nformat. As the format is unsigned this most resembles the UQ variant\nof the TI implementation detailed on Wikipedia:\n\nhttps://en.wikipedia.org/wiki/Q_(number_format)\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\nChanges in v3:\n\n\t- New patch\n\n src/ipa/libipa/helpers.cpp | 29 +++++++++++++++++++++++++++++\n src/ipa/libipa/helpers.h   |  2 ++\n 2 files changed, 31 insertions(+)","diff":"diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\nindex 6c038895..908c6e93 100644\n--- a/src/ipa/libipa/helpers.cpp\n+++ b/src/ipa/libipa/helpers.cpp\n@@ -72,6 +72,35 @@ uint32_t estimateCCT(double red, double green, double blue)\n \treturn 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33;\n }\n \n+/**\n+ * \\brief Convert double to Q(m.n) format\n+ * \\param[in] value The value to convert\n+ * \\param[in] m The number of bits used to represent the integer part\n+ * \\param[in] n The number of bits used to represent the fraction part\n+ *\n+ * This function converts a double into an unsigned fractional Q format,\n+ * clamping at the largest possible value given m and n. As these formats are\n+ * unsigned the m figure does not include a sign bit.\n+ */\n+unsigned int toUnsignedQFormat(double value, unsigned int m, unsigned int n)\n+{\n+\tdouble maxVal = (std::pow(2, m + n) - 1) / std::pow(2, n);\n+\n+\treturn std::clamp(value, 0.0, maxVal) * std::pow(2, n);\n+}\n+\n+/**\n+ * \\brief Convert Q(m.n) formatted number to double\n+ * \\param[in] value The value to convert\n+ * \\param[in] n The number of bits used to represent the fraction part\n+ *\n+ * This function converts an unsigned Q formatted value into a double.\n+ */\n+double fromUnsignedQFormat(unsigned int value, unsigned int n)\n+{\n+\treturn value / std::pow(2, n);\n+}\n+\n } /* namespace ipa */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/libipa/helpers.h b/src/ipa/libipa/helpers.h\nindex 51c74a36..1f26e768 100644\n--- a/src/ipa/libipa/helpers.h\n+++ b/src/ipa/libipa/helpers.h\n@@ -15,6 +15,8 @@ namespace ipa {\n \n double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n uint32_t estimateCCT(double red, double green, double blue);\n+unsigned int toUnsignedQFormat(double value, unsigned int m, unsigned int n);\n+double fromUnsignedQFormat(unsigned int value, unsigned int n);\n \n } /* namespace ipa */\n \n","prefixes":["v3","01/11"]}