libcamera v0.2.0+3-70b69666-nvm
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
swstats.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.h - software statistics base class
10 */
11
12#pragma once
13
14#include <stdint.h>
15
16#include <libcamera/base/log.h>
18
19#include <libcamera/geometry.h>
20
21namespace libcamera {
22
23class PixelFormat;
24struct SharedFD;
25struct StreamConfiguration;
26
28
29
36{
37public:
38 virtual ~SwStats() = 0;
39
45 virtual bool isValid() const = 0;
46
53 virtual int configure(const StreamConfiguration &inputCfg) = 0;
54
60 virtual const SharedFD &getStatsFD() = 0;
61
62protected:
67 typedef void (SwStats::*statsProcessFn)(const uint8_t *src[]);
71 typedef void (SwStats::*statsVoidFn)();
72
73 /* Variables set by configure(), used every line */
79 statsProcessFn stats0_;
85 statsProcessFn stats2_;
86
90 unsigned int bpp_;
94 unsigned int y_skip_mask_;
95
100
104 statsVoidFn startFrame_;
108 statsVoidFn finishFrame_;
120 unsigned int x_shift_;
121
122public:
134 const Size &patternSize() { return patternSize_; }
135
140 void setWindow(Rectangle window)
141 {
142 window_ = window;
143
144 window_.x &= ~(patternSize_.width - 1);
145 window_.x += x_shift_;
146 window_.y &= ~(patternSize_.height - 1);
147
148 /* width_ - x_shift_ to make sure the window fits */
149 window_.width -= x_shift_;
150 window_.width &= ~(patternSize_.width - 1);
151 window_.height &= ~(patternSize_.height - 1);
152 }
153
160 {
161 (this->*startFrame_)();
162 }
163
173 void processLine0(unsigned int y, const uint8_t *src[])
174 {
175 if ((y & y_skip_mask_) || y < (unsigned int)window_.y ||
176 y >= (window_.y + window_.height))
177 return;
178
179 (this->*stats0_)(src);
180 }
181
190 void processLine2(unsigned int y, const uint8_t *src[])
191 {
192 if ((y & y_skip_mask_) || y < (unsigned int)window_.y ||
193 y >= (window_.y + window_.height))
194 return;
195
196 (this->*stats2_)(src);
197 }
198
205 {
206 (this->*finishFrame_)();
207 }
208
215};
216
217} /* namespace libcamera */
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
unsigned int width
The distance between the left and right sides.
Definition geometry.h:267
int x
The horizontal coordinate of the rectangle's top-left corner.
Definition geometry.h:265
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
Generic signal and slot communication mechanism.
Definition signal.h:39
Describe a two-dimensional size.
Definition geometry.h:53
unsigned int width
The Size width.
Definition geometry.h:65
unsigned int height
The Size height.
Definition geometry.h:66
Base class for the software ISP statistics.
Definition swstats.h:36
statsVoidFn finishFrame_
The function called at the end of a frame.
Definition swstats.h:108
void processLine2(unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition swstats.h:190
void processLine0(unsigned int y, const uint8_t *src[])
Process line 0.
Definition swstats.h:173
statsProcessFn stats2_
The function called when a line is ready for statistics processing.
Definition swstats.h:85
Signal< int > statsReady
Signals that the statistics are ready.
Definition swstats.h:214
Size patternSize_
The size of the bayer pattern.
Definition swstats.h:114
unsigned int y_skip_mask_
Skip lines where this bitmask is set in y.
Definition swstats.h:94
virtual int configure(const StreamConfiguration &inputCfg)=0
Configure the statistics object for the passed in input format.
virtual const SharedFD & getStatsFD()=0
Get the file descriptor for the statistics.
virtual bool isValid() const =0
Gets wether the statistics object is valid.
void setWindow(Rectangle window)
Specify window coordinates over which to gather statistics.
Definition swstats.h:140
void startFrame()
Reset state to start statistics gathering for a new frame.
Definition swstats.h:159
unsigned int x_shift_
The offset of x, applied to window_.x for bayer variants.
Definition swstats.h:120
unsigned int bpp_
The memory used per pixel in bits.
Definition swstats.h:90
void finishFrame()
Finish statistics calculation for the current frame.
Definition swstats.h:204
const Size & patternSize()
Get the pattern size.
Definition swstats.h:134
statsProcessFn stats0_
The function called when a line is ready for statistics processing.
Definition swstats.h:79
Rectangle window_
Statistics window, set by setWindow(), used ever line.
Definition swstats.h:99
statsVoidFn startFrame_
The function called at the start of a frame.
Definition swstats.h:104
Data structures related to geometric objects.
Logging infrastructure.
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:47
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
Configuration parameters for a stream.
Definition stream.h:41