ipa: ipu3: agc: Rewrite and simplify the brightness loop
Now that we know how the AWB statistics are formatted, use a simplified loop in processBrightness() to parse the green values and get the histogram. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
8437893900
commit
e34ebe008f
2 changed files with 21 additions and 35 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "agc.h"
|
#include "agc.h"
|
||||||
|
#include "awb.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -47,9 +48,6 @@ static constexpr uint32_t kMaxExposure = 1976;
|
||||||
static constexpr uint32_t knumHistogramBins = 256;
|
static constexpr uint32_t knumHistogramBins = 256;
|
||||||
static constexpr double kEvGainTarget = 0.5;
|
static constexpr double kEvGainTarget = 0.5;
|
||||||
|
|
||||||
/* A cell is 8 bytes and contains averages for RGB values and saturation ratio */
|
|
||||||
static constexpr uint8_t kCellSize = 8;
|
|
||||||
|
|
||||||
Agc::Agc()
|
Agc::Agc()
|
||||||
: frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),
|
: frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),
|
||||||
maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s),
|
maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s),
|
||||||
|
@ -57,9 +55,10 @@ Agc::Agc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int Agc::configure([[maybe_unused]] IPAContext &context,
|
int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)
|
||||||
const IPAConfigInfo &configInfo)
|
|
||||||
{
|
{
|
||||||
|
stride_ = context.configuration.grid.stride;
|
||||||
|
|
||||||
lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s
|
lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s
|
||||||
/ configInfo.sensorInfo.pixelRate;
|
/ configInfo.sensorInfo.pixelRate;
|
||||||
maxExposureTime_ = kMaxExposure * lineDuration_;
|
maxExposureTime_ = kMaxExposure * lineDuration_;
|
||||||
|
@ -70,37 +69,22 @@ int Agc::configure([[maybe_unused]] IPAContext &context,
|
||||||
void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,
|
void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,
|
||||||
const ipu3_uapi_grid_config &grid)
|
const ipu3_uapi_grid_config &grid)
|
||||||
{
|
{
|
||||||
const struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid;
|
|
||||||
Rectangle aeRegion = { statsAeGrid.x_start,
|
|
||||||
statsAeGrid.y_start,
|
|
||||||
static_cast<unsigned int>(statsAeGrid.x_end - statsAeGrid.x_start) + 1,
|
|
||||||
static_cast<unsigned int>(statsAeGrid.y_end - statsAeGrid.y_start) + 1 };
|
|
||||||
Point topleft = aeRegion.topLeft();
|
|
||||||
int topleftX = topleft.x >> grid.block_width_log2;
|
|
||||||
int topleftY = topleft.y >> grid.block_height_log2;
|
|
||||||
|
|
||||||
/* Align to the grid cell width and height */
|
|
||||||
uint32_t startX = topleftX << grid.block_width_log2;
|
|
||||||
uint32_t startY = topleftY * grid.width << grid.block_width_log2;
|
|
||||||
uint32_t endX = (startX + (aeRegion.size().width >> grid.block_width_log2)) << grid.block_width_log2;
|
|
||||||
uint32_t i, j;
|
|
||||||
uint32_t count = 0;
|
|
||||||
|
|
||||||
uint32_t hist[knumHistogramBins] = { 0 };
|
uint32_t hist[knumHistogramBins] = { 0 };
|
||||||
for (j = topleftY;
|
|
||||||
j < topleftY + (aeRegion.size().height >> grid.block_height_log2);
|
for (unsigned int cellY = 0; cellY < grid.height; cellY++) {
|
||||||
j++) {
|
for (unsigned int cellX = 0; cellX < grid.width; cellX++) {
|
||||||
for (i = startX + startY; i < endX + startY; i += kCellSize) {
|
uint32_t cellPosition = (cellY * stride_ + cellX)
|
||||||
/*
|
* sizeof(Ipu3AwbCell);
|
||||||
* The grid width (and maybe height) is not reliable.
|
|
||||||
* We observed a bit shift which makes the value 160 to be 32 in the stats grid.
|
const Ipu3AwbCell *cell =
|
||||||
* Use the one passed at init time.
|
reinterpret_cast<const Ipu3AwbCell *>(
|
||||||
*/
|
&stats->awb_raw_buffer.meta_data[cellPosition]
|
||||||
if (stats->awb_raw_buffer.meta_data[i + 4 + j * grid.width] == 0) {
|
);
|
||||||
uint8_t Gr = stats->awb_raw_buffer.meta_data[i + 0 + j * grid.width];
|
|
||||||
uint8_t Gb = stats->awb_raw_buffer.meta_data[i + 3 + j * grid.width];
|
if (cell->satRatio == 0) {
|
||||||
hist[(Gr + Gb) / 2]++;
|
uint8_t gr = cell->greenRedAvg;
|
||||||
count++;
|
uint8_t gb = cell->greenBlueAvg;
|
||||||
|
hist[(gr + gb) / 2]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ private:
|
||||||
Duration prevExposureNoDg_;
|
Duration prevExposureNoDg_;
|
||||||
Duration currentExposure_;
|
Duration currentExposure_;
|
||||||
Duration currentExposureNoDg_;
|
Duration currentExposureNoDg_;
|
||||||
|
|
||||||
|
uint32_t stride_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ipa::ipu3::algorithms */
|
} /* namespace ipa::ipu3::algorithms */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue