Loading...
Searching...
No Matches
BayerExternalOES.hpp
Go to the documentation of this file.
1#pragma once
2
29#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
30#include <Gfx/Graph/decoders/Bayer.hpp>
31
32extern "C" {
33#include <libavformat/avformat.h>
34}
35
36namespace score::gfx
37{
38
39struct SCORE_PLUGIN_GFX_EXPORT BayerExternalOESDecoder : GPUVideoDecoder
40{
41 // Baked with sampler2D so glslang accepts it; the GLSL variant is swapped to
42 // samplerExternalOES after baking, which is the only place the type is legal.
43 // %1 = red-site x offset, %2 = red-site y offset, %3 = sample scale.
44 static const constexpr auto oes_filter = R"_(#version 450
45
47
48layout(binding=3) uniform sampler2D tex;
49
50layout(location = 0) in vec2 v_texcoord;
51layout(location = 0) out vec4 fragColor;
52
53void main()
54{
55 vec2 ts = mat.texSz;
56 vec2 inv = 1.0 / ts;
57 vec2 tp = v_texcoord * ts;
58 vec2 base = floor(tp) + 0.5;
59 ivec2 ip = ivec2(floor(tp));
60
61 // (0,0) marks the red site; the other three cells follow from its parity.
62 ivec2 c = (ip + ivec2(%1, %2)) & 1;
63
64 float ctr = texture(tex, base * inv).r;
65 float n = texture(tex, (base + vec2( 0.0,-1.0)) * inv).r;
66 float s = texture(tex, (base + vec2( 0.0, 1.0)) * inv).r;
67 float w = texture(tex, (base + vec2(-1.0, 0.0)) * inv).r;
68 float e = texture(tex, (base + vec2( 1.0, 0.0)) * inv).r;
69 float nw = texture(tex, (base + vec2(-1.0,-1.0)) * inv).r;
70 float ne = texture(tex, (base + vec2( 1.0,-1.0)) * inv).r;
71 float sw = texture(tex, (base + vec2(-1.0, 1.0)) * inv).r;
72 float se = texture(tex, (base + vec2( 1.0, 1.0)) * inv).r;
73
74 float cross4 = (n + s + w + e) * 0.25;
75 float diag4 = (nw + ne + sw + se) * 0.25;
76 float horz2 = (w + e) * 0.5;
77 float vert2 = (n + s) * 0.5;
78
79 vec3 rgb;
80 if(c.x == 0 && c.y == 0)
81 rgb = vec3(ctr, cross4, diag4);
82 else if(c.x == 1 && c.y == 1)
83 rgb = vec3(diag4, cross4, ctr);
84 else if(c.x == 1 && c.y == 0)
85 rgb = vec3(horz2, ctr, vert2);
86 else
87 rgb = vec3(vert2, ctr, horz2);
88
89 fragColor = vec4(adjustCapture(rgb * %3), 1.0);
90}
91)_";
92
94 Video::ImageFormat& d, BayerDecoder::Phase phase, double sampleScale = 1.0)
95 : decoder{d}
96 , phase{phase}
97 , sampleScale{sampleScale}
98 {
99 }
100
101 Video::ImageFormat& decoder;
102 BayerDecoder::Phase phase{};
103 double sampleScale{1.0};
104
105 std::pair<QShader, QShader> init(RenderList& r) override;
106
112 void exec(RenderList&, QRhiResourceUpdateBatch&, AVFrame&) override { }
113};
114
115}
The sensor corrections, as shader source shared by every demosaicer.
#define SCORE_GFX_CAPTURE_ADJUST_FN
Definition CaptureAdjustGLSL.hpp:48
#define SCORE_GFX_CAPTURE_UNIFORMS
Definition CaptureAdjustGLSL.hpp:30
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:30
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition VideoInterface.hpp:26
Phase
Definition Bayer.hpp:44
Definition BayerExternalOES.hpp:40
void exec(RenderList &, QRhiResourceUpdateBatch &, AVFrame &) override
Definition BayerExternalOES.hpp:112