blob: 595bb13098b39656c0e970521ef7d8ae86bc26b4 [file] [log] [blame]
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +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 "ChannelExtract.h"
25
26#include "arm_compute/core/Types.h"
27#include "tests/validation/FixedPoint.h"
28#include "tests/validation/Helpers.h"
29
30namespace arm_compute
31{
32namespace test
33{
34namespace validation
35{
36namespace reference
37{
38template <typename T>
39SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel)
40{
41 // Find plane and channel index
42 const unsigned int plane_idx = plane_idx_from_channel(format, channel);
43 const unsigned int channel_idx = channel_idx_from_format(format, channel);
44
45 // Create dst and get src tensor
46 SimpleTensor<T> src = tensor_planes[plane_idx];
47 SimpleTensor<T> dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 };
48
49 // Single planar formats with subsampling require a double horizontal step
50 const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1;
51 const int width = dst.shape().x();
52 const int height = dst.shape().y();
53
54 // Loop over each pixel and extract channel
55 for(int y = 0; y < height; ++y)
56 {
57 for(int x = 0; x < width; ++x)
58 {
59 const Coordinates src_coord{ x * step_x, y };
60 const Coordinates dst_coord{ x, y };
61
62 const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord));
63 auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord));
64
65 dst_pixel[0] = src_pixel[channel_idx];
66 }
67 }
68
69 return dst;
70}
71
72template SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format format, Channel channel);
73} // namespace reference
74} // namespace validation
75} // namespace test
76} // namespace arm_compute