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 | #ifndef ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/AssetsLibrary.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Fixture.h" |
| 34 | #include "tests/validation/Helpers.h" |
| 35 | #include "tests/validation/reference/ColorConvert.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | } |
| 46 | template <typename MultiImageType, typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 47 | class ColorConvertValidationFixture : public framework::Fixture |
| 48 | { |
| 49 | public: |
| 50 | template <typename...> |
| 51 | void setup(TensorShape shape, Format src_format, Format dst_format) |
| 52 | { |
| 53 | shape = adjust_odd_shape(shape, src_format); |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 54 | shape = adjust_odd_shape(shape, dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 55 | |
| 56 | _target = compute_target(shape, src_format, dst_format); |
| 57 | _reference = compute_reference(shape, src_format, dst_format); |
| 58 | } |
| 59 | |
| 60 | protected: |
| 61 | template <typename U> |
| 62 | void fill(U &&tensor, int i) |
| 63 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 64 | library->fill_tensor_uniform(tensor, i); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | std::vector<SimpleTensor<T>> create_tensor_planes_reference(const TensorShape &shape, Format format) |
| 68 | { |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 69 | std::vector<SimpleTensor<T>> tensor_planes; |
| 70 | |
| 71 | switch(format) |
| 72 | { |
| 73 | case Format::RGB888: |
| 74 | case Format::RGBA8888: |
| 75 | case Format::YUYV422: |
| 76 | case Format::UYVY422: |
| 77 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 78 | tensor_planes.emplace_back(shape, format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 79 | break; |
| 80 | } |
| 81 | case Format::NV12: |
| 82 | case Format::NV21: |
| 83 | { |
| 84 | const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88); |
| 85 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 86 | tensor_planes.emplace_back(shape, Format::U8); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 87 | tensor_planes.emplace_back(shape_uv88, Format::UV88); |
| 88 | break; |
| 89 | } |
| 90 | case Format::IYUV: |
| 91 | { |
| 92 | const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV); |
| 93 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 94 | tensor_planes.emplace_back(shape, Format::U8); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 95 | tensor_planes.emplace_back(shape_sub2, Format::U8); |
| 96 | tensor_planes.emplace_back(shape_sub2, Format::U8); |
| 97 | break; |
| 98 | } |
| 99 | case Format::YUV444: |
| 100 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 101 | tensor_planes.emplace_back(shape, Format::U8); |
| 102 | tensor_planes.emplace_back(shape, Format::U8); |
| 103 | tensor_planes.emplace_back(shape, Format::U8); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 104 | break; |
| 105 | } |
| 106 | default: |
| 107 | ARM_COMPUTE_ERROR("Not supported"); |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | return tensor_planes; |
| 112 | } |
| 113 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 114 | MultiImageType compute_target(const TensorShape &shape, Format src_format, Format dst_format) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 115 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 116 | _src_num_planes = num_planes_from_format(src_format); |
| 117 | _dst_num_planes = num_planes_from_format(dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 118 | |
| 119 | // Create tensors |
| 120 | MultiImageType ref_src = create_multi_image<MultiImageType>(shape, src_format); |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 121 | MultiImageType ref_dst = create_multi_image<MultiImageType>(shape, dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 122 | |
| 123 | // Create and configure function |
| 124 | FunctionType color_convert; |
| 125 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 126 | if(1U == _src_num_planes) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 127 | { |
| 128 | const TensorType *plane_src = static_cast<TensorType *>(ref_src.plane(0)); |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 129 | |
| 130 | if(1U == _dst_num_planes) |
| 131 | { |
| 132 | TensorType *dst_plane = static_cast<TensorType *>(ref_dst.plane(0)); |
| 133 | color_convert.configure(plane_src, dst_plane); |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | color_convert.configure(plane_src, &ref_dst); |
| 138 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 142 | if(1U == _dst_num_planes) |
| 143 | { |
| 144 | TensorType *dst_plane = static_cast<TensorType *>(ref_dst.plane(0)); |
| 145 | color_convert.configure(&ref_src, dst_plane); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | color_convert.configure(&ref_src, &ref_dst); |
| 150 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 153 | for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 154 | { |
| 155 | const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx)); |
| 156 | |
| 157 | ARM_COMPUTE_EXPECT(src_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 158 | } |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 159 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 160 | { |
| 161 | const TensorType *dst_plane = static_cast<const TensorType *>(ref_dst.plane(plane_idx)); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 162 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 163 | ARM_COMPUTE_EXPECT(dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 164 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 165 | |
| 166 | // Allocate tensors |
| 167 | ref_src.allocate(); |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 168 | ref_dst.allocate(); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 169 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 170 | for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 171 | { |
| 172 | const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx)); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 173 | ARM_COMPUTE_EXPECT(!src_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 174 | } |
| 175 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 176 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 177 | { |
| 178 | const TensorType *dst_plane = static_cast<const TensorType *>(ref_dst.plane(plane_idx)); |
| 179 | ARM_COMPUTE_EXPECT(!dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 180 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 181 | |
| 182 | // Fill tensor planes |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 183 | for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 184 | { |
| 185 | TensorType *src_plane = static_cast<TensorType *>(ref_src.plane(plane_idx)); |
| 186 | |
| 187 | fill(AccessorType(*src_plane), plane_idx); |
| 188 | } |
| 189 | |
| 190 | // Compute function |
| 191 | color_convert.run(); |
| 192 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 193 | return ref_dst; |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 196 | std::vector<SimpleTensor<T>> compute_reference(const TensorShape &shape, Format src_format, Format dst_format) |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 197 | { |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 198 | // Create reference |
| 199 | std::vector<SimpleTensor<T>> ref_src = create_tensor_planes_reference(shape, src_format); |
| 200 | |
| 201 | // Fill references |
| 202 | for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx) |
| 203 | { |
| 204 | fill(ref_src[plane_idx], plane_idx); |
| 205 | } |
| 206 | |
| 207 | return reference::color_convert<T>(shape, ref_src, src_format, dst_format); |
| 208 | } |
| 209 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame^] | 210 | unsigned int _src_num_planes{}; |
| 211 | unsigned int _dst_num_planes{}; |
| 212 | MultiImageType _target{}; |
| 213 | std::vector<SimpleTensor<T>> _reference{}; |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 214 | }; |
| 215 | } // namespace validation |
| 216 | } // namespace test |
| 217 | } // namespace arm_compute |
| 218 | #endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE */ |