libcamera  v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
formats.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2019, Google Inc.
4  *
5  * libcamera image formats
6  */
7 
8 #pragma once
9 
10 #include <array>
11 #include <map>
12 #include <vector>
13 
14 #include <libcamera/geometry.h>
15 #include <libcamera/pixel_format.h>
16 
18 
19 namespace libcamera {
20 
22 {
23 public:
28  };
29 
30  struct Plane {
31  unsigned int bytesPerGroup;
32  unsigned int verticalSubSampling;
33  };
34 
35  bool isValid() const { return format.isValid(); }
36 
37  static const PixelFormatInfo &info(const PixelFormat &format);
38  static const PixelFormatInfo &info(const V4L2PixelFormat &format);
39  static const PixelFormatInfo &info(const std::string &name);
40 
41  unsigned int stride(unsigned int width, unsigned int plane,
42  unsigned int align = 1) const;
43  unsigned int planeSize(const Size &size, unsigned int plane,
44  unsigned int align = 1) const;
45  unsigned int planeSize(unsigned int height, unsigned int plane,
46  unsigned int stride) const;
47  unsigned int frameSize(const Size &size, unsigned int align = 1) const;
48  unsigned int frameSize(const Size &size,
49  const std::array<unsigned int, 3> &strides) const;
50 
51  unsigned int numPlanes() const;
52 
53  /* \todo Add support for non-contiguous memory planes */
54  const char *name;
56  std::vector<V4L2PixelFormat> v4l2Formats;
57  unsigned int bitsPerPixel;
59  bool packed;
60 
61  unsigned int pixelsPerGroup;
62 
63  std::array<Plane, 3> planes;
64 };
65 
66 } /* namespace libcamera */
libcamera image pixel format
Definition: pixel_format.h:17
V4L2 pixel format FourCC wrapper.
Definition: v4l2_pixelformat.h:23
unsigned int bytesPerGroup
The number of bytes that a pixel group consumes.
Definition: formats.h:31
RGB colour encoding.
Definition: formats.h:25
unsigned int stride(unsigned int width, unsigned int plane, unsigned int align=1) const
Compute the stride.
Definition: formats.cpp:1061
unsigned int frameSize(const Size &size, unsigned int align=1) const
Compute the number of bytes necessary to store a frame.
Definition: formats.cpp:1148
const char * name
The format name as a human-readable string, used as the text representation of the PixelFormat...
Definition: formats.h:54
unsigned int planeSize(const Size &size, unsigned int plane, unsigned int align=1) const
Compute the number of bytes necessary to store a plane of a frame.
Definition: formats.cpp:1098
std::array< Plane, 3 > planes
Information about pixels for each plane.
Definition: formats.h:63
Information about a single plane of a pixel format.
Definition: formats.h:30
enum ColourEncoding colourEncoding
The colour encoding type.
Definition: formats.h:58
Top-level libcamera namespace.
Definition: backtrace.h:17
PixelFormat format
The PixelFormat described by this instance.
Definition: formats.h:55
static const PixelFormatInfo & info(const PixelFormat &format)
Retrieve information about a pixel format.
Definition: formats.cpp:993
unsigned int pixelsPerGroup
The number of pixels in a pixel group.
Definition: formats.h:61
RAW colour encoding.
Definition: formats.h:27
Describe a two-dimensional size.
Definition: geometry.h:52
unsigned int verticalSubSampling
Vertical subsampling multiplier.
Definition: formats.h:32
V4L2 Pixel Format.
ColourEncoding
The colour encoding type.
Definition: formats.h:24
Information about pixel formats.
Definition: formats.h:21
unsigned int numPlanes() const
Retrieve the number of planes represented by the format.
Definition: formats.cpp:1195
constexpr bool isValid() const
Check if the pixel format is valid.
Definition: pixel_format.h:34
unsigned int bitsPerPixel
The average number of bits per pixel.
Definition: formats.h:57
std::vector< V4L2PixelFormat > v4l2Formats
The V4L2 pixel formats corresponding to the PixelFormat.
Definition: formats.h:56
bool packed
Tell if multiple pixels are packed in the same bytes.
Definition: formats.h:59
YUV colour encoding.
Definition: formats.h:26
Data structures related to geometric objects.
bool isValid() const
Check if the pixel format info is valid.
Definition: formats.h:35
libcamera pixel format