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}
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:43
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:394
Definition VideoInterface.hpp:18
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