Ocean
Loading...
Searching...
No Matches
FrameConverterBGR565.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_BGR_565_H
9#define META_OCEAN_CV_FRAME_CONVERTER_BGR_565_H
10
11#include "ocean/cv/CV.h"
14
15#include "ocean/base/Worker.h"
16
17namespace Ocean
18{
19
20namespace CV
21{
22
23/**
24 * This class provides functions to convert or to change frames with BGR 565 pixel format.
25 * @ingroup cv
26 */
27class OCEAN_CV_EXPORT FrameConverterBGR565 : public FrameConverter
28{
29 public:
30
31 /**
32 * Converts a BGR565 (16 bit) frame to a BGR24 bit frame.
33 * @param source The source frame buffer, must be valid
34 * @param target The target frame buffer, must be valid
35 * @param width The width of the frame in pixel, with range (0, infinity)
36 * @param height The height of the frame in pixel, with range (0, infinity)
37 * @param flag Determining the type of conversion
38 * @param sourcePaddingElements The number of padding elements at the end of each source row, in (uint16_t) elements, with range [0, infinity)
39 * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
40 * @param worker Optional worker object to distribute the computational load
41 */
42 static inline void convertBGR565ToBGR24(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);
43
44 /**
45 * Converts a BGR565 (16 bit) frame to a RGB24 bit frame.
46 * @param source The source frame buffer, must be valid
47 * @param target The target frame buffer, must be valid
48 * @param width The width of the frame in pixel, with range (0, infinity)
49 * @param height The height of the frame in pixel, with range (0, infinity)
50 * @param flag Determining the type of conversion
51 * @param sourcePaddingElements The number of padding elements at the end of each source row, in (uint16_t) elements, with range [0, infinity)
52 * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
53 * @param worker Optional worker object to distribute the computational load
54 */
55 static inline void convertBGR565ToRGB24(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);
56
57 /**
58 * Converts a BGR565 (16 bit) frame to a Y8 bit frame.
59 * @param source The source frame buffer, must be valid
60 * @param target The target frame buffer, must be valid
61 * @param width The width of the frame in pixel, with range (0, infinity)
62 * @param height The height of the frame in pixel, with range (0, infinity)
63 * @param flag Determining the type of conversion
64 * @param sourcePaddingElements The number of padding elements at the end of each source row, in (uint16_t) elements, with range [0, infinity)
65 * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
66 * @param worker Optional worker object to distribute the computational load
67 */
68 static inline void convertBGR565ToY8(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);
69
70 protected:
71
72 /**
73 * Converts a row of a BGR565 frame to a row of a BGR24 frame.
74 * @param source The source row, must be valid
75 * @param target The target row, must be valid
76 * @param width The width of the row in pixel, with range [1, infinity)
77 * @param unusedOptions Unused options parameter, must be nullptr
78 */
79 static void convertRowBGR565ToBGR24(const uint16_t* source, uint8_t* target, const size_t width, const void* unusedOptions);
80
81 /**
82 * Converts a row of a BGR565 frame to a row of a RGB24 frame.
83 * @param source The source row, must be valid
84 * @param target The target row, must be valid
85 * @param width The width of the row in pixel, with range [1, infinity)
86 * @param unusedOptions Unused options parameter, must be nullptr
87 */
88 static void convertRowBGR565ToRGB24(const uint16_t* source, uint8_t* target, const size_t width, const void* unusedOptions);
89
90 /**
91 * Converts a row of a BGR565 frame to a row of a Y8 frame.
92 * @param source The source row, must be valid
93 * @param target The target row, must be valid
94 * @param width The width of the row in pixel, with range [1, infinity)
95 * @param unusedOptions Unused options parameter, must be nullptr
96 */
97 static void convertRowBGR565ToY8(const uint16_t* source, uint8_t* target, const size_t width, const void* unusedOptions);
98
99#if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
100
101 /**
102 * Converts a row of a BGR565 frame to a row of a BGR24 frame using NEON instructions.
103 * @param source The source row, must be valid
104 * @param target The target row, must be valid
105 * @param width The width of the row in pixel, with range [8, infinity)
106 */
107 static void convertRowBGR565ToBGR24NEON(const uint16_t* source, uint8_t* target, const unsigned int width);
108
109 /**
110 * Converts a row of a BGR565 frame to a row of a RGB24 frame using NEON instructions.
111 * @param source The source row, must be valid
112 * @param target The target row, must be valid
113 * @param width The width of the row in pixel, with range [8, infinity)
114 */
115 static void convertRowBGR565ToRGB24NEON(const uint16_t* source, uint8_t* target, const unsigned int width);
116
117 /**
118 * Converts a row of a BGR565 frame to a row of a Y8 frame using NEON instructions.
119 * @param source The source row, must be valid
120 * @param target The target row, must be valid
121 * @param width The width of the row in pixel, with range [8, infinity)
122 */
123 static void convertRowBGR565ToY8NEON(const uint16_t* source, uint8_t* target, const unsigned int width);
124
125#endif // OCEAN_HARDWARE_NEON_VERSION >= 10
126};
127
128inline void FrameConverterBGR565::convertBGR565ToBGR24(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)
129{
130 ocean_assert(source != nullptr && target != nullptr);
131 ocean_assert(width >= 1u && height >= 1u);
132
133 const unsigned int sourceStrideElements = width + sourcePaddingElements;
134 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
135
136 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
137
138 FrameConverter::convertGenericPixelFormat<uint16_t, uint8_t>(source, target, width, height, sourceStrideElements, targetStrideElements, flag, CV::FrameConverterBGR565::convertRowBGR565ToBGR24, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, nullptr, worker);
139}
140
141inline void FrameConverterBGR565::convertBGR565ToRGB24(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)
142{
143 ocean_assert(source != nullptr && target != nullptr);
144 ocean_assert(width >= 1u && height >= 1u);
145
146 const unsigned int sourceStrideElements = width + sourcePaddingElements;
147 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
148
149 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
150
151 FrameConverter::convertGenericPixelFormat<uint16_t, uint8_t>(source, target, width, height, sourceStrideElements, targetStrideElements, flag, CV::FrameConverterBGR565::convertRowBGR565ToRGB24, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, nullptr, worker);
152}
153
154inline void FrameConverterBGR565::convertBGR565ToY8(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)
155{
156 ocean_assert(source != nullptr && target != nullptr);
157 ocean_assert(width >= 1u && height >= 1u);
158
159 const unsigned int sourceStrideElements = width + sourcePaddingElements;
160 const unsigned int targetStrideElements = width * 1u + targetPaddingElements;
161
162 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
163
164 FrameConverter::convertGenericPixelFormat<uint16_t, uint8_t>(source, target, width, height, sourceStrideElements, targetStrideElements, flag, CV::FrameConverterBGR565::convertRowBGR565ToY8, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 1u>, areContinuous, nullptr, worker);
165}
166
167}
168
169}
170
171#endif // META_OCEAN_CV_FRAME_CONVERTER_BGR_24_H
This class provides functions to convert or to change frames with BGR 565 pixel format.
Definition FrameConverterBGR565.h:28
static void convertRowBGR565ToY8(const uint16_t *source, uint8_t *target, const size_t width, const void *unusedOptions)
Converts a row of a BGR565 frame to a row of a Y8 frame.
static void convertRowBGR565ToRGB24NEON(const uint16_t *source, uint8_t *target, const unsigned int width)
Converts a row of a BGR565 frame to a row of a RGB24 frame using NEON instructions.
static void convertBGR565ToY8(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 a BGR565 (16 bit) frame to a Y8 bit frame.
Definition FrameConverterBGR565.h:154
static void convertRowBGR565ToBGR24NEON(const uint16_t *source, uint8_t *target, const unsigned int width)
Converts a row of a BGR565 frame to a row of a BGR24 frame using NEON instructions.
static void convertRowBGR565ToY8NEON(const uint16_t *source, uint8_t *target, const unsigned int width)
Converts a row of a BGR565 frame to a row of a Y8 frame using NEON instructions.
static void convertBGR565ToRGB24(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 a BGR565 (16 bit) frame to a RGB24 bit frame.
Definition FrameConverterBGR565.h:141
static void convertRowBGR565ToRGB24(const uint16_t *source, uint8_t *target, const size_t width, const void *unusedOptions)
Converts a row of a BGR565 frame to a row of a RGB24 frame.
static void convertBGR565ToBGR24(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 a BGR565 (16 bit) frame to a BGR24 bit frame.
Definition FrameConverterBGR565.h:128
static void convertRowBGR565ToBGR24(const uint16_t *source, uint8_t *target, const size_t width, const void *unusedOptions)
Converts a row of a BGR565 frame to a row of a BGR24 frame.
This is the base class for all frame converter classes.
Definition FrameConverter.h:32
ConversionFlag
Definition of individual conversion flags.
Definition FrameConverter.h:39
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