Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4l2formats_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QV4L2FORMATS_P_H
5#define QV4L2FORMATS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/qvideoframeformat.h>
19#include <QtMultimedia/private/qmultimedia_ranges_p.h>
20
21#include <linux/videodev2.h>
22
23#include <cstdint>
24#include <iterator>
25#include <optional>
26
27QT_BEGIN_NAMESPACE
28
29namespace QtV4L2 {
30
36
37inline constexpr V4L2FormatMapEntry formatMap[] = {
38 { QVideoFrameFormat::Format_YUV420P, V4L2_PIX_FMT_YUV420 },
39 { QVideoFrameFormat::Format_YUV422P, V4L2_PIX_FMT_YUV422P },
40 { QVideoFrameFormat::Format_YUYV, V4L2_PIX_FMT_YUYV },
41 { QVideoFrameFormat::Format_UYVY, V4L2_PIX_FMT_UYVY },
42 { QVideoFrameFormat::Format_XBGR8888, V4L2_PIX_FMT_XBGR32 },
43 { QVideoFrameFormat::Format_XRGB8888, V4L2_PIX_FMT_XRGB32 },
44 { QVideoFrameFormat::Format_ABGR8888, V4L2_PIX_FMT_ABGR32 },
45 { QVideoFrameFormat::Format_ARGB8888, V4L2_PIX_FMT_ARGB32 },
46 { QVideoFrameFormat::Format_BGRX8888, V4L2_PIX_FMT_BGR32 },
47 { QVideoFrameFormat::Format_RGBX8888, V4L2_PIX_FMT_RGB32 },
48 { QVideoFrameFormat::Format_BGRA8888, V4L2_PIX_FMT_BGRA32 },
49 { QVideoFrameFormat::Format_RGBA8888, V4L2_PIX_FMT_RGBA32 },
50 { QVideoFrameFormat::Format_Y8, V4L2_PIX_FMT_GREY },
51 { QVideoFrameFormat::Format_Y16, V4L2_PIX_FMT_Y16 },
52 { QVideoFrameFormat::Format_NV12, V4L2_PIX_FMT_NV12 },
53 { QVideoFrameFormat::Format_NV21, V4L2_PIX_FMT_NV21 },
54
55 // FIXME: V4L2_PIX_FMT_MJPEG and V4L2_PIX_FMT_JPEG both map to QVideoFrameFormat::Format_Jpeg
56 { QVideoFrameFormat::Format_Jpeg, V4L2_PIX_FMT_MJPEG },
57 { QVideoFrameFormat::Format_Jpeg, V4L2_PIX_FMT_JPEG },
58};
59
61{
62 namespace ranges = QtMultimediaPrivate::ranges;
63 const auto found = ranges::find_if(formatMap, [&](const V4L2FormatMapEntry &entry) {
64 return entry.v4l2Format == v4l2Format;
65 });
66 if (found == std::end(formatMap))
67 return QVideoFrameFormat::Format_Invalid;
68 return found->format;
69}
70
71inline std::optional<uint32_t> v4l2FormatForPixelFormat(QVideoFrameFormat::PixelFormat format)
72{
73 namespace ranges = QtMultimediaPrivate::ranges;
74 const auto found = ranges::find_if(formatMap, [&](const V4L2FormatMapEntry &entry) {
75 return entry.format == format;
76 });
77 if (found == std::end(formatMap))
78 return std::nullopt;
79 return found->v4l2Format;
80}
81
82inline QVideoFrameFormat::ColorSpace colorSpaceForV4L2Colorspace(v4l2_colorspace colorspace)
83{
84 switch (colorspace) {
85 case V4L2_COLORSPACE_REC709:
86 return QVideoFrameFormat::ColorSpace_BT709;
87 case V4L2_COLORSPACE_JPEG:
88 return QVideoFrameFormat::ColorSpace_AdobeRgb;
89 case V4L2_COLORSPACE_SRGB:
90 // ##### is this correct???
91 return QVideoFrameFormat::ColorSpace_BT601;
92 case V4L2_COLORSPACE_BT2020:
93 return QVideoFrameFormat::ColorSpace_BT2020;
94 default:
95 case V4L2_COLORSPACE_DCI_P3:
96 return QVideoFrameFormat::ColorSpace_Undefined;
97 }
98}
99
100inline std::optional<v4l2_colorspace>
101v4l2ColorspaceForColorSpace(QVideoFrameFormat::ColorSpace colorSpace)
102{
103 switch (colorSpace) {
104 case QVideoFrameFormat::ColorSpace_BT601:
105 return V4L2_COLORSPACE_SMPTE170M;
106 case QVideoFrameFormat::ColorSpace_BT709:
107 return V4L2_COLORSPACE_REC709;
108 case QVideoFrameFormat::ColorSpace_AdobeRgb:
109 return V4L2_COLORSPACE_OPRGB;
110 case QVideoFrameFormat::ColorSpace_BT2020:
111 return V4L2_COLORSPACE_BT2020;
112 case QVideoFrameFormat::ColorSpace_Undefined:
113 return std::nullopt;
114 }
115 return std::nullopt;
116}
117
118inline QSize sizeForV4L2Format(const v4l2_pix_format &pixFormat)
119{
120 return QSize{
121 int(pixFormat.width),
122 int(pixFormat.height),
123 };
124}
125
126} // namespace QtV4L2
127
128QT_END_NAMESPACE
129
130#endif // QV4L2FORMATS_P_H
constexpr V4L2FormatMapEntry formatMap[]
std::optional< v4l2_colorspace > v4l2ColorspaceForColorSpace(QVideoFrameFormat::ColorSpace colorSpace)
QSize sizeForV4L2Format(const v4l2_pix_format &pixFormat)
QVideoFrameFormat::PixelFormat formatForV4L2Format(uint32_t v4l2Format)
QVideoFrameFormat::ColorSpace colorSpaceForV4L2Colorspace(v4l2_colorspace colorspace)
std::optional< uint32_t > v4l2FormatForPixelFormat(QVideoFrameFormat::PixelFormat format)
QVideoFrameFormat::PixelFormat format