libcamera: include/libcamera/internal/v4l2_pixelformat.h Source File

libcamera v0.1.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
v4l2_pixelformat.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 * Copyright (C) 2020, Raspberry Pi Ltd
5 *
6 * v4l2_pixelformat.h - V4L2 Pixel Format
7 */
8
9#pragma once
10
11#include <functional>
12#include <ostream>
13#include <stdint.h>
14#include <string>
15#include <vector>
16
17#include <linux/videodev2.h>
18
19#include <libcamera/pixel_format.h>
20
21namespace libcamera {
22
23 class V4L2PixelFormat
24{
25public:
26 struct Info {
27 PixelFormat format;
28 const char *description;
29 };
30
31 V4L2PixelFormat()
32 : fourcc_(0)
33 {
34 }
35
36 explicit V4L2PixelFormat(uint32_t fourcc)
37 : fourcc_(fourcc)
38 {
39 }
40
41 bool isValid() const { return fourcc_ != 0; }
42 uint32_t fourcc() const { return fourcc_; }
43 operator uint32_t() const { return fourcc_; }
44
45 std::string toString() const;
46 const char *description() const;
47
48 PixelFormat toPixelFormat(bool warn = true) const;
49 static const std::vector<V4L2PixelFormat> &
50 fromPixelFormat(const PixelFormat &pixelFormat);
51
52private:
53 uint32_t fourcc_;
54};
55
56std::ostream &operator<<(std::ostream &out, const V4L2PixelFormat &f);
57
58} /* namespace libcamera */
59
60namespace std {
61
62template<>
63struct hash<libcamera::V4L2PixelFormat> {
64 size_t operator()(libcamera::V4L2PixelFormat const &format) const noexcept
65 {
66 return format.fourcc();
67 }
68};
69
70} /* namespace std */
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:18
libcamera::V4L2PixelFormat
V4L2 pixel format FourCC wrapper.
Definition v4l2_pixelformat.h:24
libcamera::V4L2PixelFormat::toString
std::string toString() const
Assemble and return a string describing the pixel format.
Definition v4l2_pixelformat.cpp:268
libcamera::V4L2PixelFormat::V4L2PixelFormat
V4L2PixelFormat(uint32_t fourcc)
Construct a V4L2PixelFormat from a FourCC value.
Definition v4l2_pixelformat.h:36
libcamera::V4L2PixelFormat::fourcc
uint32_t fourcc() const
Retrieve the pixel format FourCC numerical value.
Definition v4l2_pixelformat.h:42
libcamera::V4L2PixelFormat::fromPixelFormat
static const std::vector< V4L2PixelFormat > & fromPixelFormat(const PixelFormat &pixelFormat)
Retrieve the list of V4L2PixelFormat associated with pixelFormat.
Definition v4l2_pixelformat.cpp:346
libcamera::V4L2PixelFormat::description
const char * description() const
Retrieve the V4L2 description for the format.
Definition v4l2_pixelformat.cpp:298
libcamera::V4L2PixelFormat::V4L2PixelFormat
V4L2PixelFormat()
Construct a V4L2PixelFormat with an invalid format.
Definition v4l2_pixelformat.h:31
libcamera::V4L2PixelFormat::isValid
bool isValid() const
Check if the pixel format is valid.
Definition v4l2_pixelformat.h:41
libcamera::V4L2PixelFormat::toPixelFormat
PixelFormat toPixelFormat(bool warn=true) const
Convert the V4L2 pixel format to the corresponding PixelFormat.
Definition v4l2_pixelformat.cpp:323
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::operator<<
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91
pixel_format.h
libcamera pixel format
libcamera::V4L2PixelFormat::Info
Information about a V4L2 pixel format.
Definition v4l2_pixelformat.h:26
libcamera::V4L2PixelFormat::Info::description
const char * description
The human-readable description of the V4L2 pixel format.
Definition v4l2_pixelformat.h:28
libcamera::V4L2PixelFormat::Info::format
PixelFormat format
The corresponding libcamera PixelFormat.
Definition v4l2_pixelformat.h:27