ipa: raspberrypi: Use the generic statistics structure in the algorithms

Repurpose the StatisticsPtr type from being a shared_ptr<bcm2835_isp_stats> to
shared_ptr<RPiController::Statistics>. This removes any hardware specific header
files and structures from the algorithms source code.

Add a new function in the Raspberry Pi IPA to populate the generic statistics
structure from the values provided by the hardware in the bcm2835_isp_stats
structure.

Update the Lux, AWB, AGC, ALSC, Contrast, and Focus algorithms to use the
generic statistics structure appropriately in their calculations. Additionally,
remove references to any hardware specific headers and defines in these source
files.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Naushir Patuck 2023-02-09 12:47:35 +00:00 committed by Kieran Bingham
parent e8dd0fdc83
commit 6d60f264d1
15 changed files with 121 additions and 87 deletions

View file

@ -54,6 +54,7 @@
#include "metadata.h"
#include "sharpen_algorithm.h"
#include "sharpen_status.h"
#include "statistics.h"
namespace libcamera {
@ -152,6 +153,7 @@ private:
void prepareISP(const ISPConfig &data);
void reportMetadata(unsigned int ipaContext);
void fillDeviceStatus(const ControlList &sensorControls, unsigned int ipaContext);
RPiController::StatisticsPtr fillStatistics(bcm2835_isp_stats *stats) const;
void processStats(unsigned int bufferId, unsigned int ipaContext);
void applyFrameDurations(Duration minFrameDuration, Duration maxFrameDuration);
void applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls);
@ -1364,6 +1366,46 @@ void IPARPi::fillDeviceStatus(const ControlList &sensorControls, unsigned int ip
rpiMetadata_[ipaContext].set("device.status", deviceStatus);
}
RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) const
{
using namespace RPiController;
unsigned int i;
StatisticsPtr statistics =
std::make_unique<Statistics>(Statistics::AgcStatsPos::PreWb, Statistics::ColourStatsPos::PostLsc);
/* RGB histograms are not used, so do not populate them. */
statistics->yHist = RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS);
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 },
stats->awb_stats[i].counted,
stats->awb_stats[i].notcounted });
/*
* 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 },
stats->agc_stats[i].counted,
stats->awb_stats[i].notcounted });
statistics->focusRegions.init({ 4, 3 });
for (i = 0; i < statistics->focusRegions.numRegions(); i++)
statistics->focusRegions.set(i, { stats->focus_stats[i].contrast_val[1][1] / 1000,
stats->focus_stats[i].contrast_val_num[1][1],
stats->focus_stats[i].contrast_val_num[1][0] });
return statistics;
}
void IPARPi::processStats(unsigned int bufferId, unsigned int ipaContext)
{
RPiController::Metadata &rpiMetadata = rpiMetadata_[ipaContext];
@ -1376,7 +1418,7 @@ void IPARPi::processStats(unsigned int bufferId, unsigned int ipaContext)
Span<uint8_t> mem = it->second.planes()[0];
bcm2835_isp_stats *stats = reinterpret_cast<bcm2835_isp_stats *>(mem.data());
RPiController::StatisticsPtr statistics = std::make_shared<bcm2835_isp_stats>(*stats);
RPiController::StatisticsPtr statistics = fillStatistics(stats);
helper_->process(statistics, rpiMetadata);
controller_.process(statistics, &rpiMetadata);