Loading...
Searching...
No Matches
YUV444P10.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
19{
20 static const constexpr auto frag = R"_(#version 450
21
22)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
23
24layout(binding=3) uniform sampler2D y_tex;
25layout(binding=4) uniform sampler2D u_tex;
26layout(binding=5) uniform sampler2D v_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 float y = 64. * texture(y_tex, v_texcoord).r;
42 float u = 64. * texture(u_tex, v_texcoord).r;
43 float v = 64. * texture(v_tex, v_texcoord).r;
44
45 fragColor = processTexture(vec4(y,u,v, 1.));
46})_";
47
49 : decoder{d}
50 {
51 }
52
53 Video::ImageFormat& decoder;
54
55 std::pair<QShader, QShader> init(RenderList& r) override
56 {
57 auto& rhi = *r.state.rhi;
58 const auto w = decoder.width, h = decoder.height;
59 const auto fmt = QRhiTexture::R16;
60
61 // Y, U, V - all at full resolution
62 for(int i = 0; i < 3; i++)
63 {
64 auto tex = rhi.newTexture(fmt, {w, h}, 1, QRhiTexture::Flag{});
65 tex->create();
66
67 auto sampler = rhi.newSampler(
68 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
69 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
70 sampler->create();
71 samplers.push_back({sampler, tex});
72 }
73
75 r.state, vertexShader(), QString(frag).arg("").arg(colorMatrix(decoder)));
76 }
77
78 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
79 {
80 const auto w = decoder.width, h = decoder.height;
81 for(int i = 0; i < 3; i++)
82 {
83 QRhiTextureUploadEntry entry{
84 0, 0, createTextureUpload(frame.data[i], w, h, 2, frame.linesize[i])};
85 QRhiTextureUploadDescription desc{entry};
86 res.uploadTexture(samplers[i].texture, desc);
87 }
88 }
89};
90
91}
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 YUV444P10 videos.
Definition YUV444P10.hpp:19
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition YUV444P10.hpp:55
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition YUV444P10.hpp:78