libcamera v0.6.0
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
swstats_cpu.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2023, Linaro Ltd
4 * Copyright (C) 2023, Red Hat Inc.
5 *
6 * Authors:
7 * Hans de Goede <hdegoede@redhat.com>
8 *
9 * CPU based software statistics implementation
10 */
11
12#pragma once
13
14#include <stdint.h>
15
17
18#include <libcamera/geometry.h>
19
21#include "libcamera/internal/shared_mem_object.h"
22#include "libcamera/internal/software_isp/swisp_stats.h"
23
24namespace libcamera {
25
26class PixelFormat;
28
29class SwStatsCpu
30{
31public:
32 SwStatsCpu();
33 ~SwStatsCpu() = default;
34
35 /*
36 * The combination of pipeline + sensor delays means that
37 * exposure changes can take up to 3 frames to get applied,
38 * Run stats once every 4 frames to ensure any previous
39 * exposure changes have been applied.
40 */
41 static constexpr uint32_t kStatPerNumFrames = 4;
42
43 bool isValid() const { return sharedStats_.fd().isValid(); }
44
45 const SharedFD &getStatsFD() { return sharedStats_.fd(); }
46
47 const Size &patternSize() { return patternSize_; }
48
49 int configure(const StreamConfiguration &inputCfg);
50 void setWindow(const Rectangle &window);
51 void startFrame(uint32_t frame);
52 void finishFrame(uint32_t frame, uint32_t bufferId);
53
54 void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
55 {
56 if (frame % kStatPerNumFrames)
57 return;
58
59 if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
60 y >= (window_.y + window_.height))
61 return;
62
63 (this->*stats0_)(src);
64 }
65
66 void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
67 {
68 if (frame % kStatPerNumFrames)
69 return;
70
71 if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
72 y >= (window_.y + window_.height))
73 return;
74
75 (this->*stats2_)(src);
76 }
77
79
80private:
81 using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);
82
83 int setupStandardBayerOrder(BayerFormat::Order order);
84 /* Bayer 8 bpp unpacked */
85 void statsBGGR8Line0(const uint8_t *src[]);
86 /* Bayer 10 bpp unpacked */
87 void statsBGGR10Line0(const uint8_t *src[]);
88 /* Bayer 12 bpp unpacked */
89 void statsBGGR12Line0(const uint8_t *src[]);
90 /* Bayer 10 bpp packed */
91 void statsBGGR10PLine0(const uint8_t *src[]);
92 void statsGBRG10PLine0(const uint8_t *src[]);
93
94 /* Variables set by configure(), used every line */
95 statsProcessFn stats0_;
96 statsProcessFn stats2_;
97 bool swapLines_;
98
99 unsigned int ySkipMask_;
100
101 Rectangle window_;
102
103 Size patternSize_;
104
105 unsigned int xShift_;
106
107 SharedMemObject<SwIspStats> sharedStats_;
108 SwIspStats stats_;
109};
110
111} /* namespace libcamera */
Class to represent Bayer formats and manipulate them.
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
libcamera image pixel format
Definition pixel_format.h:17
Describe a rectangle's position and dimensions.
Definition geometry.h:247
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
Helper class to allocate an object in shareable memory.
Definition shared_mem_object.h:60
Generic signal and slot communication mechanism.
Definition signal.h:39
Describe a two-dimensional size.
Definition geometry.h:51
static constexpr uint32_t kStatPerNumFrames
Run stats once every kStatPerNumFrames frames.
Definition swstats_cpu.h:41
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition swstats_cpu.h:45
void processLine0(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 0.
Definition swstats_cpu.h:54
void processLine2(uint32_t frame, unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition swstats_cpu.h:66
Signal< uint32_t, uint32_t > statsReady
Signals that the statistics are ready.
Definition swstats_cpu.h:78
int configure(const StreamConfiguration &inputCfg)
Configure the statistics object for the passed in input format.
Definition swstats_cpu.cpp:379
void finishFrame(uint32_t frame, uint32_t bufferId)
Finish statistics calculation for the current frame.
Definition swstats_cpu.cpp:330
void setWindow(const Rectangle &window)
Specify window coordinates over which to gather statistics.
Definition swstats_cpu.cpp:454
bool isValid() const
Gets whether the statistics object is valid.
Definition swstats_cpu.h:43
const Size & patternSize()
Get the pattern size.
Definition swstats_cpu.h:47
void startFrame(uint32_t frame)
Reset state to start statistics gathering for a new frame.
Definition swstats_cpu.cpp:309
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
Configuration parameters for a stream.
Definition stream.h:40
Struct that holds the statistics for the Software ISP.
Definition swisp_stats.h:22