Ocean
Loading...
Searching...
No Matches
FrameConverterYUYV16.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_YUYV_16_H
9#define META_OCEAN_CV_FRAME_CONVERTER_YUYV_16_H
10
11#include "ocean/cv/CV.h"
14
15#include "ocean/base/Worker.h"
16
17namespace Ocean
18{
19
20namespace CV
21{
22
23/**
24 * This class provides functions to convert frames with YUYV16 pixel format.
25 * @ingroup cv
26 */
27class OCEAN_CV_EXPORT FrameConverterYUYV16 : public FrameConverter
28{
29 public:
30
31 /**
32 * Converts a YUYV16 frame to a 24 bit BGR frame into a second image buffer.
33 * @param source The source frame buffer, must be valid
34 * @param target The target frame buffer, 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 [1, infinity)
37 * @param flag Determining the type of conversion
38 * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
39 * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
40 * @param worker Optional worker object to distribute the computational to several CPU cores
41 */
42 static inline void convertYUYV16ToBGR24(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);
43
44 /**
45 * Converts a YUYV16 frame to a 24 bit RGB frame into a second image buffer.
46 * @param source The source frame buffer, must be valid
47 * @param target The target frame buffer, must be valid
48 * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
49 * @param height The height of the frame in pixel, with range [1, infinity)
50 * @param flag Determining the type of conversion
51 * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
52 * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
53 * @param worker Optional worker object to distribute the computational to several CPU cores
54 */
55 static inline void convertYUYV16ToRGB24(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);
56
57 /**
58 * Converts a YUYV16 frame to a 24 bit YUV frame into a second image buffer.
59 * @param source The source frame buffer
60 * @param target The target frame buffer
61 * @param width The width of the frame in pixel, must be a multiple of two
62 * @param height The height of the frame in pixel
63 * @param flag Determining the type of conversion
64 * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
65 * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
66 * @param worker Optional worker object to distribute the computational to several CPU cores
67 */
68 static inline void convertYUYV16ToYUV24(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);
69
70 /**
71 * Converts a YUYV16 frame to a 24 bit YVU frame into a second image buffer.
72 * @param source The source frame buffer
73 * @param target The target frame buffer
74 * @param width The width of the frame in pixel, must be a multiple of two
75 * @param height The height of the frame in pixel
76 * @param flag Determining the type of conversion
77 * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
78 * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
79 * @param worker Optional worker object to distribute the computational to several CPU cores
80 */
81 static inline void convertYUYV16ToYVU24(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);
82
83 /**
84 * Converts a YUYV16 frame to a 8 bit grayscale frame into a second image buffer.
85 * @param source The source frame buffer, must be valid
86 * @param target The target frame buffer, must be valid
87 * @param width The width of the frame in pixel, with range [2, infinity), must be a multiple of 2
88 * @param height The height of the frame in pixel, with range [1, infinity)
89 * @param flag Determining the type of conversion
90 * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
91 * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
92 * @param worker Optional worker object to distribute the computational to several CPU cores
93 */
94 static inline void convertYUYV16ToY8(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);
95};
96
97inline void FrameConverterYUYV16::convertYUYV16ToBGR24(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)
98{
99 ocean_assert(source != nullptr && target != nullptr);
100
101 ocean_assert(width >= 2u && width % 2u == 0u);
102 ocean_assert(height >= 1u);
103
104 if (width < 2u || height < 1u || width % 2u != 0u)
105 {
106 return;
107 }
108
109 // | B | | 1192 2066 0 -277 * 1024 | | Y |
110 // 1024 * | G | = | 1192 -400 -833 135 * 1024 | * | U |
111 // | R | | 1192 0 1634 -223 * 1024 | | V |
112 // | 1 |
113
114 const int options[14] =
115 {
116 // padding elements
117 int(sourcePaddingElements), int(targetPaddingElements),
118
119 // multiplication factors, with denominator 1024
120 1192, 1192, 1192, 2066, -400, 0, 0, -833, 1634,
121
122 // bias values, with denominator 1
123 -277, 135, -223
124 };
125
127}
128
129inline void FrameConverterYUYV16::convertYUYV16ToRGB24(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)
130{
131 ocean_assert(source != nullptr && target != nullptr);
132
133 ocean_assert(width >= 2u && width % 2u == 0u);
134 ocean_assert(height >= 1u);
135
136 if (width < 2u || height < 1u || width % 2u != 0u)
137 {
138 return;
139 }
140
141 // | R | | 1192 0 1634 -223 * 1024 | | Y |
142 // 1024 * | G | = | 1192 -400 -833 135 * 1024 | * | U |
143 // | B | | 1192 2066 0 -277 * 1024 | | V |
144 // | 1 |
145
146 const int options[14] =
147 {
148 // padding elements
149 int(sourcePaddingElements), int(targetPaddingElements),
150
151 // multiplication factors, with denominator 1024
152 1192, 1192, 1192, 0, -400, 2066, 1634, -833, 0,
153
154 // bias values, with denominator 1
155 -223, 135, -277
156 };
157
159}
160
161inline void FrameConverterYUYV16::convertYUYV16ToYUV24(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)
162{
163 ocean_assert(source != nullptr && target != nullptr);
164
165 ocean_assert(width >= 2u && width % 2u == 0u);
166 ocean_assert(height >= 1u);
167
168 if (width < 2u || height < 1u || width % 2u != 0u)
169 {
170 return;
171 }
172
173 const unsigned int options[2] = {sourcePaddingElements, targetPaddingElements};
174
175 FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_1Plane3ChannelsWith2ChannelsDownsampled2x1BackIsDownsampled_To_1Plane3Channels_8BitPerChannel<0u, 1u, 2u>, options, worker);
176}
177
178inline void FrameConverterYUYV16::convertYUYV16ToYVU24(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)
179{
180 ocean_assert(source != nullptr && target != nullptr);
181
182 ocean_assert(width >= 2u && width % 2u == 0u);
183 ocean_assert(height >= 1u);
184
185 if (width < 2u || height < 1u || width % 2u != 0u)
186 {
187 return;
188 }
189
190 const unsigned int options[2] = {sourcePaddingElements, targetPaddingElements};
191
192 FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_1Plane3ChannelsWith2ChannelsDownsampled2x1BackIsDownsampled_To_1Plane3Channels_8BitPerChannel<0u, 2u, 1u>, options, worker);
193}
194
195inline void FrameConverterYUYV16::convertYUYV16ToY8(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)
196{
197 ocean_assert(source != nullptr && target != nullptr);
198 ocean_assert(width >= 2u && width % 2u == 0u);
199 ocean_assert(height >= 1u);
200
201 if (width % 2u != 0u || height == 0u)
202 {
203 return;
204 }
205
206 // we simply treat YUYV as e.g., YA
207
208 // source frame Y U/V
209 // 0 1
210 // target frame Y
211 // pattern 0
212 constexpr unsigned int shufflePattern = 0x0u;
213
214 FrameChannels::shuffleChannels<uint8_t, 2u, 1u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
215}
216
217}
218
219}
220
221#endif // META_OCEAN_CV_FRAME_CONVERTER_YUYV_16_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 convertOneRow_1Plane3ChannelsWith2ChannelsDownsampled2x1BackIsDownsampled_To_1Plane3Channels_8BitPerChannel_Precision10Bit(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 e.g., a YUYV16 pixel format to one row 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 YUYV16 pixel format.
Definition FrameConverterYUYV16.h:28
static void convertYUYV16ToRGB24(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 YUYV16 frame to a 24 bit RGB frame into a second image buffer.
Definition FrameConverterYUYV16.h:129
static void convertYUYV16ToBGR24(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 YUYV16 frame to a 24 bit BGR frame into a second image buffer.
Definition FrameConverterYUYV16.h:97
static void convertYUYV16ToYUV24(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 YUYV16 frame to a 24 bit YUV frame into a second image buffer.
Definition FrameConverterYUYV16.h:161
static void convertYUYV16ToY8(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 YUYV16 frame to a 8 bit grayscale frame into a second image buffer.
Definition FrameConverterYUYV16.h:195
static void convertYUYV16ToYVU24(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 YUYV16 frame to a 24 bit YVU frame into a second image buffer.
Definition FrameConverterYUYV16.h:178
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