summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/controller/rpi/agc.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2023-02-03 09:17:34 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2023-02-09 13:11:44 +0000
commit61b43e50e76c16456b5d1873b6efd8aa0e848d6b (patch)
treecb7855fde6db4f137f291cf97e10e47a8db246bd /src/ipa/raspberrypi/controller/rpi/agc.cpp
parent6d60f264d1e05bd19640b66bc72bda9f303bf72d (diff)
ipa: raspberrypi: Normalise region sums to 16-bits
The VC4 ISP uses a pipeline bit-depth of 13-bits. The AGC algorithm needs to know this bit-depth when computing the Y value for the image. Instead of hardcoding the VC4 bit-depth in the AGC source code, normalise all region sums to 16-bits when filling the Statistics structure. AWB and ALSC are agnostic about pipeline depth, so do not need changing. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/ipa/raspberrypi/controller/rpi/agc.cpp')
-rw-r--r--src/ipa/raspberrypi/controller/rpi/agc.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index 868c30f0..ea0c82b5 100644
--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp
@@ -28,8 +28,6 @@ LOG_DEFINE_CATEGORY(RPiAgc)
#define NAME "rpi.agc"
-static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */
-
int AgcMeteringMode::read(const libcamera::YamlObject &params)
{
const YamlObject &yamlWeights = params["weights"];
@@ -586,6 +584,7 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata)
static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
double weights[], double gain)
{
+ constexpr unsigned int maxVal = 1 << Statistics::NormalisationFactorPow2;
/*
* Note how the calculation below means that equal weights give you
* "average" metering (i.e. all pixels equally important).
@@ -593,9 +592,9 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0;
for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {
auto &region = stats->agcRegions.get(i);
- double rAcc = std::min<double>(region.val.rSum * gain, ((1 << PipelineBits) - 1) * region.counted);
- double gAcc = std::min<double>(region.val.gSum * gain, ((1 << PipelineBits) - 1) * region.counted);
- double bAcc = std::min<double>(region.val.bSum * gain, ((1 << PipelineBits) - 1) * region.counted);
+ double rAcc = std::min<double>(region.val.rSum * gain, (maxVal - 1) * region.counted);
+ double gAcc = std::min<double>(region.val.gSum * gain, (maxVal - 1) * region.counted);
+ double bAcc = std::min<double>(region.val.bSum * gain, (maxVal - 1) * region.counted);
rSum += rAcc * weights[i];
gSum += gAcc * weights[i];
bSum += bAcc * weights[i];
@@ -608,7 +607,7 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
double ySum = rSum * awb.gainR * .299 +
gSum * awb.gainG * .587 +
bSum * awb.gainB * .114;
- return ySum / pixelSum / (1 << PipelineBits);
+ return ySum / pixelSum / maxVal;
}
/*