From 29892f1c56c6657a9d650aff203912212c295bd0 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 18 Nov 2024 21:07:01 +0200 Subject: ipa: libipa: colour: Use the RGB class to model RGB values The rec601LuminanceFromRGB() and estimateCCT() functions take RGB triplets as three variables. Replace them with instances of the RGB class and adapt the users accordingly. Only variables passed directly to these functions are converted to RGB instances, further conversion of IPA modules to the RGB class will be performed separately. While at it, fix a typo in the documentation of the estimateCCT() function. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal --- src/ipa/rpi/controller/rpi/agc_channel.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/ipa/rpi') diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp index 14335943..79c45973 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp @@ -13,6 +13,7 @@ #include #include "libipa/colours.h" +#include "libipa/vector.h" #include "../awb_status.h" #include "../device_status.h" @@ -681,12 +682,13 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, * Note that the weights are applied by the IPA to the statistics directly, * before they are given to us here. */ - double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0; + ipa::RGB sum{ 0.0 }; + double pixelSum = 0; for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) { auto ®ion = stats->agcRegions.get(i); - rSum += std::min(region.val.rSum * gain, (maxVal - 1) * region.counted); - gSum += std::min(region.val.gSum * gain, (maxVal - 1) * region.counted); - bSum += std::min(region.val.bSum * gain, (maxVal - 1) * region.counted); + sum.r() += std::min(region.val.rSum * gain, (maxVal - 1) * region.counted); + sum.g() += std::min(region.val.gSum * gain, (maxVal - 1) * region.counted); + sum.b() += std::min(region.val.bSum * gain, (maxVal - 1) * region.counted); pixelSum += region.counted; } if (pixelSum == 0.0) { @@ -694,14 +696,11 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb, return 0; } - double ySum; /* Factor in the AWB correction if needed. */ - if (stats->agcStatsPos == Statistics::AgcStatsPos::PreWb) { - ySum = ipa::rec601LuminanceFromRGB(rSum * awb.gainR, - gSum * awb.gainG, - bSum * awb.gainB); - } else - ySum = ipa::rec601LuminanceFromRGB(rSum, gSum, bSum); + if (stats->agcStatsPos == Statistics::AgcStatsPos::PreWb) + sum *= ipa::RGB{{ awb.gainR, awb.gainR, awb.gainB }}; + + double ySum = ipa::rec601LuminanceFromRGB(sum); return ySum / pixelSum / (1 << 16); } -- cgit v1.2.1