blob: 8674510269bac1881304f70b61c1a2ef7a1017b7 [file] [log] [blame]
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +01003 *
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 "ChannelExtract.h"
25
26#include "arm_compute/core/Types.h"
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010027#include "tests/validation/Helpers.h"
28
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
37template <typename T>
38SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel)
39{
40 // Find plane and channel index
41 const unsigned int plane_idx = plane_idx_from_channel(format, channel);
42 const unsigned int channel_idx = channel_idx_from_format(format, channel);
43
44 // Create dst and get src tensor
45 SimpleTensor<T> src = tensor_planes[plane_idx];
46 SimpleTensor<T> dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 };
47
48 // Single planar formats with subsampling require a double horizontal step
49 const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1;
50 const int width = dst.shape().x();
51 const int height = dst.shape().y();
52
53 // Loop over each pixel and extract channel
Michalis Spyroud1d77222020-04-08 14:10:15 +010054#if defined(_OPENMP)
55 #pragma omp parallel for collapse(2)
56#endif /* _OPENMP */
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010057 for(int y = 0; y < height; ++y)
58 {
59 for(int x = 0; x < width; ++x)
60 {
61 const Coordinates src_coord{ x * step_x, y };
62 const Coordinates dst_coord{ x, y };
63
64 const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord));
65 auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord));
66
Michalis Spyrou6260e192019-06-06 13:47:38 +010067 dst_pixel[0] = src_pixel[channel_idx]; // NOLINT
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +010068 }
69 }
70
71 return dst;
72}
73
74template SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format format, Channel channel);
75} // namespace reference
76} // namespace validation
77} // namespace test
78} // namespace arm_compute