Ocean
FrameConverterRGB32.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_RGB_32_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_RGB_32_H
10 
11 #include "ocean/cv/CV.h"
13 #include "ocean/cv/FrameChannels.h"
14 
15 #include "ocean/base/Worker.h"
16 
17 namespace Ocean
18 {
19 
20 namespace CV
21 {
22 
23 /**
24  * This class provides functions to convert or to change frames with RGB pixel format.
25  * @ingroup cv
26  */
27 class OCEAN_CV_EXPORT FrameConverterRGB32 : public FrameConverter
28 {
29  public:
30 
31  /**
32  * Converts a RGB 24 bit frame to a RGB 24 bit frame.
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 (0, infinity)
36  * @param height The height of the frame in pixel, with range (0, 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 load
41  */
42  static inline void convertRGB32ToRGB24(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 RGB 32 bit frame to a RGBA 32 bit frame.
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 (0, infinity)
49  * @param height The height of the frame in pixel, with range (0, 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 alphaValue The value of the alpha channel to be set, with range [0, 255]
54  * @param worker Optional worker object to distribute the computational load
55  */
56  static inline void convertRGB32ToRGBA32(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, const uint8_t alphaValue = 0xFF, Worker* worker = nullptr);
57 };
58 
59 inline void FrameConverterRGB32:: convertRGB32ToRGB24(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)
60 {
61  ocean_assert(source != nullptr && target != nullptr);
62  ocean_assert(width >= 1u && height >= 1u);
63 
64  // source frame R G B -
65  // 0 1 2 3
66  // target frame R G B A
67  // pattern 0 1 2
68  constexpr unsigned int shufflePattern = 0x210u;
69 
70  FrameChannels::shuffleChannels<uint8_t, 4u, 3u, shufflePattern>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
71 }
72 
73 inline void FrameConverterRGB32::convertRGB32ToRGBA32(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, const uint8_t alphaValue, Worker* worker)
74 {
75  ocean_assert(source != nullptr && target != nullptr);
76  ocean_assert(width >= 1u && height >= 1u);
77 
78  // source frame R G B -
79  // 0 1 2 3
80  // target frame R G B A
81  // pattern 0 1 2
82  constexpr unsigned int shufflePattern = 0x210u;
83 
84  FrameChannels::shuffleChannelsAndSetLastChannelValue<uint8_t, 4u, 4u, shufflePattern>(source, alphaValue, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
85 }
86 
87 }
88 
89 }
90 
91 
92 #endif // META_OCEAN_CV_FRAME_CONVERTER_RGB_32_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 or to change frames with RGB pixel format.
Definition: FrameConverterRGB32.h:28
static void convertRGB32ToRGBA32(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, const uint8_t alphaValue=0xFF, Worker *worker=nullptr)
Converts a RGB 32 bit frame to a RGBA 32 bit frame.
Definition: FrameConverterRGB32.h:73
static void convertRGB32ToRGB24(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 RGB 24 bit frame to a RGB 24 bit frame.
Definition: FrameConverterRGB32.h:59
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