Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | d1d7722 | 2020-04-08 14:10:15 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 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" |
Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 27 | #include "tests/validation/Helpers.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace test |
| 32 | { |
| 33 | namespace validation |
| 34 | { |
| 35 | namespace reference |
| 36 | { |
| 37 | template <typename T> |
| 38 | SimpleTensor<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 Spyrou | d1d7722 | 2020-04-08 14:10:15 +0100 | [diff] [blame] | 54 | #if defined(_OPENMP) |
| 55 | #pragma omp parallel for collapse(2) |
| 56 | #endif /* _OPENMP */ |
Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 57 | 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 Spyrou | 6260e19 | 2019-06-06 13:47:38 +0100 | [diff] [blame] | 67 | dst_pixel[0] = src_pixel[channel_idx]; // NOLINT |
Ioan-Cristian Szabo | 9414f64 | 2017-10-27 17:35:40 +0100 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | return dst; |
| 72 | } |
| 73 | |
| 74 | template 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 |