Patch Detail
Show a patch.
GET /api/patches/22490/?format=api
{ "id": 22490, "url": "https://patchwork.libcamera.org/api/patches/22490/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22490/", "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": "<20250109115412.356768-4-stefan.klug@ideasonboard.com>", "date": "2025-01-09T11:53:54", "name": "[v1,03/11] libipa: Add AWB algorithm base class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8fba5a5584bd005f718510eb3f715a9d2349a241", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22490/mbox/", "series": [ { "id": 4938, "url": "https://patchwork.libcamera.org/api/series/4938/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4938", "date": "2025-01-09T11:53:51", "name": "Add Bayesian AWB algorithm to libipa and rkisp1", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4938/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22490/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22490/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 7945BC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 9 Jan 2025 11:55:18 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7A8168516;\n\tThu, 9 Jan 2025 12:55:17 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 29D17684E2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 9 Jan 2025 12:55:13 +0100 (CET)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:93b9:eca8:897d:eae6])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A4D076F3;\n\tThu, 9 Jan 2025 12:54:19 +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=\"LJoO8apu\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736423659;\n\tbh=PxYbVII4EarCn618bzTqWAT5fn7Dx+QR10wHtw3ZamU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=LJoO8apu+EWcaRXDDQU1AMcX6GhoCps7mpeT1a1cIM6FjjHzZO+6npWxM/kzsQymU\n\tff908SDqCsRv2ViGJmfTAr973v7Rfb2XvIVM+a73ToAj8gK9T3nBvwLf2YOjXYb+7Y\n\tsOsaKr4dGMxuto2Tj994L5uamyLgz3LPKU3DxOvQ=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v1 03/11] libipa: Add AWB algorithm base class", "Date": "Thu, 9 Jan 2025 12:53:54 +0100", "Message-ID": "<20250109115412.356768-4-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20250109115412.356768-1-stefan.klug@ideasonboard.com>", "References": "<20250109115412.356768-1-stefan.klug@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 a class to provide a generic interface for auto white balance\nalgorithms. Concrete AWB algorithms are expected to subclass the\nAwbAlgorithm class to implement their functionality.\n\nPipeline handlers are expected to subclass the AwbStats class and\nimplement the necessary function to give the algorithm access to the\nhardware specific statistics data.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/libipa/awb.cpp | 137 +++++++++++++++++++++++++++++++++++++\n src/ipa/libipa/awb.h | 51 ++++++++++++++\n src/ipa/libipa/meson.build | 2 +\n 3 files changed, 190 insertions(+)\n create mode 100644 src/ipa/libipa/awb.cpp\n create mode 100644 src/ipa/libipa/awb.h", "diff": "diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp\nnew file mode 100644\nindex 000000000000..74e88d513b27\n--- /dev/null\n+++ b/src/ipa/libipa/awb.cpp\n@@ -0,0 +1,137 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024 Ideas on Board Oy\n+ *\n+ * Generic AWB algorithms\n+ */\n+\n+#include \"awb.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+/**\n+ * \\file awb.h\n+ * \\brief Base classes for AWB algorithms\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(Awb)\n+\n+namespace ipa {\n+\n+/**\n+ * \\class AwbResult\n+ * \\brief The result of an awb calculation\n+ *\n+ * This class holds the result of an auto white balance calculation.\n+ */\n+\n+/**\n+ * \\var AwbResult::gains\n+ * \\brief The calculated white balance gains\n+ */\n+\n+/**\n+ * \\var AwbResult::colourTemperature\n+ * \\brief The calculated colour temperature in Kelvin\n+ */\n+\n+/**\n+ * \\class AwbStats\n+ * \\brief A abstract class wrapping system specific AWB statistics\n+ *\n+ * Pipline handlers using an AWB algorithm based on the AwbAlgorithm class need\n+ * to implement this class to give the algorithm access to the hardware specific\n+ * statics data.\n+ */\n+\n+/**\n+ * \\fn AwbStats::computeColourError\n+ * \\brief Compute an error value for when the given gains would be applied\n+ * \\param[in] gains The gains to apply\n+ *\n+ * Compute an error value (non-greyness) assuming the given \\a gains would be\n+ * applied. To keep the actual implementations computationally inexpensive,\n+ * the squared colour error shall be returned.\n+ *\n+ * If the awb statistics provide multiple zones, the sum over all zones needs to\n+ * calculated.\n+ *\n+ * \\return The computed error value\n+ */\n+\n+/**\n+ * \\fn AwbStats::getRGBMeans\n+ * \\brief Get RGB means of the statistics\n+ *\n+ * Fetch the RGB means from the statistics. The values of each channel are\n+ * dimensionless and only the ratios are used for further calculations. This is\n+ * used by the simple gray world model to calculate the gains to apply.\n+ *\n+ * \\return The RGB means\n+ */\n+\n+/**\n+ * \\class AwbAlgorithm\n+ * \\brief A base class for auto white balance algorithms\n+ *\n+ * This class is a base class for auto white balance algorithms. It provides an\n+ * interface for the algorithms to implement, and is used by the pipeline\n+ * handler to interact with the concrete implementation.\n+ */\n+\n+/**\n+ * \\fn AwbAlgorithm::init\n+ * \\brief Initialize the algorithm with the given tuning data\n+ * \\param[in] tuningData The tuning data to use for the algorithm\n+ *\n+ * \\return 0 on success, a negative error code otherwise\n+ */\n+\n+/**\n+ * \\fn AwbAlgorithm::calculateAwb\n+ * \\brief Calculate awb data from the given statistics\n+ * \\param[in] stats The statistics to use for the calculation\n+ * \\param[in] lux The lux value of the scene\n+ *\n+ * Calculate a AwbResult object from the given statistics and lux value. A \\a\n+ * lux value of 0 means it is unknown or invalid and the algorithm shall ignore\n+ * it.\n+ *\n+ * \\return The awb result\n+ */\n+\n+/**\n+ * \\fn AwbAlgorithm::gainsFromColourTemperature\n+ * \\brief Compute white balance gains from a colour temperature\n+ * \\param[in] colourTemperature The colour temperature in Kelvin\n+ *\n+ * Compute the white balance gains from a \\a colourTemperature. This function\n+ * does not take any statistics into account. It is used to compute the colour\n+ * gains when the user manually specifies a colour temperature.\n+ *\n+ * \\return The colour gains\n+ */\n+\n+/**\n+ * \\fn AwbAlgorithm::controls\n+ * \\brief Get the controls info map for this algorithm\n+ *\n+ * \\return The controls info map\n+ */\n+\n+/**\n+ * \\fn AwbAlgorithm::handleControls\n+ * \\param[in] controls The controls to handle\n+ * \\brief Handle the controls supplied in a request\n+ */\n+\n+/**\n+ * \\var AwbAlgorithm::controls_\n+ * \\brief Controls info map for the controls provided by the algorithm\n+ */\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h\nnew file mode 100644\nindex 000000000000..2dd471606ec4\n--- /dev/null\n+++ b/src/ipa/libipa/awb.h\n@@ -0,0 +1,51 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024 Ideas on Board Oy\n+ *\n+ * Generic AWB algorithms\n+ */\n+\n+#pragma once\n+\n+#include <libcamera/controls.h>\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"vector.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa {\n+\n+struct AwbResult {\n+\tRGB<double> gains;\n+\tdouble colourTemperature;\n+};\n+\n+struct AwbStats {\n+\tvirtual double computeColourError(const RGB<double> &gains) const = 0;\n+\tvirtual RGB<double> getRGBMeans() const = 0;\n+};\n+\n+class AwbAlgorithm\n+{\n+public:\n+\tvirtual ~AwbAlgorithm() = default;\n+\n+\tvirtual int init(const YamlObject &tuningData) = 0;\n+\tvirtual AwbResult calculateAwb(const AwbStats &stats, int lux) = 0;\n+\tvirtual RGB<double> gainsFromColourTemperature(double colourTemperature) = 0;\n+\n+\tconst ControlInfoMap::Map &controls() const\n+\t{\n+\t\treturn controls_;\n+\t}\n+\n+\tvirtual void handleControls([[maybe_unused]] const ControlList &controls) {}\n+\n+protected:\n+\tControlInfoMap::Map controls_;\n+};\n+\n+} /* namespace ipa */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\nindex f2b2f4be50db..03e879c5834f 100644\n--- a/src/ipa/libipa/meson.build\n+++ b/src/ipa/libipa/meson.build\n@@ -3,6 +3,7 @@\n libipa_headers = files([\n 'agc_mean_luminance.h',\n 'algorithm.h',\n+ 'awb.h',\n 'camera_sensor_helper.h',\n 'colours.h',\n 'exposure_mode_helper.h',\n@@ -20,6 +21,7 @@ libipa_headers = files([\n libipa_sources = files([\n 'agc_mean_luminance.cpp',\n 'algorithm.cpp',\n+ 'awb.cpp',\n 'camera_sensor_helper.cpp',\n 'colours.cpp',\n 'exposure_mode_helper.cpp',\n", "prefixes": [ "v1", "03/11" ] }