libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
cscpipeline.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CSC
13#include <promeki/namespace.h>
14#include <promeki/sharedptr.h>
15#include <promeki/list.h>
16#include <promeki/error.h>
17#include <promeki/pixelformat.h>
18#include <promeki/mediaconfig.h>
19#include <promeki/csccontext.h>
20#include <promeki/cscregistry.h>
21
22PROMEKI_NAMESPACE_BEGIN
23
24class Image;
25class UncompressedVideoPayload;
26
91class CSCPipeline {
92 PROMEKI_SHARED_FINAL(CSCPipeline)
93 public:
95 using Ptr = SharedPtr<CSCPipeline>;
96
98 static constexpr size_t MaxLUTSize = 4096;
99
103 enum StageType {
104 StageUnpack,
105 StageChromaUpsample,
106 StageRangeIn,
107 StageMonoExpand,
108 StageToneMap,
109 StageEOTF,
110 StageMatrix,
111 StageOETF,
112 StageRangeOut,
113 StageChromaDownsample,
114 StagePack,
115 StageAlphaFill
116 };
117
125 struct Stage {
126 StageType type;
127
129 void (*func)(const Stage *stage, const void *const *srcPlanes, const size_t *srcStrides,
130 void *const *dstPlanes, const size_t *dstStrides, size_t width, size_t y,
131 CSCContext &ctx) = nullptr;
132
134 float matrix[3][3] = {};
135
137 float matrixOffset[3] = {};
138
140 float matrixPreOffset[3] = {};
141
143 float rangeScale[4] = {};
144
146 float rangeBias[4] = {};
147
149 float *lut = nullptr;
150
152 size_t lutSize = 0;
153
155 int compCount = 3;
156
158 float alphaValue = 1.0f;
159
161 int chromaHRatio = 1;
162
164 int chromaVRatio = 1;
165
174 int semBufMap[8] = {0, 1, 2, 3, 4, 5, 6, 7};
175
177 int pixelCompCount = 0;
178
180 int bitsPerComp = 0;
181
183 int bytesPerBlock = 0;
184
186 int pixelsPerBlock = 1;
187
189 bool hasAlpha = false;
190
192 int alphaCompIndex = -1;
193
195 bool useSimd = true;
196
198 int planeCount = 1;
199
201 int planeBytesPerSample[4] = {};
202
204 int planeHSub[4] = {};
205
207 int planeVSub[4] = {};
208
210 int compPlane[8] = {};
211
213 int compByteOffset[8] = {};
214
216 int compBits[8] = {};
217
235 int hdrTransfer = 0;
236
247 enum HdrTransfer {
248 HdrTransferNone = 0,
249 HdrTransferPqOETF = 1,
250 HdrTransferPqEOTF = 2,
251 HdrTransferHlgOETF = 3,
252 HdrTransferHlgEOTF = 4,
253 };
254
267 enum ToneMapOperator {
268 ToneMapNone = -1,
269 ToneMapBt2390 = 0,
270 ToneMapReinhard = 1,
271 ToneMapHable = 2,
272 ToneMapAces = 3,
273 ToneMapBt2446a = 4,
274 };
275
277 int toneMapOperator = ToneMapNone;
278
289 float toneMapSrcMaxPq = 0.0f;
290
297 float toneMapDstMaxPq = 0.0f;
298
299 ~Stage() { delete[] lut; }
300 Stage() = default;
301 Stage(const Stage &other);
302 Stage &operator=(const Stage &other);
303 Stage(Stage &&other) noexcept;
304 Stage &operator=(Stage &&other) noexcept;
305 };
306
308 CSCPipeline() = default;
309
317 CSCPipeline(const PixelFormat &src, const PixelFormat &dst, const MediaConfig &config = MediaConfig());
318
361 static Ptr cached(const PixelFormat &src, const PixelFormat &dst,
362 const MediaConfig &config = MediaConfig());
363
368 bool isValid() const { return _valid; }
369
374 const PixelFormat &srcDesc() const { return _srcDesc; }
375
380 const PixelFormat &dstDesc() const { return _dstDesc; }
381
386 bool isIdentity() const { return _identity; }
387
392 bool isFastPath() const { return _fastPathFunc != nullptr; }
393
398 int stageCount() const { return _stages.size(); }
399
409 const Stage &stage(int i) const { return _stages[i]; }
410
420 Error execute(const UncompressedVideoPayload &src, UncompressedVideoPayload &dst) const;
421
435 void processLine(const void *const *srcPlanes, const size_t *srcStrides, void *const *dstPlanes,
436 const size_t *dstStrides, size_t width, size_t y, CSCContext &ctx) const;
437
438 private:
439 PixelFormat _srcDesc;
440 PixelFormat _dstDesc;
441 MediaConfig _config;
442 bool _valid = false;
443 bool _identity = false;
444 bool _useSimd = true;
445 CSCRegistry::LineFuncPtr _fastPathFunc = nullptr;
446 List<Stage> _stages;
447
448 void compile();
449 void buildUnpackStage(const PixelFormat &pd, Stage &stage);
450 void buildPackStage(const PixelFormat &pd, Stage &stage);
451 void buildRangeStage(const PixelFormat &pd, Stage &stage, bool isInput);
452 void buildTransferStage(const ColorModel &cm, Stage &stage, bool isEOTF, int bits);
453 void buildMatrixStage(const ColorModel &src, const ColorModel &dst, Stage &stage);
454};
455
456PROMEKI_NAMESPACE_END
457
458#endif // PROMEKI_ENABLE_CSC