[{"id":32077,"web_url":"https://patchwork.libcamera.org/comment/32077/","msgid":"<fethinsbv54dsneinvd2pyyb3n2qvfpxpx7zetlobhtof4abup@zsh2pvvdlo2n>","date":"2024-11-08T15:18:07","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Dan\n\nOn Thu, Nov 07, 2024 at 10:25:03AM +0000, Daniel Scally wrote:\n> We start to have functions that are effectively identical crop up\n> across the IPA modules. Add a file allowing those to be centralised\n> within libipa so that a single implementation can be used in all of\n> the IPAs.\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n>\n> \t- Dropped the Q(m, n) format helpers until they're needed.\n> \t- \\return statements after long description\n> \t- Switched rec601LuminanceFromRGB() to return a double\n>\n>  src/ipa/libipa/helpers.cpp | 77 ++++++++++++++++++++++++++++++++++++++\n>  src/ipa/libipa/helpers.h   | 21 +++++++++++\n>  src/ipa/libipa/meson.build |  2 +\n>  3 files changed, 100 insertions(+)\n>  create mode 100644 src/ipa/libipa/helpers.cpp\n>  create mode 100644 src/ipa/libipa/helpers.h\n>\n> diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\n> new file mode 100644\n> index 00000000..6c038895\n> --- /dev/null\n> +++ b/src/ipa/libipa/helpers.cpp\n> @@ -0,0 +1,77 @@\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 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> + * \\return The estimated luminance value\n> + */\n> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b)\n\nIs passing arguments in as integers correct or will result in a lost\nof precision ?\n\nI see in the next patch the IPU3 IPA is converted to use this helper\n\ndouble Agc::estimateLuminance(double gain) const\n{\n\tdouble redSum = 0, greenSum = 0, blueSum = 0;\n\n\tfor (unsigned int i = 0; i < rgbTriples_.size(); i++) {\n\t\tredSum += std::min(std::get<0>(rgbTriples_[i]) * gain, 255.0);\n\t\tgreenSum += std::min(std::get<1>(rgbTriples_[i]) * gain, 255.0);\n\t\tblueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0);\n\t}\n\n\n-       double ySum = redSum * rGain_ * 0.299\n-                   + greenSum * gGain_ * 0.587\n-                   + blueSum * bGain_ * 0.114;\n+\tdouble ySum = rec601LuminanceFromRGB(redSum * rGain_,\n+\t\t\t\t\t     greenSum * gGain_,\n+\t\t\t\t\t     blueSum * bGain_);\n\n\treturn ySum / (bdsGrid_.height * bdsGrid_.width) / 255;\n}\n\nNow redSum * rGain_ (and greenSum * gGain_ and blueSum * bGain_)\nare indeed doubles. If you pass them in as integers I'm afraid you're\nimplicitly converting and rounding them. I made a little test program\n\ndouble rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b)\n{\n\treturn (r * .299) + (g * .587) + (b * .114);\n}\n\ndouble rec601LuminanceFromRGBDouble(double r, double g, double b)\n{\n\treturn (r * .299) + (g * .587) + (b * .114);\n}\n\nint main()\n{\n\tdouble r = 1.234;\n\tdouble g = 2.345;\n\tdouble b = 3.456;\n\n\tstd::cout << rec601LuminanceFromRGB(r, g, b) << std::endl;\n\tstd::cout << rec601LuminanceFromRGBDouble(r, g, b) << std::endl;\n\n\treturn 0;\n}\n\nAnd indeed it prints different results\n\n$ ./a.out\n1.815\n2.13946\n\nHave you checked in the IPU3 IPA if the results of the computation\nare the same ?\n\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> + *\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> + * \\return The estimated color temperature\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> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/libipa/helpers.h b/src/ipa/libipa/helpers.h\n> new file mode 100644\n> index 00000000..51c74a36\n> --- /dev/null\n> +++ b/src/ipa/libipa/helpers.h\n> @@ -0,0 +1,21 @@\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> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n> +uint32_t estimateCCT(double red, double green, double blue);\n> +\n> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n> index 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> --\n> 2.30.2\n>","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 82024C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 Nov 2024 15:18:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A94C0657AC;\n\tFri,  8 Nov 2024 16:18:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE28C6546C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Nov 2024 16:18:10 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 09F692E0;\n\tFri,  8 Nov 2024 16:18:00 +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=\"kLbl+vVX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731079081;\n\tbh=tBQn4rbYCRUkafvF7+jTz2YyBir1gpRnFG1YfCdW+vo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=kLbl+vVX/jPc/xUxTmaCe+t/LSPmASURl6YuRXjvcAWfAJT1GRm8jJok3O2PafmtY\n\t04ZNWRwNVGdZJWvnbrqRyZ39W8XgQwOW0h3JjH8d4FKZeUa5reS3BcHwA9pbaw1PQ8\n\tX5mN0uRPWEHoXyKkH1xRAdwlRTcvvijETGwtLgxo=","Date":"Fri, 8 Nov 2024 16:18:07 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, mike.rudenko@gmail.com","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","Message-ID":"<fethinsbv54dsneinvd2pyyb3n2qvfpxpx7zetlobhtof4abup@zsh2pvvdlo2n>","References":"<20241107102508.48322-1-dan.scally@ideasonboard.com>\n\t<20241107102508.48322-2-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241107102508.48322-2-dan.scally@ideasonboard.com>","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>"}},{"id":32115,"web_url":"https://patchwork.libcamera.org/comment/32115/","msgid":"<20241112080749.GF21062@pendragon.ideasonboard.com>","date":"2024-11-12T08:07:49","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Dan,\n\nThank you for the patch.\n\nOn Thu, Nov 07, 2024 at 10:25:03AM +0000, Daniel Scally wrote:\n> We start to have functions that are effectively identical crop up\n> across the IPA modules. Add a file allowing those to be centralised\n> within libipa so that a single implementation can be used in all of\n> the IPAs.\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n> \n> \t- Dropped the Q(m, n) format helpers until they're needed.\n> \t- \\return statements after long description\n> \t- Switched rec601LuminanceFromRGB() to return a double\n> \n>  src/ipa/libipa/helpers.cpp | 77 ++++++++++++++++++++++++++++++++++++++\n>  src/ipa/libipa/helpers.h   | 21 +++++++++++\n\nCould we call this colours.{cpp,h} ? I'd like to keep libipa organized,\nand add a generic \"helpers\" file only if we really can classify the\nhelpers in any meaningful way. I expect we'll get more colour-related\nhelpers in the future.\n\n>  src/ipa/libipa/meson.build |  2 +\n>  3 files changed, 100 insertions(+)\n>  create mode 100644 src/ipa/libipa/helpers.cpp\n>  create mode 100644 src/ipa/libipa/helpers.h\n> \n> diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\n> new file mode 100644\n> index 00000000..6c038895\n> --- /dev/null\n> +++ b/src/ipa/libipa/helpers.cpp\n> @@ -0,0 +1,77 @@\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 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> + * \\return The estimated luminance value\n> + */\n> +double 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> + *\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> + * \\return The estimated color temperature\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> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/libipa/helpers.h b/src/ipa/libipa/helpers.h\n> new file mode 100644\n> index 00000000..51c74a36\n> --- /dev/null\n> +++ b/src/ipa/libipa/helpers.h\n> @@ -0,0 +1,21 @@\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> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n> +uint32_t estimateCCT(double red, double green, double blue);\n> +\n> +} /* namespace ipa */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n> index 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',","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 4FD79C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 12 Nov 2024 08:08:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 37821657E3;\n\tTue, 12 Nov 2024 09:07:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A19065474\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Nov 2024 09:07:58 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 96FDE6AF;\n\tTue, 12 Nov 2024 09:07:45 +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=\"DsXrTIrV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731398865;\n\tbh=EpR9IDt3ai/LtQY43V5bWYuXI9eXNDYtSNu3A9LHwOE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DsXrTIrV1/hIRUicjLeRyVkwEhWCO1xohjX9Cmlmr3kq1gl2OfwDZDeZj2BvJ2qZ4\n\tLEjGCDBwYnIWyn+qdTjJkae8oEHGmOvP/2Yj1fxK1BHVS6WjA8W2P7aE2laXkMCqcV\n\t7ygQqDVHjx7W1omd/9KPBf/lAmNIZ9Fe/qZH4Qx4=","Date":"Tue, 12 Nov 2024 10:07:49 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, mike.rudenko@gmail.com","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","Message-ID":"<20241112080749.GF21062@pendragon.ideasonboard.com>","References":"<20241107102508.48322-1-dan.scally@ideasonboard.com>\n\t<20241107102508.48322-2-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241107102508.48322-2-dan.scally@ideasonboard.com>","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>"}},{"id":32140,"web_url":"https://patchwork.libcamera.org/comment/32140/","msgid":"<cf2f2593-42e9-468a-9818-2fc3b1bf8c30@ideasonboard.com>","date":"2024-11-13T10:46:58","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hello Laurent\n\nOn 12/11/2024 08:07, Laurent Pinchart wrote:\n> Hi Dan,\n>\n> Thank you for the patch.\n>\n> On Thu, Nov 07, 2024 at 10:25:03AM +0000, Daniel Scally wrote:\n>> We start to have functions that are effectively identical crop up\n>> across the IPA modules. Add a file allowing those to be centralised\n>> within libipa so that a single implementation can be used in all of\n>> the IPAs.\n>>\n>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n>> ---\n>> Changes in v2:\n>>\n>> \t- Dropped the Q(m, n) format helpers until they're needed.\n>> \t- \\return statements after long description\n>> \t- Switched rec601LuminanceFromRGB() to return a double\n>>\n>>   src/ipa/libipa/helpers.cpp | 77 ++++++++++++++++++++++++++++++++++++++\n>>   src/ipa/libipa/helpers.h   | 21 +++++++++++\n> Could we call this colours.{cpp,h} ? I'd like to keep libipa organized,\n> and add a generic \"helpers\" file only if we really can classify the\n> helpers in any meaningful way. I expect we'll get more colour-related\n> helpers in the future.\n\n\nOkedokey - will do.\n\n>\n>>   src/ipa/libipa/meson.build |  2 +\n>>   3 files changed, 100 insertions(+)\n>>   create mode 100644 src/ipa/libipa/helpers.cpp\n>>   create mode 100644 src/ipa/libipa/helpers.h\n>>\n>> diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\n>> new file mode 100644\n>> index 00000000..6c038895\n>> --- /dev/null\n>> +++ b/src/ipa/libipa/helpers.cpp\n>> @@ -0,0 +1,77 @@\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 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>> + * \\return The estimated luminance value\n>> + */\n>> +double 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>> + *\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>> + * \\return The estimated color temperature\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>> +} /* namespace ipa */\n>> +\n>> +} /* namespace libcamera */\n>> diff --git a/src/ipa/libipa/helpers.h b/src/ipa/libipa/helpers.h\n>> new file mode 100644\n>> index 00000000..51c74a36\n>> --- /dev/null\n>> +++ b/src/ipa/libipa/helpers.h\n>> @@ -0,0 +1,21 @@\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>> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n>> +uint32_t estimateCCT(double red, double green, double blue);\n>> +\n>> +} /* namespace ipa */\n>> +\n>> +} /* namespace libcamera */\n>> diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n>> index 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',","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 313C0C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Nov 2024 10:47:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 22FF965809;\n\tWed, 13 Nov 2024 11:47:03 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AA0E6605B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Nov 2024 11:47:01 +0100 (CET)","from [192.168.0.43]\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 47546752;\n\tWed, 13 Nov 2024 11:46:48 +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=\"nSl/dzyW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731494808;\n\tbh=j4E3YiA2NJ2xSSSGz3Juy4YkyboptFD5lPLHcfbD5io=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=nSl/dzyWktGuJNXitiJZjiNqr6mrw1vvFYCoOEjSLjS1Z62xRJIymgXjyk/pz49Y0\n\t8LjUHmItLmoKrZWWmi56XAB10zXpHp3SIbwWjxCYsW6QAwYg/wnmV6iP+YYey9hu0n\n\tdHGt0Rnu2JVDyY2c5rEsUQIglbrQsvWd27HAL6tQ=","Message-ID":"<cf2f2593-42e9-468a-9818-2fc3b1bf8c30@ideasonboard.com>","Date":"Wed, 13 Nov 2024 10:46:58 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, mike.rudenko@gmail.com","References":"<20241107102508.48322-1-dan.scally@ideasonboard.com>\n\t<20241107102508.48322-2-dan.scally@ideasonboard.com>\n\t<20241112080749.GF21062@pendragon.ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideasonboard.com; keydata=\n\txsFNBGLydlEBEADa5O2s0AbUguprfvXOQun/0a8y2Vk6BqkQALgeD6KnXSWwaoCULp18etYW\n\tB31bfgrdphXQ5kUQibB0ADK8DERB4wrzrUb5CMxLBFE7mQty+v5NsP0OFNK9XTaAOcmD+Ove\n\teIjYvqurAaro91jrRVrS1gBRxIFqyPgNvwwL+alMZhn3/2jU2uvBmuRrgnc/e9cHKiuT3Dtq\n\tMHGPKL2m+plk+7tjMoQFfexoQ1JKugHAjxAhJfrkXh6uS6rc01bYCyo7ybzg53m1HLFJdNGX\n\tsUKR+dQpBs3SY4s66tc1sREJqdYyTsSZf80HjIeJjU/hRunRo4NjRIJwhvnK1GyjOvvuCKVU\n\tRWpY8dNjNu5OeAfdrlvFJOxIE9M8JuYCQTMULqd1NuzbpFMjc9524U3Cngs589T7qUMPb1H1\n\tNTA81LmtJ6Y+IV5/kiTUANflpzBwhu18Ok7kGyCq2a2jsOcVmk8gZNs04gyjuj8JziYwwLbf\n\tvzABwpFVcS8aR+nHIZV1HtOzyw8CsL8OySc3K9y+Y0NRpziMRvutrppzgyMb9V+N31mK9Mxl\n\t1YkgaTl4ciNWpdfUe0yxH03OCuHi3922qhPLF4XX5LN+NaVw5Xz2o3eeWklXdouxwV7QlN33\n\tu4+u2FWzKxDqO6WLQGjxPE0mVB4Gh5Pa1Vb0ct9Ctg0qElvtGQARAQABzShEYW4gU2NhbGx5\n\tIDxkYW4uc2NhbGx5QGlkZWFzb25ib2FyZC5jb20+wsGNBBMBCAA3FiEEsdtt8OWP7+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z6UzUGKoJVbxmSW/EJLEGoI5p3NWxWtScEVv8mO49gqQdrRIOheZycDmHnItt\n\t9Qjv00uFhEwv2YfiyGk6iGF2W40s2pH2t6oeuGgmiZ7g6d0MEK8Ql/4zPItvr1c1rpwpXUC1\n\tu1kQWgtnNjFHX3KiYdqjcZeRBiry1X0zY+4Y24wUU0KsEewJwjhmCKAsju1RpdlPg2kC","In-Reply-To":"<20241112080749.GF21062@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}},{"id":32176,"web_url":"https://patchwork.libcamera.org/comment/32176/","msgid":"<12d41ea5-5378-4f2e-81d5-75f5c2a714bb@ideasonboard.com>","date":"2024-11-14T22:25:28","subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Jacopo\n\nOn 08/11/2024 15:18, Jacopo Mondi wrote:\n> Hi Dan\n>\n> On Thu, Nov 07, 2024 at 10:25:03AM +0000, Daniel Scally wrote:\n>> We start to have functions that are effectively identical crop up\n>> across the IPA modules. Add a file allowing those to be centralised\n>> within libipa so that a single implementation can be used in all of\n>> the IPAs.\n>>\n>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n>> ---\n>> Changes in v2:\n>>\n>> \t- Dropped the Q(m, n) format helpers until they're needed.\n>> \t- \\return statements after long description\n>> \t- Switched rec601LuminanceFromRGB() to return a double\n>>\n>>   src/ipa/libipa/helpers.cpp | 77 ++++++++++++++++++++++++++++++++++++++\n>>   src/ipa/libipa/helpers.h   | 21 +++++++++++\n>>   src/ipa/libipa/meson.build |  2 +\n>>   3 files changed, 100 insertions(+)\n>>   create mode 100644 src/ipa/libipa/helpers.cpp\n>>   create mode 100644 src/ipa/libipa/helpers.h\n>>\n>> diff --git a/src/ipa/libipa/helpers.cpp b/src/ipa/libipa/helpers.cpp\n>> new file mode 100644\n>> index 00000000..6c038895\n>> --- /dev/null\n>> +++ b/src/ipa/libipa/helpers.cpp\n>> @@ -0,0 +1,77 @@\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 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>> + * \\return The estimated luminance value\n>> + */\n>> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b)\n> Is passing arguments in as integers correct or will result in a lost\n> of precision ?\n>\n> I see in the next patch the IPU3 IPA is converted to use this helper\n>\n> double Agc::estimateLuminance(double gain) const\n> {\n> \tdouble redSum = 0, greenSum = 0, blueSum = 0;\n>\n> \tfor (unsigned int i = 0; i < rgbTriples_.size(); i++) {\n> \t\tredSum += std::min(std::get<0>(rgbTriples_[i]) * gain, 255.0);\n> \t\tgreenSum += std::min(std::get<1>(rgbTriples_[i]) * gain, 255.0);\n> \t\tblueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0);\n> \t}\n>\n>\n> -       double ySum = redSum * rGain_ * 0.299\n> -                   + greenSum * gGain_ * 0.587\n> -                   + blueSum * bGain_ * 0.114;\n> +\tdouble ySum = rec601LuminanceFromRGB(redSum * rGain_,\n> +\t\t\t\t\t     greenSum * gGain_,\n> +\t\t\t\t\t     blueSum * bGain_);\n>\n> \treturn ySum / (bdsGrid_.height * bdsGrid_.width) / 255;\n> }\n>\n> Now redSum * rGain_ (and greenSum * gGain_ and blueSum * bGain_)\n> are indeed doubles. If you pass them in as integers I'm afraid you're\n> implicitly converting and rounding them. I made a little test program\n>\n> double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b)\n> {\n> \treturn (r * .299) + (g * .587) + (b * .114);\n> }\n>\n> double rec601LuminanceFromRGBDouble(double r, double g, double b)\n> {\n> \treturn (r * .299) + (g * .587) + (b * .114);\n> }\n>\n> int main()\n> {\n> \tdouble r = 1.234;\n> \tdouble g = 2.345;\n> \tdouble b = 3.456;\n>\n> \tstd::cout << rec601LuminanceFromRGB(r, g, b) << std::endl;\n> \tstd::cout << rec601LuminanceFromRGBDouble(r, g, b) << std::endl;\n>\n> \treturn 0;\n> }\n>\n> And indeed it prints different results\n>\n> $ ./a.out\n> 1.815\n> 2.13946\n>\n> Have you checked in the IPU3 IPA if the results of the computation\n> are the same ?\n\n\nYou are right of course - I hadn't checked in the IPU3 one carefully enough, for some reason I \nthought they were all the same. I'll use doubles across the board so there's no rounding.\n\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>> + *\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>> + * \\return The estimated color temperature\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>> +} /* namespace ipa */\n>> +\n>> +} /* namespace libcamera */\n>> diff --git a/src/ipa/libipa/helpers.h b/src/ipa/libipa/helpers.h\n>> new file mode 100644\n>> index 00000000..51c74a36\n>> --- /dev/null\n>> +++ b/src/ipa/libipa/helpers.h\n>> @@ -0,0 +1,21 @@\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>> +double rec601LuminanceFromRGB(unsigned int r, unsigned int g, unsigned int b);\n>> +uint32_t estimateCCT(double red, double green, double blue);\n>> +\n>> +} /* namespace ipa */\n>> +\n>> +} /* namespace libcamera */\n>> diff --git a/src/ipa/libipa/meson.build b/src/ipa/libipa/meson.build\n>> index 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>> --\n>> 2.30.2\n>>","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 3F75AC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Nov 2024 22:25:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5176665852;\n\tThu, 14 Nov 2024 23:25:34 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C3323657E0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Nov 2024 23:25:31 +0100 (CET)","from [192.168.0.43]\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 6CAB4827;\n\tThu, 14 Nov 2024 23:25: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=\"oR40ovFi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1731623117;\n\tbh=Tp17hdwHw34PnoIgypNFU/SfCyo9IqkSxd8C5xW7MVE=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=oR40ovFiW0daK+dZ4g4XIOEznBFm4p5s1keXmqj7sl6NjNthg+mdfbNwvXwpNR+gU\n\t5xSNzw4T7W8CQlNv9l94keAqouHNQmai5HGsAIVqTbNj+ZFG7t39VNwLPgO95t3w9a\n\tDpi3WSgAODOvgIVKRQDInBWUMUyLHNyu7B8Iv1CU=","Message-ID":"<12d41ea5-5378-4f2e-81d5-75f5c2a714bb@ideasonboard.com>","Date":"Thu, 14 Nov 2024 22:25:28 +0000","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 1/6] ipa: libipa: Add miscellaneous helpers","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, mike.rudenko@gmail.com","References":"<20241107102508.48322-1-dan.scally@ideasonboard.com>\n\t<20241107102508.48322-2-dan.scally@ideasonboard.com>\n\t<fethinsbv54dsneinvd2pyyb3n2qvfpxpx7zetlobhtof4abup@zsh2pvvdlo2n>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard.com>","Autocrypt":"addr=dan.scally@ideasonboard.com; keydata=\n\txsFNBGLydlEBEADa5O2s0AbUguprfvXOQun/0a8y2V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set=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>"}}]