Message ID | 20231006132000.23504-11-naush@raspberrypi.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Naush On Fri, Oct 06, 2023 at 02:19:50PM +0100, Naushir Patuck via libcamera-devel wrote: > Prepare the AWB algorithm to support the PiSP hardware. The key change > is to factor in the LS correction in the AWB zone statistics. This is > different from VC4 where the LS correction happens before statistics > gathering. > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Thanks j > --- > src/ipa/rpi/controller/rpi/awb.cpp | 29 ++++++++++++++++++++--------- > 1 file changed, 20 insertions(+), 9 deletions(-) > > diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp > index ef3435d66106..5ae0c2fad6e9 100644 > --- a/src/ipa/rpi/controller/rpi/awb.cpp > +++ b/src/ipa/rpi/controller/rpi/awb.cpp > @@ -12,6 +12,7 @@ > > #include "../lux_status.h" > > +#include "alsc_status.h" > #include "awb.h" > > using namespace RPiController; > @@ -398,18 +399,28 @@ void Awb::asyncFunc() > } > > static void generateStats(std::vector<Awb::RGB> &zones, > - RgbyRegions &stats, double minPixels, > - double minG) > + StatisticsPtr &stats, double minPixels, > + double minG, Metadata &globalMetadata) > { > - for (auto const ®ion : stats) { > + std::scoped_lock<RPiController::Metadata> l(globalMetadata); > + > + for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) { > Awb::RGB zone; > + auto ®ion = stats->awbRegions.get(i); > if (region.counted >= minPixels) { > zone.G = region.val.gSum / region.counted; > - if (zone.G >= minG) { > - zone.R = region.val.rSum / region.counted; > - zone.B = region.val.bSum / region.counted; > - zones.push_back(zone); > + if (zone.G < minG) > + continue; > + zone.R = region.val.rSum / region.counted; > + zone.B = region.val.bSum / region.counted; > + /* Factor in the ALSC applied colour shading correction if required. */ > + const AlscStatus *alscStatus = globalMetadata.getLocked<AlscStatus>("alsc.status"); > + if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) { > + zone.R *= alscStatus->r[i]; > + zone.G *= alscStatus->g[i]; > + zone.B *= alscStatus->b[i]; > } > + zones.push_back(zone); > } > } > } > @@ -421,8 +432,8 @@ void Awb::prepareStats() > * LSC has already been applied to the stats in this pipeline, so stop > * any LSC compensation. We also ignore config_.fast in this version. > */ > - generateStats(zones_, statistics_->awbRegions, config_.minPixels, > - config_.minG); > + generateStats(zones_, statistics_, config_.minPixels, > + config_.minG, getGlobalMetadata()); > /* > * apply sensitivities, so values appear to come from our "canonical" > * sensor. > -- > 2.34.1 >
diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index ef3435d66106..5ae0c2fad6e9 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -12,6 +12,7 @@ #include "../lux_status.h" +#include "alsc_status.h" #include "awb.h" using namespace RPiController; @@ -398,18 +399,28 @@ void Awb::asyncFunc() } static void generateStats(std::vector<Awb::RGB> &zones, - RgbyRegions &stats, double minPixels, - double minG) + StatisticsPtr &stats, double minPixels, + double minG, Metadata &globalMetadata) { - for (auto const ®ion : stats) { + std::scoped_lock<RPiController::Metadata> l(globalMetadata); + + for (unsigned int i = 0; i < stats->awbRegions.numRegions(); i++) { Awb::RGB zone; + auto ®ion = stats->awbRegions.get(i); if (region.counted >= minPixels) { zone.G = region.val.gSum / region.counted; - if (zone.G >= minG) { - zone.R = region.val.rSum / region.counted; - zone.B = region.val.bSum / region.counted; - zones.push_back(zone); + if (zone.G < minG) + continue; + zone.R = region.val.rSum / region.counted; + zone.B = region.val.bSum / region.counted; + /* Factor in the ALSC applied colour shading correction if required. */ + const AlscStatus *alscStatus = globalMetadata.getLocked<AlscStatus>("alsc.status"); + if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) { + zone.R *= alscStatus->r[i]; + zone.G *= alscStatus->g[i]; + zone.B *= alscStatus->b[i]; } + zones.push_back(zone); } } } @@ -421,8 +432,8 @@ void Awb::prepareStats() * LSC has already been applied to the stats in this pipeline, so stop * any LSC compensation. We also ignore config_.fast in this version. */ - generateStats(zones_, statistics_->awbRegions, config_.minPixels, - config_.minG); + generateStats(zones_, statistics_, config_.minPixels, + config_.minG, getGlobalMetadata()); /* * apply sensitivities, so values appear to come from our "canonical" * sensor.