Patch Detail
Show a patch.
GET /api/1.1/patches/21791/?format=api
{ "id": 21791, "url": "https://patchwork.libcamera.org/api/1.1/patches/21791/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21791/", "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": "<20241031160741.253855-2-dan.scally@ideasonboard.com>", "date": "2024-10-31T16:07:36", "name": "[1/6] ipa: libipa: Add miscellaneous helpers", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "bd3d5e2e20351c74f763868f7ed20567f281e46c", "submitter": { "id": 156, "url": "https://patchwork.libcamera.org/api/1.1/people/156/?format=api", "name": "Dan Scally", "email": "dan.scally@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21791/mbox/", "series": [ { "id": 4762, "url": "https://patchwork.libcamera.org/api/1.1/series/4762/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4762", "date": "2024-10-31T16:07:35", "name": "Centralise common functions in IPA modules", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4762/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21791/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21791/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 CA85EC3292\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Oct 2024 16:08:22 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1819E653AD;\n\tThu, 31 Oct 2024 17:08:20 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A0DBB6039B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Oct 2024 17:08:12 +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 7465BE0D;\n\tThu, 31 Oct 2024 17:08:08 +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=\"FWXXuDzH\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1730390888;\n\tbh=/FxZ1eFssi/jct/GeklGlD2CrAQhC5ZephJEYXf+Uuc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=FWXXuDzHvlnbozP5Yhti0zULpVYl7T1pDgIQIqp1Df6DOK5UUdwLnT9l9hqMcfxr0\n\toMozwc7bWDu0Ba+wa3s04A8OnJRsBoPFMpvc8Ey1w0OBX86tpTISmBCvbpFoLmI3R5\n\tDF4jyIFfy4k1exEfxvmPWhiwsZ4WPp2n3V+Ry3Yw=", "From": "Daniel Scally <dan.scally@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "mike.rudenko@gmail.com,\n\tDaniel Scally <dan.scally@ideasonboard.com>", "Subject": "[PATCH 1/6] ipa: libipa: Add miscellaneous helpers", "Date": "Thu, 31 Oct 2024 16:07:36 +0000", "Message-Id": "<20241031160741.253855-2-dan.scally@ideasonboard.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20241031160741.253855-1-dan.scally@ideasonboard.com>", "References": "<20241031160741.253855-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": "We start to have functions that are effectively identical crop up\nacross the IPA modules. Add a file allowing those to be centralised\nwithin libipa so that a single implementation can be used in all of\nthe IPAs.\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\n src/ipa/libipa/helpers.cpp | 103 +++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/helpers.h | 23 +++++++++\n src/ipa/libipa/meson.build | 2 +\n 3 files changed, 128 insertions(+)\n create mode 100644 src/ipa/libipa/helpers.cpp\n create mode 100644 src/ipa/libipa/helpers.h", "diff": "diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\nnew file mode 100644\nindex 00000000..cc0cd586\n--- /dev/null\n+++ b/src/ipa/libipa/helpers.cpp\n@@ -0,0 +1,103 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy\n+ *\n+ * libipa miscellaneous helpers\n+ */\n+\n+#include \"helpers.h\"\n+\n+#include <algorithm>\n+#include <cmath>\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+/**\n+ * \\file helpers.h\n+ * \\brief Functions to reduce code duplication between IPA modules\n+ */\n+\n+/**\n+ * \\brief Estimate luminance from RGB values following ITU-R BT.601\n+ * \\param[in] r The red value\n+ * \\param[in] g The green value\n+ * \\param[in] b The blue valye\n+ * \\return The estimated luminance value\n+ *\n+ * This function estimates a luminance value from a triplet of Red, Green and\n+ * Blue values, following the formula defined by ITU-R Recommendation BT.601-7\n+ * which can be found at https://www.itu.int/rec/R-REC-BT.601\n+ */\n+unsigned int rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b)\n+{\n+\treturn (r * .299) + (g * .587) + (b * .114);\n+}\n+\n+/**\n+ * \\brief Estimate correlated colour temperature from RGB color space input\n+ * \\param[in] red The input red value\n+ * \\param[in] green The input green value\n+ * \\param[in] blue The input blue value\n+ * \\return The estimated color temperature\n+ *\n+ * This function estimates the correlated color temperature RGB color space\n+ * input. In physics and color science, the Planckian locus or black body locus\n+ * is the path or locus that the color of an incandescent black body would take\n+ * in a particular chromaticity space as the blackbody temperature changes.\n+ *\n+ * If a narrow range of color temperatures is considered (those encapsulating\n+ * daylight being the most practical case) one can approximate the Planckian\n+ * locus in order to calculate the CCT in terms of chromaticity coordinates.\n+ *\n+ * More detailed information can be found in:\n+ * https://en.wikipedia.org/wiki/Color_temperature#Approximation\n+ */\n+uint32_t estimateCCT(double red, double green, double blue)\n+{\n+\t/* Convert the RGB values to CIE tristimulus values (XYZ) */\n+\tdouble X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue);\n+\tdouble Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue);\n+\tdouble Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue);\n+\n+\t/* Calculate the normalized chromaticity values */\n+\tdouble x = X / (X + Y + Z);\n+\tdouble y = Y / (X + Y + Z);\n+\n+\t/* Calculate CCT */\n+\tdouble n = (x - 0.3320) / (0.1858 - y);\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 Q format, clamping at the\n+ * largest possible value given m and n.\n+ */\n+unsigned int toQFormat(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 fromQFormat(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\nnew file mode 100644\nindex 00000000..361b63bd\n--- /dev/null\n+++ b/src/ipa/libipa/helpers.h\n@@ -0,0 +1,23 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2024, Ideas on Board Oy\n+ *\n+ * libipa miscellaneous helpers\n+ */\n+\n+#pragma once\n+\n+#include <stdint.h>\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+unsigned int rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n+uint32_t estimateCCT(double red, double green, double blue);\n+unsigned int toQFormat(double value, unsigned int m, unsigned int n);\n+double fromQFormat(unsigned int value, unsigned int n);\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex e78cbcd6..ca4f3e28 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -6,6 +6,7 @@ libipa_headers = files([\n 'camera_sensor_helper.h',\n 'exposure_mode_helper.h',\n 'fc_queue.h',\n+ 'helpers.h',\n 'histogram.h',\n 'interpolator.h',\n 'lsc_polynomial.h',\n@@ -21,6 +22,7 @@ libipa_sources = files([\n 'camera_sensor_helper.cpp',\n 'exposure_mode_helper.cpp',\n 'fc_queue.cpp',\n+ 'helpers.cpp',\n 'histogram.cpp',\n 'interpolator.cpp',\n 'lsc_polynomial.cpp',\n", "prefixes": [ "1/6" ] }