libcamera v0.5.1 Supporting cameras in Linux since 2019 |

Loading...
Searching...
No Matches
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 <vector>
12
13#include <libcamera/geometry.h>
14#include <libcamera/pixel_format.h>
15
16#include "libcamera/internal/v4l2_pixelformat.h"
17
18 namespace libcamera {
19
20 class PixelFormatInfo
21{
22 public:
23 enum ColourEncoding {
24 ColourEncodingRGB,
25 ColourEncodingYUV,
26 ColourEncodingRAW,
27 };
28
29 struct Plane {
30 unsigned int bytesPerGroup;
31 unsigned int verticalSubSampling;
32 };
33
34 bool isValid() const { return format.isValid(); }
35
36 static const PixelFormatInfo &info(const PixelFormat &format);
37 static const PixelFormatInfo &info(const V4L2PixelFormat &format);
38 static const PixelFormatInfo &info(const std::string &name);
39
40 unsigned int stride(unsigned int width, unsigned int plane,
41 unsigned int align = 1) const;
42 unsigned int planeSize(const Size &size, unsigned int plane,
43 unsigned int align = 1) const;
44 unsigned int planeSize(unsigned int height, unsigned int plane,
45 unsigned int stride) const;
46 unsigned int frameSize(const Size &size, unsigned int align = 1) const;
47 unsigned int frameSize(const Size &size,
48 const std::array<unsigned int, 3> &strides) const;
49
50 unsigned int numPlanes() const;
51
52 /* \todo Add support for non-contiguous memory planes */
53 const char *name;
54 PixelFormat format;
55 std::vector<V4L2PixelFormat> v4l2Formats;
56 unsigned int bitsPerPixel;
57 enum ColourEncoding colourEncoding;
58 bool packed;
59
60 unsigned int pixelsPerGroup;
61
62 std::array<Plane, 3> planes;
63};
64
65} /* namespace libcamera */
libcamera::PixelFormatInfo
Information about pixel formats.
Definition formats.h:21
libcamera::PixelFormatInfo::ColourEncoding
ColourEncoding
The colour encoding type.
Definition formats.h:23
libcamera::PixelFormatInfo::ColourEncodingRGB
@ ColourEncodingRGB
RGB colour encoding.
Definition formats.h:24
libcamera::PixelFormatInfo::ColourEncodingRAW
@ ColourEncodingRAW
RAW colour encoding.
Definition formats.h:26
libcamera::PixelFormatInfo::ColourEncodingYUV
@ ColourEncodingYUV
YUV colour encoding.
Definition formats.h:25
libcamera::PixelFormatInfo::stride
unsigned int stride(unsigned int width, unsigned int plane, unsigned int align=1) const
Compute the stride.
Definition formats.cpp:1070
libcamera::PixelFormatInfo::numPlanes
unsigned int numPlanes() const
Retrieve the number of planes represented by the format.
Definition formats.cpp:1204
libcamera::PixelFormatInfo::format
PixelFormat format
The PixelFormat described by this instance.
Definition formats.h:54
libcamera::PixelFormatInfo::bitsPerPixel
unsigned int bitsPerPixel
The average number of bits per pixel.
Definition formats.h:56
libcamera::PixelFormatInfo::planes
std::array< Plane, 3 > planes
Information about pixels for each plane.
Definition formats.h:62
libcamera::PixelFormatInfo::packed
bool packed
Tell if multiple pixels are packed in the same bytes.
Definition formats.h:58
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:1157
libcamera::PixelFormatInfo::name
const char * name
The format name as a human-readable string, used as the text representation of the PixelFormat.
Definition formats.h:53
libcamera::PixelFormatInfo::info
static const PixelFormatInfo & info(const PixelFormat &format)
Retrieve information about a pixel format.
Definition formats.cpp:1002
libcamera::PixelFormatInfo::pixelsPerGroup
unsigned int pixelsPerGroup
The number of pixels in a pixel group.
Definition formats.h:60
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:1107
libcamera::PixelFormatInfo::isValid
bool isValid() const
Check if the pixel format info is valid.
Definition formats.h:34
libcamera::PixelFormatInfo::colourEncoding
enum ColourEncoding colourEncoding
The colour encoding type.
Definition formats.h:57
libcamera::PixelFormatInfo::v4l2Formats
std::vector< V4L2PixelFormat > v4l2Formats
The V4L2 pixel formats corresponding to the PixelFormat.
Definition formats.h:55
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::V4L2PixelFormat
V4L2 pixel format FourCC wrapper.
Definition v4l2_pixelformat.h:24
geometry.h
Data structures related to geometric objects.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
pixel_format.h
libcamera pixel format
libcamera::PixelFormatInfo::Plane
Information about a single plane of a pixel format.
Definition formats.h:29
libcamera::PixelFormatInfo::Plane::verticalSubSampling
unsigned int verticalSubSampling
Vertical subsampling multiplier.
Definition formats.h:31
libcamera::PixelFormatInfo::Plane::bytesPerGroup
unsigned int bytesPerGroup
The number of bytes that a pixel group consumes.
Definition formats.h:30
v4l2_pixelformat.h
V4L2 Pixel Format.