libcamera v0.2.0
Supporting cameras in Linux since 2019
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 * swstats_cpu.h - 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;
27struct StreamConfiguration;
28
30{
31public:
32 SwStatsCpu();
33 ~SwStatsCpu() = default;
34
40 bool isValid() const { return sharedStats_.fd().isValid(); }
41
47 const SharedFD &getStatsFD() { return sharedStats_.fd(); }
48
60 const Size &patternSize() { return patternSize_; }
61
62 int configure(const StreamConfiguration &inputCfg);
63 void setWindow(Rectangle window);
64 void startFrame();
65 void finishFrame();
66
76 void processLine0(unsigned int y, const uint8_t *src[])
77 {
78 if ((y & ySkipMask_) || y < (unsigned int)window_.y ||
79 y >= (window_.y + window_.height))
80 return;
81
82 (this->*stats0_)(src);
83 }
84
93 void processLine2(unsigned int y, const uint8_t *src[])
94 {
95 if ((y & ySkipMask_) || y < (unsigned int)window_.y ||
96 y >= (window_.y + window_.height))
97 return;
98
99 (this->*stats2_)(src);
100 }
101
108private:
121 typedef void (SwStatsCpu::*statsProcessFn)(const uint8_t *src[]);
122
123 int setupStandardBayerOrder(BayerFormat::Order order);
124 /* Bayer 8 bpp unpacked */
125 void statsBGGR8Line0(const uint8_t *src[]);
126 /* Bayer 10 bpp unpacked */
127 void statsBGGR10Line0(const uint8_t *src[]);
128 /* Bayer 12 bpp unpacked */
129 void statsBGGR12Line0(const uint8_t *src[]);
130 /* Bayer 10 bpp packed */
131 void statsBGGR10PLine0(const uint8_t *src[]);
132 void statsGBRG10PLine0(const uint8_t *src[]);
133
134 /* Variables set by configure(), used every line */
135 statsProcessFn stats0_;
136 statsProcessFn stats2_;
137 bool swapLines_;
138
142 unsigned int ySkipMask_;
143
147 Rectangle window_;
148
154 Size patternSize_;
155
161 unsigned int xShift_;
162
163 SharedMemObject<SwIspStats> sharedStats_;
164 SwIspStats stats_;
165};
166
167} /* 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
Describe a rectangle's position and dimensions.
Definition: geometry.h:243
int y
The vertical coordinate of the rectangle's top-left corner.
Definition: geometry.h:266
unsigned int height
The distance between the top and bottom sides.
Definition: geometry.h:268
RAII-style wrapper for file descriptors.
Definition: shared_fd.h:17
Helper class for allocating objects in shared memory.
Definition: shared_mem_object.h:74
Describe a two-dimensional size.
Definition: geometry.h:53
Class for gathering statistics on the CPU.
Definition: swstats_cpu.h:30
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition: swstats_cpu.h:47
Signal< int > statsReady
Signals that the statistics are ready.
Definition: swstats_cpu.h:107
int configure(const StreamConfiguration &inputCfg)
Configure the statistics object for the passed in input format.
Definition: swstats_cpu.cpp:269
void startFrame()
Reset state to start statistics gathering for a new frame.
Definition: swstats_cpu.cpp:208
void setWindow(Rectangle window)
Specify window coordinates over which to gather statistics.
Definition: swstats_cpu.cpp:322
void processLine0(unsigned int y, const uint8_t *src[])
Process line 0.
Definition: swstats_cpu.h:76
void finishFrame()
Finish statistics calculation for the current frame.
Definition: swstats_cpu.cpp:221
void processLine2(unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition: swstats_cpu.h:93
bool isValid() const
Gets wether the statistics object is valid.
Definition: swstats_cpu.h:40
const Size & patternSize()
Get the pattern size.
Definition: swstats_cpu.h:60
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:41
Struct that holds the statistics for the Software ISP.
Definition: swisp_stats.h:15