libcamera v0.0.1
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
af.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2021, Red Hat
4 *
5 * af.h - IPU3 Af algorithm
6 */
7
8#pragma once
9
10#include <linux/intel-ipu3.h>
11
13
14#include <libcamera/geometry.h>
15
16#include "algorithm.h"
17
18namespace libcamera {
19
20namespace ipa::ipu3::algorithms {
21
22class Af : public Algorithm
23{
24 /* The format of y_table. From ipu3-ipa repo */
25 typedef struct __attribute__((packed)) y_table_item {
26 uint16_t y1_avg;
27 uint16_t y2_avg;
28 } y_table_item_t;
29public:
30 Af();
31 ~Af() = default;
32
33 int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
34 void prepare(IPAContext &context, const uint32_t frame,
35 IPAFrameContext &frameContext,
36 ipu3_uapi_params *params) override;
37 void process(IPAContext &context, const uint32_t frame,
38 IPAFrameContext &frameContext,
39 const ipu3_uapi_stats_3a *stats) override;
40
41private:
42 void afCoarseScan(IPAContext &context);
43 void afFineScan(IPAContext &context);
44 bool afScan(IPAContext &context, int min_step);
45 void afReset(IPAContext &context);
46 bool afNeedIgnoreFrame();
47 void afIgnoreFrameReset();
48 double afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1);
49
50 bool afIsOutOfFocus(IPAContext &context);
51
52 /* VCM step configuration. It is the current setting of the VCM step. */
53 uint32_t focus_;
54 /* The best VCM step. It is a local optimum VCM step during scanning. */
55 uint32_t bestFocus_;
56 /* Current AF statistic variance. */
57 double currentVariance_;
58 /* The frames are ignore before starting measuring. */
59 uint32_t ignoreCounter_;
60 /* It is used to determine the derivative during scanning */
61 double previousVariance_;
62 /* The designated maximum range of focus scanning. */
63 uint32_t maxStep_;
64 /* If the coarse scan completes, it is set to true. */
65 bool coarseCompleted_;
66 /* If the fine scan completes, it is set to true. */
67 bool fineCompleted_;
68};
69
70} /* namespace ipa::ipu3::algorithms */
71
72} /* namespace libcamera */
The base class for all IPA algorithms.
Definition: algorithm.h:23
An auto-focus algorithm based on IPU3 statistics.
Definition: af.h:23
void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, ipu3_uapi_params *params) override
Fill the params buffer with ISP processing parameters for a frame.
Definition: af.cpp:119
void process(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats) override
Determine the max contrast image and lens position.
Definition: af.cpp:424
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override
Configure the Af given a configInfo.
Definition: af.cpp:138
Data structures related to geometric objects.
Algorithm common interface.
Top-level libcamera namespace.
Definition: backtrace.h:17
Global IPA context data shared between all algorithms.
Definition: ipa_context.h:82
IPU3-specific FrameContext.
Definition: ipa_context.h:75
Miscellaneous utility functions.