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.b;
43 float u = vuya.g;
44 float v = vuya.r;
45
46 vec4 rgb = processTexture(vec4(y, u, v, 1.));
47 fragColor = vec4(rgb.rgb, %3);
48})_";
49
50 Video::ImageFormat& decoder;
51 bool opaque{};
52
53 VUYADecoder(Video::ImageFormat& d, bool opaque_)
54 : decoder{d}
55 , opaque{opaque_}
56 {
57 }
58
59 std::pair<QShader, QShader> init(RenderList& r) override
60 {
61 auto& rhi = *r.state.rhi;
62 const auto w = decoder.width, h = decoder.height;
63
64 {
65 auto tex = rhi.newTexture(QRhiTexture::RGBA8, {w, h}, 1, QRhiTexture::Flag{});
66 tex->create();
67
68 auto sampler = rhi.newSampler(
69 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
70 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
71 sampler->create();
72 samplers.push_back({sampler, tex});
73 }
74
75 // VUYX has undefined alpha, use 1.0; VUYA preserves alpha
76 QString alpha = opaque ? "1.0" : "vuya.a";
77
79 r.state, vertexShader(),
80 QString(frag).arg("").arg(colorMatrix(decoder)).arg(alpha));
81 }
82
83 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
84 {
85 auto pixels = frame.data[0];
86 auto stride = frame.linesize[0];
87 const auto w = decoder.width, h = decoder.height;
88
89 QRhiTextureUploadEntry entry{
90 0, 0, createTextureUpload(pixels, w, h, 4, stride)};
91 res.uploadTexture(samplers[0].texture, {entry});
92 }
93};
94
95#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(60, 8, 100)
96#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
97
107{
108 static const constexpr auto frag = R"_(#version 450
109
110)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
111
112layout(binding=3) uniform sampler2D u_tex;
113
114layout(location = 0) in vec2 v_texcoord;
115layout(location = 0) out vec4 fragColor;
116
117%2
118
119vec4 processTexture(vec4 tex) {
120 vec4 processed = convert_to_rgb(tex);
121 { %1 }
122 return processed;
123}
124
125void main()
126{
127 vec4 xvyu = texture(u_tex, v_texcoord);
128 float y = xvyu.g;
129 float u = xvyu.r;
130 float v = xvyu.b;
131
132 fragColor = processTexture(vec4(y, u, v, 1.));
133})_";
134
135 Video::ImageFormat& decoder;
136
138 : decoder{d}
139 {
140 }
141
142 std::pair<QShader, QShader> init(RenderList& r) override
143 {
144 auto& rhi = *r.state.rhi;
145 const auto w = decoder.width, h = decoder.height;
146
147 {
148 auto tex
149 = rhi.newTexture(QRhiTexture::RGB10A2, {w, h}, 1, QRhiTexture::Flag{});
150 tex->create();
151
152 auto sampler = rhi.newSampler(
153 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
154 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
155 sampler->create();
156 samplers.push_back({sampler, tex});
157 }
158
160 r.state, vertexShader(),
161 QString(frag).arg("").arg(colorMatrix(decoder)));
162 }
163
164 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
165 {
166 auto pixels = frame.data[0];
167 auto stride = frame.linesize[0];
168 const auto w = decoder.width, h = decoder.height;
169
170 QRhiTextureUploadEntry entry{
171 0, 0, createTextureUpload(pixels, w, h, 4, stride)};
172 res.uploadTexture(samplers[0].texture, {entry});
173 }
174};
175
176#endif // QT_VERSION >= 6.4.0
177#endif // LIBAVUTIL_VERSION >= 60.8.100
178
179}
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:19
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:94
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:395
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:83
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition VUYA.hpp:59
Decodes XV30 packed 4:4:4 10-bit videos.
Definition VUYA.hpp:107
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition VUYA.hpp:164
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition VUYA.hpp:142