summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/raspberrypi.cpp
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2023-03-27 13:20:30 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2023-03-31 13:29:18 +0100
commitac7511dc4c594f567ddff27ccc02c30bf6c00bfd (patch)
tree539bdcc2e877095b97f9455449464d86882f5a3e /src/ipa/raspberrypi/raspberrypi.cpp
parent43f57f26b44648e609f66770e43294a361bd6657 (diff)
ipa: raspberrypi: Generalise the focus reporting code
Use the generalised focus statistics structure to compute the centre window focus FoM value. This avoids needed to hard-code a specific grid size. Remove the focus reporting algorithm as the functionality is duplicated by this bit of IPA code. Remove focus_status.h as it is no longer needed. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@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.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index e2662938..9f3f3ac3 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -50,7 +50,6 @@
#include "denoise_algorithm.h"
#include "denoise_status.h"
#include "dpc_status.h"
-#include "focus_status.h"
#include "geq_status.h"
#include "lux_status.h"
#include "metadata.h"
@@ -642,14 +641,28 @@ void IPARPi::reportMetadata(unsigned int ipaContext)
static_cast<int32_t>(blackLevelStatus->blackLevelG),
static_cast<int32_t>(blackLevelStatus->blackLevelB) });
- FocusStatus *focusStatus = rpiMetadata.getLocked<FocusStatus>("focus.status");
- if (focusStatus && focusStatus->num == 12) {
+ RPiController::FocusRegions *focusStatus =
+ rpiMetadata.getLocked<RPiController::FocusRegions>("focus.status");
+ if (focusStatus) {
/*
- * We get a 4x3 grid of regions by default. Calculate the average
- * FoM over the central two positions to give an overall scene FoM.
- * This can change later if it is not deemed suitable.
+ * Calculate the average FoM over the central (symmetric) positions
+ * to give an overall scene FoM. This can change later if it is
+ * not deemed suitable.
*/
- int32_t focusFoM = (focusStatus->focusMeasures[5] + focusStatus->focusMeasures[6]) / 2;
+ libcamera::Size size = focusStatus->size();
+ unsigned rows = size.height;
+ unsigned cols = size.width;
+
+ uint64_t sum = 0;
+ unsigned int numRegions = 0;
+ for (unsigned r = rows / 3; r < rows - rows / 3; ++r) {
+ for (unsigned c = cols / 4; c < cols - cols / 4; ++c) {
+ sum += focusStatus->get({ (int)c, (int)r }).val;
+ numRegions++;
+ }
+ }
+
+ uint32_t focusFoM = (sum / numRegions) >> 16;
libcameraMetadata_.set(controls::FocusFoM, focusFoM);
}
@@ -1428,7 +1441,6 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co
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;
}
@@ -1445,6 +1457,10 @@ 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 = fillStatistics(stats);
+
+ /* Save the focus stats in the metadata structure to report out later. */
+ rpiMetadata_[ipaContext].set("focus.status", statistics->focusRegions);
+
helper_->process(statistics, rpiMetadata);
controller_.process(statistics, &rpiMetadata);