Loading...
Searching...
No Matches
YUV444P12.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
20{
21 static const constexpr auto frag = R"_(#version 450
22
23)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
24
25layout(binding=3) uniform sampler2D y_tex;
26layout(binding=4) uniform sampler2D u_tex;
27layout(binding=5) uniform sampler2D v_tex;
28
29layout(location = 0) in vec2 v_texcoord;
30layout(location = 0) out vec4 fragColor;
31
32%2
33
34vec4 processTexture(vec4 tex) {
35 vec4 processed = convert_to_rgb(tex);
36 { %1 }
37 return processed;
38}
39
40void main ()
41{
42 float y = 16. * texture(y_tex, v_texcoord).r;
43 float u = 16. * texture(u_tex, v_texcoord).r;
44 float v = 16. * texture(v_tex, v_texcoord).r;
45
46 fragColor = processTexture(vec4(y,u,v, 1.));
47})_";
48
50 : decoder{d}
51 {
52 }
53
54 Video::ImageFormat& decoder;
55
56 std::pair<QShader, QShader> init(RenderList& r) override
57 {
58 auto& rhi = *r.state.rhi;
59 const auto w = decoder.width, h = decoder.height;
60 const auto fmt = QRhiTexture::R16;
61
62 // Y, U, V - all at full resolution
63 for(int i = 0; i < 3; i++)
64 {
65 auto tex = rhi.newTexture(fmt, {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
76 r.state, vertexShader(), QString(frag).arg("").arg(colorMatrix(decoder)));
77 }
78
79 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
80 {
81 const auto w = decoder.width, h = decoder.height;
82 for(int i = 0; i < 3; i++)
83 {
84 QRhiTextureUploadEntry entry{
85 0, 0, createTextureUpload(frame.data[i], w, h, 2, frame.linesize[i])};
86 QRhiTextureUploadDescription desc{entry};
87 res.uploadTexture(samplers[i].texture, desc);
88 }
89 }
90};
91
92}
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 YUV444P12 videos.
Definition YUV444P12.hpp:20
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition YUV444P12.hpp:79
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition YUV444P12.hpp:56