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 "arm_compute/runtime/MultiImage.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEColorConvert.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/datasets/ShapeDatasets.h" |
| 30 | #include "tests/framework/Asserts.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/validation/Validation.h" |
| 33 | #include "tests/validation/fixtures/ColorConvertFixture.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace validation |
| 40 | { |
| 41 | namespace |
| 42 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 43 | constexpr AbsoluteTolerance<uint8_t> tolerance_nv(2); |
| 44 | |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 45 | // Input data sets |
| 46 | const auto ColorConvertRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }), |
| 47 | framework::dataset::make("FormatType", { Format::RGB888 })); |
| 48 | const auto ColorConvertYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }), |
| 49 | framework::dataset::make("FormatType", { Format::RGB888, Format::RGBA8888 })); |
| 50 | |
| 51 | const auto ColorConvertYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::NV12, Format::NV21 }), |
| 52 | framework::dataset::make("FormatType", { Format::RGB888, Format::RGBA8888 })); |
| 53 | |
| 54 | const auto ColorConvertRGBDataset = combine(framework::dataset::make("FormatType", { Format::RGB888 }), |
| 55 | framework::dataset::make("FormatType", { Format::RGBA8888 })); |
| 56 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 57 | const auto ColorConvertNVDataset = combine(framework::dataset::make("FormatType", { Format::RGB888, Format::RGBA8888 }), |
| 58 | framework::dataset::make("FormatType", { Format::NV12, Format::IYUV, Format::YUV444 })); |
| 59 | |
| 60 | const auto ColorConvertYUYVtoNVDataset = combine(framework::dataset::make("FormatType", { Format::UYVY422, Format::YUYV422 }), |
| 61 | framework::dataset::make("FormatType", { Format::NV12, Format::IYUV })); |
| 62 | |
| 63 | const auto ColorConvertNVtoYUVDataset = combine(framework::dataset::make("FormatType", { Format::NV12, Format::NV21 }), |
| 64 | framework::dataset::make("FormatType", { Format::IYUV, Format::YUV444 })); |
| 65 | |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 66 | inline void validate_configuration(const TensorShape &shape, Format src_format, Format dst_format) |
| 67 | { |
| 68 | const unsigned int src_num_planes = num_planes_from_format(src_format); |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 69 | const unsigned int dst_num_planes = num_planes_from_format(dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 70 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 71 | TensorShape input = adjust_odd_shape(shape, src_format); |
| 72 | input = adjust_odd_shape(input, dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 73 | |
| 74 | // Create tensors |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 75 | MultiImage ref_src = create_multi_image<MultiImage>(input, src_format); |
| 76 | MultiImage ref_dst = create_multi_image<MultiImage>(input, dst_format); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 77 | |
| 78 | // Create and Configure function |
| 79 | NEColorConvert color_convert; |
| 80 | |
| 81 | if(1U == src_num_planes) |
| 82 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 83 | const Tensor *src_plane = ref_src.plane(0); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 84 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 85 | if(1U == dst_num_planes) |
| 86 | { |
| 87 | Tensor *dst_plane = ref_dst.plane(0); |
| 88 | color_convert.configure(src_plane, dst_plane); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | color_convert.configure(src_plane, &ref_dst); |
| 93 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 94 | } |
| 95 | else |
| 96 | { |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 97 | if(1U == dst_num_planes) |
| 98 | { |
| 99 | Tensor *dst_plane = ref_dst.plane(0); |
| 100 | color_convert.configure(&ref_src, dst_plane); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | color_convert.configure(&ref_src, &ref_dst); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | for(unsigned int plane_idx = 0; plane_idx < src_num_planes; ++plane_idx) |
| 109 | { |
| 110 | const Tensor *src_plane = ref_src.plane(plane_idx); |
| 111 | |
| 112 | ARM_COMPUTE_EXPECT(src_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
| 113 | } |
| 114 | for(unsigned int plane_idx = 0; plane_idx < dst_num_planes; ++plane_idx) |
| 115 | { |
| 116 | const Tensor *dst_plane = ref_dst.plane(plane_idx); |
| 117 | |
| 118 | ARM_COMPUTE_EXPECT(dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS); |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | } // namespace |
| 122 | |
| 123 | TEST_SUITE(NEON) |
| 124 | TEST_SUITE(ColorConvert) |
| 125 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 126 | template <typename T> |
| 127 | using NEColorConvertFixture = ColorConvertValidationFixture<MultiImage, Tensor, Accessor, NEColorConvert, T>; |
| 128 | |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 129 | TEST_SUITE(Configuration) |
| 130 | DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertRGBADataset), |
| 131 | shape, src_format, dst_format) |
| 132 | { |
| 133 | validate_configuration(shape, src_format, dst_format); |
| 134 | } |
| 135 | |
| 136 | DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertYUVDataset), |
| 137 | shape, src_format, dst_format) |
| 138 | { |
| 139 | validate_configuration(shape, src_format, dst_format); |
| 140 | } |
| 141 | |
| 142 | DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertYUVPlanarDataset), |
| 143 | shape, src_format, dst_format) |
| 144 | { |
| 145 | validate_configuration(shape, src_format, dst_format); |
| 146 | } |
| 147 | |
| 148 | DATA_TEST_CASE(RGB, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertRGBDataset), |
| 149 | shape, src_format, dst_format) |
| 150 | { |
| 151 | validate_configuration(shape, src_format, dst_format); |
| 152 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 153 | |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 154 | DATA_TEST_CASE(NV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertNVDataset), |
| 155 | shape, src_format, dst_format) |
| 156 | { |
| 157 | validate_configuration(shape, src_format, dst_format); |
| 158 | } |
| 159 | |
| 160 | DATA_TEST_CASE(YUVtoNV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertYUYVtoNVDataset), |
| 161 | shape, src_format, dst_format) |
| 162 | { |
| 163 | validate_configuration(shape, src_format, dst_format); |
| 164 | } |
| 165 | |
| 166 | DATA_TEST_CASE(NVtoYUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertNVtoYUVDataset), |
| 167 | shape, src_format, dst_format) |
| 168 | { |
| 169 | validate_configuration(shape, src_format, dst_format); |
| 170 | } |
| 171 | TEST_SUITE_END() |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 172 | |
| 173 | TEST_SUITE(RGBA) |
| 174 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertRGBADataset)) |
| 175 | { |
| 176 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 177 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 178 | { |
| 179 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 180 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 181 | } |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 182 | |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 183 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertRGBADataset)) |
| 184 | { |
| 185 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 186 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 187 | { |
| 188 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 189 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 190 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 191 | TEST_SUITE_END() |
| 192 | |
| 193 | TEST_SUITE(YUV) |
| 194 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertYUVDataset)) |
| 195 | { |
| 196 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 197 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 198 | { |
| 199 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 200 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 201 | } |
| 202 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertYUVDataset)) |
| 203 | { |
| 204 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 205 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 206 | { |
| 207 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 208 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | TEST_SUITE_END() |
| 212 | |
| 213 | TEST_SUITE(YUVPlanar) |
| 214 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertYUVPlanarDataset)) |
| 215 | { |
| 216 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 217 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 218 | { |
| 219 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 220 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 221 | } |
| 222 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertYUVPlanarDataset)) |
| 223 | { |
| 224 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 225 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 226 | { |
| 227 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 228 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 229 | } |
| 230 | TEST_SUITE_END() |
| 231 | |
| 232 | TEST_SUITE(RGB) |
| 233 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertRGBDataset)) |
| 234 | { |
| 235 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 236 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 237 | { |
| 238 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 239 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 240 | } |
| 241 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertRGBDataset)) |
| 242 | { |
| 243 | // Validate output |
Sanghoon Lee | dec32a9 | 2018-06-29 10:52:57 +0100 | [diff] [blame] | 244 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 245 | { |
| 246 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 247 | } |
| 248 | } |
| 249 | TEST_SUITE_END() |
| 250 | |
| 251 | TEST_SUITE(NV) |
| 252 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertNVDataset)) |
| 253 | { |
| 254 | // Validate output |
| 255 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 256 | { |
| 257 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx], tolerance_nv); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertNVDataset)) |
| 262 | { |
| 263 | // Validate output |
| 264 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 265 | { |
| 266 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx], tolerance_nv); |
| 267 | } |
| 268 | } |
| 269 | TEST_SUITE_END() |
| 270 | |
| 271 | TEST_SUITE(YUVtoNV) |
| 272 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertYUYVtoNVDataset)) |
| 273 | { |
| 274 | // Validate output |
| 275 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 276 | { |
| 277 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertYUYVtoNVDataset)) |
| 282 | { |
| 283 | // Validate output |
| 284 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 285 | { |
| 286 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 287 | } |
| 288 | } |
| 289 | TEST_SUITE_END() |
| 290 | |
| 291 | TEST_SUITE(NVtoYUV) |
| 292 | FIXTURE_DATA_TEST_CASE(RunSmall, NEColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertNVtoYUVDataset)) |
| 293 | { |
| 294 | // Validate output |
| 295 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 296 | { |
| 297 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 298 | } |
| 299 | } |
| 300 | FIXTURE_DATA_TEST_CASE(RunLarge, NEColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertNVtoYUVDataset)) |
| 301 | { |
| 302 | // Validate output |
| 303 | for(unsigned int plane_idx = 0; plane_idx < _dst_num_planes; ++plane_idx) |
| 304 | { |
| 305 | validate(Accessor(*_target.plane(plane_idx)), _reference[plane_idx]); |
| 306 | } |
Sanghoon Lee | 1fad27a | 2018-04-05 10:57:57 +0100 | [diff] [blame] | 307 | } |
| 308 | TEST_SUITE_END() |
| 309 | |
| 310 | TEST_SUITE_END() |
| 311 | TEST_SUITE_END() |
| 312 | } // namespace validation |
| 313 | } // namespace test |
| 314 | } // namespace arm_compute |