Loading...
Searching...
No Matches
Y210.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
26{
27 static const constexpr auto frag = R"_(#version 450
28
29)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
30
31layout(binding=3) uniform sampler2D u_tex;
32
33layout(location = 0) in vec2 v_texcoord;
34layout(location = 0) out vec4 fragColor;
35
36%2
37
38vec4 processTexture(vec4 tex) {
39 vec4 processed = convert_to_rgb(tex);
40 { %1 }
41 return processed;
42}
43
44void main()
45{
46 int x = int(floor(v_texcoord.x * mat.texSz.x));
47 int y = int(floor(v_texcoord.y * mat.texSz.y));
48 int cx = (x / 2) * 2;
49
50 const float s = )_" SCORE_GFX_MSB_ALIGNED_SCALE R"_(;
51 float luma = texelFetch(u_tex, ivec2(x, y), 0).r * s;
52 float cb = texelFetch(u_tex, ivec2(cx, y), 0).g * s;
53 float cr = texelFetch(u_tex, ivec2(cx + 1, y), 0).g * s;
54
55 fragColor = processTexture(vec4(luma, cb, cr, 1.));
56})_";
57
58 Video::ImageFormat& decoder;
59
61 : decoder{d}
62 {
63 }
64
65 std::pair<QShader, QShader> init(RenderList& r) override
66 {
67 auto& rhi = *r.state.rhi;
68 const auto w = decoder.width, h = decoder.height;
69
70 {
71 auto tex = rhi.newTexture(QRhiTexture::RG16, {w, h}, 1, QRhiTexture::Flag{});
72 tex->create();
73
74 auto sampler = rhi.newSampler(
75 QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
76 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
77 sampler->create();
78 samplers.push_back({sampler, tex});
79 }
80
82 r.state, vertexShader(),
83 QString(frag).arg("").arg(colorMatrix(decoder)));
84 }
85
86 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
87 {
88 const auto w = decoder.width, h = decoder.height;
89 auto pixels = frame.data[0];
90 auto stride = frame.linesize[0];
91
92 // One RG16 texel per pixel: 4 bytes = one 16-bit luma + one 16-bit chroma
93 QRhiTextureUploadEntry entry{0, 0, createTextureUpload(pixels, w, h, 4, stride)};
94 res.uploadTexture(samplers[0].texture, {entry});
95 }
96};
97
98}
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
Definition VideoInterface.hpp:26
Decodes Y210 packed 4:2:2 10-bit videos.
Definition Y210.hpp:26
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition Y210.hpp:86
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition Y210.hpp:65