Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018 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 | #include "ColorConvert.h" |
| 25 | |
| 26 | #include "arm_compute/core/Types.h" |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 27 | #include "tests/validation/Helpers.h" |
| 28 | #include "tests/validation/reference/ColorConvertHelper.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace test |
| 33 | { |
| 34 | namespace validation |
| 35 | { |
| 36 | namespace reference |
| 37 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 38 | namespace |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 39 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 40 | template <typename T> |
| 41 | inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format) |
| 42 | { |
| 43 | TensorShape image_shape = adjust_odd_shape(shape, format); |
| 44 | |
| 45 | std::vector<SimpleTensor<T>> image_planes; |
| 46 | |
| 47 | switch(format) |
| 48 | { |
Manuel Bottini | 4284bfa | 2018-09-26 15:33:15 +0100 | [diff] [blame] | 49 | case Format::U8: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 50 | case Format::RGB888: |
| 51 | case Format::RGBA8888: |
| 52 | case Format::YUYV422: |
| 53 | case Format::UYVY422: |
| 54 | { |
| 55 | image_planes.emplace_back(image_shape, format); |
| 56 | break; |
| 57 | } |
| 58 | case Format::NV12: |
| 59 | case Format::NV21: |
| 60 | { |
| 61 | TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88); |
| 62 | |
| 63 | image_planes.emplace_back(image_shape, Format::U8); |
| 64 | image_planes.emplace_back(shape_uv88, Format::UV88); |
| 65 | break; |
| 66 | } |
| 67 | case Format::IYUV: |
| 68 | { |
| 69 | TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV); |
| 70 | |
| 71 | image_planes.emplace_back(image_shape, Format::U8); |
| 72 | image_planes.emplace_back(shape_sub2, Format::U8); |
| 73 | image_planes.emplace_back(shape_sub2, Format::U8); |
| 74 | break; |
| 75 | } |
| 76 | case Format::YUV444: |
| 77 | { |
| 78 | image_planes.emplace_back(image_shape, Format::U8); |
| 79 | image_planes.emplace_back(image_shape, Format::U8); |
| 80 | image_planes.emplace_back(image_shape, Format::U8); |
| 81 | break; |
| 82 | } |
| 83 | default: |
| 84 | ARM_COMPUTE_ERROR("Not supported"); |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | return image_planes; |
| 89 | } |
| 90 | } // namespace |
| 91 | |
| 92 | template <typename T> |
| 93 | std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format) |
| 94 | { |
| 95 | std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 96 | |
| 97 | switch(src_format) |
| 98 | { |
| 99 | case Format::RGB888: |
| 100 | { |
| 101 | switch(dst_format) |
| 102 | { |
| 103 | case Format::RGBA8888: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 104 | colorconvert_helper::detail::colorconvert_rgb_to_rgbx(tensor_planes[0], dst[0]); |
| 105 | break; |
Manuel Bottini | 4284bfa | 2018-09-26 15:33:15 +0100 | [diff] [blame] | 106 | case Format::U8: |
| 107 | colorconvert_helper::detail::colorconvert_rgb_to_u8(tensor_planes[0], dst[0]); |
| 108 | break; |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 109 | case Format::NV12: |
| 110 | colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); |
| 111 | break; |
| 112 | case Format::IYUV: |
| 113 | colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); |
| 114 | break; |
| 115 | case Format::YUV444: |
| 116 | colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 117 | break; |
| 118 | default: |
| 119 | ARM_COMPUTE_ERROR("Not Supported"); |
| 120 | break; |
| 121 | } |
| 122 | break; |
| 123 | } |
| 124 | case Format::RGBA8888: |
| 125 | { |
| 126 | switch(dst_format) |
| 127 | { |
| 128 | case Format::RGB888: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 129 | colorconvert_helper::detail::colorconvert_rgbx_to_rgb(tensor_planes[0], dst[0]); |
| 130 | break; |
| 131 | case Format::NV12: |
| 132 | colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst); |
| 133 | break; |
| 134 | case Format::IYUV: |
| 135 | colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst); |
| 136 | break; |
| 137 | case Format::YUV444: |
| 138 | colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 139 | break; |
| 140 | default: |
| 141 | ARM_COMPUTE_ERROR("Not Supported"); |
| 142 | break; |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | case Format::UYVY422: |
| 147 | case Format::YUYV422: |
| 148 | { |
| 149 | switch(dst_format) |
| 150 | { |
| 151 | case Format::RGB888: |
| 152 | case Format::RGBA8888: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 153 | colorconvert_helper::detail::colorconvert_yuyv_to_rgb(tensor_planes[0], src_format, dst[0]); |
| 154 | break; |
| 155 | case Format::NV12: |
| 156 | colorconvert_helper::detail::colorconvert_yuyv_to_nv12(tensor_planes[0], src_format, dst); |
| 157 | break; |
| 158 | case Format::IYUV: |
| 159 | colorconvert_helper::detail::colorconvert_yuyv_to_iyuv(tensor_planes[0], src_format, dst); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 160 | break; |
| 161 | default: |
| 162 | ARM_COMPUTE_ERROR("Not Supported"); |
| 163 | break; |
| 164 | } |
| 165 | break; |
| 166 | } |
| 167 | case Format::IYUV: |
| 168 | { |
| 169 | switch(dst_format) |
| 170 | { |
| 171 | case Format::RGB888: |
| 172 | case Format::RGBA8888: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 173 | colorconvert_helper::detail::colorconvert_iyuv_to_rgb(shape, tensor_planes, dst[0]); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 174 | break; |
| 175 | default: |
| 176 | ARM_COMPUTE_ERROR("Not Supported"); |
| 177 | break; |
| 178 | } |
| 179 | break; |
| 180 | } |
| 181 | case Format::NV12: |
| 182 | case Format::NV21: |
| 183 | { |
| 184 | switch(dst_format) |
| 185 | { |
| 186 | case Format::RGB888: |
| 187 | case Format::RGBA8888: |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 188 | colorconvert_helper::detail::colorconvert_nv12_to_rgb(shape, src_format, tensor_planes, dst[0]); |
| 189 | break; |
| 190 | case Format::IYUV: |
| 191 | colorconvert_helper::detail::colorconvert_nv_to_iyuv(tensor_planes, src_format, dst); |
| 192 | break; |
| 193 | case Format::YUV444: |
| 194 | colorconvert_helper::detail::colorconvert_nv_to_yuv4(tensor_planes, src_format, dst); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 195 | break; |
| 196 | default: |
| 197 | ARM_COMPUTE_ERROR("Not Supported"); |
| 198 | break; |
| 199 | } |
| 200 | break; |
| 201 | } |
| 202 | default: |
| 203 | ARM_COMPUTE_ERROR("Not supported"); |
| 204 | break; |
| 205 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 206 | return dst; |
| 207 | } |
| 208 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 209 | template std::vector<SimpleTensor<uint8_t>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format src_format, Format dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 210 | } // namespace reference |
| 211 | } // namespace validation |
| 212 | } // namespace test |
| 213 | } // namespace arm_compute |