Ocean
FrameConverterYA16.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_YA_16_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_YA_16_H
10 
11 #include "ocean/cv/CV.h"
13 #include "ocean/cv/FrameChannels.h"
14 
15 namespace Ocean
16 {
17 
18 namespace CV
19 {
20 
21 /**
22  * This class provides functions to convert frames with YA16 pixel format.
23  * @ingroup cv
24  */
25 class OCEAN_CV_EXPORT FrameConverterYA16 : public FrameConverter
26 {
27  public:
28 
29  /**
30  * Converts a YA 16 bit frame to a BGRA 32 bit frame.
31  * @param source The source frame, must be valid
32  * @param target The target frame, must be valid
33  * @param width The width of the frame in pixel, with range [1, infinity)
34  * @param height The height of the frame in pixel, with range [1, infinity)
35  * @param flag Determining the type of conversion
36  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
37  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
38  * @param worker Optional worker object to distribute the computational load
39  */
40  static inline void convertYA16ToBGRA32(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);
41 
42  /**
43  * Converts a YA 16 bit frame to a RGBA 32 bit frame.
44  * @param source The source frame, must be valid
45  * @param target The target frame, must be valid
46  * @param width The width of the frame in pixel, with range [1, infinity)
47  * @param height The height of the frame in pixel, with range [1, infinity)
48  * @param flag Determining the type of conversion
49  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
50  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
51  * @param worker Optional worker object to distribute the computational load
52  */
53  static inline void convertYA16ToRGBA32(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);
54 
55  /**
56  * Converts a YA 16 bit frame to a Y 8 bit frame.
57  * @param source The source frame, must be valid
58  * @param target The target frame, must be valid
59  * @param width The width of the frame in pixel, with range [1, infinity)
60  * @param height The height of the frame in pixel, with range [1, infinity)
61  * @param flag Determining the type of conversion
62  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
63  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
64  * @param worker Optional worker to distribute the computation to several CPU cores
65  */
66  static inline void convertYA16ToY8(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);
67 
68  /**
69  * Converts a YA 16 bit frame to a YA 16 bit frame.
70  * @param source The source frame, must be valid
71  * @param target The target frame, must be valid
72  * @param width The width of the frame in pixel, with range [1, infinity)
73  * @param height The height of the frame in pixel, with range [1, infinity)
74  * @param flag Determining the type of conversion
75  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
76  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
77  * @param worker Optional worker object to distribute the computational load
78  */
79  static inline void convertYA16ToYA16(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);
80 };
81 
82 inline void FrameConverterYA16::convertYA16ToBGRA32(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)
83 {
84  ocean_assert(source != nullptr && target != nullptr);
85  ocean_assert(width >= 1u && height >= 1u);
86 
87  // source frame Y A
88  // 0 1
89  // target frame B G R A
90  // pattern 0 0 0 1
91  constexpr unsigned int shufflePattern = 0x1000u;
92 
93  FrameChannels::shuffleChannels<uint8_t, 2u, 4u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
94 }
95 
96 inline void FrameConverterYA16::convertYA16ToRGBA32(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)
97 {
98  ocean_assert(source != nullptr && target != nullptr);
99  ocean_assert(width >= 1u && height >= 1u);
100 
101  // source frame Y A
102  // 0 1
103  // target frame R G B A
104  // pattern 0 0 0 1
105  constexpr unsigned int shufflePattern = 0x1000u;
106 
107  FrameChannels::shuffleChannels<uint8_t, 2u, 4u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
108 }
109 
110 inline void FrameConverterYA16::convertYA16ToY8(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)
111 {
112  ocean_assert(source != nullptr && target != nullptr);
113  ocean_assert(width >= 1u && height >= 1u);
114 
115  FrameChannels::removeLastChannel<uint8_t, 2u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
116 }
117 
118 inline void FrameConverterYA16::convertYA16ToYA16(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)
119 {
120  ocean_assert(source != nullptr && target != nullptr);
121  ocean_assert(width >= 1u && height >= 1u);
122 
123  FrameChannels::transformGeneric<uint8_t, 2u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
124 }
125 
126 }
127 
128 }
129 
130 #endif // META_OCEAN_CV_FRAME_CONVERTER_YA_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
This class provides functions to convert frames with YA16 pixel format.
Definition: FrameConverterYA16.h:26
static void convertYA16ToRGBA32(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 YA 16 bit frame to a RGBA 32 bit frame.
Definition: FrameConverterYA16.h:96
static void convertYA16ToY8(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 YA 16 bit frame to a Y 8 bit frame.
Definition: FrameConverterYA16.h:110
static void convertYA16ToBGRA32(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 YA 16 bit frame to a BGRA 32 bit frame.
Definition: FrameConverterYA16.h:82
static void convertYA16ToYA16(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 YA 16 bit frame to a YA 16 bit frame.
Definition: FrameConverterYA16.h:118
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