Ocean
FrameConverterARGB32.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_ARGB_32_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_ARGB_32_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 implements functions to convert frames with ARGB 32 bit pixel format.
23  * @ingroup cv
24  */
26 {
27  public:
28 
29  /**
30  * Converts a frame with ARGB32 pixel format to ARGB32 pixel format.
31  * @param source The source frame buffer, must be valid
32  * @param target The target frame buffer, 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 computation
39  */
40  static inline void convertARGB32ToARGB32(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 frame with ARGB32 pixel format to BGRA32 pixel format.
44  * @param source The source frame buffer, must be valid
45  * @param target The target frame buffer, 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 computation
52  */
53  static inline void convertARGB32ToBGRA32(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 frame with ARGB32 pixel format to RGB24 pixel format.
57  * @param source The source frame buffer, must be valid
58  * @param target The target frame buffer, 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 object to distribute the computation
65  */
66  static inline void convertARGB32ToRGB24(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 frame with ARGB32 pixel format to RGBA32 pixel format.
70  * @param source The source frame buffer, must be valid
71  * @param target The target frame buffer, 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 computation
78  */
79  static inline void convertARGB32ToRGBA32(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 FrameConverterARGB32::convertARGB32ToARGB32(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  FrameChannels::transformGeneric<uint8_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
88 }
89 
90 inline void FrameConverterARGB32::convertARGB32ToBGRA32(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)
91 {
92  ocean_assert(source != nullptr && target != nullptr);
93  ocean_assert(width >= 1u && height >= 1u);
94 
95  FrameChannels::reverseChannelOrder<uint8_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
96 }
97 
98 inline void FrameConverterARGB32::convertARGB32ToRGB24(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)
99 {
100  ocean_assert(source != nullptr && target != nullptr);
101  ocean_assert(width >= 1u && height >= 1u);
102 
103  FrameChannels::removeFirstChannel<uint8_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
104 }
105 
106 inline void FrameConverterARGB32::convertARGB32ToRGBA32(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)
107 {
108  ocean_assert(source != nullptr && target != nullptr);
109  ocean_assert(width >= 1u && height >= 1u);
110 
111  // source frame A R G B
112  // 0 1 2 3
113  // target frame R G B A
114  // pattern 1 2 3 0
115  constexpr unsigned int shufflePattern = 0x0321;
116 
117  FrameChannels::shuffleChannels<uint8_t, 4u, 4u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
118 }
119 
120 }
121 
122 }
123 
124 #endif // META_OCEAN_CV_FRAME_CONVERTER_ARGB_32_H
This class implements functions to convert frames with ARGB 32 bit pixel format.
Definition: FrameConverterARGB32.h:26
static void convertARGB32ToBGRA32(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 frame with ARGB32 pixel format to BGRA32 pixel format.
Definition: FrameConverterARGB32.h:90
static void convertARGB32ToARGB32(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 frame with ARGB32 pixel format to ARGB32 pixel format.
Definition: FrameConverterARGB32.h:82
static void convertARGB32ToRGBA32(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 frame with ARGB32 pixel format to RGBA32 pixel format.
Definition: FrameConverterARGB32.h:106
static void convertARGB32ToRGB24(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 frame with ARGB32 pixel format to RGB24 pixel format.
Definition: FrameConverterARGB32.h:98
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 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