blob: 8047b34688d09db8a4afebc93234091aed000603 [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 "ColorConvert.h"
25
26#include "arm_compute/core/Types.h"
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010027#include "tests/validation/Helpers.h"
28#include "tests/validation/reference/ColorConvertHelper.h"
29
30namespace arm_compute
31{
32namespace test
33{
34namespace validation
35{
36namespace reference
37{
Sanghoon Leedec32a92018-06-29 10:52:57 +010038namespace
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010039{
Sanghoon Leedec32a92018-06-29 10:52:57 +010040template <typename T>
41inline std::vector<SimpleTensor<T>> create_image_planes(const TensorShape &shape, Format format)
42{
43 TensorShape image_shape = adjust_odd_shape(shape, format);
44
45 std::vector<SimpleTensor<T>> image_planes;
46
47 switch(format)
48 {
49 case Format::RGB888:
50 case Format::RGBA8888:
51 case Format::YUYV422:
52 case Format::UYVY422:
53 {
54 image_planes.emplace_back(image_shape, format);
55 break;
56 }
57 case Format::NV12:
58 case Format::NV21:
59 {
60 TensorShape shape_uv88 = calculate_subsampled_shape(image_shape, Format::UV88);
61
62 image_planes.emplace_back(image_shape, Format::U8);
63 image_planes.emplace_back(shape_uv88, Format::UV88);
64 break;
65 }
66 case Format::IYUV:
67 {
68 TensorShape shape_sub2 = calculate_subsampled_shape(image_shape, Format::IYUV);
69
70 image_planes.emplace_back(image_shape, Format::U8);
71 image_planes.emplace_back(shape_sub2, Format::U8);
72 image_planes.emplace_back(shape_sub2, Format::U8);
73 break;
74 }
75 case Format::YUV444:
76 {
77 image_planes.emplace_back(image_shape, Format::U8);
78 image_planes.emplace_back(image_shape, Format::U8);
79 image_planes.emplace_back(image_shape, Format::U8);
80 break;
81 }
82 default:
83 ARM_COMPUTE_ERROR("Not supported");
84 break;
85 }
86
87 return image_planes;
88}
89} // namespace
90
91template <typename T>
92std::vector<SimpleTensor<T>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format src_format, Format dst_format)
93{
94 std::vector<SimpleTensor<T>> dst = create_image_planes<T>(shape, dst_format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +010095
96 switch(src_format)
97 {
98 case Format::RGB888:
99 {
100 switch(dst_format)
101 {
102 case Format::RGBA8888:
Sanghoon Leedec32a92018-06-29 10:52:57 +0100103 colorconvert_helper::detail::colorconvert_rgb_to_rgbx(tensor_planes[0], dst[0]);
104 break;
105 case Format::NV12:
106 colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst);
107 break;
108 case Format::IYUV:
109 colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst);
110 break;
111 case Format::YUV444:
112 colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100113 break;
114 default:
115 ARM_COMPUTE_ERROR("Not Supported");
116 break;
117 }
118 break;
119 }
120 case Format::RGBA8888:
121 {
122 switch(dst_format)
123 {
124 case Format::RGB888:
Sanghoon Leedec32a92018-06-29 10:52:57 +0100125 colorconvert_helper::detail::colorconvert_rgbx_to_rgb(tensor_planes[0], dst[0]);
126 break;
127 case Format::NV12:
128 colorconvert_helper::detail::colorconvert_rgb_to_nv12(tensor_planes[0], dst);
129 break;
130 case Format::IYUV:
131 colorconvert_helper::detail::colorconvert_rgb_to_iyuv(tensor_planes[0], dst);
132 break;
133 case Format::YUV444:
134 colorconvert_helper::detail::colorconvert_rgb_to_yuv4(tensor_planes[0], dst);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100135 break;
136 default:
137 ARM_COMPUTE_ERROR("Not Supported");
138 break;
139 }
140 break;
141 }
142 case Format::UYVY422:
143 case Format::YUYV422:
144 {
145 switch(dst_format)
146 {
147 case Format::RGB888:
148 case Format::RGBA8888:
Sanghoon Leedec32a92018-06-29 10:52:57 +0100149 colorconvert_helper::detail::colorconvert_yuyv_to_rgb(tensor_planes[0], src_format, dst[0]);
150 break;
151 case Format::NV12:
152 colorconvert_helper::detail::colorconvert_yuyv_to_nv12(tensor_planes[0], src_format, dst);
153 break;
154 case Format::IYUV:
155 colorconvert_helper::detail::colorconvert_yuyv_to_iyuv(tensor_planes[0], src_format, dst);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100156 break;
157 default:
158 ARM_COMPUTE_ERROR("Not Supported");
159 break;
160 }
161 break;
162 }
163 case Format::IYUV:
164 {
165 switch(dst_format)
166 {
167 case Format::RGB888:
168 case Format::RGBA8888:
Sanghoon Leedec32a92018-06-29 10:52:57 +0100169 colorconvert_helper::detail::colorconvert_iyuv_to_rgb(shape, tensor_planes, dst[0]);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100170 break;
171 default:
172 ARM_COMPUTE_ERROR("Not Supported");
173 break;
174 }
175 break;
176 }
177 case Format::NV12:
178 case Format::NV21:
179 {
180 switch(dst_format)
181 {
182 case Format::RGB888:
183 case Format::RGBA8888:
Sanghoon Leedec32a92018-06-29 10:52:57 +0100184 colorconvert_helper::detail::colorconvert_nv12_to_rgb(shape, src_format, tensor_planes, dst[0]);
185 break;
186 case Format::IYUV:
187 colorconvert_helper::detail::colorconvert_nv_to_iyuv(tensor_planes, src_format, dst);
188 break;
189 case Format::YUV444:
190 colorconvert_helper::detail::colorconvert_nv_to_yuv4(tensor_planes, src_format, dst);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100191 break;
192 default:
193 ARM_COMPUTE_ERROR("Not Supported");
194 break;
195 }
196 break;
197 }
198 default:
199 ARM_COMPUTE_ERROR("Not supported");
200 break;
201 }
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100202 return dst;
203}
204
Sanghoon Leedec32a92018-06-29 10:52:57 +0100205template std::vector<SimpleTensor<uint8_t>> color_convert(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format src_format, Format dst_format);
Sanghoon Lee1fad27a2018-04-05 10:57:57 +0100206} // namespace reference
207} // namespace validation
208} // namespace test
209} // namespace arm_compute