[libcamera-devel] [PATCH v1 5/5] ipa: raspberrypi: Normalise region sums to 16-bits
Naushir Patuck
naush at raspberrypi.com
Tue Nov 22 12:22:24 CET 2022
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
agonistic about pipline depth, so do not need chaning.
Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
---
src/ipa/raspberrypi/controller/rpi/agc.cpp | 10 ++++------
src/ipa/raspberrypi/raspberrypi.cpp | 21 ++++++++++++++-------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp
index 79c83e0a9eae..358af8f2544b 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 ¶ms)
{
const YamlObject &yamlWeights = params["weights"];
@@ -593,9 +591,9 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {
uint32_t counted, uncounted;
auto s = stats->agcRegions.get(i, counted, uncounted);
- double rAcc = std::min<double>(s.rSum * gain, ((1 << PipelineBits) - 1) * counted);
- double gAcc = std::min<double>(s.gSum * gain, ((1 << PipelineBits) - 1) * counted);
- double bAcc = std::min<double>(s.bSum * gain, ((1 << PipelineBits) - 1) * counted);
+ double rAcc = std::min<double>(s.rSum * gain, ((1 << 16) - 1) * counted);
+ double gAcc = std::min<double>(s.gSum * gain, ((1 << 16) - 1) * counted);
+ double bAcc = std::min<double>(s.bSum * gain, ((1 << 16) - 1) * counted);
rSum += rAcc * weights[i];
gSum += gAcc * weights[i];
bSum += bAcc * weights[i];
@@ -608,7 +606,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 / (1 << 16);
}
/*
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 8fcfa0b3ea50..fcecd60bcf6d 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -1132,19 +1132,26 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co
/* RGB histograms are not used, so do not populate them. */
statistics->yHist = std::move(RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS));
+ /*
+ * All region sums are based on a 13-bit pipeline bit-depth. Normalise
+ * this to 16-bits for the AGC/AWB/ALSC algorithms.
+ */
statistics->awbRegions.init(DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y);
for (i = 0; i < statistics->awbRegions.numRegions(); i++)
- statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum,
- stats->awb_stats[i].g_sum,
- stats->awb_stats[i].b_sum },
+ statistics->awbRegions.set(i, { stats->awb_stats[i].r_sum << 3,
+ stats->awb_stats[i].g_sum << 3,
+ stats->awb_stats[i].b_sum << 3 },
stats->awb_stats[i].counted, stats->awb_stats[i].notcounted);
- /* There are only ever 15 regions computed by the firmware, but the HW defines AGC_REGIONS == 16! */
+ /*
+ * There are only ever 15 regions computed by the firmware due to zoning,
+ * but the HW defines AGC_REGIONS == 16!
+ */
statistics->agcRegions.init(15);
for (i = 0; i < statistics->agcRegions.numRegions(); i++)
- statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum,
- stats->agc_stats[i].g_sum,
- stats->agc_stats[i].b_sum },
+ statistics->agcRegions.set(i, { stats->agc_stats[i].r_sum << 3,
+ stats->agc_stats[i].g_sum << 3,
+ stats->agc_stats[i].b_sum << 3 },
stats->agc_stats[i].counted, 0);
statistics->focusRegions.init(4, 3);
--
2.25.1
More information about the libcamera-devel
mailing list