Loading...
Searching...
No Matches
WireEncoderFactory.hpp
Go to the documentation of this file.
1#pragma once
2
30#include <Gfx/Graph/encoders/BGRA.hpp>
31#include <Gfx/Graph/encoders/BGRACompute.hpp>
32#include <Gfx/Graph/encoders/ComputeEncoder.hpp>
33#include <Gfx/Graph/encoders/GPUVideoEncoder.hpp>
34#include <Gfx/Graph/encoders/NV12.hpp>
35#include <Gfx/Graph/encoders/P010.hpp>
36#include <Gfx/Graph/encoders/P216.hpp>
37#include <Gfx/Graph/encoders/P216Packed.hpp>
38#include <Gfx/Graph/encoders/YUV420Packed.hpp>
39#include <Gfx/Graph/encoders/PackedRGB.hpp>
40#include <Gfx/Graph/encoders/UYVY.hpp>
41#include <Gfx/Graph/encoders/UYVYCompute.hpp>
42#include <Gfx/Graph/encoders/V210.hpp>
43#include <Gfx/Graph/encoders/V210Compute.hpp>
44#include <Gfx/Graph/encoders/YUV422P10.hpp>
45#include <Gfx/Graph/encoders/YUVPlanar.hpp>
46#include <Gfx/Graph/encoders/YUY2.hpp>
48
49#include <memory>
50
51namespace score::gfx
52{
53
66inline std::unique_ptr<GPUVideoEncoder>
68 Video::VideoPixelFormat fmt, bool contiguousFramestore = false)
69{
71
72 if(contiguousFramestore)
73 {
74 switch(fmt)
75 {
76 case F::P216:
77 return std::make_unique<P216PackedEncoder>();
78
79 // 4:2:0, where the plane-based route costs two or three GPU->CPU round
80 // trips plus a concatenation. See YUV420Packed.hpp.
81 case F::NV12:
82 return Yuv420PackedEncoder::nv12();
83 case F::YUV420P:
84 return Yuv420PackedEncoder::i420();
85
86 // YVU420P (YV12) exists only here: with planes, which of Cb/Cr comes
87 // first is the consumer's business, and only a framestore has to commit.
88 case F::YVU420P:
89 return Yuv420PackedEncoder::yv12();
90
91 default:
92 break; // no packed variant; fall through to the plane-based one
93 }
94 }
95
96 switch(fmt)
97 {
98 // -- packed 8-bit YUV 4:2:2 --
99 case F::UYVY422:
100 return std::make_unique<UYVYEncoder>();
101 case F::YUYV422:
102 return std::make_unique<YUY2Encoder>();
103
104 // -- packed 10-bit YUV 4:2:2 --
105 case F::V210:
106 return std::make_unique<V210Encoder>();
107
108 // -- packed 8-bit RGB (Video::VideoPixelFormat names are *memory* byte order) --
109 case F::BGRA8: // memory [B,G,R,A]
110 return std::make_unique<BGRAEncoder>(BGRAEncoder::Swizzle::BGRA);
111 case F::RGBA8: // memory [R,G,B,A]
112 return std::make_unique<BGRAEncoder>(BGRAEncoder::Swizzle::RGBA);
113 case F::ARGB8: // memory [A,R,G,B]
114 return std::make_unique<BGRAEncoder>(BGRAEncoder::Swizzle::ARGB);
115 case F::ABGR8: // memory [A,B,G,R]
116 return std::make_unique<BGRAEncoder>(BGRAEncoder::Swizzle::ABGR);
117 case F::RGB24:
118 return PackedRGBEncoder::rgb24();
119 case F::BGR24:
120 return PackedRGBEncoder::bgr24();
121
122 // -- packed 10/12-bit RGB --
123 case F::R210:
124 return PackedRGBEncoder::r210be(); // DeckLink r210: R-high, big-endian
125 case F::RGB10:
126 return PackedRGBEncoder::rgb10(); // AJA 10BIT_RGB: B-high, little-endian
127 case F::ARGB10:
128 return PackedRGBEncoder::argb10();
129 case F::DPX10:
130 return PackedRGBEncoder::dpx10be();
131 case F::DPX10LE:
132 return PackedRGBEncoder::dpx10le();
133 case F::RGB12P:
134 return PackedRGBEncoder::rgb12packed();
135 case F::RGB48:
136 return PackedRGBEncoder::rgb48();
137
138 // -- planar / semi-planar (capture-card output is rare; mostly capture) --
139 case F::YUV422P10:
140 return std::make_unique<YUV422P10Encoder>();
141 case F::YUV422P:
142 return YUVPlanarEncoder::p422_8();
143 case F::YUV420P:
144 return YUVPlanarEncoder::p420_8();
145 case F::YUV420P10:
146 return YUVPlanarEncoder::p420_10();
147 case F::NV12:
148 return std::make_unique<NV12Encoder>();
149 case F::P010:
150 return std::make_unique<P010Encoder>();
151 case F::P216:
152 return std::make_unique<P216Encoder>();
153
154 default:
155 return nullptr;
156 }
157}
158
161inline std::unique_ptr<ComputeEncoder>
163{
164 using F = Video::VideoPixelFormat;
165 switch(fmt)
166 {
167 case F::V210:
168 return std::make_unique<V210ComputeEncoder>();
169 case F::UYVY422:
170 return std::make_unique<UYVYComputeEncoder>();
171 case F::BGRA8:
172 return std::make_unique<BGRAComputeEncoder>();
173 default:
174 return nullptr;
175 }
176}
177
180inline bool
182{
183 using F = Video::VideoPixelFormat;
184 switch(fmt)
185 {
186 case F::V210:
187 return (width % 6) == 0;
188 case F::UYVY422:
189 return (width % 2) == 0;
190 case F::BGRA8:
191 return true;
192 default:
193 return false;
194 }
195}
196
197} // namespace score::gfx
Vendor-neutral pixel format vocabulary + descriptive metadata.
VideoPixelFormat
Definition VideoPixelFormat.hpp:235
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
std::unique_ptr< GPUVideoEncoder > makeWireEncoder(Video::VideoPixelFormat fmt, bool contiguousFramestore=false)
Render (fragment-shader) encoder producing fmt's exact on-wire bytes.
Definition WireEncoderFactory.hpp:67
bool wireComputeSupports(Video::VideoPixelFormat fmt, int width)
Definition WireEncoderFactory.hpp:181
std::unique_ptr< ComputeEncoder > makeWireComputeEncoder(Video::VideoPixelFormat fmt)
Definition WireEncoderFactory.hpp:162