Loading...
Searching...
No Matches
VUYA.hpp
1#pragma once
2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4
5extern "C" {
6#include <libavformat/avformat.h>
7}
8
9namespace score::gfx
10{
11
21{
22 static const constexpr auto frag = R"_(#version 450
23
24)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
25
26layout(binding=3) uniform sampler2D u_tex;
27
28layout(location = 0) in vec2 v_texcoord;
29layout(location = 0) out vec4 fragColor;
30
31%2
32
33vec4 processTexture(vec4 tex) {
34 vec4 processed = convert_to_rgb(tex);
35 { %1 }
36 return processed;
37}
38
39void main()
40{
41 vec4 vuya = texture(u_tex, v_texcoord);
42 float y = vuya.%3;
43 float u = vuya.%4;
44 float v = vuya.%5;
45
46 vec4 rgb = processTexture(vec4(y, u, v, 1.));
47 fragColor = vec4(rgb.rgb, %6);
48})_";
49
50 Video::ImageFormat& decoder;
51 bool opaque{};
52 QString swizzle{"bgr"};
53 QChar alphaComp{'a'};
54
58 VUYADecoder(Video::ImageFormat& d, bool opaque_, QString swz = "bgr", QChar aComp = 'a')
59 : decoder{d}
60 , opaque{opaque_}
61 , swizzle{std::move(swz)}
62 , alphaComp{aComp}
63 {
64 }
65
66 std::pair<QShader, QShader> init(RenderList& r) override
67 {
68 auto& rhi = *r.state.rhi;
69 const auto w = decoder.width, h = decoder.height;
70
71 {
72 auto tex = rhi.newTexture(QRhiTexture::RGBA8, {w, h}, 1, QRhiTexture::Flag{});
73 tex->create();
74
75 auto sampler = rhi.newSampler(
76 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
77 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
78 sampler->create();
79 samplers.push_back({sampler, tex});
80 }
81
82 // VUYX has undefined alpha, use 1.0; VUYA preserves alpha
83 QString alpha = opaque ? "1.0" : QString("vuya.%1").arg(alphaComp);
84
86 r.state, vertexShader(),
87 QString(frag)
88 .arg("")
89 .arg(colorMatrix(decoder))
90 .arg(swizzle[0])
91 .arg(swizzle[1])
92 .arg(swizzle[2])
93 .arg(alpha));
94 }
95
96 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
97 {
98 auto pixels = frame.data[0];
99 auto stride = frame.linesize[0];
100 const auto w = decoder.width, h = decoder.height;
101
102 QRhiTextureUploadEntry entry{
103 0, 0, createTextureUpload(pixels, w, h, 4, stride)};
104 res.uploadTexture(samplers[0].texture, {entry});
105 }
106};
107
108#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 29, 100)
109#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
110
120{
121 static const constexpr auto frag = R"_(#version 450
122
123)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
124
125layout(binding=3) uniform sampler2D u_tex;
126
127layout(location = 0) in vec2 v_texcoord;
128layout(location = 0) out vec4 fragColor;
129
130%2
131
132vec4 processTexture(vec4 tex) {
133 vec4 processed = convert_to_rgb(tex);
134 { %1 }
135 return processed;
136}
137
138void main()
139{
140 const float s = )_" SCORE_GFX_UNORM10_SCALE R"_(;
141 vec4 xvyu = texture(u_tex, v_texcoord) * s;
142 float y = xvyu.g;
143 float u = xvyu.r;
144 float v = xvyu.b;
145
146 fragColor = processTexture(vec4(y, u, v, 1.));
147})_";
148
149 Video::ImageFormat& decoder;
150
152 : decoder{d}
153 {
154 }
155
156 std::pair<QShader, QShader> init(RenderList& r) override
157 {
158 auto& rhi = *r.state.rhi;
159 const auto w = decoder.width, h = decoder.height;
160
161 {
162 auto tex
163 = rhi.newTexture(QRhiTexture::RGB10A2, {w, h}, 1, QRhiTexture::Flag{});
164 tex->create();
165
166 auto sampler = rhi.newSampler(
167 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
168 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
169 sampler->create();
170 samplers.push_back({sampler, tex});
171 }
172
174 r.state, vertexShader(),
175 QString(frag).arg("").arg(colorMatrix(decoder)));
176 }
177
178 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
179 {
180 auto pixels = frame.data[0];
181 auto stride = frame.linesize[0];
182 const auto w = decoder.width, h = decoder.height;
183
184 QRhiTextureUploadEntry entry{
185 0, 0, createTextureUpload(pixels, w, h, 4, stride)};
186 res.uploadTexture(samplers[0].texture, {entry});
187 }
188};
189
190#endif // QT_VERSION >= 6.4.0
191#endif // LIBAVUTIL_VERSION >= 58.29.100
192
193}
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:90
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
List of nodes to be rendered to an output.
Definition RenderList.hpp:30
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:169
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag, int multiViewCount)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1238
STL namespace.
Definition VideoInterface.hpp:26
Decodes VUYA / VUYX packed 4:4:4 8-bit videos.
Definition VUYA.hpp:21
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition VUYA.hpp:96
VUYADecoder(Video::ImageFormat &d, bool opaque_, QString swz="bgr", QChar aComp='a')
Definition VUYA.hpp:58
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition VUYA.hpp:66
Decodes XV30 packed 4:4:4 10-bit videos.
Definition VUYA.hpp:120
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition VUYA.hpp:178
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition VUYA.hpp:156