libcamera  v0.1.0
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  * formats.h - 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::PixelFormat
libcamera image pixel format
Definition: pixel_format.h:18
libcamera::PixelFormatInfo::pixelsPerGroup
unsigned int pixelsPerGroup
The number of pixels in a pixel group.
Definition: formats.h:61
libcamera::PixelFormatInfo
Information about pixel formats.
Definition: formats.h:22
libcamera::PixelFormatInfo::stride
unsigned int stride(unsigned int width, unsigned int plane, unsigned int align=1) const
Compute the stride.
Definition: formats.cpp:982
geometry.h
Data structures related to geometric objects.
libcamera::PixelFormatInfo::numPlanes
unsigned int numPlanes() const
Retrieve the number of planes represented by the format.
Definition: formats.cpp:1116
libcamera::V4L2PixelFormat
V4L2 pixel format FourCC wrapper.
Definition: v4l2_pixelformat.h:24
libcamera::PixelFormatInfo::Plane::bytesPerGroup
unsigned int bytesPerGroup
The number of bytes that a pixel group consumes.
Definition: formats.h:31
libcamera::PixelFormatInfo::planeSize
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:1019
pixel_format.h
libcamera pixel format
v4l2_pixelformat.h
V4L2 Pixel Format.
libcamera::PixelFormatInfo::Plane::verticalSubSampling
unsigned int verticalSubSampling
Vertical subsampling multiplier.
Definition: formats.h:32
libcamera::PixelFormatInfo::ColourEncodingRGB
@ ColourEncodingRGB
RGB colour encoding.
Definition: formats.h:25
libcamera::PixelFormatInfo::ColourEncoding
ColourEncoding
The colour encoding type.
Definition: formats.h:24
libcamera
Top-level libcamera namespace.
Definition: backtrace.h:17
libcamera::PixelFormatInfo::info
static const PixelFormatInfo & info(const PixelFormat &format)
Retrieve information about a pixel format.
Definition: formats.cpp:914
libcamera::PixelFormatInfo::colourEncoding
enum ColourEncoding colourEncoding
The colour encoding type.
Definition: formats.h:58
libcamera::PixelFormatInfo::isValid
bool isValid() const
Check if the pixel format info is valid.
Definition: formats.h:35
libcamera::PixelFormatInfo::planes
std::array< Plane, 3 > planes
Information about pixels for each plane.
Definition: formats.h:63
libcamera::PixelFormatInfo::ColourEncodingYUV
@ ColourEncodingYUV
YUV colour encoding.
Definition: formats.h:26
libcamera::PixelFormatInfo::packed
bool packed
Tell if multiple pixels are packed in the same bytes.
Definition: formats.h:59
libcamera::PixelFormatInfo::frameSize
unsigned int frameSize(const Size &size, unsigned int align=1) const
Compute the number of bytes necessary to store a frame.
Definition: formats.cpp:1069
libcamera::PixelFormatInfo::bitsPerPixel
unsigned int bitsPerPixel
The average number of bits per pixel.
Definition: formats.h:57
libcamera::Size
Describe a two-dimensional size.
Definition: geometry.h:53
libcamera::PixelFormatInfo::v4l2Formats
std::vector< V4L2PixelFormat > v4l2Formats
The V4L2 pixel formats corresponding to the PixelFormat.
Definition: formats.h:56
libcamera::PixelFormatInfo::format
PixelFormat format
The PixelFormat described by this instance.
Definition: formats.h:55
libcamera::PixelFormatInfo::Plane
Information about a single plane of a pixel format.
Definition: formats.h:30
libcamera::PixelFormat::isValid
constexpr bool isValid() const
Check if the pixel format is valid.
Definition: pixel_format.h:34
libcamera::PixelFormatInfo::name
const char * name
The format name as a human-readable string, used as the test representation of the PixelFormat.
Definition: formats.h:54
libcamera::PixelFormatInfo::ColourEncodingRAW
@ ColourEncodingRAW
RAW colour encoding.
Definition: formats.h:27