libcamera v0.0.0
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 void prepare(IPAContext &context, ipu3_uapi_params *params) override;
34 int configure(IPAContext &context, const IPAConfigInfo &configInfo) override;
35 void process(IPAContext &context, IPAFrameContext *frameContext,
36 const ipu3_uapi_stats_3a *stats) override;
37
38private:
39 void afCoarseScan(IPAContext &context);
40 void afFineScan(IPAContext &context);
41 bool afScan(IPAContext &context, int min_step);
42 void afReset(IPAContext &context);
43 bool afNeedIgnoreFrame();
44 void afIgnoreFrameReset();
45 double afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1);
46
47 bool afIsOutOfFocus(IPAContext context);
48
49 /* VCM step configuration. It is the current setting of the VCM step. */
50 uint32_t focus_;
51 /* The best VCM step. It is a local optimum VCM step during scanning. */
52 uint32_t bestFocus_;
53 /* Current AF statistic variance. */
54 double currentVariance_;
55 /* The frames are ignore before starting measuring. */
56 uint32_t ignoreCounter_;
57 /* It is used to determine the derivative during scanning */
58 double previousVariance_;
59 /* The designated maximum range of focus scanning. */
60 uint32_t maxStep_;
61 /* If the coarse scan completes, it is set to true. */
62 bool coarseCompleted_;
63 /* If the fine scan completes, it is set to true. */
64 bool fineCompleted_;
65};
66
67} /* namespace ipa::ipu3::algorithms */
68
69} /* namespace libcamera */
The base class for all IPA algorithms.
Definition: algorithm.h:22
An auto-focus algorithm based on IPU3 statistics.
Definition: af.h:23
void process(IPAContext &context, IPAFrameContext *frameContext, const ipu3_uapi_stats_3a *stats) override
Determine the max contrast image and lens position.
Definition: af.cpp:423
void prepare(IPAContext &context, ipu3_uapi_params *params) override
Fill the params buffer with ISP processing parameters for a frame.
Definition: af.cpp:119
int configure(IPAContext &context, const IPAConfigInfo &configInfo) override
Configure the Af given a configInfo.
Definition: af.cpp:135
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:92
Context for a frame.
Definition: ipa_context.h:79
Miscellaneous utility functions.