11#include <promeki/config.h>
22PROMEKI_NAMESPACE_BEGIN
25class UncompressedVideoPayload;
92 PROMEKI_SHARED_FINAL(CSCPipeline)
95 using Ptr = SharedPtr<CSCPipeline>;
98 static constexpr size_t MaxLUTSize = 4096;
113 StageChromaDownsample,
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;
134 float matrix[3][3] = {};
137 float matrixOffset[3] = {};
140 float matrixPreOffset[3] = {};
143 float rangeScale[4] = {};
146 float rangeBias[4] = {};
149 float *lut =
nullptr;
158 float alphaValue = 1.0f;
161 int chromaHRatio = 1;
164 int chromaVRatio = 1;
174 int semBufMap[8] = {0, 1, 2, 3, 4, 5, 6, 7};
177 int pixelCompCount = 0;
183 int bytesPerBlock = 0;
186 int pixelsPerBlock = 1;
189 bool hasAlpha =
false;
192 int alphaCompIndex = -1;
201 int planeBytesPerSample[4] = {};
204 int planeHSub[4] = {};
207 int planeVSub[4] = {};
210 int compPlane[8] = {};
213 int compByteOffset[8] = {};
216 int compBits[8] = {};
249 HdrTransferPqOETF = 1,
250 HdrTransferPqEOTF = 2,
251 HdrTransferHlgOETF = 3,
252 HdrTransferHlgEOTF = 4,
267 enum ToneMapOperator {
277 int toneMapOperator = ToneMapNone;
289 float toneMapSrcMaxPq = 0.0f;
297 float toneMapDstMaxPq = 0.0f;
299 ~Stage() {
delete[] lut; }
301 Stage(
const Stage &other);
302 Stage &operator=(
const Stage &other);
303 Stage(Stage &&other)
noexcept;
304 Stage &operator=(Stage &&other)
noexcept;
308 CSCPipeline() =
default;
317 CSCPipeline(
const PixelFormat &src,
const PixelFormat &dst,
const MediaConfig &config = MediaConfig());
361 static Ptr cached(
const PixelFormat &src,
const PixelFormat &dst,
362 const MediaConfig &config = MediaConfig());
368 bool isValid()
const {
return _valid; }
374 const PixelFormat &srcDesc()
const {
return _srcDesc; }
380 const PixelFormat &dstDesc()
const {
return _dstDesc; }
386 bool isIdentity()
const {
return _identity; }
392 bool isFastPath()
const {
return _fastPathFunc !=
nullptr; }
398 int stageCount()
const {
return _stages.size(); }
409 const Stage &stage(
int i)
const {
return _stages[i]; }
420 Error execute(
const UncompressedVideoPayload &src, UncompressedVideoPayload &dst)
const;
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;
439 PixelFormat _srcDesc;
440 PixelFormat _dstDesc;
443 bool _identity =
false;
444 bool _useSimd =
true;
445 CSCRegistry::LineFuncPtr _fastPathFunc =
nullptr;
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);