Ocean
FrameConverterY_UV12.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_FRAME_CONVERTER_Y_UV_12_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_Y_UV_12_H
10 
11 #include "ocean/cv/CV.h"
12 #include "ocean/cv/FrameChannels.h"
15 
16 namespace Ocean
17 {
18 
19 namespace CV
20 {
21 
22 /**
23  * This class provides functions to convert frames with Y_UV12 pixel format.
24  * @ingroup cv
25  */
26 class OCEAN_CV_EXPORT FrameConverterY_UV12 : public FrameConverter
27 {
28  public:
29 
30  /**
31  * Converts a Y_UV12 frame to an 8 bit gray scale frame into a second image buffer.
32  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
33  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, can be invalid, as this parameter is not used
34  * @param target The target frame buffer, with (width + targetPaddingElements) * height elements, must be valid
35  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
36  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
37  * @param flag Determining the type of conversion
38  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
39  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity), actually this parameter is not used
40  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
41  * @param worker Optional worker object to distribute the computational to several CPU cores
42  */
43  static inline void convertY_UV12ToY8(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
44 
45  /**
46  * Converts a Y_UV12 frame to a 24 bit BGR frame into a second image buffer.
47  * <pre>
48  * YUV input value range: [16, 235]x[16, 240]x[16, 240]
49  * BGR output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
50  * </pre>
51  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
52  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
53  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
54  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
55  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
56  * @param flag Determining the type of conversion
57  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
58  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
59  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
60  * @param worker Optional worker object to distribute the computational to several CPU cores
61  */
62  static inline void convertY_UV12LimitedRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
63 
64  /**
65  * Converts a Y_UV12 frame to a 24 bit RGB frame into a second image buffer.
66  * <pre>
67  * YUV input value range: [16, 235]x[16, 240]x[16, 240]
68  * RGB output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
69  * </pre>
70  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
71  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
72  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
73  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
74  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
75  * @param flag Determining the type of conversion
76  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
77  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
78  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
79  * @param worker Optional worker object to distribute the computational to several CPU cores
80  */
81  static inline void convertY_UV12LimitedRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
82 
83  /**
84  * Converts a full range Y_UV12 frame to a full range 24 bit RGB frame into a second image buffer.
85  * <pre>
86  * YUV input value range: [0, 255]x[0, 255]x[0, 255]
87  * RGB output value range: [0, 255]x[0, 255]x[0, 255]
88  * </pre>
89  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
90  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
91  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
92  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
93  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
94  * @param flag Determining the type of conversion
95  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
96  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
97  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
98  * @param worker Optional worker object to distribute the computational to several CPU cores
99  */
100  static inline void convertY_UV12FullRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
101 
102  /**
103  * Converts a full range Y_UV12 frame to a full range 24 bit RGB frame into a second image buffer.
104  * <pre>
105  * YUV input value range: [0, 255]x[0, 255]x[0, 255]
106  * RGB output value range: [0, 255]x[0, 255]x[0, 255]
107  * </pre>
108  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
109  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
110  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
111  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
112  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
113  * @param flag Determining the type of conversion
114  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
115  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
116  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
117  * @param worker Optional worker object to distribute the computational to several CPU cores
118  */
119  static inline void convertY_UV12FullRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
120 
121  /**
122  * Converts a Y_UV12 frame to a 24 bit YUV frame into a second image buffer.
123  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
124  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
125  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
126  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
127  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
128  * @param flag Determining the type of conversion
129  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
130  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
131  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
132  * @param worker Optional worker object to distribute the computational to several CPU cores
133  */
134  static inline void convertY_UV12ToYUV24(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
135 
136  /**
137  * Converts a Y_UV12 frame to a 24 bit YVU frame into a second image buffer.
138  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
139  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
140  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
141  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
142  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
143  * @param flag Determining the type of conversion
144  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
145  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
146  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
147  * @param worker Optional worker object to distribute the computational to several CPU cores
148  */
149  static inline void convertY_UV12ToYVU24(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
150 
151  /**
152  * Converts a Y_UV12 frame to a Y_U_V12 frame into a second image buffer.
153  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
154  * @param uvSource The uv source frame buffer, with (2 * width/2 + uvPaddingElements) * height/2 elements, must be valid
155  * @param yTarget The target frame buffer, with (width + yTargetPaddingElements) * height elements, must be valid
156  * @param uTarget The target frame buffer, with (width/2 + uTargetPaddingElements) * height/2 elements, must be valid
157  * @param vTarget The target frame buffer, with (width/2 + vTargetPaddingElements) * height/2 elements, must be valid
158  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
159  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
160  * @param flag Determining the type of conversion
161  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
162  * @param uvSourcePaddingElements The number of padding elements at the end of each uv-source row, in (uint8_t) elements, with range [0, infinity)
163  * @param yTargetPaddingElements The number of padding elements at the end of each y-target row, in (uint8_t) elements, with range [0, infinity)
164  * @param uTargetPaddingElements The number of padding elements at the end of each u-target row, in (uint8_t) elements, with range [0, infinity)
165  * @param vTargetPaddingElements The number of padding elements at the end of each v-target row, in (uint8_t) elements, with range [0, infinity)
166  * @param worker Optional worker object to distribute the computational to several CPU cores
167  */
168  static inline void convertY_UV12ToY_U_V12(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* yTarget, uint8_t* uTarget, uint8_t* vTarget, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int yTargetPaddingElements, const unsigned int uTargetPaddingElements, const unsigned int vTargetPaddingElements, Worker* worker = nullptr);
169 };
170 
171 inline void FrameConverterY_UV12::convertY_UV12ToY8(const uint8_t* ySource, const uint8_t* /* uvSource */, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int /* uvSourcePaddingElements */, const unsigned int targetPaddingElements, Worker* worker)
172 {
173  ocean_assert(ySource != nullptr && target != nullptr);
174  ocean_assert(width >= 1u && height >= 1u);
175 
176  FrameChannels::transformGeneric<uint8_t, 1u>(ySource, target, width, height, flag, ySourcePaddingElements, targetPaddingElements, worker);
177 }
178 
179 inline void FrameConverterY_UV12::convertY_UV12LimitedRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
180 {
181  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
182 
183  ocean_assert(width >= 2u && width % 2u == 0u);
184  ocean_assert(height >= 2u && height % 2u == 0u);
185 
186  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
187  {
188  return;
189  }
190 
191  // YUV input value range: [16, 235]x[16, 240]x[16, 240]
192  // BGR output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
193 
194  // precise color space conversion:
195  // | B | | 1.1639404296875 2.0179443359375 0.0 -276.919921875 | | Y |
196  // | G | = | 1.1639404296875 -0.3909912109375 -0.81298828125 135.486328125 | * | U |
197  // | R | | 1.1639404296875 0.0 1.595947265625 -222.904296875 | | V |
198  // | 1 |
199 
200 #if 1
201 
202  // Approximation with 6 bit precision:
203  // | B | | 75 128 0 | | Y - 16 |
204  // 64 * | G | = | 75 -25 -52 | * | U - 128 |
205  // | R | | 75 0 102 | | V - 128 |
206 
207  const int options[3 + 12] =
208  {
209  // padding parameters
210  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
211 
212  // multiplication parameters
213  75, 75, 75, 128, -25, 0, 0, -52, 102,
214 
215  // bias/translation parameters
216  16, 128, 128
217  };
218 
219  const void* sources[2] =
220  {
221  ySource,
222  uvSource
223  };
224 
226 
227 #else
228 
229  // Approximation with 10 bit precision:
230  // | B | | 1192 2066 0 -277 | | Y |
231  // | G | = | 1192 -400 -833 135 | * | U |
232  // | R | | 1192 0 1634 -223 | | V |
233  // | 1 |
234 
235  const int options[3 + 12] =
236  {
237  // padding parameters
238  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
239 
240  // multiplication parameters (with denominator 1024)
241  1192, 1192, 1192, 2066, -400, 0, 0, -833, 1634,
242 
243  // bias/translation parameters (with denominator 1)
244  -277, 135, -223
245  };
246 
247  const void* sources[2] =
248  {
249  ySource,
250  uvSource
251  };
252 
253  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::convertOneRow1PlaneAnd2ChannelsZippedDownsampled2x2ToZipped3Channels8BitPerChannelPrecision10Bit, options, worker);
254 
255 #endif
256 }
257 
258 inline void FrameConverterY_UV12::convertY_UV12LimitedRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
259 {
260  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
261 
262  ocean_assert(width >= 2u && width % 2u == 0u);
263  ocean_assert(height >= 2u && height % 2u == 0u);
264 
265  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
266  {
267  return;
268  }
269 
270  // YUV input value range: [16, 235]x[16, 240]x[16, 240]
271  // RGB output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
272 
273  // precise color space conversion:
274  // | R | | 1.1639404296875 0.0 1.595947265625 -222.904296875 | | Y |
275  // | G | = | 1.1639404296875 -0.3909912109375 -0.81298828125 135.486328125 | * | U |
276  // | B | | 1.1639404296875 2.0179443359375 0.0 -276.919921875 | | V |
277  // | 1 |
278 
279 #if 1
280 
281  // Approximation with 6 bit precision:
282  // | R | | 75 0 102 | | Y - 16 |
283  // 64 * | G | = | 75 -25 -52 | * | U - 128 |
284  // | B | | 75 128 0 | | V - 128 |
285 
286  const int options[3 + 12] =
287  {
288  // padding parameters
289  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
290 
291  // multiplication parameters
292  75, 75, 75, 0, -25, 128, 102, -52, 0,
293 
294  // bias/translation parameters
295  16, 128, 128
296  };
297 
298  const void* sources[2] =
299  {
300  ySource,
301  uvSource
302  };
303 
305 
306 #else
307 
308  // Approximation with 10 bit precision:
309  // | R | | 1192 0 1634 -223 | | Y |
310  // | G | = | 1192 -400 -833 135 | * | U |
311  // | B | | 1192 2066 0 -277 | | V |
312  // | 1 |
313 
314  const int options[3 + 12] =
315  {
316  // padding parameters
317  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
318 
319  // multiplication parameters (with denominator 1024)
320  1192, 1192, 1192, 0, -400, 2066, 1634, -833, 0,
321 
322  // bias/translation parameters (with denominator 1)
323  -223, 135, -277
324  };
325 
326  const void* sources[2] =
327  {
328  ySource,
329  uvSource
330  };
331 
332  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::convertOneRow1PlaneAnd2ChannelsZippedDownsampled2x2ToZipped3Channels8BitPerChannelPrecision10Bit, options, worker);
333 
334 #endif
335 
336 }
337 
338 inline void FrameConverterY_UV12::convertY_UV12FullRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
339 {
340  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
341 
342  ocean_assert(width >= 2u && width % 2u == 0u);
343  ocean_assert(height >= 2u && height % 2u == 0u);
344 
345  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
346  {
347  return;
348  }
349 
350  /*
351  * YUV input value range: [0, 255]x[0, 255]x[0, 255s]
352  * RGB output value range: [0, 255]x[0, 255]x[0, 255]
353  *
354  * | B | | 1.0 1.772 0.0 -226.816 | | Y |
355  * | G | = | 1.0 -0.34414 -0.71414 135.45984 | * | U |
356  * | R | | 1.0 0.0 1.402 -179.456 | | V |
357  * | 1 |
358  *
359  * Approximation with 6 bit precision:
360  * | B | | 64 113 0 | | Y |
361  * 64 * | G | = | 64 -22 -46 | * | U - 128 |
362  * | R | | 64 0 90 | | V - 128 |
363  */
364 
365  const int options[3 + 12] =
366  {
367  // padding parameters
368  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
369 
370  // multiplication parameters
371  64, 64, 64, 113, -22, 0, 0, -46, 90,
372 
373  // bias/translation parameters
374  0, 128, 128
375  };
376 
377  const void* sources[2] =
378  {
379  ySource,
380  uvSource
381  };
382 
384 }
385 
386 inline void FrameConverterY_UV12::convertY_UV12FullRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
387 {
388  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
389 
390  ocean_assert(width >= 2u && width % 2u == 0u);
391  ocean_assert(height >= 2u && height % 2u == 0u);
392 
393  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
394  {
395  return;
396  }
397 
398  /*
399  * YUV input value range: [0, 255]x[0, 255]x[0, 255s]
400  * RGB output value range: [0, 255]x[0, 255]x[0, 255]
401  *
402  * | R | | 1.0 0.0 1.402 -179.456 | | Y |
403  * | G | = | 1.0 -0.34414 -0.71414 135.45984 | * | U |
404  * | B | | 1.0 1.772 0.0 -226.816 | | V |
405  * | 1 |
406  *
407  * Approximation with 6 bit precision:
408  * | R | | 64 0 90 | | Y |
409  * 64 * | G | = | 64 -22 -46 | * | U - 128 |
410  * | B | | 64 113 0 | | V - 128 |
411  */
412 
413  const int options[3 + 12] =
414  {
415  // padding parameters
416  int(ySourcePaddingElements), int(uvSourcePaddingElements), int(targetPaddingElements),
417 
418  // multiplication parameters
419  64, 64, 64, 0, -22, 113, 90, -46, 0,
420 
421  // bias/translation parameters
422  0, 128, 128
423  };
424 
425  const void* sources[2] =
426  {
427  ySource,
428  uvSource
429  };
430 
432 }
433 
434 inline void FrameConverterY_UV12::convertY_UV12ToYUV24(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
435 {
436  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
437 
438  ocean_assert(width >= 2u && width % 2u == 0u);
439  ocean_assert(height >= 2u && height % 2u == 0u);
440 
441  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
442  {
443  return;
444  }
445 
446  const unsigned int options[3] = {ySourcePaddingElements, uvSourcePaddingElements, targetPaddingElements};
447 
448  const void* sources[2] =
449  {
450  ySource,
451  uvSource
452  };
453 
454  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_1Plane1ChannelAnd1Plane2ChannelsDownsampled2x2_To_1Plane3Channels_8BitPerChannel<0u, 1u, 2u>, options, worker);
455 }
456 
457 inline void FrameConverterY_UV12::convertY_UV12ToYVU24(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
458 {
459  ocean_assert(ySource != nullptr && uvSource != nullptr && target != nullptr);
460 
461  ocean_assert(width >= 2u && width % 2u == 0u);
462  ocean_assert(height >= 2u && height % 2u == 0u);
463 
464  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
465  {
466  return;
467  }
468 
469  const unsigned int options[3] = {ySourcePaddingElements, uvSourcePaddingElements, targetPaddingElements};
470 
471  const void* sources[2] =
472  {
473  ySource,
474  uvSource
475  };
476 
477  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_1Plane1ChannelAnd1Plane2ChannelsDownsampled2x2_To_1Plane3Channels_8BitPerChannel<0u, 2u, 1u>, options, worker);
478 }
479 
480 inline void FrameConverterY_UV12::convertY_UV12ToY_U_V12(const uint8_t* ySource, const uint8_t* uvSource, uint8_t* yTarget, uint8_t* uTarget, uint8_t* vTarget, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int yTargetPaddingElements, const unsigned int uTargetPaddingElements, const unsigned int vTargetPaddingElements, Worker* worker)
481 {
482  ocean_assert(ySource != nullptr && uvSource != nullptr && yTarget != nullptr && yTarget != nullptr && vTarget != nullptr);
483 
484  ocean_assert(width >= 2u && width % 2u == 0u);
485  ocean_assert(height >= 2u && height % 2u == 0u);
486 
487  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
488  {
489  return;
490  }
491 
492  // first, we handle the y-plane
493  FrameChannels::transformGeneric<uint8_t, 1u>(ySource, yTarget, width, height, flag, ySourcePaddingElements, yTargetPaddingElements, worker);
494 
495  // now we handle the uv-plane
496 
497  const unsigned int options[3] = {uvSourcePaddingElements, uTargetPaddingElements, vTargetPaddingElements};
498 
499  void* targets[2] =
500  {
501  uTarget,
502  vTarget
503  };
504 
505  FrameConverter::convertArbitraryPixelFormat((const void**)(&uvSource), targets, width / 2u, height / 2u, flag, 1u, FrameConverter::mapOneRow_1Plane2Channels_To_2Planes1Channel_8BitPerChannel, options, worker);
506 }
507 
508 }
509 
510 }
511 
512 #endif // META_OCEAN_CV_FRAME_CONVERTER_Y_UV_12_H
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 convertTwoRows_1Plane1ChannelAnd1Plane2ChannelsDownsampled2x2_To_1Plane3Channels_8BitPerChannel_Precision6Bit(const void **sources, void **targets, const unsigned int multipleRowIndex, const unsigned int width, const unsigned int height, const ConversionFlag conversionFlag, const void *options)
Converts two rows of an image with e.g., a Y_UV12 pixel format to two rows of an image with e....
static void mapOneRow_1Plane2Channels_To_2Planes1Channel_8BitPerChannel(const void **sources, void **targets, const unsigned int multipleRowIndex, const unsigned int width, const unsigned int height, const ConversionFlag conversionFlag, const void *options)
Maps one row of a 1-plane, 2-channel image to two planes with 1 channels.
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:3183
This class provides functions to convert frames with Y_UV12 pixel format.
Definition: FrameConverterY_UV12.h:27
static void convertY_UV12LimitedRangeToRGB24FullRange(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to a 24 bit RGB frame into a second image buffer.
Definition: FrameConverterY_UV12.h:258
static void convertY_UV12FullRangeToBGR24FullRange(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a full range Y_UV12 frame to a full range 24 bit RGB frame into a second image buffer.
Definition: FrameConverterY_UV12.h:338
static void convertY_UV12ToYVU24(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to a 24 bit YVU frame into a second image buffer.
Definition: FrameConverterY_UV12.h:457
static void convertY_UV12LimitedRangeToBGR24FullRange(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to a 24 bit BGR frame into a second image buffer.
Definition: FrameConverterY_UV12.h:179
static void convertY_UV12ToY8(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to an 8 bit gray scale frame into a second image buffer.
Definition: FrameConverterY_UV12.h:171
static void convertY_UV12FullRangeToRGB24FullRange(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a full range Y_UV12 frame to a full range 24 bit RGB frame into a second image buffer.
Definition: FrameConverterY_UV12.h:386
static void convertY_UV12ToYUV24(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to a 24 bit YUV frame into a second image buffer.
Definition: FrameConverterY_UV12.h:434
static void convertY_UV12ToY_U_V12(const uint8_t *ySource, const uint8_t *uvSource, uint8_t *yTarget, uint8_t *uTarget, uint8_t *vTarget, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int uvSourcePaddingElements, const unsigned int yTargetPaddingElements, const unsigned int uTargetPaddingElements, const unsigned int vTargetPaddingElements, Worker *worker=nullptr)
Converts a Y_UV12 frame to a Y_U_V12 frame into a second image buffer.
Definition: FrameConverterY_UV12.h:480
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15