Ocean
Loading...
Searching...
No Matches
FrameConverterRGB565.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_RGB_565_H
9#define META_OCEAN_CV_FRAME_CONVERTER_RGB_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 RGB 565 pixel format.
25 * @ingroup cv
26 */
27class OCEAN_CV_EXPORT FrameConverterRGB565 : public FrameConverter
28{
29 public:
30
31 /**
32 * Converts a RGB565 (16 bit) frame to a RGB24 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 convertRGB565ToRGB24(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 RGB565 (16 bit) frame to a Y8 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 sourcePaddingElements The number of padding elements at the end of each source row, in (uint16_t) elements, with range [0, infinity)
51 * @param targetPaddingElements The number of padding elements at the end of each target row, in (uint8_t) elements, with range [0, infinity)
52 * @param flag Determining the type of conversion
53 * @param worker Optional worker object to distribute the computational load
54 */
55 static inline void convertRGB565ToY8(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 protected:
58
59 /**
60 * Converts a row of a RGB656 frame to a row of a RGB24 frame.
61 * @param source The source row, must be valid
62 * @param target The target row, must be valid
63 * @param width The width of the row in pixel, with range [1, infinity)
64 * @param unusedOptions Unused options parameter, must be nullptr
65 */
66 static void convertRowRGB565ToRGB24(const uint16_t* source, uint8_t* target, const size_t width, const void* unusedOptions);
67
68 /**
69 * Converts a row of a RGB656 frame to a row of a Y8 frame.
70 * @param source The source row, must be valid
71 * @param target The target row, must be valid
72 * @param width The width of the row in pixel, with range [1, infinity)
73 * @param unusedOptions Unused options parameter, must be nullptr
74 */
75 static void convertRowRGB565ToY8(const uint16_t* source, uint8_t* target, const size_t width, const void* unusedOptions);
76
77#if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
78
79 /**
80 * Converts a row of a RGB656 frame to a row of a RGB24 frame using NEON instructions.
81 * @param source The source row, must be valid
82 * @param target The target row, must be valid
83 * @param width The width of the row in pixel, with range [8, infinity)
84 */
85 static void convertRowRGB565ToRGB24NEON(const uint16_t* source, uint8_t* target, const unsigned int width);
86
87 /**
88 * Converts a row of a RGB656 frame to a row of a Y8 frame using NEON instructions.
89 * @param source The source row, must be valid
90 * @param target The target row, must be valid
91 * @param width The width of the row in pixel, with range [8, infinity)
92 */
93 static void convertRowRGB565ToY8NEON(const uint16_t* source, uint8_t* target, const unsigned int width);
94
95#endif // OCEAN_HARDWARE_NEON_VERSION >= 10
96};
97
98inline void FrameConverterRGB565::convertRGB565ToRGB24(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)
99{
100 ocean_assert(source != nullptr && target != nullptr);
101 ocean_assert(width >= 1u && height >= 1u);
102
103 const unsigned int sourceStrideElements = width + sourcePaddingElements;
104 const unsigned int targetStrideElements = width * 3u + targetPaddingElements;
105
106 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
107
108 FrameConverter::convertGenericPixelFormat<uint16_t, uint8_t>(source, target, width, height, sourceStrideElements, targetStrideElements, flag, CV::FrameConverterRGB565::convertRowRGB565ToRGB24, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 3u>, areContinuous, nullptr, worker);
109}
110
111inline void FrameConverterRGB565::convertRGB565ToY8(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)
112{
113 ocean_assert(source != nullptr && target != nullptr);
114 ocean_assert(width >= 1u && height >= 1u);
115
116 const unsigned int sourceStrideElements = width + sourcePaddingElements;
117 const unsigned int targetStrideElements = width * 1u + targetPaddingElements;
118
119 const bool areContinuous = sourcePaddingElements == 0u && targetPaddingElements == 0u;
120
121 FrameConverter::convertGenericPixelFormat<uint16_t, uint8_t>(source, target, width, height, sourceStrideElements, targetStrideElements, flag, CV::FrameConverterRGB565::convertRowRGB565ToY8, CV::FrameChannels::reverseRowPixelOrderInPlace<uint8_t, 1u>, areContinuous, nullptr, worker);
122}
123
124}
125
126}
127
128#endif // META_OCEAN_CV_FRAME_CONVERTER_RGB_24_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
This class provides functions to convert or to change frames with RGB 565 pixel format.
Definition FrameConverterRGB565.h:28
static void convertRowRGB565ToY8(const uint16_t *source, uint8_t *target, const size_t width, const void *unusedOptions)
Converts a row of a RGB656 frame to a row of a Y8 frame.
static void convertRowRGB565ToRGB24NEON(const uint16_t *source, uint8_t *target, const unsigned int width)
Converts a row of a RGB656 frame to a row of a RGB24 frame using NEON instructions.
static void convertRGB565ToRGB24(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 RGB565 (16 bit) frame to a RGB24 bit frame.
Definition FrameConverterRGB565.h:98
static void convertRGB565ToY8(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 RGB565 (16 bit) frame to a Y8 bit frame.
Definition FrameConverterRGB565.h:111
static void convertRowRGB565ToRGB24(const uint16_t *source, uint8_t *target, const size_t width, const void *unusedOptions)
Converts a row of a RGB656 frame to a row of a RGB24 frame.
static void convertRowRGB565ToY8NEON(const uint16_t *source, uint8_t *target, const unsigned int width)
Converts a row of a RGB656 frame to a row of a Y8 frame using NEON instructions.
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