8 #ifndef META_OCEAN_CV_FRAME_CONVERTER_YUV_24_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_YUV_24_H
43 static inline void convertYUV24ToBGR24(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
57 static inline void convertYUV24ToBGRA32Precision6Bit(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const uint8_t alphaValue = 0xFF,
Worker* worker =
nullptr);
70 static inline void convertYUV24ToRGB24(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
83 static inline void convertYUV24ToRGB24Precision6Bit(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
96 static inline void convertYUV24ToY8(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
109 static inline void convertYUV24ToYUV24(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
122 static inline void convertYUV24ToYVU24(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
139 static inline void convertYUV24ToY_U_V12(
const uint8_t* source, uint8_t* yTarget, uint8_t* uTarget, uint8_t* vTarget,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int yTargetPaddingElements,
const unsigned int uTargetPaddingElements,
const unsigned int vTargetPaddingElements,
Worker* worker =
nullptr);
150 static inline void convertYUV24ToRGB24Pixel(
const uint8_t y,
const uint8_t u,
const uint8_t v, uint8_t& r, uint8_t& g, uint8_t& b);
154 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
172 static OCEAN_FORCE_INLINE
void convert16PixelsYUV24ToRGB24Precision6BitNEON(
const uint8_t*
const source, uint8_t*
const target);
180 ocean_assert(source !=
nullptr && target !=
nullptr);
181 ocean_assert(width >= 1u && height >= 1u);
183 const unsigned int sourceStrideElements = width * 3u + sourcePaddingElements;
184 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
198 const int parameters[12] = {1192, 1192, 1192, 2066, -400, 0, 0, -833, 1634, -277, 135, -223};
200 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
202 FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag,
CV::FrameChannels::convertRow3ChannelsTo3Channels8BitPerChannel10BitPrecision, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, parameters, worker);
207 ocean_assert(source !=
nullptr && target !=
nullptr);
208 ocean_assert(width >= 1u && height >= 1u);
210 const unsigned int sourceStrideElements = width * 3u + sourcePaddingElements;
211 const unsigned int targetStrideElements = width * 4u + targetPaddingElements;
225 const int parameters[13] = {64, 64, 64, 111, -22, 0, 0, -45, 88, 0, 128, 128, int(alphaValue)};
227 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
229 FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag,
CV::FrameChannels::convertRow3ChannelsTo4Channels8BitPerChannel6BitPrecision, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 4u>, areContinuous, parameters, worker);
234 ocean_assert(source !=
nullptr && target !=
nullptr);
235 ocean_assert(width >= 1u && height >= 1u);
237 const unsigned int sourceStrideElements = width * 3u + sourcePaddingElements;
238 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
252 const int parameters[12] = {1192, 1192, 1192, 0, -400, 2066, 1634, -833, 0, -223, 135, -277};
254 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
256 FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag,
CV::FrameChannels::convertRow3ChannelsTo3Channels8BitPerChannel10BitPrecision, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, parameters, worker);
261 ocean_assert(source !=
nullptr && target !=
nullptr);
262 ocean_assert(width >= 1u && height >= 1u);
264 const unsigned int sourceStrideElements = width * 3u + sourcePaddingElements;
265 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
267 #if defined(OCEAN_USE_HARDCODED_YUV24_TO_RGB24_CONVERTER) && OCEAN_HARDWARE_NEON_VERSION >= 10
271 FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag,
FrameConverterYUV24::convertYUV24ToRGB24RowPrecision6BitNEON, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>,
nullptr, worker);
279 const int parameters[12] = {64, 64, 64, 0, -22, 111, 88, -45, 0, 0, 128, 128};
281 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
283 FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag,
CV::FrameChannels::convertRow3ChannelsTo3Channels8BitPerChannel6BitPrecision, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, parameters, worker);
290 ocean_assert(source !=
nullptr && target !=
nullptr);
291 ocean_assert(width >= 1u && height >= 1u);
297 constexpr
unsigned int shufflePattern = 0x0u;
299 FrameChannels::shuffleChannels<uint8_t, 3u, 1u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
304 ocean_assert(source !=
nullptr && target !=
nullptr);
305 ocean_assert(width >= 1u && height >= 1u);
307 FrameChannels::transformGeneric<uint8_t, 3u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
312 ocean_assert(source !=
nullptr && target !=
nullptr);
313 ocean_assert(width >= 1u && height >= 1u);
320 constexpr
unsigned int shufflePattern = 0x120u;
322 FrameChannels::shuffleChannels<uint8_t, 3u, 3u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
325 inline void FrameConverterYUV24::convertYUV24ToY_U_V12(
const uint8_t* source, uint8_t* yTarget, uint8_t* uTarget, uint8_t* vTarget,
const unsigned int width,
const unsigned int height,
const ConversionFlag flag,
const unsigned int sourcePaddingElements,
const unsigned int yTargetPaddingElements,
const unsigned int uTargetPaddingElements,
const unsigned int vTargetPaddingElements,
Worker* worker)
327 ocean_assert(source !=
nullptr && yTarget !=
nullptr && uTarget !=
nullptr && vTarget !=
nullptr);
329 ocean_assert(width >= 2u && width % 2u == 0u);
330 ocean_assert(height >= 2u && height % 2u == 0u);
332 if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
337 const unsigned int options[4] = {sourcePaddingElements, yTargetPaddingElements, uTargetPaddingElements, vTargetPaddingElements};
346 FrameConverter::convertArbitraryPixelFormat((
const void**)(&source), targets, width, height, flag, 2u, FrameConverter::mapTwoRows_1Plane3Channels_To_1Plane1ChannelAnd2Planes1ChannelDownsampled2x2_8BitPerChannel<0u, 1u, 2u>, options, worker);
351 const int y_ = (y - 16) * 298 + 128;
352 const int u_ = u - 128;
353 const int v_ = v - 128;
355 r = (uint8_t)(
minmax(0, (y_ + 409 * v_) >> 8, 255));
356 g = (uint8_t)(
minmax(0, (y_ - 100 * u_ - 208 * v_) >> 8, 255));
357 b = (uint8_t)(
minmax(0, (y_ + 516 * u_) >> 8, 255));
360 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
364 ocean_assert(source !=
nullptr && target !=
nullptr);
379 const uint8x8_t constant_128_u_8x8 = vdup_n_u8(128);
380 const int16x8_t constant_22_s_16x8 = vdupq_n_s16(-22);
381 const int16x8_t constant_111_s_16x8 = vdupq_n_s16(111);
382 const int16x8_t constant_88_s_16x8 = vdupq_n_s16(88);
383 const int16x8_t constant_45_s_16x8 = vdupq_n_s16(-45);
385 const uint8x16x3_t source_u_8x16x3 = vld3q_u8(source);
388 const int16x8_t sourceMultiplied0_low_s_16x8 = vreinterpretq_s16_u16(vshll_n_u8(vget_low_u8(source_u_8x16x3.val[0]), 6));
389 const int16x8_t source1_low_s_16x8 = vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(source_u_8x16x3.val[1]), constant_128_u_8x8));
390 const int16x8_t source2_low_s_16x8 = vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(source_u_8x16x3.val[2]), constant_128_u_8x8));
392 const int16x8_t sourceMultiplied0_high_s_16x8 = vreinterpretq_s16_u16(vshll_n_u8(vget_high_u8(source_u_8x16x3.val[0]), 6));
393 const int16x8_t source1_high_s_16x8 = vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(source_u_8x16x3.val[1]), constant_128_u_8x8));
394 const int16x8_t source2_high_s_16x8 = vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(source_u_8x16x3.val[2]), constant_128_u_8x8));
398 int16x8_t intermediateResults1_low_s_16x8 = vmlaq_s16(sourceMultiplied0_low_s_16x8, source1_low_s_16x8, constant_22_s_16x8);
399 int16x8_t intermediateResults2_low_s_16x8 = vmlaq_s16(sourceMultiplied0_low_s_16x8, source1_low_s_16x8, constant_111_s_16x8);
401 int16x8_t intermediateResults1_high_s_16x8 = vmlaq_s16(sourceMultiplied0_high_s_16x8, source1_high_s_16x8, constant_22_s_16x8);
402 int16x8_t intermediateResults2_high_s_16x8 = vmlaq_s16(sourceMultiplied0_high_s_16x8, source1_high_s_16x8, constant_111_s_16x8);
404 int16x8_t intermediateResults0_low_s_16x8 = vmlaq_s16(sourceMultiplied0_low_s_16x8, source2_low_s_16x8, constant_88_s_16x8);
405 intermediateResults1_low_s_16x8 = vmlaq_s16(intermediateResults1_low_s_16x8, source2_low_s_16x8, constant_45_s_16x8);
407 int16x8_t intermediateResults0_high_s_16x8 = vmlaq_s16(sourceMultiplied0_high_s_16x8, source2_high_s_16x8, constant_88_s_16x8);
408 intermediateResults1_high_s_16x8 = vmlaq_s16(intermediateResults1_high_s_16x8, source2_high_s_16x8, constant_45_s_16x8);
410 uint8x16x3_t results_u_8x16x3;
413 results_u_8x16x3.val[0] = vcombine_u8(vqrshrun_n_s16(intermediateResults0_low_s_16x8, 6), vqrshrun_n_s16(intermediateResults0_high_s_16x8, 6));
414 results_u_8x16x3.val[1] = vcombine_u8(vqrshrun_n_s16(intermediateResults1_low_s_16x8, 6), vqrshrun_n_s16(intermediateResults1_high_s_16x8, 6));
415 results_u_8x16x3.val[2] = vcombine_u8(vqrshrun_n_s16(intermediateResults2_low_s_16x8, 6), vqrshrun_n_s16(intermediateResults2_high_s_16x8, 6));
418 vst3q_u8(target, results_u_8x16x3);
static void convertRow3ChannelsTo3Channels8BitPerChannel6BitPrecision(const uint8_t *source, uint8_t *target, const size_t size, const void *parameters)
Converts a row of pixels with 3 channels to pixels with 3 channels by a linear combination of the thr...
static void convertRow3ChannelsTo4Channels8BitPerChannel6BitPrecision(const uint8_t *source, uint8_t *target, const size_t size, const void *parameters)
Converts a row of pixels with 3 channels to pixels with 4 channels by a linear combination of the thr...
static void convertRow3ChannelsTo3Channels8BitPerChannel10BitPrecision(const uint8_t *source, uint8_t *target, const size_t size, const void *parameters)
Converts a row of pixels with 3 channels to pixels with 3 channels by a linear combination of the thr...
This is the base class for all frame converter classes.
Definition: FrameConverter.h:32
ConversionFlag
Definition of individual conversion flags.
Definition: FrameConverter.h:39
static void convertGenericPixelFormat(const TSource *source, TTarget *target, const unsigned int width, const unsigned int height, const unsigned int sourceStrideElements, const unsigned int targetStrideElements, const ConversionFlag flag, const RowConversionFunction< TSource, TTarget > rowConversionFunction, const RowReversePixelOrderInPlaceFunction< TTarget > targetReversePixelOrderInPlaceFunction, const bool areContinuous, const void *options, Worker *worker)
Converts a frame with generic pixel format (e.g., RGBA32, BGR24, YUV24, ...) to a frame with generic ...
Definition: FrameConverter.h:3211
static void convertArbitraryPixelFormat(const void **sources, void **targets, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int multipleRowsPerIteration, const MultipleRowsConversionFunction multipleRowsConversionFunction, const void *options, Worker *worker)
Converts a frame with arbitrary pixel format (e.g., Y_UV12, Y_VU12, YUYV16, ...) to a frame with arbi...
Definition: FrameConverter.h:3234
This class provides functions to convert frames with YUV24 pixel format to other pixel formats.
Definition: FrameConverterYUV24.h:29
static void convertYUV24ToYUV24(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a YUV 24 bit frame.
Definition: FrameConverterYUV24.h:302
static OCEAN_FORCE_INLINE void convert16PixelsYUV24ToRGB24Precision6BitNEON(const uint8_t *const source, uint8_t *const target)
Converts 16 YUV24 pixels to 16 RGB24 pixels by using NEON instructions.
Definition: FrameConverterYUV24.h:362
static void convertYUV24ToY8(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a Y 8 bit frame.
Definition: FrameConverterYUV24.h:288
static void convertYUV24ToBGRA32Precision6Bit(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const uint8_t alphaValue=0xFF, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a BGRA 32 bit frame with 6 bit precision.
Definition: FrameConverterYUV24.h:205
static void convertYUV24ToBGR24(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a BGR 24 bit frame.
Definition: FrameConverterYUV24.h:178
static void convertYUV24ToYVU24(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a YVU 24 bit frame.
Definition: FrameConverterYUV24.h:310
static void convertYUV24ToRGB24RowPrecision6BitNEON(const uint8_t *source, uint8_t *target, const size_t size, const void *parameters)
Converts a YUV 24 bit row to a RGB 24 bit row by using NEON instructions.
static void convertYUV24ToRGB24(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a RGB 24 bit frame.
Definition: FrameConverterYUV24.h:232
static void convertYUV24ToRGB24Precision6Bit(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a RGB 24 bit frame with 6 bit precision.
Definition: FrameConverterYUV24.h:259
static void convertYUV24ToRGB24Pixel(const uint8_t y, const uint8_t u, const uint8_t v, uint8_t &r, uint8_t &g, uint8_t &b)
Converts one YUV 24 bit pixel to a RGB 24 bit pixel.
Definition: FrameConverterYUV24.h:349
static void convertYUV24ToY_U_V12(const uint8_t *source, uint8_t *yTarget, uint8_t *uTarget, uint8_t *vTarget, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int yTargetPaddingElements, const unsigned int uTargetPaddingElements, const unsigned int vTargetPaddingElements, Worker *worker=nullptr)
Converts a YUV 24 bit frame to a Y_U_V 12 bit frame.
Definition: FrameConverterYUV24.h:325
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
T minmax(const T &lowerBoundary, const T &value, const T &upperBoundary)
This function fits a given parameter into a specified value range.
Definition: base/Utilities.h:903
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15