blob: 6d045116294fd41c6d10aaea3d2d33735b1e2a1d [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#include "arm_compute/runtime/CL/CLMultiImage.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLColorConvert.h"
28#include "tests/CL/CLAccessor.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
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
41namespace
42{
43// Input data sets
44const auto ColorConvertRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }),
45 framework::dataset::make("FormatType", { Format::RGB888 }));
46const auto ColorConvertYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }),
47 framework::dataset::make("FormatType", { Format::RGB888, Format::RGBA8888 }));
48
49const auto ColorConvertYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::NV12, Format::NV21 }),
50 framework::dataset::make("FormatType", { Format::RGB888, Format::RGBA8888 }));
51
52const auto ColorConvertRGBDataset = combine(framework::dataset::make("FormatType", { Format::RGB888 }),
53 framework::dataset::make("FormatType", { Format::RGBA8888 }));
54
55inline void validate_configuration(const TensorShape &shape, Format src_format, Format dst_format)
56{
57 const unsigned int src_num_planes = num_planes_from_format(src_format);
58
59 const TensorShape dst_shape = adjust_odd_shape(shape, src_format);
60
61 // Create tensors
62 CLMultiImage ref_src = create_multi_image<CLMultiImage>(shape, src_format);
63 CLTensor dst = create_tensor<CLTensor>(dst_shape, dst_format);
64
65 // Create and Configure function
66 CLColorConvert color_convert;
67
68 if(1U == src_num_planes)
69 {
70 const CLTensor *plane_src = ref_src.cl_plane(0);
71
72 color_convert.configure(plane_src, &dst);
73 const ValidRegion dst_valid_region = shape_to_valid_region(dst_shape);
74 validate(dst.info()->valid_region(), dst_valid_region);
75 }
76 else
77 {
78 color_convert.configure(&ref_src, &dst);
79 }
80}
81} // namespace
82
83TEST_SUITE(CL)
84TEST_SUITE(ColorConvert)
85
86TEST_SUITE(Configuration)
87DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertRGBADataset),
88 shape, src_format, dst_format)
89{
90 validate_configuration(shape, src_format, dst_format);
91}
92
93DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertYUVDataset),
94 shape, src_format, dst_format)
95{
96 validate_configuration(shape, src_format, dst_format);
97}
98
99DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertYUVPlanarDataset),
100 shape, src_format, dst_format)
101{
102 validate_configuration(shape, src_format, dst_format);
103}
104
105DATA_TEST_CASE(RGB, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ColorConvertRGBDataset),
106 shape, src_format, dst_format)
107{
108 validate_configuration(shape, src_format, dst_format);
109}
110TEST_SUITE_END()
111
112template <typename T>
113using CLColorConvertFixture = ColorConvertValidationFixture<CLMultiImage, CLTensor, CLAccessor, CLColorConvert, T>;
114
115TEST_SUITE(RGBA)
116FIXTURE_DATA_TEST_CASE(RunSmall, CLColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertRGBADataset))
117{
118 // Validate output
119 validate(CLAccessor(_target), _reference);
120}
121
122FIXTURE_DATA_TEST_CASE(RunLarge, CLColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertRGBADataset))
123{
124 // Validate output
125 validate(CLAccessor(_target), _reference);
126}
127TEST_SUITE_END()
128
129TEST_SUITE(YUV)
130FIXTURE_DATA_TEST_CASE(RunSmall, CLColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertYUVDataset))
131{
132 // Validate output
133 validate(CLAccessor(_target), _reference);
134}
135FIXTURE_DATA_TEST_CASE(RunLarge, CLColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertYUVDataset))
136{
137 validate(CLAccessor(_target), _reference);
138}
139TEST_SUITE_END()
140
141TEST_SUITE(YUVPlanar)
142FIXTURE_DATA_TEST_CASE(RunSmall, CLColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertYUVPlanarDataset))
143{
144 // Validate output
145 validate(CLAccessor(_target), _reference);
146}
147FIXTURE_DATA_TEST_CASE(RunLarge, CLColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertYUVPlanarDataset))
148{
149 // Validate output
150 validate(CLAccessor(_target), _reference);
151}
152TEST_SUITE_END()
153
154TEST_SUITE(RGB)
155FIXTURE_DATA_TEST_CASE(RunSmall, CLColorConvertFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ColorConvertRGBDataset))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference);
159}
160FIXTURE_DATA_TEST_CASE(RunLarge, CLColorConvertFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ColorConvertRGBDataset))
161{
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164}
165TEST_SUITE_END()
166TEST_SUITE_END()
167TEST_SUITE_END()
168} // namespace validation
169} // namespace test
170} // namespace arm_compute