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>
This commit is contained in:
parent
6d60f264d1
commit
61b43e50e7
2 changed files with 17 additions and 12 deletions
|
@ -28,8 +28,6 @@ LOG_DEFINE_CATEGORY(RPiAgc)
|
||||||
|
|
||||||
#define NAME "rpi.agc"
|
#define NAME "rpi.agc"
|
||||||
|
|
||||||
static constexpr unsigned int PipelineBits = 13; /* seems to be a 13-bit pipeline */
|
|
||||||
|
|
||||||
int AgcMeteringMode::read(const libcamera::YamlObject ¶ms)
|
int AgcMeteringMode::read(const libcamera::YamlObject ¶ms)
|
||||||
{
|
{
|
||||||
const YamlObject &yamlWeights = params["weights"];
|
const YamlObject &yamlWeights = params["weights"];
|
||||||
|
@ -586,6 +584,7 @@ void Agc::fetchAwbStatus(Metadata *imageMetadata)
|
||||||
static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
|
static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
|
||||||
double weights[], double gain)
|
double weights[], double gain)
|
||||||
{
|
{
|
||||||
|
constexpr unsigned int maxVal = 1 << Statistics::NormalisationFactorPow2;
|
||||||
/*
|
/*
|
||||||
* Note how the calculation below means that equal weights give you
|
* Note how the calculation below means that equal weights give you
|
||||||
* "average" metering (i.e. all pixels equally important).
|
* "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;
|
double rSum = 0, gSum = 0, bSum = 0, pixelSum = 0;
|
||||||
for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {
|
for (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {
|
||||||
auto ®ion = stats->agcRegions.get(i);
|
auto ®ion = stats->agcRegions.get(i);
|
||||||
double rAcc = std::min<double>(region.val.rSum * 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, ((1 << PipelineBits) - 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, ((1 << PipelineBits) - 1) * region.counted);
|
double bAcc = std::min<double>(region.val.bSum * gain, (maxVal - 1) * region.counted);
|
||||||
rSum += rAcc * weights[i];
|
rSum += rAcc * weights[i];
|
||||||
gSum += gAcc * weights[i];
|
gSum += gAcc * weights[i];
|
||||||
bSum += bAcc * weights[i];
|
bSum += bAcc * weights[i];
|
||||||
|
@ -608,7 +607,7 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,
|
||||||
double ySum = rSum * awb.gainR * .299 +
|
double ySum = rSum * awb.gainR * .299 +
|
||||||
gSum * awb.gainG * .587 +
|
gSum * awb.gainG * .587 +
|
||||||
bSum * awb.gainB * .114;
|
bSum * awb.gainB * .114;
|
||||||
return ySum / pixelSum / (1 << PipelineBits);
|
return ySum / pixelSum / maxVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1377,11 +1377,17 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co
|
||||||
/* RGB histograms are not used, so do not populate them. */
|
/* RGB histograms are not used, so do not populate them. */
|
||||||
statistics->yHist = RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS);
|
statistics->yHist = 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.
|
||||||
|
*/
|
||||||
|
constexpr unsigned int scale = Statistics::NormalisationFactorPow2 - 13;
|
||||||
|
|
||||||
statistics->awbRegions.init({ DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y });
|
statistics->awbRegions.init({ DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y });
|
||||||
for (i = 0; i < statistics->awbRegions.numRegions(); i++)
|
for (i = 0; i < statistics->awbRegions.numRegions(); i++)
|
||||||
statistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum,
|
statistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum << scale,
|
||||||
stats->awb_stats[i].g_sum,
|
stats->awb_stats[i].g_sum << scale,
|
||||||
stats->awb_stats[i].b_sum },
|
stats->awb_stats[i].b_sum << scale },
|
||||||
stats->awb_stats[i].counted,
|
stats->awb_stats[i].counted,
|
||||||
stats->awb_stats[i].notcounted });
|
stats->awb_stats[i].notcounted });
|
||||||
|
|
||||||
|
@ -1391,9 +1397,9 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co
|
||||||
*/
|
*/
|
||||||
statistics->agcRegions.init(15);
|
statistics->agcRegions.init(15);
|
||||||
for (i = 0; i < statistics->agcRegions.numRegions(); i++)
|
for (i = 0; i < statistics->agcRegions.numRegions(); i++)
|
||||||
statistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum,
|
statistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum << scale,
|
||||||
stats->agc_stats[i].g_sum,
|
stats->agc_stats[i].g_sum << scale,
|
||||||
stats->agc_stats[i].b_sum },
|
stats->agc_stats[i].b_sum << scale },
|
||||||
stats->agc_stats[i].counted,
|
stats->agc_stats[i].counted,
|
||||||
stats->awb_stats[i].notcounted });
|
stats->awb_stats[i].notcounted });
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue