blob: bd00d4f724683b1be527f17ffb19e9b871ca037f [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);
54
55 _target = compute_target(shape, src_format, dst_format);
56 _reference = compute_reference(shape, src_format, dst_format);
57 }
58
59protected:
60 template <typename U>
61 void fill(U &&tensor, int i)
62 {
63 library->fill_tensor_uniform(tensor, 1);
64 }
65
66 std::vector<SimpleTensor<T>> create_tensor_planes_reference(const TensorShape &shape, Format format)
67 {
68 TensorShape input = adjust_odd_shape(shape, format);
69
70 std::vector<SimpleTensor<T>> tensor_planes;
71
72 switch(format)
73 {
74 case Format::RGB888:
75 case Format::RGBA8888:
76 case Format::YUYV422:
77 case Format::UYVY422:
78 {
79 tensor_planes.emplace_back(input, format);
80 break;
81 }
82 case Format::NV12:
83 case Format::NV21:
84 {
85 const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
86
87 tensor_planes.emplace_back(input, Format::U8);
88 tensor_planes.emplace_back(shape_uv88, Format::UV88);
89 break;
90 }
91 case Format::IYUV:
92 {
93 const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
94
95 tensor_planes.emplace_back(input, Format::U8);
96 tensor_planes.emplace_back(shape_sub2, Format::U8);
97 tensor_planes.emplace_back(shape_sub2, Format::U8);
98 break;
99 }
100 case Format::YUV444:
101 {
102 tensor_planes.emplace_back(input, Format::U8);
103 tensor_planes.emplace_back(input, Format::U8);
104 tensor_planes.emplace_back(input, Format::U8);
105 break;
106 }
107 default:
108 ARM_COMPUTE_ERROR("Not supported");
109 break;
110 }
111
112 return tensor_planes;
113 }
114
115 TensorType compute_target(const TensorShape &shape, Format src_format, Format dst_format)
116 {
117 const unsigned int num_planes = num_planes_from_format(src_format);
118
119 // Create tensors
120 MultiImageType ref_src = create_multi_image<MultiImageType>(shape, src_format);
121 TensorType dst = create_tensor<TensorType>(shape, dst_format);
122
123 // Create and configure function
124 FunctionType color_convert;
125
126 if(1U == num_planes)
127 {
128 const TensorType *plane_src = static_cast<TensorType *>(ref_src.plane(0));
129 color_convert.configure(plane_src, &dst);
130 }
131 else
132 {
133 color_convert.configure(&ref_src, &dst);
134 }
135
136 for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
137 {
138 const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx));
139
140 ARM_COMPUTE_EXPECT(src_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
141 }
142
143 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
144
145 // Allocate tensors
146 ref_src.allocate();
147 dst.allocator()->allocate();
148
149 for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
150 {
151 const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx));
152
153 ARM_COMPUTE_EXPECT(!src_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
154 }
155
156 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
157
158 // Fill tensor planes
159 for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
160 {
161 TensorType *src_plane = static_cast<TensorType *>(ref_src.plane(plane_idx));
162
163 fill(AccessorType(*src_plane), plane_idx);
164 }
165
166 // Compute function
167 color_convert.run();
168
169 return dst;
170 }
171
172 SimpleTensor<T> compute_reference(const TensorShape &shape, Format src_format, Format dst_format)
173 {
174 _num_planes = num_planes_from_format(dst_format);
175
176 // Create reference
177 std::vector<SimpleTensor<T>> ref_src = create_tensor_planes_reference(shape, src_format);
178
179 // Fill references
180 for(unsigned int plane_idx = 0; plane_idx < ref_src.size(); ++plane_idx)
181 {
182 fill(ref_src[plane_idx], plane_idx);
183 }
184
185 return reference::color_convert<T>(shape, ref_src, src_format, dst_format);
186 }
187
188 unsigned int _num_planes{};
189 TensorType _target{};
190 SimpleTensor<T> _reference{};
191};
192} // namespace validation
193} // namespace test
194} // namespace arm_compute
195#endif /* ARM_COMPUTE_TEST_COLOR_CONVERT_FIXTURE */