Loading...
Searching...
No Matches
PAL8.hpp
1#pragma once
2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
3
4extern "C" {
5#include <libavformat/avformat.h>
6}
7
8namespace score::gfx
9{
10
23{
24 static const constexpr auto frag = R"_(#version 450
25
26)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
27
28layout(binding=3) uniform sampler2D y_tex;
29layout(binding=4) uniform sampler2D p_tex;
30
31layout(location = 0) in vec2 v_texcoord;
32layout(location = 0) out vec4 fragColor;
33
34vec4 processTexture(vec4 tex) {
35 vec4 processed = tex;
36 { %1 }
37 return processed;
38}
39
40void main ()
41{
42 float index = texture(y_tex, score_tc(v_texcoord)).r;
43 fragColor = processTexture(texelFetch(p_tex, ivec2(int(index * 255.0 + 0.5), 0), 0));
44})_";
45
46 explicit PAL8Decoder(Video::ImageFormat& d, QString f = "")
47 : decoder{d}
48 , filter{std::move(f)}
49 {
50 }
51
52 Video::ImageFormat& decoder;
53 QString filter;
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
60 // Indices are not values: interpolating between two of them picks an
61 // unrelated palette entry.
62 {
63 auto tex = rhi.newTexture(QRhiTexture::R8, {w, h}, 1, QRhiTexture::Flag{});
64 tex->create();
65 auto sampler = rhi.newSampler(
66 QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
67 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
68 sampler->create();
69 samplers.push_back({sampler, tex});
70 }
71 {
72 auto tex = rhi.newTexture(QRhiTexture::BGRA8, {256, 1}, 1, QRhiTexture::Flag{});
73 tex->create();
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
81 return score::gfx::makeShaders(r.state, vertexShader(), QString(frag).arg(filter));
82 }
83
84 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
85 {
86 const auto w = decoder.width, h = decoder.height;
87 {
88 QRhiTextureUploadEntry entry{
89 0, 0, createTextureUpload(frame.data[0], w, h, 1, frame.linesize[0])};
90 QRhiTextureUploadDescription desc{entry};
91 res.uploadTexture(samplers[0].texture, desc);
92 }
93 if(frame.data[1])
94 {
95 QRhiTextureUploadEntry entry{
96 0, 0, createTextureUpload(frame.data[1], 256, 1, 4, 256 * 4)};
97 QRhiTextureUploadDescription desc{entry};
98 res.uploadTexture(samplers[1].texture, desc);
99 }
100 }
101};
102
103}
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:161
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:33
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:274
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:1359
Definition VideoInterface.hpp:29
Decodes 8-bit palettized video (AV_PIX_FMT_PAL8): GIF, QuickTime and MS RLE, and the screen and game ...
Definition PAL8.hpp:23
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition PAL8.hpp:84
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition PAL8.hpp:55