Ocean
FrameConverterABGR32.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_ABGR_32_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_ABGR_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 ABGR 32 bit pixel format.
23  * @ingroup cv
24  */
26 {
27  public:
28 
29  /**
30  * Converts a frame with ABGR32 pixel format to ABGR32 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 convertABGR32ToABGR32(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 ABGR32 pixel format to BGR24 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 convertABGR32ToBGR24(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 ABGR32 pixel format to BGRA32 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 convertABGR32ToBGRA32(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 ABGR32 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 convertABGR32ToRGBA32(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 FrameConverterABGR32::convertABGR32ToABGR32(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 FrameConverterABGR32::convertABGR32ToBGR24(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::removeFirstChannel<uint8_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
96 }
97 
98 inline void FrameConverterABGR32::convertABGR32ToBGRA32(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  // source frame A B G R
104  // 0 1 2 3
105  // target frame B G R A
106  // pattern 1 2 3 0
107 
108  constexpr unsigned int shufflePattern = 0x0321u;
109 
110  FrameChannels::shuffleChannels<uint8_t, 4u, 4u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
111 }
112 
113 inline void FrameConverterABGR32::convertABGR32ToRGBA32(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)
114 {
115  ocean_assert(source != nullptr && target != nullptr);
116  ocean_assert(width >= 1u && height >= 1u);
117 
118  FrameChannels::reverseChannelOrder<uint8_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
119 }
120 
121 }
122 
123 }
124 
125 #endif // META_OCEAN_CV_FRAME_CONVERTER_ABGR_32_H
This class implements functions to convert frames with ABGR 32 bit pixel format.
Definition: FrameConverterABGR32.h:26
static void convertABGR32ToBGRA32(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 ABGR32 pixel format to BGRA32 pixel format.
Definition: FrameConverterABGR32.h:98
static void convertABGR32ToBGR24(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 ABGR32 pixel format to BGR24 pixel format.
Definition: FrameConverterABGR32.h:90
static void convertABGR32ToABGR32(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 ABGR32 pixel format to ABGR32 pixel format.
Definition: FrameConverterABGR32.h:82
static void convertABGR32ToRGBA32(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 ABGR32 pixel format to RGBA32 pixel format.
Definition: FrameConverterABGR32.h:113
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