blob: cbaff6dfce7da4cde57ab1e4d43d5b210bc10483 [file] [log] [blame]
Sanghoon Lee1fad27a2018-04-05 10:57:57 +01001/*
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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45}
46template <typename MultiImageType, typename TensorType, typename AccessorType, typename FunctionType, typename T>
47class ColorConvertValidationFixture : public framework::Fixture
48{
49public:
50 template <typename...>
51 void setup(TensorShape shape, Format src_format, Format dst_format)
52 {
53 shape = adjust_odd_shape(shape, src_format);
Sanghoon Leedec32a92018-06-29 10:52:57 +010054 shape = adjust_odd_shape(shape, dst_format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010055
56 _target = compute_target(shape, src_format, dst_format);
57 _reference = compute_reference(shape, src_format, dst_format);
58 }
59
60protected:
61 template <typename U>
62 void fill(U &&tensor, int i)
63 {
Sanghoon Leedec32a92018-06-29 10:52:57 +010064 library->fill_tensor_uniform(tensor, i);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010065 }
66
67 std::vector<SimpleTensor<T>> create_tensor_planes_reference(const TensorShape &shape, Format format)
68 {
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010069 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 Leedec32a92018-06-29 10:52:57 +010078 tensor_planes.emplace_back(shape, format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010079 break;
80 }
81 case Format::NV12:
82 case Format::NV21:
83 {
84 const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
85
Sanghoon Leedec32a92018-06-29 10:52:57 +010086 tensor_planes.emplace_back(shape, Format::U8);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010087 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 Leedec32a92018-06-29 10:52:57 +010094 tensor_planes.emplace_back(shape, Format::U8);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010095 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 Leedec32a92018-06-29 10:52:57 +0100101 tensor_planes.emplace_back(shape, Format::U8);
102 tensor_planes.emplace_back(shape, Format::U8);
103 tensor_planes.emplace_back(shape, Format::U8);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100104 break;
105 }
106 default:
107 ARM_COMPUTE_ERROR("Not supported");
108 break;
109 }
110
111 return tensor_planes;
112 }
113
Sanghoon Leedec32a92018-06-29 10:52:57 +0100114 MultiImageType compute_target(const TensorShape &shape, Format src_format, Format dst_format)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100115 {
Sanghoon Leedec32a92018-06-29 10:52:57 +0100116 _src_num_planes = num_planes_from_format(src_format);
117 _dst_num_planes = num_planes_from_format(dst_format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100118
119 // Create tensors
120 MultiImageType ref_src = create_multi_image<MultiImageType>(shape, src_format);
Sanghoon Leedec32a92018-06-29 10:52:57 +0100121 MultiImageType ref_dst = create_multi_image<MultiImageType>(shape, dst_format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100122
123 // Create and configure function
124 FunctionType color_convert;
125
Sanghoon Leedec32a92018-06-29 10:52:57 +0100126 if(1U == _src_num_planes)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100127 {
128 const TensorType *plane_src = static_cast<TensorType *>(ref_src.plane(0));
Sanghoon Leedec32a92018-06-29 10:52:57 +0100129
130 if(1U == _dst_num_planes)
131 {
Sanghoon Leec7b82f12018-07-06 13:27:27 +0100132 TensorType *plane_dst = static_cast<TensorType *>(ref_dst.plane(0));
133 color_convert.configure(plane_src, plane_dst);
Sanghoon Leedec32a92018-06-29 10:52:57 +0100134 }
135 else
136 {
137 color_convert.configure(plane_src, &ref_dst);
138 }
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100139 }
140 else
141 {
Sanghoon Leedec32a92018-06-29 10:52:57 +0100142 if(1U == _dst_num_planes)
143 {
Sanghoon Leec7b82f12018-07-06 13:27:27 +0100144 TensorType *plane_dst = static_cast<TensorType *>(ref_dst.plane(0));
145 color_convert.configure(&ref_src, plane_dst);
Sanghoon Leedec32a92018-06-29 10:52:57 +0100146 }
147 else
148 {
149 color_convert.configure(&ref_src, &ref_dst);
150 }
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100151 }
152
Sanghoon Leedec32a92018-06-29 10:52:57 +0100153 for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100154 {
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 Leedec32a92018-06-29 10:52:57 +0100159 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 Lee1fad27a2018-04-05 10:57:57 +0100162
Sanghoon Leedec32a92018-06-29 10:52:57 +0100163 ARM_COMPUTE_EXPECT(dst_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
164 }
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100165
166 // Allocate tensors
167 ref_src.allocate();
Sanghoon Leedec32a92018-06-29 10:52:57 +0100168 ref_dst.allocate();
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100169
Sanghoon Leedec32a92018-06-29 10:52:57 +0100170 for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100171 {
172 const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx));
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100173 ARM_COMPUTE_EXPECT(!src_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
174 }
175
Sanghoon Leedec32a92018-06-29 10:52:57 +0100176 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 Lee1fad27a2018-04-05 10:57:57 +0100181
182 // Fill tensor planes
Sanghoon Leedec32a92018-06-29 10:52:57 +0100183 for(unsigned int plane_idx = 0; plane_idx < _src_num_planes; ++plane_idx)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100184 {
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 Leedec32a92018-06-29 10:52:57 +0100193 return ref_dst;
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100194 }
195
Sanghoon Leedec32a92018-06-29 10:52:57 +0100196 std::vector<SimpleTensor<T>> compute_reference(const TensorShape &shape, Format src_format, Format dst_format)
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100197 {
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100198 // 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 Leedec32a92018-06-29 10:52:57 +0100210 unsigned int _src_num_planes{};
211 unsigned int _dst_num_planes{};
212 MultiImageType _target{};
213 std::vector<SimpleTensor<T>> _reference{};
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100214};
215} // namespace validation
216} // namespace test
217} // namespace arm_compute
218#endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE */