Ocean
FrameConverterRGBA64.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_RGBA_64_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_RGBA_64_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 provides functions to convert frames with RGBA64 pixel format.
23  * @ingroup cv
24  */
25 class OCEAN_CV_EXPORT FrameConverterRGBA64 : public FrameConverter
26 {
27  public:
28 
29  /**
30  * Converts an RGBA 64 bit frame to a RGB 24 bit frame.
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 to distribute the computation to several CPU cores
39  */
40  static inline void convertRGBA64ToRGB24(const uint16_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 an RGBA 64 bit frame to a RGBA 32 bit frame.
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 to distribute the computation to several CPU cores
52  */
53  static inline void convertRGBA64ToRGBA32(const uint16_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 an RGBA 64 bit frame to a RGBA 64 bit frame.
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 to distribute the computation to several CPU cores
65  */
66  static inline void convertRGBA64ToRGBA64(const uint16_t* source, uint16_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  protected:
69 
70  /**
71  * Converts a RGBA64 row to a RGB24 row applying a linear conversion.
72  * @param source The pointer to the source pixels, must be valid
73  * @param target The pointer to the target pixels receiving the converted pixel data, must be valid
74  * @param size The number of source (and target pixels) to convert, with range [1, infinity)
75  * @param unusedParameters Unused parameters, must be nullptr
76  */
77  static inline void convertRowRGBA64ToRGB24(const uint16_t* source, uint8_t* target, const size_t size, const void* unusedParameters = nullptr);
78 
79  /**
80  * Converts a RGBA64 row to a RGBA32 row applying a linear conversion.
81  * @param source The pointer to the source pixels, must be valid
82  * @param target The pointer to the target pixels receiving the converted pixel data, must be valid
83  * @param size The number of source (and target pixels) to convert, with range [1, infinity)
84  * @param unusedParameters Unused parameters, must be nullptr
85  */
86  static inline void convertRowRGBA64ToRGBA32(const uint16_t* source, uint8_t* target, const size_t size, const void* unusedParameters = nullptr);
87 
88 };
89 
90 inline void FrameConverterRGBA64::convertRGBA64ToRGB24(const uint16_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  const unsigned int sourceStrideElements = width * 4u + sourcePaddingElements;
96  const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
97 
98  const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
99 
100  FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag, convertRowRGBA64ToRGB24, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, nullptr, worker);
101 }
102 
103 inline void FrameConverterRGBA64::convertRGBA64ToRGBA32(const uint16_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 >= 1u && height >= 1u);
107 
108  const unsigned int sourceStrideElements = width * 4u + sourcePaddingElements;
109  const unsigned int targetStrideElements = width * 4u + targetPaddingElements;
110 
111  const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
112 
113  FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag, convertRowRGBA64ToRGBA32, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 4u>, areContinuous, nullptr, worker);
114 }
115 
116 inline void FrameConverterRGBA64::convertRGBA64ToRGBA64(const uint16_t* source, uint16_t* target, const unsigned int width, const unsigned int height, const ConversionFlag flag, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker* worker)
117 {
118  ocean_assert(source != nullptr && target != nullptr);
119  ocean_assert(width >= 1u && height >= 1u);
120 
121  FrameChannels::transformGeneric<uint16_t, 4u>(source, target, width, height, flag, sourcePaddingElements, targetPaddingElements, worker);
122 }
123 
124 inline void FrameConverterRGBA64::convertRowRGBA64ToRGB24(const uint16_t* source, uint8_t* target, const size_t size, const void* /*unusedParameters*/)
125 {
126  ocean_assert(source != nullptr && target != nullptr);
127  ocean_assert(size >= 1);
128 
129  const uint8_t* source8 = (const uint8_t*)(source);
130 
131  for (size_t n = 0; n < size; ++n)
132  {
133  // instead of right shifting, we simply extract the second byte
134  target[n * 3 + 0] = source8[n * 8 + 1];
135  target[n * 3 + 1] = source8[n * 8 + 3];
136  target[n * 3 + 2] = source8[n * 8 + 5];
137  }
138 }
139 
140 inline void FrameConverterRGBA64::convertRowRGBA64ToRGBA32(const uint16_t* source, uint8_t* target, const size_t size, const void* /*unusedParameters*/)
141 {
142  ocean_assert(source != nullptr && target != nullptr);
143  ocean_assert(size >= 1);
144 
145  const uint8_t* source8 = (const uint8_t*)(source);
146 
147  for (size_t n = 0; n < size; ++n)
148  {
149  // instead of right shifting, we simply extract the second byte
150  target[n * 4 + 0] = source8[n * 8 + 1];
151  target[n * 4 + 1] = source8[n * 8 + 3];
152  target[n * 4 + 2] = source8[n * 8 + 5];
153  target[n * 4 + 3] = source8[n * 8 + 7];
154  }
155 }
156 
157 }
158 
159 }
160 
161 #endif // META_OCEAN_CV_FRAME_CONVERTER_RGBA_64_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 convertGenericPixelFormat(const TSource *source, TTarget *target, const unsigned int width, const unsigned int height, const unsigned int sourceStrideElements, const unsigned int targetStrideElements, const ConversionFlag flag, const RowConversionFunction< TSource, TTarget > rowConversionFunction, const RowReversePixelOrderInPlaceFunction< TTarget > targetReversePixelOrderInPlaceFunction, const bool areContinuous, const void *options, Worker *worker)
Converts a frame with generic pixel format (e.g., RGBA32, BGR24, YUV24, ...) to a frame with generic ...
Definition: FrameConverter.h:3211
This class provides functions to convert frames with RGBA64 pixel format.
Definition: FrameConverterRGBA64.h:26
static void convertRGBA64ToRGBA32(const uint16_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 an RGBA 64 bit frame to a RGBA 32 bit frame.
Definition: FrameConverterRGBA64.h:103
static void convertRowRGBA64ToRGBA32(const uint16_t *source, uint8_t *target, const size_t size, const void *unusedParameters=nullptr)
Converts a RGBA64 row to a RGBA32 row applying a linear conversion.
Definition: FrameConverterRGBA64.h:140
static void convertRowRGBA64ToRGB24(const uint16_t *source, uint8_t *target, const size_t size, const void *unusedParameters=nullptr)
Converts a RGBA64 row to a RGB24 row applying a linear conversion.
Definition: FrameConverterRGBA64.h:124
static void convertRGBA64ToRGB24(const uint16_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 an RGBA 64 bit frame to a RGB 24 bit frame.
Definition: FrameConverterRGBA64.h:90
static void convertRGBA64ToRGBA64(const uint16_t *source, uint16_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 an RGBA 64 bit frame to a RGBA 64 bit frame.
Definition: FrameConverterRGBA64.h:116
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