libcamera  v0.3.1+12-19bbca3c
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  * CPU based software statistics implementation
10  */
11 
12 #pragma once
13 
14 #include <stdint.h>
15 
16 #include <libcamera/base/signal.h>
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 
24 namespace libcamera {
25 
26 class PixelFormat;
27 struct StreamConfiguration;
28 
30 {
31 public:
32  SwStatsCpu();
33  ~SwStatsCpu() = default;
34 
35  bool isValid() const { return sharedStats_.fd().isValid(); }
36 
37  const SharedFD &getStatsFD() { return sharedStats_.fd(); }
38 
39  const Size &patternSize() { return patternSize_; }
40 
41  int configure(const StreamConfiguration &inputCfg);
42  void setWindow(const Rectangle &window);
43  void startFrame();
44  void finishFrame();
45 
46  void processLine0(unsigned int y, const uint8_t *src[])
47  {
48  if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
49  y >= (window_.y + window_.height))
50  return;
51 
52  (this->*stats0_)(src);
53  }
54 
55  void processLine2(unsigned int y, const uint8_t *src[])
56  {
57  if ((y & ySkipMask_) || y < static_cast<unsigned int>(window_.y) ||
58  y >= (window_.y + window_.height))
59  return;
60 
61  (this->*stats2_)(src);
62  }
63 
65 
66 private:
67  using statsProcessFn = void (SwStatsCpu::*)(const uint8_t *src[]);
68 
69  int setupStandardBayerOrder(BayerFormat::Order order);
70  /* Bayer 8 bpp unpacked */
71  void statsBGGR8Line0(const uint8_t *src[]);
72  /* Bayer 10 bpp unpacked */
73  void statsBGGR10Line0(const uint8_t *src[]);
74  /* Bayer 12 bpp unpacked */
75  void statsBGGR12Line0(const uint8_t *src[]);
76  /* Bayer 10 bpp packed */
77  void statsBGGR10PLine0(const uint8_t *src[]);
78  void statsGBRG10PLine0(const uint8_t *src[]);
79 
80  /* Variables set by configure(), used every line */
81  statsProcessFn stats0_;
82  statsProcessFn stats2_;
83  bool swapLines_;
84 
85  unsigned int ySkipMask_;
86 
87  Rectangle window_;
88 
89  Size patternSize_;
90 
91  unsigned int xShift_;
92 
93  SharedMemObject<SwIspStats> sharedStats_;
94  SwIspStats stats_;
95 };
96 
97 } /* namespace libcamera */
RAII-style wrapper for file descriptors.
Definition: shared_fd.h:16
const Size & patternSize()
Get the pattern size.
Definition: swstats_cpu.h:39
void startFrame()
Reset state to start statistics gathering for a new frame.
Definition: swstats_cpu.cpp:301
void processLine0(unsigned int y, const uint8_t *src[])
Process line 0.
Definition: swstats_cpu.h:46
Class for gathering statistics on the CPU.
Definition: swstats_cpu.h:29
Top-level libcamera namespace.
Definition: backtrace.h:17
int y
The vertical coordinate of the rectangle&#39;s top-left corner.
Definition: geometry.h:266
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition: swstats_cpu.h:37
Describe a two-dimensional size.
Definition: geometry.h:52
Helper class to allocate an object in shareable memory.
Definition: shared_mem_object.h:60
void setWindow(const Rectangle &window)
Specify window coordinates over which to gather statistics.
Definition: swstats_cpu.cpp:418
int configure(const StreamConfiguration &inputCfg)
Configure the statistics object for the passed in input format.
Definition: swstats_cpu.cpp:365
Signal & slot implementation.
bool isValid() const
Gets whether the statistics object is valid.
Definition: swstats_cpu.h:35
Describe a rectangle&#39;s position and dimensions.
Definition: geometry.h:242
Class to represent Bayer formats and manipulate them.
Generic signal and slot communication mechanism.
Definition: object.h:20
Struct that holds the statistics for the Software ISP.
Definition: swisp_stats.h:22
Order
The order of the colour channels in the Bayer pattern.
Definition: bayer_format.h:25
Data structures related to geometric objects.
Signal statsReady
Signals that the statistics are ready.
Definition: swstats_cpu.h:64
unsigned int height
The distance between the top and bottom sides.
Definition: geometry.h:268
void processLine2(unsigned int y, const uint8_t *src[])
Process line 2 and 3.
Definition: swstats_cpu.h:55
Configuration parameters for a stream.
Definition: stream.h:41
void finishFrame()
Finish statistics calculation for the current frame.
Definition: swstats_cpu.cpp:317