Ocean
FrameConverterR_G_B24.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_R_G_B_24_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_R_G_B_24_H
10 
11 #include "ocean/cv/CV.h"
12 #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 frames with R_G_B24 pixel format.
25  * The R_G_B24 format holds the three planes/blocks of color channels.<br>
26  * The first block covers the R channel and holds 8 bit per pixel.<br>
27  * The second block covers the G channel and holds 8 bit per pixel.<br>
28  * The third block covers the B channel and also holds 8 bit per pixel.
29  * The layout of a R_G_B24 image looks like this:
30  * <pre>
31  * r-plane: g-plane: b-plane:
32  * --------- --------- ---------
33  * | R R R R | | G G G G | | B B B B |
34  * | R R R R | | G G G G | | B B B B |
35  * | R R R R | | G G G G | | B B B B |
36  * | R R R R | | G G G G | | B B B B |
37  * --------- --------- ---------
38  * </pre>
39  * @ingroup cv
40  */
42 {
43  public:
44 
45  /**
46  * Converts a R_G_B24 frame to a 24 bit RGB frame into a second image buffer.
47  * @param rSource The r source frame buffer, must be valid
48  * @param gSource The g source frame buffer, must be valid
49  * @param bSource The b source frame buffer, must be valid
50  * @param target The target frame buffer, must be valid
51  * @param width The width of the frame in pixel, with range [1, infinity)
52  * @param height The height of the frame in pixel, with range [1, infinity)
53  * @param flag Determining the type of conversion
54  * @param rSourcePaddingElements The number of padding elements at the end of each r-source row, in (uint8_t) elements, with range [0, infinity)
55  * @param gSourcePaddingElements The number of padding elements at the end of each g-source row, in (uint8_t) elements, with range [0, infinity)
56  * @param bSourcePaddingElements The number of padding elements at the end of each b-source row, in (uint8_t) elements, with range [0, infinity)
57  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
58  * @param worker Optional worker object to distribute the computational to several CPU cores
59  */
60  static inline void convertR_G_B24ToRGB24(const uint8_t* rSource, const uint8_t* gSource, const uint8_t* bSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
61 
62  /**
63  * Converts a R_G_B24 frame to a 24 bit BGR frame into a second image buffer.
64  * @param rSource The r source frame buffer, must be valid
65  * @param gSource The g source frame buffer, must be valid
66  * @param bSource The b source frame buffer, must be valid
67  * @param target The target frame buffer, must be valid
68  * @param width The width of the frame in pixel, with range [1, infinity)
69  * @param height The height of the frame in pixel, with range [1, infinity)
70  * @param flag Determining the type of conversion
71  * @param rSourcePaddingElements The number of padding elements at the end of each r-source row, in (uint8_t) elements, with range [0, infinity)
72  * @param gSourcePaddingElements The number of padding elements at the end of each g-source row, in (uint8_t) elements, with range [0, infinity)
73  * @param bSourcePaddingElements The number of padding elements at the end of each b-source row, in (uint8_t) elements, with range [0, infinity)
74  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
75  * @param worker Optional worker object to distribute the computational to several CPU cores
76  */
77  static inline void convertR_G_B24ToBGR24(const uint8_t* rSource, const uint8_t* gSource, const uint8_t* bSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
78 };
79 
80 inline void FrameConverterR_G_B24::convertR_G_B24ToRGB24(const uint8_t* rSource, const uint8_t* gSource, const uint8_t* bSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
81 {
82  ocean_assert(rSource != nullptr && gSource != nullptr && bSource != nullptr && target != nullptr);
83 
84  const int options[4] =
85  {
86  // padding parameters
87  int(rSourcePaddingElements), int(gSourcePaddingElements), int(bSourcePaddingElements), int(targetPaddingElements)
88  };
89 
90  const void* sources[3] =
91  {
92  rSource,
93  gSource,
94  bSource
95  };
96 
97  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_3Plane1Channel_To_1Plane3Channels_8BitPerChannel<0u, 1u, 2u>, options, worker);
98 }
99 
100 inline void FrameConverterR_G_B24::convertR_G_B24ToBGR24(const uint8_t* rSource, const uint8_t* gSource, const uint8_t* bSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
101 {
102  ocean_assert(rSource != nullptr && gSource != nullptr && bSource != nullptr && target != nullptr);
103 
104  const int options[4] =
105  {
106  // padding parameters
107  int(rSourcePaddingElements), int(gSourcePaddingElements), int(bSourcePaddingElements), int(targetPaddingElements)
108  };
109 
110  const void* sources[3] =
111  {
112  rSource,
113  gSource,
114  bSource
115  };
116 
117  FrameConverter::convertArbitraryPixelFormat(sources, (void**)(&target), width, height, flag, 1u, FrameConverter::mapOneRow_3Plane1Channel_To_1Plane3Channels_8BitPerChannel<2u, 1u, 0u>, options, worker);
118 }
119 
120 }
121 
122 }
123 
124 #endif // META_OCEAN_CV_FRAME_CONVERTER_R_G_B_24_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 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 R_G_B24 pixel format.
Definition: FrameConverterR_G_B24.h:42
static void convertR_G_B24ToRGB24(const uint8_t *rSource, const uint8_t *gSource, const uint8_t *bSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a R_G_B24 frame to a 24 bit RGB frame into a second image buffer.
Definition: FrameConverterR_G_B24.h:80
static void convertR_G_B24ToBGR24(const uint8_t *rSource, const uint8_t *gSource, const uint8_t *bSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int rSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int bSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a R_G_B24 frame to a 24 bit BGR frame into a second image buffer.
Definition: FrameConverterR_G_B24.h:100
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