blob: 63405560ea3f99f382796194726abc7fc1dff549 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_PIXELVALUE_H__
25#define __ARM_COMPUTE_PIXELVALUE_H__
26
Georgios Pinitas583137c2017-08-31 18:12:42 +010027#include "arm_compute/core/Types.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
Georgios Pinitas583137c2017-08-31 18:12:42 +010029#include <cstdint>
Pablo Tello0c34fe22017-06-26 17:17:42 +010030
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031namespace arm_compute
32{
33/** Class describing the value of a pixel for any image format. */
34class PixelValue
35{
36public:
37 /** Default constructor: value initialized to 0 */
38 PixelValue()
39 : value{ { 0 } }
40 {
41 }
42 /** Initialize the union with a U8 pixel value
43 *
44 * @param[in] v U8 value.
45 */
46 PixelValue(uint8_t v)
47 : PixelValue()
48 {
49 value.u8 = v;
50 }
51 /** Initialize the union with a U16 pixel value
52 *
53 * @param[in] v U16 value.
54 */
55 PixelValue(uint16_t v)
56 : PixelValue()
57 {
58 value.u16 = v;
59 }
60 /** Initialize the union with a S16 pixel value
61 *
62 * @param[in] v S16 value.
63 */
64 PixelValue(int16_t v)
65 : PixelValue()
66 {
67 value.s16 = v;
68 }
69 /** Initialize the union with a U32 pixel value
70 *
71 * @param[in] v U32 value.
72 */
73 PixelValue(uint32_t v)
74 : PixelValue()
75 {
76 value.u32 = v;
77 }
78 /** Initialize the union with a S32 pixel value
79 *
80 * @param[in] v S32 value.
81 */
82 PixelValue(int32_t v)
83 : PixelValue()
84 {
85 value.s32 = v;
86 }
Pablo Tello0c34fe22017-06-26 17:17:42 +010087 /** Initialize the union with a F16 pixel value
88 *
89 * @param[in] v F16 value.
90 */
Georgios Pinitas583137c2017-08-31 18:12:42 +010091 PixelValue(half v)
Pablo Tello0c34fe22017-06-26 17:17:42 +010092 : PixelValue()
93 {
94 value.f16 = v;
95 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096 /** Initialize the union with a F32 pixel value
97 *
98 * @param[in] v F32 value.
99 */
100 PixelValue(float v)
101 : PixelValue()
102 {
103 value.f32 = v;
104 }
105 /** Union which describes the value of a pixel for any image format.
106 * Use the field corresponding to the image format
107 */
108 union
109 {
Georgios Pinitas583137c2017-08-31 18:12:42 +0100110 uint8_t rgb[3]; /**< 3 channels: RGB888 */
111 uint8_t yuv[3]; /**< 3 channels: Any YUV format */
112 uint8_t rgbx[4]; /**< 4 channels: RGBX8888 */
113 float f32; /**< Single channel float 32 */
114 half f16; /**< Single channel F16 */
115 uint8_t u8; /**< Single channel U8 */
116 int8_t s8; /**< Single channel S8 */
117 uint16_t u16; /**< Single channel U16 */
118 int16_t s16; /**< Single channel S16 */
119 uint32_t u32; /**< Single channel U32 */
120 int32_t s32; /**< Single channel S32 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121 } value;
122 /** Interpret the pixel value as a U8
123 *
124 * @param[out] v Returned value
125 */
126 void get(uint8_t &v) const
127 {
128 v = value.u8;
129 }
130 /** Interpret the pixel value as a S8
131 *
132 * @param[out] v Returned value
133 */
134 void get(int8_t &v) const
135 {
136 v = value.s8;
137 }
138 /** Interpret the pixel value as a U16
139 *
140 * @param[out] v Returned value
141 */
142 void get(uint16_t &v) const
143 {
144 v = value.u16;
145 }
146 /** Interpret the pixel value as a S16
147 *
148 * @param[out] v Returned value
149 */
150 void get(int16_t &v) const
151 {
152 v = value.s16;
153 }
154 /** Interpret the pixel value as a U32
155 *
156 * @param[out] v Returned value
157 */
158 void get(uint32_t &v) const
159 {
160 v = value.u32;
161 }
162 /** Interpret the pixel value as a S32
163 *
164 * @param[out] v Returned value
165 */
166 void get(int32_t &v) const
167 {
168 v = value.s32;
169 }
Pablo Tello0c34fe22017-06-26 17:17:42 +0100170 /** Interpret the pixel value as a F16
171 *
172 * @param[out] v Returned value
173 */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100174 void get(half &v) const
Pablo Tello0c34fe22017-06-26 17:17:42 +0100175 {
176 v = value.f16;
177 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178 /** Interpret the pixel value as a F32
179 *
180 * @param[out] v Returned value
181 */
182 void get(float &v) const
183 {
184 v = value.f32;
185 }
186};
187}
188#endif /* __ARM_COMPUTE_PIXELVALUE_H__ */