Ocean
FrameConverterB_G_R24.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_B_G_R_24_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_B_G_R_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 B_G_R24 pixel format.
25  * The B_G_R24 format holds the three planes/blocks of color channels.<br>
26  * The first block covers the B 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 R channel and also holds 8 bit per pixel.
29  * The layout of a B_G_R24 image looks like this:
30  * <pre>
31  * b-plane: g-plane: r-plane:
32  * --------- --------- ---------
33  * | B B B B | | G G G G | | R R R R |
34  * | B B B B | | G G G G | | R R R R |
35  * | B B B B | | G G G G | | R R R R |
36  * | B B B B | | G G G G | | R R R R |
37  * --------- --------- ---------
38  * </pre>
39  * @ingroup cv
40  */
42 {
43  public:
44 
45  /**
46  * Converts a B_G_R24 frame to a 24 bit BGR frame into a second image buffer.
47  * @param bSource The b source frame buffer, must be valid
48  * @param gSource The g source frame buffer, must be valid
49  * @param rSource The r 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 bSourcePaddingElements The number of padding elements at the end of each b-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 rSourcePaddingElements The number of padding elements at the end of each r-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 convertB_G_R24ToBGR24(const uint8_t* bSource, const uint8_t* gSource, const uint8_t* rSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
61 
62  /**
63  * Converts a B_G_R24 frame to a 24 bit RGB frame into a second image buffer.
64  * @param bSource The b source frame buffer, must be valid
65  * @param gSource The g source frame buffer, must be valid
66  * @param rSource The r 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 bSourcePaddingElements The number of padding elements at the end of each b-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 rSourcePaddingElements The number of padding elements at the end of each r-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 convertB_G_R24ToRGB24(const uint8_t* bSource, const uint8_t* gSource, const uint8_t* rSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
78 };
79 
80 inline void FrameConverterB_G_R24::convertB_G_R24ToBGR24(const uint8_t* bSource, const uint8_t* gSource, const uint8_t* rSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
81 {
82  ocean_assert(bSource != nullptr && gSource != nullptr && rSource != nullptr && target != nullptr);
83 
84  const int options[4] =
85  {
86  // padding parameters
87  int(bSourcePaddingElements), int(gSourcePaddingElements), int(rSourcePaddingElements), int(targetPaddingElements)
88  };
89 
90  const void* sources[3] =
91  {
92  bSource,
93  gSource,
94  rSource
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 FrameConverterB_G_R24::convertB_G_R24ToRGB24(const uint8_t* bSource, const uint8_t* gSource, const uint8_t* rSource, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
101 {
102  ocean_assert(bSource != nullptr && gSource != nullptr && rSource != nullptr && target != nullptr);
103 
104  const int options[4] =
105  {
106  // padding parameters
107  int(bSourcePaddingElements), int(gSourcePaddingElements), int(rSourcePaddingElements), int(targetPaddingElements)
108  };
109 
110  const void* sources[3] =
111  {
112  bSource,
113  gSource,
114  rSource
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_B_G_R_24_H
This class provides functions to convert frames with B_G_R24 pixel format.
Definition: FrameConverterB_G_R24.h:42
static void convertB_G_R24ToRGB24(const uint8_t *bSource, const uint8_t *gSource, const uint8_t *rSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a B_G_R24 frame to a 24 bit RGB frame into a second image buffer.
Definition: FrameConverterB_G_R24.h:100
static void convertB_G_R24ToBGR24(const uint8_t *bSource, const uint8_t *gSource, const uint8_t *rSource, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int bSourcePaddingElements, const unsigned int gSourcePaddingElements, const unsigned int rSourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a B_G_R24 frame to a 24 bit BGR frame into a second image buffer.
Definition: FrameConverterB_G_R24.h:80
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 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