Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | #include <cstdint> |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | /** Class describing the value of a pixel for any image format. */ |
| 32 | class PixelValue |
| 33 | { |
| 34 | public: |
| 35 | /** Default constructor: value initialized to 0 */ |
| 36 | PixelValue() |
| 37 | : value{ { 0 } } |
| 38 | { |
| 39 | } |
| 40 | /** Initialize the union with a U8 pixel value |
| 41 | * |
| 42 | * @param[in] v U8 value. |
| 43 | */ |
| 44 | PixelValue(uint8_t v) |
| 45 | : PixelValue() |
| 46 | { |
| 47 | value.u8 = v; |
| 48 | } |
| 49 | /** Initialize the union with a U16 pixel value |
| 50 | * |
| 51 | * @param[in] v U16 value. |
| 52 | */ |
| 53 | PixelValue(uint16_t v) |
| 54 | : PixelValue() |
| 55 | { |
| 56 | value.u16 = v; |
| 57 | } |
| 58 | /** Initialize the union with a S16 pixel value |
| 59 | * |
| 60 | * @param[in] v S16 value. |
| 61 | */ |
| 62 | PixelValue(int16_t v) |
| 63 | : PixelValue() |
| 64 | { |
| 65 | value.s16 = v; |
| 66 | } |
| 67 | /** Initialize the union with a U32 pixel value |
| 68 | * |
| 69 | * @param[in] v U32 value. |
| 70 | */ |
| 71 | PixelValue(uint32_t v) |
| 72 | : PixelValue() |
| 73 | { |
| 74 | value.u32 = v; |
| 75 | } |
| 76 | /** Initialize the union with a S32 pixel value |
| 77 | * |
| 78 | * @param[in] v S32 value. |
| 79 | */ |
| 80 | PixelValue(int32_t v) |
| 81 | : PixelValue() |
| 82 | { |
| 83 | value.s32 = v; |
| 84 | } |
| 85 | /** Initialize the union with a F32 pixel value |
| 86 | * |
| 87 | * @param[in] v F32 value. |
| 88 | */ |
| 89 | PixelValue(float v) |
| 90 | : PixelValue() |
| 91 | { |
| 92 | value.f32 = v; |
| 93 | } |
| 94 | /** Union which describes the value of a pixel for any image format. |
| 95 | * Use the field corresponding to the image format |
| 96 | */ |
| 97 | union |
| 98 | { |
| 99 | uint8_t rgb[3]; /**< 3 channels: RGB888 */ |
| 100 | uint8_t yuv[3]; /**< 3 channels: Any YUV format */ |
| 101 | uint8_t rgbx[4]; /**< 4 channels: RGBX8888 */ |
| 102 | float f32; /**< Single channel float 32 */ |
| 103 | uint8_t u8; /**< Single channel U8 */ |
| 104 | int8_t s8; /**< Single channel S8 */ |
| 105 | uint16_t u16; /**< Single channel U16 */ |
| 106 | int16_t s16; /**< Single channel S16 */ |
| 107 | uint32_t u32; /**< Single channel U32 */ |
| 108 | int32_t s32; /**< Single channel S32 */ |
| 109 | } value; |
| 110 | /** Interpret the pixel value as a U8 |
| 111 | * |
| 112 | * @param[out] v Returned value |
| 113 | */ |
| 114 | void get(uint8_t &v) const |
| 115 | { |
| 116 | v = value.u8; |
| 117 | } |
| 118 | /** Interpret the pixel value as a S8 |
| 119 | * |
| 120 | * @param[out] v Returned value |
| 121 | */ |
| 122 | void get(int8_t &v) const |
| 123 | { |
| 124 | v = value.s8; |
| 125 | } |
| 126 | /** Interpret the pixel value as a U16 |
| 127 | * |
| 128 | * @param[out] v Returned value |
| 129 | */ |
| 130 | void get(uint16_t &v) const |
| 131 | { |
| 132 | v = value.u16; |
| 133 | } |
| 134 | /** Interpret the pixel value as a S16 |
| 135 | * |
| 136 | * @param[out] v Returned value |
| 137 | */ |
| 138 | void get(int16_t &v) const |
| 139 | { |
| 140 | v = value.s16; |
| 141 | } |
| 142 | /** Interpret the pixel value as a U32 |
| 143 | * |
| 144 | * @param[out] v Returned value |
| 145 | */ |
| 146 | void get(uint32_t &v) const |
| 147 | { |
| 148 | v = value.u32; |
| 149 | } |
| 150 | /** Interpret the pixel value as a S32 |
| 151 | * |
| 152 | * @param[out] v Returned value |
| 153 | */ |
| 154 | void get(int32_t &v) const |
| 155 | { |
| 156 | v = value.s32; |
| 157 | } |
| 158 | /** Interpret the pixel value as a F32 |
| 159 | * |
| 160 | * @param[out] v Returned value |
| 161 | */ |
| 162 | void get(float &v) const |
| 163 | { |
| 164 | v = value.f32; |
| 165 | } |
| 166 | }; |
| 167 | } |
| 168 | #endif /* __ARM_COMPUTE_PIXELVALUE_H__ */ |