Message ID | 20241115074628.417215-3-dan.scally@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Quoting Daniel Scally (2024-11-15 07:46:24) > Use the centralised libipa helpers instead of open coding common > functions. > > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> > --- > Changes in v3: > > - None > > Changes in v2: > > - Dropped the ipa:: prefix for function calls > > src/ipa/ipu3/algorithms/agc.cpp | 7 ++++--- > src/ipa/ipu3/algorithms/awb.cpp | 32 ++------------------------------ > src/ipa/ipu3/algorithms/awb.h | 1 - > 3 files changed, 6 insertions(+), 34 deletions(-) > > diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp > index c5f3d8f0..466b3fb3 100644 > --- a/src/ipa/ipu3/algorithms/agc.cpp > +++ b/src/ipa/ipu3/algorithms/agc.cpp > @@ -17,6 +17,7 @@ > > #include <libcamera/ipa/core_ipa_interface.h> > > +#include "libipa/colours.h" > #include "libipa/histogram.h" > > /** > @@ -185,9 +186,9 @@ double Agc::estimateLuminance(double gain) const > blueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0); > } > > - double ySum = redSum * rGain_ * 0.299 > - + greenSum * gGain_ * 0.587 > - + blueSum * bGain_ * 0.114; > + double ySum = rec601LuminanceFromRGB(redSum * rGain_, > + greenSum * gGain_, > + blueSum * bGain_); \o/ Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > return ySum / (bdsGrid_.height * bdsGrid_.width) / 255; > } > diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp > index 4d6e3994..c3c8b074 100644 > --- a/src/ipa/ipu3/algorithms/awb.cpp > +++ b/src/ipa/ipu3/algorithms/awb.cpp > @@ -13,6 +13,8 @@ > > #include <libcamera/control_ids.h> > > +#include "libipa/colours.h" > + > /** > * \file awb.h > */ > @@ -301,36 +303,6 @@ void Awb::prepare(IPAContext &context, > params->use.acc_ccm = 1; > } > > -/** > - * The function estimates the correlated color temperature using > - * from RGB color space input. > - * In physics and color science, the Planckian locus or black body locus is > - * the path or locus that the color of an incandescent black body would take > - * in a particular chromaticity space as the blackbody temperature changes. > - * > - * If a narrow range of color temperatures is considered (those encapsulating > - * daylight being the most practical case) one can approximate the Planckian > - * locus in order to calculate the CCT in terms of chromaticity coordinates. > - * > - * More detailed information can be found in: > - * https://en.wikipedia.org/wiki/Color_temperature#Approximation > - */ > -uint32_t Awb::estimateCCT(double red, double green, double blue) > -{ > - /* Convert the RGB values to CIE tristimulus values (XYZ) */ > - double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue); > - double Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue); > - double Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue); > - > - /* Calculate the normalized chromaticity values */ > - double x = X / (X + Y + Z); > - double y = Y / (X + Y + Z); > - > - /* Calculate CCT */ > - double n = (x - 0.3320) / (0.1858 - y); > - return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33; > -} > - > /* Generate an RGB vector with the average values for each zone */ > void Awb::generateZones() > { > diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h > index c0202823..a13c49ac 100644 > --- a/src/ipa/ipu3/algorithms/awb.h > +++ b/src/ipa/ipu3/algorithms/awb.h > @@ -75,7 +75,6 @@ private: > void generateAwbStats(const ipu3_uapi_stats_3a *stats); > void clearAwbStats(); > void awbGreyWorld(); > - uint32_t estimateCCT(double red, double green, double blue); > static constexpr uint16_t threshold(float value); > static constexpr uint16_t gainValue(double gain); > > -- > 2.30.2 >
Daniel Scally <dan.scally@ideasonboard.com> writes: > Use the centralised libipa helpers instead of open coding common > functions. > > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com> > --- > Changes in v3: > > - None > > Changes in v2: > > - Dropped the ipa:: prefix for function calls > > src/ipa/ipu3/algorithms/agc.cpp | 7 ++++--- > src/ipa/ipu3/algorithms/awb.cpp | 32 ++------------------------------ > src/ipa/ipu3/algorithms/awb.h | 1 - > 3 files changed, 6 insertions(+), 34 deletions(-) > > diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp > index c5f3d8f0..466b3fb3 100644 > --- a/src/ipa/ipu3/algorithms/agc.cpp > +++ b/src/ipa/ipu3/algorithms/agc.cpp > @@ -17,6 +17,7 @@ > > #include <libcamera/ipa/core_ipa_interface.h> > > +#include "libipa/colours.h" > #include "libipa/histogram.h" > > /** > @@ -185,9 +186,9 @@ double Agc::estimateLuminance(double gain) const > blueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0); > } > > - double ySum = redSum * rGain_ * 0.299 > - + greenSum * gGain_ * 0.587 > - + blueSum * bGain_ * 0.114; > + double ySum = rec601LuminanceFromRGB(redSum * rGain_, > + greenSum * gGain_, > + blueSum * bGain_); > > return ySum / (bdsGrid_.height * bdsGrid_.width) / 255; > } > diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp > index 4d6e3994..c3c8b074 100644 > --- a/src/ipa/ipu3/algorithms/awb.cpp > +++ b/src/ipa/ipu3/algorithms/awb.cpp > @@ -13,6 +13,8 @@ > > #include <libcamera/control_ids.h> > > +#include "libipa/colours.h" > + > /** > * \file awb.h > */ > @@ -301,36 +303,6 @@ void Awb::prepare(IPAContext &context, > params->use.acc_ccm = 1; > } > > -/** > - * The function estimates the correlated color temperature using > - * from RGB color space input. > - * In physics and color science, the Planckian locus or black body locus is > - * the path or locus that the color of an incandescent black body would take > - * in a particular chromaticity space as the blackbody temperature changes. > - * > - * If a narrow range of color temperatures is considered (those encapsulating > - * daylight being the most practical case) one can approximate the Planckian > - * locus in order to calculate the CCT in terms of chromaticity coordinates. > - * > - * More detailed information can be found in: > - * https://en.wikipedia.org/wiki/Color_temperature#Approximation > - */ > -uint32_t Awb::estimateCCT(double red, double green, double blue) > -{ > - /* Convert the RGB values to CIE tristimulus values (XYZ) */ > - double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue); > - double Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue); > - double Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue); > - > - /* Calculate the normalized chromaticity values */ > - double x = X / (X + Y + Z); > - double y = Y / (X + Y + Z); > - > - /* Calculate CCT */ > - double n = (x - 0.3320) / (0.1858 - y); > - return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33; > -} > - > /* Generate an RGB vector with the average values for each zone */ > void Awb::generateZones() > { > diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h > index c0202823..a13c49ac 100644 > --- a/src/ipa/ipu3/algorithms/awb.h > +++ b/src/ipa/ipu3/algorithms/awb.h > @@ -75,7 +75,6 @@ private: > void generateAwbStats(const ipu3_uapi_stats_3a *stats); > void clearAwbStats(); > void awbGreyWorld(); > - uint32_t estimateCCT(double red, double green, double blue); > static constexpr uint16_t threshold(float value); > static constexpr uint16_t gainValue(double gain);
Hi Dan, Thank you for the patch. On Fri, Nov 15, 2024 at 07:46:24AM +0000, Daniel Scally wrote: > Use the centralised libipa helpers instead of open coding common > functions. > > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > Changes in v3: > > - None > > Changes in v2: > > - Dropped the ipa:: prefix for function calls > > src/ipa/ipu3/algorithms/agc.cpp | 7 ++++--- > src/ipa/ipu3/algorithms/awb.cpp | 32 ++------------------------------ > src/ipa/ipu3/algorithms/awb.h | 1 - > 3 files changed, 6 insertions(+), 34 deletions(-) > > diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp > index c5f3d8f0..466b3fb3 100644 > --- a/src/ipa/ipu3/algorithms/agc.cpp > +++ b/src/ipa/ipu3/algorithms/agc.cpp > @@ -17,6 +17,7 @@ > > #include <libcamera/ipa/core_ipa_interface.h> > > +#include "libipa/colours.h" > #include "libipa/histogram.h" > > /** > @@ -185,9 +186,9 @@ double Agc::estimateLuminance(double gain) const > blueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0); > } > > - double ySum = redSum * rGain_ * 0.299 > - + greenSum * gGain_ * 0.587 > - + blueSum * bGain_ * 0.114; > + double ySum = rec601LuminanceFromRGB(redSum * rGain_, > + greenSum * gGain_, > + blueSum * bGain_); > > return ySum / (bdsGrid_.height * bdsGrid_.width) / 255; > } > diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp > index 4d6e3994..c3c8b074 100644 > --- a/src/ipa/ipu3/algorithms/awb.cpp > +++ b/src/ipa/ipu3/algorithms/awb.cpp > @@ -13,6 +13,8 @@ > > #include <libcamera/control_ids.h> > > +#include "libipa/colours.h" > + > /** > * \file awb.h > */ > @@ -301,36 +303,6 @@ void Awb::prepare(IPAContext &context, > params->use.acc_ccm = 1; > } > > -/** > - * The function estimates the correlated color temperature using > - * from RGB color space input. > - * In physics and color science, the Planckian locus or black body locus is > - * the path or locus that the color of an incandescent black body would take > - * in a particular chromaticity space as the blackbody temperature changes. > - * > - * If a narrow range of color temperatures is considered (those encapsulating > - * daylight being the most practical case) one can approximate the Planckian > - * locus in order to calculate the CCT in terms of chromaticity coordinates. > - * > - * More detailed information can be found in: > - * https://en.wikipedia.org/wiki/Color_temperature#Approximation > - */ > -uint32_t Awb::estimateCCT(double red, double green, double blue) > -{ > - /* Convert the RGB values to CIE tristimulus values (XYZ) */ > - double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue); > - double Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue); > - double Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue); > - > - /* Calculate the normalized chromaticity values */ > - double x = X / (X + Y + Z); > - double y = Y / (X + Y + Z); > - > - /* Calculate CCT */ > - double n = (x - 0.3320) / (0.1858 - y); > - return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33; > -} > - > /* Generate an RGB vector with the average values for each zone */ > void Awb::generateZones() > { > diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h > index c0202823..a13c49ac 100644 > --- a/src/ipa/ipu3/algorithms/awb.h > +++ b/src/ipa/ipu3/algorithms/awb.h > @@ -75,7 +75,6 @@ private: > void generateAwbStats(const ipu3_uapi_stats_3a *stats); > void clearAwbStats(); > void awbGreyWorld(); > - uint32_t estimateCCT(double red, double green, double blue); > static constexpr uint16_t threshold(float value); > static constexpr uint16_t gainValue(double gain); >
diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index c5f3d8f0..466b3fb3 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -17,6 +17,7 @@ #include <libcamera/ipa/core_ipa_interface.h> +#include "libipa/colours.h" #include "libipa/histogram.h" /** @@ -185,9 +186,9 @@ double Agc::estimateLuminance(double gain) const blueSum += std::min(std::get<2>(rgbTriples_[i]) * gain, 255.0); } - double ySum = redSum * rGain_ * 0.299 - + greenSum * gGain_ * 0.587 - + blueSum * bGain_ * 0.114; + double ySum = rec601LuminanceFromRGB(redSum * rGain_, + greenSum * gGain_, + blueSum * bGain_); return ySum / (bdsGrid_.height * bdsGrid_.width) / 255; } diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 4d6e3994..c3c8b074 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -13,6 +13,8 @@ #include <libcamera/control_ids.h> +#include "libipa/colours.h" + /** * \file awb.h */ @@ -301,36 +303,6 @@ void Awb::prepare(IPAContext &context, params->use.acc_ccm = 1; } -/** - * The function estimates the correlated color temperature using - * from RGB color space input. - * In physics and color science, the Planckian locus or black body locus is - * the path or locus that the color of an incandescent black body would take - * in a particular chromaticity space as the blackbody temperature changes. - * - * If a narrow range of color temperatures is considered (those encapsulating - * daylight being the most practical case) one can approximate the Planckian - * locus in order to calculate the CCT in terms of chromaticity coordinates. - * - * More detailed information can be found in: - * https://en.wikipedia.org/wiki/Color_temperature#Approximation - */ -uint32_t Awb::estimateCCT(double red, double green, double blue) -{ - /* Convert the RGB values to CIE tristimulus values (XYZ) */ - double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue); - double Y = (-0.32466) * (red) + (1.57837) * (green) + (-0.73191) * (blue); - double Z = (-0.68202) * (red) + (0.77073) * (green) + (0.56332) * (blue); - - /* Calculate the normalized chromaticity values */ - double x = X / (X + Y + Z); - double y = Y / (X + Y + Z); - - /* Calculate CCT */ - double n = (x - 0.3320) / (0.1858 - y); - return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33; -} - /* Generate an RGB vector with the average values for each zone */ void Awb::generateZones() { diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index c0202823..a13c49ac 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -75,7 +75,6 @@ private: void generateAwbStats(const ipu3_uapi_stats_3a *stats); void clearAwbStats(); void awbGreyWorld(); - uint32_t estimateCCT(double red, double green, double blue); static constexpr uint16_t threshold(float value); static constexpr uint16_t gainValue(double gain);
Use the centralised libipa helpers instead of open coding common functions. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com> --- Changes in v3: - None Changes in v2: - Dropped the ipa:: prefix for function calls src/ipa/ipu3/algorithms/agc.cpp | 7 ++++--- src/ipa/ipu3/algorithms/awb.cpp | 32 ++------------------------------ src/ipa/ipu3/algorithms/awb.h | 1 - 3 files changed, 6 insertions(+), 34 deletions(-)