Ocean
FrameConverterRGGB10_Packed.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_RGGB_10_PACKED_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_RGGB_10_PACKED_H
10 
11 #include "ocean/cv/CV.h"
12 #include "ocean/cv/FrameChannels.h"
15 
16 #include "ocean/base/Worker.h"
17 
18 namespace Ocean
19 {
20 
21 namespace CV
22 {
23 
24 /**
25  * This class provides functions to convert frames with RGGB10_PACKED pixel format.
26  * @ingroup cv
27  */
28 class OCEAN_CV_EXPORT FrameConverterRGGB10_Packed : public FrameConverter
29 {
30  public:
31 
32  /**
33  * Converts a RGGB10_PACKED frame to a BGR24 frame.
34  * @param source The source frame buffer, must be valid
35  * @param target The target frame buffer, must be valid
36  * @param width The width of the frame in pixel, with range [4, infinity), must be a multiple of 4
37  * @param height The height of the frame in pixel, with range [1, infinity)
38  * @param flag Determining the type of conversion
39  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
40  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
41  * @param worker Optional worker object to distribute the computational load
42  */
43  static inline void convertRGGB10_PackedToBGR24(const uint8_t* const source, uint8_t* const target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
44 
45  /**
46  * Converts a RGGB10_PACKED frame to a RGB24 frame.
47  * @param source The source frame buffer, must be valid
48  * @param target The target frame buffer, must be valid
49  * @param width The width of the frame in pixel, with range [4, infinity), must be a multiple of 4
50  * @param height The height of the frame in pixel, with range [1, infinity)
51  * @param flag Determining the type of conversion
52  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
53  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
54  * @param worker Optional worker object to distribute the computational load
55  */
56  static inline void convertRGGB10_PackedToRGB24(const uint8_t* const source, uint8_t* const target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
57 
58  /**
59  * Converts a RGGB10_PACKED frame to a RGB48 frame.
60  * @param source The source frame buffer, must be valid
61  * @param target The target frame buffer, must be valid
62  * @param width The width of the frame in pixel, with range [4, infinity), must be a multiple of 4
63  * @param height The height of the frame in pixel, with range [1, infinity)
64  * @param flag Determining the type of conversion
65  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
66  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
67  * @param worker Optional worker object to distribute the computational load
68  */
69  static inline void convertRGGB10_PackedToRGB48(const uint8_t* const source, uint16_t* const target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
70 
71  /**
72  * Converts a RGGB10_PACKED frame to a RGB24 frame with black level subtraction, white balance, and gamma encoding
73  * @param source The source frame buffer, must be valid
74  * @param target The target frame buffer, must be valid
75  * @param width The width of the frame in pixel, with range [4, infinity), must be a multiple of 4
76  * @param height The height of the frame in pixel, with range [1, infinity)
77  * @param flag Determining the type of conversion
78  * @param blackLevel The black level value that is subtracted from each element of the raw image before any other operation, range: [0, 1024)
79  * @param whiteBalance The white balancing scalars of the red, green, and blue channel (in that order), range: [0, infinity), must be valid, will be ignored channel-wise for values < 0
80  * @param gamma The gamma value that each pixel will be encoded with, range: [0, infinity), will be ignored if value is < 0
81  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
82  * @param targetPaddingElements The number of padding elements at the end of each target row, in elements, with range [0, infinity)
83  * @param worker Optional worker object to distribute the computational load
84  */
85  static inline void convertRGGB10_PackedToRGB24BlacklevelWhiteBalanceGammaLUT(const uint8_t* source, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const uint16_t blackLevel, const float* whiteBalance, const float gamma, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker = nullptr);
86 };
87 
88 inline void FrameConverterRGGB10_Packed::convertRGGB10_PackedToBGR24(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)
89 {
90  ocean_assert(source != nullptr && target != nullptr);
91  ocean_assert(width >= 4u && height >= 1u);
92  ocean_assert(width % 4u == 0u);
93 
94  const int options[2] =
95  {
96  // padding parameters
97  int(sourcePaddingElements), int(targetPaddingElements)
98  };
99 
100  FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 2u, FrameConverter::convertTwoRows_1PlaneMosaicPacked10Bit_To_1PlaneUnpacked3Channels8Bit<2u, 1u, 0u>, options, worker);
101 }
102 
103 inline void FrameConverterRGGB10_Packed::convertRGGB10_PackedToRGB24(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)
104 {
105  ocean_assert(source != nullptr && target != nullptr);
106  ocean_assert(width >= 4u && height >= 1u);
107  ocean_assert(width % 4u == 0u);
108 
109  const int options[2] =
110  {
111  // padding parameters
112  int(sourcePaddingElements), int(targetPaddingElements)
113  };
114 
115  FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 2u, FrameConverter::convertTwoRows_1PlaneMosaicPacked10Bit_To_1PlaneUnpacked3Channels8Bit<0u, 1u, 2u>, options, worker);
116 }
117 
118 inline void FrameConverterRGGB10_Packed::convertRGGB10_PackedToRGB48(const uint8_t* const source, uint16_t* const target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
119 {
120  ocean_assert(source != nullptr && target != nullptr);
121  ocean_assert(width >= 4u && height >= 1u);
122  ocean_assert(width % 4u == 0u);
123 
124  const int options[2] =
125  {
126  // padding parameters
127  int(sourcePaddingElements), int(targetPaddingElements)
128  };
129 
130  FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 2u, FrameConverter::convertTwoRows_1PlaneMosaicPacked10Bit_To_1PlaneUnpacked3Channels16Bit<0u, 1u, 2u>, options, worker);
131 }
132 
133 inline void FrameConverterRGGB10_Packed::convertRGGB10_PackedToRGB24BlacklevelWhiteBalanceGammaLUT(const uint8_t* source, uint8_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const uint16_t blackLevel, const float* whiteBalance, const float gamma, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
134 {
135  ocean_assert(source != nullptr && target != nullptr);
136  ocean_assert(width >= 4u && height >= 1u);
137  ocean_assert(width % 4u == 0u);
138  ocean_assert(whiteBalance != nullptr && whiteBalance[0] >= 0.0f && whiteBalance[1] >= 0.0f && whiteBalance[2] >= 0.0f);
139  ocean_assert(gamma > 0.0f);
140 
141  // White balance as fixed-point numbers with 7 bit precision
142  const unsigned int whiteBalance7[3] =
143  {
144  (unsigned int)(whiteBalance[0] * 128.0f + 0.5f),
145  (unsigned int)(whiteBalance[1] * 128.0f + 0.5f),
146  (unsigned int)(whiteBalance[2] * 128.0f + 0.5f),
147  };
148 
149  const uint8_t* gammaLookupValues = FrameConverterY10_Packed::LookupTableManager::get().lookupTable(gamma);
150 
151  const FrameConverter::RGGB10ToRGB24AdvancedOptions options{blackLevel, {whiteBalance7[0], whiteBalance7[1], whiteBalance7[2]}, gammaLookupValues, sourcePaddingElements, targetPaddingElements};
152 
153  FrameConverter::convertArbitraryPixelFormat((const void**)(&source), (void**)(&target), width, height, flag, 2u, FrameConverter::convertTwoRows_1PlaneMosaicPacked10Bit_To_1PlaneUnpacked3Channels8BitAdvanced<0u, 1u, 2u>, &options, worker);
154 }
155 
156 }
157 
158 }
159 
160 #endif // META_OCEAN_CV_FRAME_CONVERTER_RGGB_10_PACKED_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 RGGB10_PACKED pixel format.
Definition: FrameConverterRGGB10_Packed.h:29
static void convertRGGB10_PackedToRGB24BlacklevelWhiteBalanceGammaLUT(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const uint16_t blackLevel, const float *whiteBalance, const float gamma, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Converts a RGGB10_PACKED frame to a RGB24 frame with black level subtraction, white balance,...
Definition: FrameConverterRGGB10_Packed.h:133
static void convertRGGB10_PackedToRGB48(const uint8_t *const source, uint16_t *const 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 RGGB10_PACKED frame to a RGB48 frame.
Definition: FrameConverterRGGB10_Packed.h:118
static void convertRGGB10_PackedToRGB24(const uint8_t *const source, uint8_t *const 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 RGGB10_PACKED frame to a RGB24 frame.
Definition: FrameConverterRGGB10_Packed.h:103
static void convertRGGB10_PackedToBGR24(const uint8_t *const source, uint8_t *const 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 RGGB10_PACKED frame to a BGR24 frame.
Definition: FrameConverterRGGB10_Packed.h:88
static LookupTableManager & get()
Returns a reference to the unique object.
Definition: Singleton.h:115
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
Definition of the parameters used by the function for row-wise conversion of RGGB14_PACKED to RGB24/B...
Definition: FrameConverter.h:595