Message ID | 20250326090849.15494-3-mzamazal@redhat.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Quoting Milan Zamazal (2025-03-26 09:08:39) > Rather than using a custom struct to represent RGB values, let's use the > corresponding type and its facilities. > > Signed-off-by: Milan Zamazal <mzamazal@redhat.com> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Milan Zamazal <mzamazal@redhat.com> > --- > src/ipa/simple/algorithms/awb.cpp | 16 +++++++++------- > src/ipa/simple/algorithms/lut.cpp | 14 ++++---------- > src/ipa/simple/ipa_context.h | 8 +++----- > 3 files changed, 16 insertions(+), 22 deletions(-) > > diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp > index 1efc7090..310be6a7 100644 > --- a/src/ipa/simple/algorithms/awb.cpp > +++ b/src/ipa/simple/algorithms/awb.cpp > @@ -25,7 +25,7 @@ int Awb::configure(IPAContext &context, > [[maybe_unused]] const IPAConfigInfo &configInfo) > { > auto &gains = context.activeState.awb.gains; > - gains.red = gains.green = gains.blue = 1.0; > + gains = { { 1.0, 1.0, 1.0 } }; > > return 0; > } > @@ -56,16 +56,18 @@ void Awb::process(IPAContext &context, > * Clamp max gain at 4.0, this also avoids 0 division. > */ > auto &gains = context.activeState.awb.gains; > - gains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR; > - gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB; > - /* Green gain is fixed to 1.0 */ > + gains = { { > + sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR, > + 1.0, > + sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB, > + } }; > > - RGB<double> rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } }; > + RGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } }; > context.activeState.awb.temperatureK = estimateCCT(rgbGains); > > LOG(IPASoftAwb, Debug) > - << "gain R/B: " << gains.red << "/" << gains.blue > - << "; temperature: " << context.activeState.awb.temperatureK; > + << "gain R/B: " << gains << "; temperature: " > + << context.activeState.awb.temperatureK; > } > > REGISTER_IPA_ALGORITHM(Awb, "Awb") > diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp > index a2e11d3b..83df71a9 100644 > --- a/src/ipa/simple/algorithms/lut.cpp > +++ b/src/ipa/simple/algorithms/lut.cpp > @@ -103,16 +103,10 @@ void Lut::prepare(IPAContext &context, > const double div = static_cast<double>(DebayerParams::kRGBLookupSize) / > gammaTableSize; > /* Apply gamma after gain! */ > - unsigned int idx; > - idx = std::min({ static_cast<unsigned int>(i * gains.red / div), > - gammaTableSize - 1 }); > - params->red[i] = gammaTable[idx]; > - idx = std::min({ static_cast<unsigned int>(i * gains.green / div), > - gammaTableSize - 1 }); > - params->green[i] = gammaTable[idx]; > - idx = std::min({ static_cast<unsigned int>(i * gains.blue / div), > - gammaTableSize - 1 }); > - params->blue[i] = gammaTable[idx]; > + const RGB<double> lutGains = (gains * i / div).min(gammaTableSize - 1); > + params->red[i] = gammaTable[static_cast<unsigned int>(lutGains.r())]; > + params->green[i] = gammaTable[static_cast<unsigned int>(lutGains.g())]; > + params->blue[i] = gammaTable[static_cast<unsigned int>(lutGains.b())]; > } > } > > diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h > index 607af45a..6a285414 100644 > --- a/src/ipa/simple/ipa_context.h > +++ b/src/ipa/simple/ipa_context.h > @@ -13,6 +13,8 @@ > > #include <libcamera/controls.h> > > +#include "libcamera/internal/vector.h" > + > #include <libipa/fc_queue.h> > > namespace libcamera { > @@ -36,11 +38,7 @@ struct IPAActiveState { > } blc; > > struct { > - struct { > - double red; > - double green; > - double blue; > - } gains; > + RGB<double> gains; > unsigned int temperatureK; > } awb; > > -- > 2.49.0 >
diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index 1efc7090..310be6a7 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -25,7 +25,7 @@ int Awb::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { auto &gains = context.activeState.awb.gains; - gains.red = gains.green = gains.blue = 1.0; + gains = { { 1.0, 1.0, 1.0 } }; return 0; } @@ -56,16 +56,18 @@ void Awb::process(IPAContext &context, * Clamp max gain at 4.0, this also avoids 0 division. */ auto &gains = context.activeState.awb.gains; - gains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR; - gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB; - /* Green gain is fixed to 1.0 */ + gains = { { + sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR, + 1.0, + sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB, + } }; - RGB<double> rgbGains{ { 1 / gains.red, 1 / gains.green, 1 / gains.blue } }; + RGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } }; context.activeState.awb.temperatureK = estimateCCT(rgbGains); LOG(IPASoftAwb, Debug) - << "gain R/B: " << gains.red << "/" << gains.blue - << "; temperature: " << context.activeState.awb.temperatureK; + << "gain R/B: " << gains << "; temperature: " + << context.activeState.awb.temperatureK; } REGISTER_IPA_ALGORITHM(Awb, "Awb") diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index a2e11d3b..83df71a9 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -103,16 +103,10 @@ void Lut::prepare(IPAContext &context, const double div = static_cast<double>(DebayerParams::kRGBLookupSize) / gammaTableSize; /* Apply gamma after gain! */ - unsigned int idx; - idx = std::min({ static_cast<unsigned int>(i * gains.red / div), - gammaTableSize - 1 }); - params->red[i] = gammaTable[idx]; - idx = std::min({ static_cast<unsigned int>(i * gains.green / div), - gammaTableSize - 1 }); - params->green[i] = gammaTable[idx]; - idx = std::min({ static_cast<unsigned int>(i * gains.blue / div), - gammaTableSize - 1 }); - params->blue[i] = gammaTable[idx]; + const RGB<double> lutGains = (gains * i / div).min(gammaTableSize - 1); + params->red[i] = gammaTable[static_cast<unsigned int>(lutGains.r())]; + params->green[i] = gammaTable[static_cast<unsigned int>(lutGains.g())]; + params->blue[i] = gammaTable[static_cast<unsigned int>(lutGains.b())]; } } diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 607af45a..6a285414 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -13,6 +13,8 @@ #include <libcamera/controls.h> +#include "libcamera/internal/vector.h" + #include <libipa/fc_queue.h> namespace libcamera { @@ -36,11 +38,7 @@ struct IPAActiveState { } blc; struct { - struct { - double red; - double green; - double blue; - } gains; + RGB<double> gains; unsigned int temperatureK; } awb;