summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/raspberrypi.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2023-02-09 12:47:35 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2023-02-09 13:11:30 +0000
commit6d60f264d1e05bd19640b66bc72bda9f303bf72d (patch)
tree18d98783e0346b315dbeb61ba04af6f12377cb61 /src/ipa/raspberrypi/raspberrypi.cpp
parente8dd0fdc8321dce4c15b55b895e9efb5181ddb4c (diff)
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>
Diffstat (limited to 'src/ipa/raspberrypi/raspberrypi.cpp')
-rw-r--r--src/ipa/raspberrypi/raspberrypi.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 5f7397e2..8c0df0ec 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -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);