Ocean
FrameConverterY32.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_Y_32_H
9 #define META_OCEAN_CV_FRAME_CONVERTER_Y_32_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 Y32 pixel format.
23  * @ingroup cv
24  */
25 class OCEAN_CV_EXPORT FrameConverterY32 : public FrameConverter
26 {
27  public:
28 
29  /**
30  * Converts a Y 32 bit frame to a Y 8 bit frame by dividing by 2^24
31  * @param source The source frame buffer
32  * @param target The target frame buffer
33  * @param width The width of the frame in pixel
34  * @param height The height of the frame in pixel
35  * @param flag Determining the type of conversion
36  * @param sourcePaddingElements The number of padding elements at the end of each source row, in (uint32_t) elements, with range [0, infinity)
37  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
38  * @param worker Optional worker object to distribute the computational load
39  */
40  static inline void convertY32ToY8(const uint32_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 a Y 32 bit frame to a Y 16 bit frame by dividing by 2^16
44  * @param source The source frame buffer
45  * @param target The target frame buffer
46  * @param width The width of the frame in pixel
47  * @param height The height of the frame in pixel
48  * @param flag Determining the type of conversion
49  * @param sourcePaddingElements The number of padding elements at the end of each source row, in (uint32_t) elements, with range [0, infinity)
50  * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint16_t) elements, with range [0, infinity)
51  * @param worker Optional worker object to distribute the computational load
52  */
53  static inline void convertY32ToY16(const uint32_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);
54 
55  protected:
56 
57  /**
58  * Converts a Y32 row to a Y8 row.
59  * @param source The pointer to the source pixels, must be valid
60  * @param target The pointer to the target pixels receiving the converted pixel data, must be valid
61  * @param size The number of source (and target pixels) to convert, with range [1, infinity)
62  * @param unusedParameters Unused parameters, must be nullptr
63  */
64  static inline void convertRowY32ToY8(const uint32_t* source, uint8_t* target, const size_t size, const void* unusedParameters = nullptr);
65 
66  /**
67  * Converts a Y32 row to a Y16 row.
68  * @param source The pointer to the source pixels, must be valid
69  * @param target The pointer to the target pixels receiving the converted pixel data, must be valid
70  * @param size The number of source (and target pixels) to convert, with range [1, infinity)
71  * @param unusedParameters Unused parameters, must be nullptr
72  */
73  static inline void convertRowY32ToY16(const uint32_t* source, uint16_t* target, const size_t size, const void* unusedParameters = nullptr);
74 };
75 
76 inline void FrameConverterY32::convertY32ToY8(const uint32_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)
77 {
78  ocean_assert(source != nullptr && target != nullptr);
79  ocean_assert(width >= 1u && height >= 1u);
80 
81  const unsigned int sourceStrideElements = width + sourcePaddingElements;
82  const unsigned int targetStrideElements = width + targetPaddingElements;
83 
84  const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
85 
86  FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag, convertRowY32ToY8, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 1u>, areContinuous, nullptr, worker);
87 }
88 
89 inline void FrameConverterY32::convertY32ToY16(const uint32_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)
90 {
91  ocean_assert(source != nullptr && target != nullptr);
92  ocean_assert(width >= 1u && height >= 1u);
93 
94  const unsigned int sourceStrideElements = width + sourcePaddingElements;
95  const unsigned int targetStrideElements = width + targetPaddingElements;
96 
97  const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
98 
99  FrameConverter::convertGenericPixelFormat(source, target, width, height, sourceStrideElements, targetStrideElements, flag, convertRowY32ToY16, CV::FrameChannels::reverseRowPixelOrderInPlace<uint16_t, 1u>, areContinuous, nullptr, worker);
100 }
101 
102 inline void FrameConverterY32::convertRowY32ToY8(const uint32_t* source, uint8_t* target, const size_t size, const void* /*unusedParameters*/)
103 {
104  ocean_assert(source != nullptr && target != nullptr);
105  ocean_assert(size >= 1);
106 
107  for (size_t n = 0; n < size; ++n)
108  {
109  const uint32_t* const sourcePixel = source + n;
110  uint8_t* const targetPixel = target + n;
111 
112  // instead of right shifhting, we simply extract the fourth byte
113  *targetPixel = ((uint8_t*)sourcePixel)[3];
114  }
115 }
116 
117 inline void FrameConverterY32::convertRowY32ToY16(const uint32_t* source, uint16_t* target, const size_t size, const void* /*unusedParameters*/)
118 {
119  ocean_assert(source != nullptr && target != nullptr);
120  ocean_assert(size >= 1);
121 
122  for (size_t n = 0; n < size; ++n)
123  {
124  const uint32_t* const sourcePixel = source + n;
125  uint16_t* const targetPixel = target + n;
126 
127  // instead of right shifhting, we simply extract the two high bytes
128  *targetPixel = ((uint16_t*)sourcePixel)[1];
129  }
130 }
131 
132 }
133 
134 }
135 
136 #endif // META_OCEAN_CV_FRAME_CONVERTER_Y_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
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:3160
This class provides functions to convert frames with Y32 pixel format.
Definition: FrameConverterY32.h:26
static void convertRowY32ToY16(const uint32_t *source, uint16_t *target, const size_t size, const void *unusedParameters=nullptr)
Converts a Y32 row to a Y16 row.
Definition: FrameConverterY32.h:117
static void convertY32ToY16(const uint32_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 a Y 32 bit frame to a Y 16 bit frame by dividing by 2^16.
Definition: FrameConverterY32.h:89
static void convertRowY32ToY8(const uint32_t *source, uint8_t *target, const size_t size, const void *unusedParameters=nullptr)
Converts a Y32 row to a Y8 row.
Definition: FrameConverterY32.h:102
static void convertY32ToY8(const uint32_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 Y 32 bit frame to a Y 8 bit frame by dividing by 2^24.
Definition: FrameConverterY32.h:76
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