Ocean
FrameConverterY_VU12.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_VU_12_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_Y_VU_12_H
10 
11 #include "ocean/cv/CV.h"
14 
15 namespace Ocean
16 {
17 
18 namespace CV
19 {
20 
21 /**
22  * This class provides functions to convert frames with Y_VU12 pixel format.
23  * @ingroup cv
24  */
25 class OCEAN_CV_EXPORT FrameConverterY_VU12 : public FrameConverter
26 {
27  public:
28 
29  /**
30  * Converts a Y_VU12 frame to an 8 bit gray scale frame into a second image buffer.
31  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
32  * @param vuSource The vu source frame buffer, with (2 * width/2 + vuPaddingElements) * height/2 elements, can be invalid, as this parameter is not used
33  * @param target The target frame buffer, with (width + targetPaddingElements) * height elements, must be valid
34  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
35  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
36  * @param flag Determining the type of conversion
37  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
38  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity), actually this parameter is not used
39  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
40  * @param worker Optional worker object to distribute the computational to several CPU cores
41  */
42  static inline void convertY_VU12ToY8(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
43 
44  /**
45  * Converts a Y_VU12 frame to an 24 bit BGR frame into a second image buffer.
46  * <pre>
47  * YVU input value range: [16, 235]x[16, 240]x[16, 240]
48  * BGR output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
49  * </pre>
50  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
51  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
52  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * 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 vuSourcePaddingElements The number of padding elements at the end of each vu-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_VU12LimitedRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
63 
64  /**
65  * Converts a full range Y_VU12 frame to a full range BGRA32 frame into a second image buffer applying a transformation similar to BT.601.
66  * The actual transformation is close to the official BT.601 standard and used on Android for conversion from Y'UV420sp (NV21).<br>
67  * <pre>
68  * YVU input value range: [0, 255]x[0, 255]x[0, 255]
69  * BGRA output value range: [0, 255]x[0, 255]x[0, 255]x[0, 255]
70  * </pre>
71  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
72  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
73  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * height/2 elements, must be valid
74  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
75  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
76  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
77  * @param flag Determining the type of conversion
78  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
79  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity)
80  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
81  * @param alphaValue The value of the alpha channel to be set, with range [0, 255]
82  * @param worker Optional worker object to distribute the computational to several CPU cores
83  */
84  static inline void convertY_VU12FullRangeToBGRA32FullRangeAndroid(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, const uint8_t alphaValue = 0xFF, Worker* worker = nullptr);
85 
86  /**
87  * Converts a Y_VU12 frame to an 24 bit RGB frame into a second image buffer.
88  * <pre>
89  * YVU input value range: [16, 235]x[16, 240]x[16, 240]
90  * RGB output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
91  * </pre>
92  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
93  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
94  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * height/2 elements, must be valid
95  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
96  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
97  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
98  * @param flag Determining the type of conversion
99  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
100  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity)
101  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
102  * @param worker Optional worker object to distribute the computational to several CPU cores
103  */
104  static inline void convertY_VU12LimitedRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
105 
106  /**
107  * Converts a Y_VU12 full range frame to an 24 bit RGB frame into a second image buffer.
108  * <pre>
109  * YVU input value range: [0, 255]x[0, 255]x[0, 255]
110  * RGB output value range: [0, 255]x[0, 255]x[0, 255]
111  * </pre>
112  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
113  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
114  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * height/2 elements, must be valid
115  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
116  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
117  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
118  * @param flag Determining the type of conversion
119  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
120  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity)
121  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
122  * @param worker Optional worker object to distribute the computational to several CPU cores
123  */
124  static inline void convertY_VU12FullRangeToRGB24FullRangePrecision6Bit(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
125 
126  /**
127  * Converts a Y_VU12 frame to an 24 bit YUV frame into a second image buffer.
128  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
129  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
130  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * height/2 elements, must be valid
131  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
132  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
133  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
134  * @param flag Determining the type of conversion
135  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
136  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity)
137  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
138  * @param worker Optional worker object to distribute the computational to several CPU cores
139  */
140  static inline void convertY_VU12ToYUV24(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
141 
142  /**
143  * Converts a Y_VU12 frame to an 24 bit YVU frame into a second image buffer.
144  * Note: In case the given source memory contains y and uv data without any padding elements, 'vuSource' is given by 'uvSource = ySource + width * height'.
145  * @param ySource The y source frame buffer, with (width + yPaddingElements) * height elements, must be valid
146  * @param vuSource The vu source frame buffer, with (2 * width/2 + vvuPaddingElements) * height/2 elements, must be valid
147  * @param target The target frame buffer, with (3 * width + targetPaddingElements) * height elements, must be valid
148  * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
149  * @param height The height of the frame in pixel, with range [2, infinity), must be a multiple of 2
150  * @param flag Determining the type of conversion
151  * @param ySourcePaddingElements The number of padding elements at the end of each y-source row, in (uint8_t) elements, with range [0, infinity)
152  * @param vuSourcePaddingElements The number of padding elements at the end of each vu-source row, in (uint8_t) elements, with range [0, infinity)
153  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
154  * @param worker Optional worker object to distribute the computational to several CPU cores
155  */
156  static inline void convertY_VU12ToYVU24(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
157 
158  protected:
159 
160  /**
161  * Converts one row of an image with Y_UV12 pixel format to one row of an image with BGRA32 pixel format.
162  * This function needs one plane with the first channel and another plane/block of 2x2 sub-sampled pixels containing the second and third channels.<br>
163  * The layout of the options parameters is as follows:
164  * <pre>
165  * options[0] uint32_t: sourcePlanePaddingElements
166  * options[1] uint32_t: sourceZippedPaddingElements
167  * options[2] uint32_t: targetZippedPaddingElements
168  * options[3] uint32_t: alphaValue
169  * </pre>
170  * @param sources The pointer to the first and second memory block of the source image, must be valid
171  * @param targets The one pointer to the target image, must be valid
172  * @param multipleRowIndex The index of the multiple-row to be handled, with range [0, height / multipleRowsPerIteration - 1]
173  * @param width The width of the frame in pixel, with range [1, infinity)
174  * @param height The height of the frame in pixel, with range [multipleRowsPerIteration, infinity)
175  * @param conversionFlag The conversion to be applied
176  * @param options The 4 options parameters: 3 padding parameters, 1 alpha value parameter, must be valid
177  */
178  static void convertOneRowY_VU12FullRangeToBGRA32FullRangeAndroidPrecision6Bit(const void** sources, void** targets, const unsigned int multipleRowIndex, const unsigned int width, const unsigned int height, const ConversionFlag conversionFlag, const void* options);
179 
180  /**
181  * Converts two rows of an image with Y_UV12 pixel format to two rows of an image with BGRA32 pixel format.
182  * This function needs one plane with the first channel and another plane/block of 2x2 sub-sampled pixels containing the second and third channels.<br>
183  * The layout of the options parameters is as follows:
184  * <pre>
185  * options[0] uint32_t: sourcePlanePaddingElements
186  * options[1] uint32_t: sourceZippedPaddingElements
187  * options[2] uint32_t: targetZippedPaddingElements
188  * options[3] uint32_t: alphaValue
189  * </pre>
190  * @param sources The pointer to the first and second memory block of the source image, must be valid
191  * @param targets The one pointer to the target image, must be valid
192  * @param multipleRowIndex The index of the multiple-row to be handled, with range [0, height / multipleRowsPerIteration - 1]
193  * @param width The width of the frame in pixel, with range [1, infinity)
194  * @param height The height of the frame in pixel, with range [multipleRowsPerIteration, infinity)
195  * @param conversionFlag The conversion to be applied
196  * @param options The 4 options parameters: 3 padding parameters, 1 alpha value parameter, must be valid
197  */
198  static void convertTwoRowsY_VU12FullRangeToBGRA32FullRangeAndroidPrecision6Bit(const void** sources, void** targets, const unsigned int multipleRowIndex, const unsigned int width, const unsigned int height, const ConversionFlag conversionFlag, const void* options);
199 };
200 
201 inline void FrameConverterY_VU12::convertY_VU12ToY8(const uint8_t* ySource, const uint8_t* /* vuSource */, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int /* vuSourcePaddingElements */, const unsigned int targetPaddingElements, Worker* worker)
202 {
203  ocean_assert(ySource != nullptr && target != nullptr);
204  ocean_assert(width >= 1u && height >= 1u);
205 
206  FrameChannels::transformGeneric<uint8_t, 1u>(ySource, target, width, height, flag, ySourcePaddingElements, targetPaddingElements, worker);
207 }
208 
209 inline void FrameConverterY_VU12::convertY_VU12LimitedRangeToBGR24FullRange(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
210 {
211  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
212 
213  ocean_assert(width >= 2u && width % 2u == 0u);
214  ocean_assert(height >= 2u && height % 2u == 0u);
215 
216  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
217  {
218  return;
219  }
220 
221  // YVU input value range: [16, 235]x[16, 240]x[16, 240]
222  // BGR output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
223 
224  // precise color space conversion:
225  // | B | | 1.1639404296875 0.0 2.0179443359375 -276.919921875 | | Y |
226  // | G | = | 1.1639404296875 -0.81298828125 -0.3909912109375 135.486328125 | * | V |
227  // | R | | 1.1639404296875 1.595947265625 0.0 -222.904296875 | | U |
228  // | 1 |
229 
230 #if 1
231 
232  // Approximation with 6 bit precision:
233  // | B | | 75 0 128 | | Y - 16 |
234  // 64 * | G | = | 75 -52 -25 | * | V - 128 |
235  // | R | | 75 102 0 | | U - 128 |
236 
237  const int options[3 + 12] =
238  {
239  // padding parameters
240  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
241 
242  // multiplication parameters
243  75, 75, 75, 0, -52, 102, 128, -25, 0,
244 
245  // bias/translation parameters
246  16, 128, 128
247  };
248 
249  const void* sources[2] =
250  {
251  ySource,
252  vuSource
253  };
254 
256 
257 #else
258 
259  // Approximation with 10 bit precision:
260  // | B | | 1192 0 2066 -277 | | Y |
261  // | G | = | 1192 -833 -400 135 | * | V |
262  // | R | | 1192 1634 0 -223 | | U |
263  // | 1 |
264 
265  const int options[3 + 12] =
266  {
267  // padding parameters
268  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
269 
270  // multiplication parameters (with denominator 1024)
271  1192, 1192, 1192, 0, -833, 1634, 2066, -400, 0,
272 
273  // bias/translation parameters (with denominator 1)
274  -277, 135, -223
275  };
276 
277  const void* sources[2] =
278  {
279  ySource,
280  vuSource
281  };
282 
283  FrameConverter::convertArbitraryPixelFormat(sources, (void**)&target, width, height, flag, 1u, FrameConverter::convertOneRow1PlaneAnd2ChannelsZippedDownsampled2x2ToZipped3Channels8BitPerChannelPrecision10Bit, options, worker);
284 
285 #endif
286 
287 }
288 
289 inline void FrameConverterY_VU12::convertY_VU12FullRangeToBGRA32FullRangeAndroid(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, const uint8_t alphaValue, Worker* worker)
290 {
291  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
292 
293  ocean_assert(width >= 2u && width % 2u == 0u);
294  ocean_assert(height >= 2u && height % 2u == 0u);
295 
296  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
297  {
298  return;
299  }
300 
301  const int options[3 + 1] =
302  {
303  // padding parameters
304  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
305 
306  // alpha value
307  int(alphaValue)
308  };
309 
310  const void* sources[2] =
311  {
312  ySource,
313  vuSource
314  };
315 
316 #if 1
318 #else
320 #endif
321 
322 }
323 
324 inline void FrameConverterY_VU12::convertY_VU12LimitedRangeToRGB24FullRange(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
325 {
326  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
327 
328  ocean_assert(width >= 2u && width % 2u == 0u);
329  ocean_assert(height >= 2u && height % 2u == 0u);
330 
331  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
332  {
333  return;
334  }
335 
336  // YVU input value range: [16, 235]x[16, 240]x[16, 240]
337  // RGB output value range: [ 0, 255]x[ 0, 255]x[ 0, 255]
338 
339  // precise color space conversion:
340  // | R | | 1.1639404296875 1.595947265625 0.0 -222.904296875 | | Y |
341  // | G | = | 1.1639404296875 -0.81298828125 -0.3909912109375 135.486328125 | * | V |
342  // | B | | 1.1639404296875 0.0 2.0179443359375 -276.919921875 | | U |
343  // | 1 |
344 
345 #if 1
346 
347  // Approximation with 6 bit precision:
348  // | R | | 75 102 0 | | Y - 16 |
349  // 64 * | G | = | 75 -52 -25 | * | V - 128 |
350  // | B | | 75 0 128 | | U - 128 |
351 
352  const int options[3 + 12] =
353  {
354  // padding parameters
355  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
356 
357  // multiplication parameters
358  75, 75, 75, 102, -52, 0, 0, -25, 128,
359 
360  // bias/translation parameters
361  16, 128, 128
362  };
363 
364  const void* sources[2] =
365  {
366  ySource,
367  vuSource
368  };
369 
371 
372 #else
373 
374  // Approximation with 10 bit precision:
375  // | R | | 1192 1634 0 -223 | | Y |
376  // | G | = | 1192 -833 -400 135 | * | U |
377  // | B | | 1192 0 2066 -277 | | V |
378  // | 1 |
379 
380  const int options[3 + 12] =
381  {
382  // padding parameters
383  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
384 
385  // multiplication parameters (with denominator 1024)
386  1192, 1192, 1192, 1634, -833, 0, 0, -400, 2066,
387 
388  // bias/translation parameters (with denominator 1)
389  -223, 135, -277
390  };
391 
392  const void* sources[2] =
393  {
394  ySource,
395  vuSource
396  };
397 
398  FrameConverter::convertArbitraryPixelFormat(sources, (void**)&target, width, height, flag, 1u, FrameConverter::convertOneRow1PlaneAnd2ChannelsZippedDownsampled2x2ToZipped3Channels8BitPerChannelPrecision10Bit, options, worker);
399 
400 #endif
401 
402 }
403 
404 inline void FrameConverterY_VU12::convertY_VU12FullRangeToRGB24FullRangePrecision6Bit(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
405 {
406  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
407 
408  ocean_assert(width >= 2u && width % 2u == 0u);
409  ocean_assert(height >= 2u && height % 2u == 0u);
410 
411  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
412  {
413  return;
414  }
415 
416  /*
417  * | R | | 1.0 1.402 0.0 1.402 -179.456 | | Y |
418  * | G | = | 1.0 -0.71414 -0.34414 -0.71414 135.45984 | * | V |
419  * | B | | 1.0 0.0 1.772 0.0 -226.816 | | U |
420  * | 1 |
421  *
422  * Approximation with 6 bit precision:
423  * | R | | 64 90 0 | | Y |
424  * 64 * | G | = | 64 -46 -22 | * | V - 128 |
425  * | B | | 64 0 113 | | U - 128 |
426  */
427 
428  const int options[3 + 12] =
429  {
430  // padding parameters
431  int(ySourcePaddingElements), int(vuSourcePaddingElements), int(targetPaddingElements),
432 
433  // multiplication parameters
434  64, 64, 64, 90, -46, 0, 0, -22, 113,
435 
436  // bias/translation parameters
437  0, 128, 128
438  };
439 
440  const void* sources[2] =
441  {
442  ySource,
443  vuSource
444  };
445 
447 }
448 
449 inline void FrameConverterY_VU12::convertY_VU12ToYUV24(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
450 {
451  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
452 
453  ocean_assert(width >= 2u && width % 2u == 0u);
454  ocean_assert(height >= 2u && height % 2u == 0u);
455 
456  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
457  {
458  return;
459  }
460 
461  const unsigned int options[3] = {ySourcePaddingElements, vuSourcePaddingElements, targetPaddingElements};
462 
463  const void* sources[2] =
464  {
465  ySource,
466  vuSource
467  };
468 
469  FrameConverter::convertArbitraryPixelFormat(sources, (void**)&target, width, height, flag, 2u, FrameConverter::mapTwoRows_1Plane1ChannelAnd1Plane2ChannelsDownsampled2x2_To_1Plane3Channels_8BitPerChannel<0u, 2u, 1u>, options, worker);
470 }
471 
472 inline void FrameConverterY_VU12::convertY_VU12ToYVU24(const uint8_t* ySource, const uint8_t* vuSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
473 {
474  ocean_assert(ySource != nullptr && vuSource != nullptr && target != nullptr);
475 
476  ocean_assert(width >= 2u && width % 2u == 0u);
477  ocean_assert(height >= 2u && height % 2u == 0u);
478 
479  if (width < 2u || height < 2u || width % 2u != 0u || height % 2u != 0u)
480  {
481  return;
482  }
483 
484  const unsigned int options[3] = {ySourcePaddingElements, vuSourcePaddingElements, targetPaddingElements};
485 
486  const void* sources[2] =
487  {
488  ySource,
489  vuSource
490  };
491 
492  FrameConverter::convertArbitraryPixelFormat(sources, (void**)&target, width, height, flag, 2u, FrameConverter::mapTwoRows_1Plane1ChannelAnd1Plane2ChannelsDownsampled2x2_To_1Plane3Channels_8BitPerChannel<0u, 1u, 2u>, options, worker);
493 }
494 
495 }
496 
497 }
498 
499 #endif // META_OCEAN_CV_FRAME_CONVERTER_Y_VU_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 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 Y_VU12 pixel format.
Definition: FrameConverterY_VU12.h:26
static void convertY_VU12LimitedRangeToBGR24FullRange(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 frame to an 24 bit BGR frame into a second image buffer.
Definition: FrameConverterY_VU12.h:209
static void convertY_VU12FullRangeToBGRA32FullRangeAndroid(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, const uint8_t alphaValue=0xFF, Worker *worker=nullptr)
Converts a full range Y_VU12 frame to a full range BGRA32 frame into a second image buffer applying a...
Definition: FrameConverterY_VU12.h:289
static void convertTwoRowsY_VU12FullRangeToBGRA32FullRangeAndroidPrecision6Bit(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 Y_UV12 pixel format to two rows of an image with BGRA32 pixel form...
static void convertY_VU12LimitedRangeToRGB24FullRange(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 frame to an 24 bit RGB frame into a second image buffer.
Definition: FrameConverterY_VU12.h:324
static void convertY_VU12ToY8(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 frame to an 8 bit gray scale frame into a second image buffer.
Definition: FrameConverterY_VU12.h:201
static void convertY_VU12ToYVU24(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 frame to an 24 bit YVU frame into a second image buffer.
Definition: FrameConverterY_VU12.h:472
static void convertOneRowY_VU12FullRangeToBGRA32FullRangeAndroidPrecision6Bit(const void **sources, void **targets, const unsigned int multipleRowIndex, const unsigned int width, const unsigned int height, const ConversionFlag conversionFlag, const void *options)
Converts one row of an image with Y_UV12 pixel format to one row of an image with BGRA32 pixel format...
static void convertY_VU12ToYUV24(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 frame to an 24 bit YUV frame into a second image buffer.
Definition: FrameConverterY_VU12.h:449
static void convertY_VU12FullRangeToRGB24FullRangePrecision6Bit(const uint8_t *ySource, const uint8_t *vuSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int ySourcePaddingElements, const unsigned int vuSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a Y_VU12 full range frame to an 24 bit RGB frame into a second image buffer.
Definition: FrameConverterY_VU12.h:404
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