Loading...
Searching...
No Matches
HAP.hpp
1#pragma once
2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
3
4#include <hap/source/hap.h>
5
6#if !defined(__EMSCRIPTEN__)
7#include <snappy.h>
8
9extern "C" {
10#include <libavformat/avformat.h>
11}
12
13namespace score::gfx
14{
19{
21 {
22 static HAPSection read(const uint8_t* bytes);
23
24 uint32_t type{};
25 uint32_t size{};
26 const uint8_t* data{};
27 };
28
29 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override;
30 void setPixels_noEncoding(
31 QRhiResourceUpdateBatch& res, const uint8_t* data_start, std::size_t size);
32 void setPixels_snappy(
33 QRhiResourceUpdateBatch& res, const uint8_t* data_start, std::size_t size);
34
35 static constexpr int buffer_size = 1024 * 1024 * 16;
36 std::unique_ptr<char[]> m_buffer = std::make_unique<char[]>(1024 * 1024 * 16);
37};
38
43{
44 static inline const QString fragment = QStringLiteral(R"_(#version 450
45
46)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
47
48layout(binding=3) uniform sampler2D y_tex;
49
50layout(location = 0) in vec2 v_texcoord;
51layout(location = 0) out vec4 fragColor;
52
53vec4 processYCoCg(vec4 CoCgSY) {
54 const vec4 offsets = vec4(-0.50196078431373, -0.50196078431373, 0.0, 0.0);
55 CoCgSY += offsets;
56 float scale = ( CoCgSY.z * ( 255.0 / 8.0 ) ) + 1.0;
57
58 float Co = CoCgSY.x / scale;
59 float Cg = CoCgSY.y / scale;
60 float Y = CoCgSY.w;
61
62 vec4 rgba = vec4(Y + Co - Cg, Y + Cg, Y - Co - Cg, 1.0);
63 return rgba;
64}
65
66vec4 processTexture(vec4 tex) {
67 vec4 processed = tex;
68 { %1 }
69 return processed;
70}
71
72void main ()
73{
74 fragColor = processTexture(texture(y_tex, v_texcoord));
75})_");
76
77 static inline const QString ycocg_filter
78 = QStringLiteral("processed = processYCoCg(processed);\n");
79
80 HAPDefaultDecoder(QRhiTexture::Format fmt, Video::ImageFormat& d, QString f = "");
81 QRhiTexture::Format format;
82 Video::ImageFormat& decoder;
83 QString filter;
84
85 std::pair<QShader, QShader> init(RenderList& r) override;
86};
87
92{
93 static inline const QString fragment = QStringLiteral(R"_(#version 450
94
95)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
96
97layout(binding=3) uniform sampler2D y_tex;
98layout(binding=4) uniform sampler2D alpha_tex;
99
100layout(location = 0) in vec2 v_texcoord;
101layout(location = 0) out vec4 fragColor;
102
103// FIXME what's that???
104vec4 processYCoCg(vec4 CoCgSY, vec4 alpha) {
105 const vec4 offsets = vec4(-0.50196078431373, -0.50196078431373, 0.0, 0.0);
106 CoCgSY += offsets;
107 float scale = ( CoCgSY.z * ( 255.0 / 8.0 ) ) + 1.0;
108
109 float Co = CoCgSY.x / scale;
110 float Cg = CoCgSY.y / scale;
111 float Y = CoCgSY.w;
112
113 vec4 rgba = vec4(Y + Co - Cg, Y + Cg, Y - Co - Cg, alpha.r);
114 return rgba;
115}
116
117vec4 processTexture(vec4 tex) {
118 vec4 processed = tex;
119 { %1 }
120 return processed;
121}
122
123void main ()
124{
125 vec4 ycocg = texture(y_tex, v_texcoord);
126 vec4 alpha = texture(alpha_tex, v_texcoord);
127 fragColor = processTexture(processYCoCg(ycocg, alpha));
128})_");
129
130 HAPMDecoder(Video::ImageFormat& d, QString f = "");
131 Video::ImageFormat& decoder;
132 QString filter;
133 std::pair<QShader, QShader> init(RenderList& r) override;
134
135 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override;
136
137 static void setPixels(
138 QRhiResourceUpdateBatch& res, QRhiTexture* tex, const uint8_t* ycocg_start,
139 std::size_t ycocg_size);
140
141 std::unique_ptr<char[]> m_alphaBuffer = std::make_unique<char[]>(1024 * 1024 * 16);
142};
143
144}
145
146#endif
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:90
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Definition VideoInterface.hpp:26
Base class for HAP ((c) Vidvox) decoding.
Definition HAP.hpp:19
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition HAP.cpp:33
Decodes HAP basic format.
Definition HAP.hpp:43
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition HAP.cpp:113
Decodes HAP-M (HAP + alpha channel)
Definition HAP.hpp:92
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition HAP.cpp:141
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition HAP.cpp:175