[{"id":31999,"web_url":"https://patchwork.libcamera.org/comment/31999/","msgid":"<dpvxlgkub3rhs33fagvppkbeq45zy62amr3ad6mdsds3uds5uc@ugaoqbbzqmuu>","date":"2024-11-04T11:08:09","subject":"Re: [PATCH 2/6] ipa: ipu3: Use centralised libipa 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, Oct 31, 2024 at 04:07:37PM +0000, Daniel Scally wrote:\n> Use the centralised libipa helpers instead of open coding common\n> functions.\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n>  src/ipa/ipu3/algorithms/agc.cpp |  7 ++++---\n>  src/ipa/ipu3/algorithms/awb.cpp | 34 +++------------------------------\n>  src/ipa/ipu3/algorithms/awb.h   |  1 -\n>  3 files changed, 7 insertions(+), 35 deletions(-)\n>\n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\n> index c5f3d8f0..3eb73ef0 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc.cpp\n> @@ -17,6 +17,7 @@\n>\n>  #include <libcamera/ipa/core_ipa_interface.h>\n>\n> +#include \"libipa/helpers.h\"\n>  #include \"libipa/histogram.h\"\n>\n>  /**\n> @@ -185,9 +186,9 @@ double Agc::estimateLuminance(double gain) const\n>  \t\tblueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0);\n>  \t}\n>\n> -\tdouble ySum = redSum * rGain_ * 0.299\n> -\t\t    + greenSum * gGain_ * 0.587\n> -\t\t    + blueSum * bGain_ * 0.114;\n> +\tdouble ySum = ipa::rec601LuminanceFromRGB(redSum * rGain_,\n\nHere and in the next patches you can drop the ipa:: namespace\nqualifier\n\n> +\t\t\t\t\t\t  greenSum * gGain_,\n> +\t\t\t\t\t\t  blueSum * bGain_);\n>\n>  \treturn ySum / (bdsGrid_.height * bdsGrid_.width) / 255;\n>  }\n> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\n> index 4d6e3994..0085edf4 100644\n> --- a/src/ipa/ipu3/algorithms/awb.cpp\n> +++ b/src/ipa/ipu3/algorithms/awb.cpp\n> @@ -13,6 +13,8 @@\n>\n>  #include <libcamera/control_ids.h>\n>\n> +#include \"libipa/helpers.h\"\n> +\n>  /**\n>   * \\file awb.h\n>   */\n> @@ -301,36 +303,6 @@ void Awb::prepare(IPAContext &context,\n>  \tparams->use.acc_ccm = 1;\n>  }\n>\n> -/**\n> - * The function estimates the correlated color temperature using\n> - * from RGB color space input.\n> - * In physics and color science, the Planckian locus or black body locus is\n> - * 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 Awb::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>  /* Generate an RGB vector with the average values for each zone */\n>  void Awb::generateZones()\n>  {\n> @@ -437,7 +409,7 @@ void Awb::awbGreyWorld()\n>  \t       blueGain = sumBlue.G / (sumBlue.B + 1);\n>\n>  \t/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */\n> -\tasyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);\n> +\tasyncResults_.temperatureK = ipa::estimateCCT(sumRed.R, sumRed.G, sumBlue.B);\n>\n>  \t/*\n>  \t * Gain values are unsigned integer value ranging [0, 8) with 13 bit\n> diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h\n> index c0202823..a13c49ac 100644\n> --- a/src/ipa/ipu3/algorithms/awb.h\n> +++ b/src/ipa/ipu3/algorithms/awb.h\n> @@ -75,7 +75,6 @@ private:\n>  \tvoid generateAwbStats(const ipu3_uapi_stats_3a *stats);\n>  \tvoid clearAwbStats();\n>  \tvoid awbGreyWorld();\n> -\tuint32_t estimateCCT(double red, double green, double blue);\n>  \tstatic constexpr uint16_t threshold(float value);\n>  \tstatic constexpr uint16_t gainValue(double gain);\n>\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 9BA35BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Nov 2024 11:08:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 58E9D65399;\n\tMon,  4 Nov 2024 12:08:15 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 49D2865399\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Nov 2024 12:08:13 +0100 (CET)","from ideasonboard.com (mob-5-90-48-188.net.vodafone.it\n\t[5.90.48.188])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C7EB22E;\n\tMon,  4 Nov 2024 12:08:06 +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=\"qvLUJmha\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1730718486;\n\tbh=TvJW48zaIU9AgrFfmW69xTUlkoMnHoTuilkT2ntR19A=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qvLUJmha7X1mDDFNVOGzGjJQxXcXTU3IV6PP2IPWnSglE0MfnLoWSRJp8EYMZI/yh\n\t8DwZuVbfZ/g+NUojtJauKlH/riobjtjDSMYyRJT/VVXtU9H1khqNDY34ZoWC0p8kGJ\n\tQkTUTI6+5UmLQ5cYr3cdUekhtDExMi+rReOE2KqE=","Date":"Mon, 4 Nov 2024 12:08:09 +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 2/6] ipa: ipu3: Use centralised libipa helpers","Message-ID":"<dpvxlgkub3rhs33fagvppkbeq45zy62amr3ad6mdsds3uds5uc@ugaoqbbzqmuu>","References":"<20241031160741.253855-1-dan.scally@ideasonboard.com>\n\t<20241031160741.253855-3-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241031160741.253855-3-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>"}}]