summaryrefslogtreecommitdiff
path: root/src/ipa/ipu3/algorithms/af.h
diff options
context:
space:
mode:
authorKate Hsuan <hpa@redhat.com>2022-02-14 17:51:36 +0800
committerKieran Bingham <kieran.bingham@ideasonboard.com>2022-03-15 17:20:50 +0000
commitb608984e78824f8738a089136721b1fe54016248 (patch)
treed24e8665930783f9a90be20274a880412c565d05 /src/ipa/ipu3/algorithms/af.h
parente41854a4e6fde2dd9e2a2a7290670943235776cd (diff)
ipa: ipu3: af: Auto focus for dw9719 Surface Go2 VCM
Since VCM for surface Go 2 (dw9719) had been successfully driven, this Af module can be used to control the VCM and determine the focus value based on the IPU3 AF state. Based on the values from the IPU3 AF buffer, the variance of each focus step is determined and a greedy approach is used to find the maximum variance of the AF state and an appropriate focus value. The grid configuration is implemented as a context. Also, the grid parameter- AF_MIN_BLOCK_WIDTH is set to 4 (default is 3) since if the default value is used, x_start (x_start > 640) will be at an incorrect location of the image (rightmost of the sensor). Signed-off-by: Kate Hsuan <hpa@redhat.com> Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/ipa/ipu3/algorithms/af.h')
-rw-r--r--src/ipa/ipu3/algorithms/af.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h
new file mode 100644
index 00000000..13c7e0e8
--- /dev/null
+++ b/src/ipa/ipu3/algorithms/af.h
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021, Red Hat
+ *
+ * af.h - IPU3 Af algorithm
+ */
+
+#pragma once
+
+#include <linux/intel-ipu3.h>
+
+#include <libcamera/base/utils.h>
+
+#include <libcamera/geometry.h>
+
+#include "algorithm.h"
+
+/* Static variables from repo of chromium */
+static constexpr uint8_t kAfMinGridWidth = 16;
+static constexpr uint8_t kAfMinGridHeight = 16;
+static constexpr uint8_t kAfMaxGridWidth = 32;
+static constexpr uint8_t kAfMaxGridHeight = 24;
+static constexpr uint16_t kAfMinGridBlockWidth = 4;
+static constexpr uint16_t kAfMinGridBlockHeight = 3;
+static constexpr uint16_t kAfMaxGridBlockWidth = 6;
+static constexpr uint16_t kAfMaxGridBlockHeight = 6;
+static constexpr uint16_t kAfDefaultHeightPerSlice = 2;
+
+namespace libcamera {
+
+namespace ipa::ipu3::algorithms {
+
+class Af : public Algorithm
+{
+ /* The format of y_table. From ipu3-ipa repo */
+ typedef struct __attribute__((packed)) y_table_item {
+ uint16_t y1_avg;
+ uint16_t y2_avg;
+ } y_table_item_t;
+public:
+ Af();
+ ~Af() = default;
+
+ void prepare(IPAContext &context, ipu3_uapi_params *params) override;
+ int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
+ void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;
+
+private:
+ void afCoarseScan(IPAContext &context);
+ void afFineScan(IPAContext &context);
+ bool afScan(IPAContext &context, int min_step);
+ void afReset(IPAContext &context);
+ bool afNeedIgnoreFrame();
+ void afIgnoreFrameReset();
+ double afEstimateVariance(y_table_item_t *y_item, uint32_t len,
+ bool isY1);
+ bool afIsOutOfFocus(IPAContext context);
+
+ /* VCM step configuration. It is the current setting of the VCM step. */
+ uint32_t focus_;
+ /* The best VCM step. It is a local optimum VCM step during scanning. */
+ uint32_t bestFocus_;
+ /* Current AF statistic variance. */
+ double currentVariance_;
+ /* The frames are ignore before starting measuring. */
+ uint32_t ignoreCounter_;
+ /* It is used to determine the derivative during scanning */
+ double previousVariance_;
+ /* The designated maximum range of focus scanning. */
+ uint32_t maxStep_;
+ /* If the coarse scan completes, it is set to true. */
+ bool coarseCompleted_;
+ /* If the fine scan completes, it is set to true. */
+ bool fineCompleted_;
+};
+
+} /* namespace ipa::ipu3::algorithms */
+
+} /* namespace libcamera */