@@ -59,6 +59,29 @@ struct ipu3_uapi_grid_config {
__u16 y_end;
} __attribute__((packed));
+/**
+ * struct ipu3_uapi_awb_set_item - Memory layout for each cell in AWB
+ *
+ * @Gr_avg: Green average for red lines in the cell.
+ * @R_avg: Red average in the cell.
+ * @B_avg: Blue average in the cell.
+ * @Gb_avg: Green average for blue lines in the cell.
+ * @sat_ratio: Saturation ratio in the cell.
+ * @padding0: Unused byte for padding.
+ * @padding1: Unused byte for padding.
+ * @padding2: Unused byte for padding.
+ */
+struct ipu3_uapi_awb_set_item {
+ unsigned char Gr_avg;
+ unsigned char R_avg;
+ unsigned char B_avg;
+ unsigned char Gb_avg;
+ unsigned char sat_ratio;
+ unsigned char padding0;
+ unsigned char padding1;
+ unsigned char padding2;
+} __attribute__((packed));
+
/*
* The grid based data is divided into "slices" called set, each slice of setX
* refers to ipu3_uapi_grid_config width * height_per_slice.
@@ -72,7 +95,8 @@ struct ipu3_uapi_grid_config {
IPU3_UAPI_AWB_MD_ITEM_SIZE)
#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \
(IPU3_UAPI_AWB_MAX_SETS * \
- (IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES))
+ (IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES)) / \
+ sizeof(ipu3_uapi_awb_set_item)
/**
@@ -82,7 +106,7 @@ struct ipu3_uapi_grid_config {
* the average values for each color channel.
*/
struct ipu3_uapi_awb_raw_buffer {
- __u8 meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]
+ struct ipu3_uapi_awb_set_item meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]
__attribute__((aligned(32)));
} __attribute__((packed));
@@ -47,9 +47,6 @@ static constexpr uint32_t kMaxExposure = 1976;
static constexpr uint32_t knumHistogramBins = 256;
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()
: frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),
maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s),
@@ -90,15 +87,16 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,
for (j = topleftY;
j < topleftY + (aeRegion.size().height >> grid.block_height_log2);
j++) {
- for (i = startX + startY; i < endX + startY; i += kCellSize) {
+ for (i = startX + startY; i < endX + startY; i++) {
/*
* 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.
* Use the one passed at init time.
*/
- 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];
+ const ipu3_uapi_awb_set_item *currentCell = &stats->awb_raw_buffer.meta_data[i + j * grid.width];
+ if (currentCell->sat_ratio == 0) {
+ uint8_t Gr = currentCell->Gr_avg;
+ uint8_t Gb = currentCell->Gb_avg;
hist[(Gr + Gb) / 2]++;
count++;
}
@@ -234,17 +234,16 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
uint32_t cellY = ((cellPosition / grid.width) / regionHeight) % kAwbStatsSizeY;
uint32_t awbRegionPosition = cellY * kAwbStatsSizeX + cellX;
- cellPosition *= 8;
/* Cast the initial IPU3 structure to simplify the reading */
- Ipu3AwbCell *currentCell = reinterpret_cast<Ipu3AwbCell *>(const_cast<uint8_t *>(&stats->awb_raw_buffer.meta_data[cellPosition]));
- if (currentCell->satRatio == 0) {
+ const ipu3_uapi_awb_set_item *currentCell = &stats->awb_raw_buffer.meta_data[cellPosition];
+ if (currentCell->sat_ratio == 0) {
/* The cell is not saturated, use the current cell */
awbStats_[awbRegionPosition].counted++;
- uint32_t greenValue = currentCell->greenRedAvg + currentCell->greenBlueAvg;
+ uint32_t greenValue = currentCell->Gr_avg + currentCell->Gb_avg;
awbStats_[awbRegionPosition].sum.green += greenValue / 2;
- awbStats_[awbRegionPosition].sum.red += currentCell->redAvg;
- awbStats_[awbRegionPosition].sum.blue += currentCell->blueAvg;
+ awbStats_[awbRegionPosition].sum.red += currentCell->R_avg;
+ awbStats_[awbRegionPosition].sum.blue += currentCell->B_avg;
}
}
}
@@ -23,16 +23,6 @@ namespace ipa::ipu3::algorithms {
static constexpr uint32_t kAwbStatsSizeX = 16;
static constexpr uint32_t kAwbStatsSizeY = 12;
-/* \todo Move the cell layout into intel-ipu3.h kernel header */
-struct Ipu3AwbCell {
- unsigned char greenRedAvg;
- unsigned char redAvg;
- unsigned char blueAvg;
- unsigned char greenBlueAvg;
- unsigned char satRatio;
- unsigned char padding[3];
-} __attribute__((packed));
-
struct Accumulator {
unsigned int counted;
struct {