1 | // Copyright (C) 2021 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 QVIDEOTEXTUREHELPER_H |
5 | #define QVIDEOTEXTUREHELPER_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 <qvideoframeformat.h> |
19 | #include <rhi/qrhi.h> |
20 | |
21 | #include <QtGui/qtextlayout.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QVideoFrame; |
26 | class QTextLayout; |
27 | class QVideoFrameTextures; |
28 | |
29 | namespace QVideoTextureHelper |
30 | { |
31 | |
32 | struct TextureDescription |
33 | { |
34 | static constexpr int maxPlanes = 3; |
35 | struct SizeScale { |
36 | int x; |
37 | int y; |
38 | }; |
39 | using BytesRequired = int(*)(int stride, int height); |
40 | |
41 | inline int strideForWidth(int width) const { return (width*strideFactor + 15) & ~15; } |
42 | inline int bytesForSize(QSize s) const { return bytesRequired(strideForWidth(width: s.width()), s.height()); } |
43 | int widthForPlane(int width, int plane) const |
44 | { |
45 | if (plane > nplanes) return 0; |
46 | return (width + sizeScale[plane].x - 1)/sizeScale[plane].x; |
47 | } |
48 | int heightForPlane(int height, int plane) const |
49 | { |
50 | if (plane > nplanes) return 0; |
51 | return (height + sizeScale[plane].y - 1)/sizeScale[plane].y; |
52 | } |
53 | |
54 | int nplanes; |
55 | int strideFactor; |
56 | BytesRequired bytesRequired; |
57 | QRhiTexture::Format textureFormat[maxPlanes]; |
58 | SizeScale sizeScale[maxPlanes]; |
59 | }; |
60 | |
61 | Q_MULTIMEDIA_EXPORT const TextureDescription *textureDescription(QVideoFrameFormat::PixelFormat format); |
62 | |
63 | Q_MULTIMEDIA_EXPORT QString vertexShaderFileName(const QVideoFrameFormat &format); |
64 | Q_MULTIMEDIA_EXPORT QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat = QRhiSwapChain::SDR); |
65 | Q_MULTIMEDIA_EXPORT void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const QVideoFrame &frame, |
66 | const QMatrix4x4 &transform, float opacity, float maxNits = 100); |
67 | Q_MULTIMEDIA_EXPORT std::unique_ptr<QVideoFrameTextures> createTextures(QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, std::unique_ptr<QVideoFrameTextures> &&oldTextures); |
68 | |
69 | struct UniformData { |
70 | float transformMatrix[4][4]; |
71 | float colorMatrix[4][4]; |
72 | float opacity; |
73 | float width; |
74 | float masteringWhite; |
75 | float maxLum; |
76 | }; |
77 | |
78 | struct Q_MULTIMEDIA_EXPORT SubtitleLayout |
79 | { |
80 | QSize videoSize; |
81 | QRectF bounds; |
82 | QTextLayout layout; |
83 | |
84 | bool update(const QSize &frameSize, QString text); |
85 | void draw(QPainter *painter, const QPointF &translate) const; |
86 | QImage toImage() const; |
87 | }; |
88 | |
89 | } |
90 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif |
94 | |