1 /* 2 * Copyright (c) 2016-2020 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 #ifndef ARM_COMPUTE_NECHANNELCOMBINEKERNEL_H 25 #define ARM_COMPUTE_NECHANNELCOMBINEKERNEL_H 26 27 #include "src/core/NEON/INEKernel.h" 28 29 #include <array> 30 #include <cstdint> 31 32 namespace arm_compute 33 { 34 class IMultiImage; 35 class ITensor; 36 using IImage = ITensor; 37 38 /** Interface for the channel combine kernel */ 39 class NEChannelCombineKernel : public INEKernel 40 { 41 public: name()42 const char *name() const override 43 { 44 return "NEChannelCombineKernel"; 45 } 46 /** Default constructor */ 47 NEChannelCombineKernel(); 48 /** Prevent instances of this class from being copied (As this class contains pointers) */ 49 NEChannelCombineKernel(const NEChannelCombineKernel &) = delete; 50 /** Prevent instances of this class from being copied (As this class contains pointers) */ 51 NEChannelCombineKernel &operator=(const NEChannelCombineKernel &) = delete; 52 /** Allow instances of this class to be moved */ 53 NEChannelCombineKernel(NEChannelCombineKernel &&) = default; 54 /** Allow instances of this class to be moved */ 55 NEChannelCombineKernel &operator=(NEChannelCombineKernel &&) = default; 56 /** Default destructor */ 57 ~NEChannelCombineKernel() = default; 58 59 /** Configure function's inputs and outputs. 60 * 61 * @param[in] plane0 The 2D plane that forms channel 0. Data type supported: U8 62 * @param[in] plane1 The 2D plane that forms channel 1. Data type supported: U8 63 * @param[in] plane2 The 2D plane that forms channel 2. Data type supported: U8 64 * @param[in] plane3 The 2D plane that forms channel 3. Data type supported: U8 65 * @param[out] output The single planar output tensor. Formats supported: RGB888/RGBA8888/UYVY422/YUYV422 66 */ 67 void configure(const ITensor *plane0, const ITensor *plane1, const ITensor *plane2, const ITensor *plane3, ITensor *output); 68 /** Configure function's inputs and outputs. 69 * 70 * @param[in] plane0 The 2D plane that forms channel 0. Data type supported: U8 71 * @param[in] plane1 The 2D plane that forms channel 1. Data type supported: U8 72 * @param[in] plane2 The 2D plane that forms channel 2. Data type supported: U8 73 * @param[out] output The multi planar output tensor. Formats supported: NV12/NV21/IYUV/YUV444 74 */ 75 void configure(const IImage *plane0, const IImage *plane1, const IImage *plane2, IMultiImage *output); 76 77 // Inherited methods overridden: 78 void run(const Window &window, const ThreadInfo &info) override; 79 bool is_parallelisable() const override; 80 81 private: 82 /** Combine 3 planes to form a three channel single plane tensor. 83 * 84 * @param[in] win Region on which to execute the kernel. 85 */ 86 void combine_3C(const Window &win); 87 /** Combine 4 planes to form a four channel single plane tensor. 88 * 89 * @param[in] win Region on which to execute the kernel. 90 */ 91 void combine_4C(const Window &win); 92 /** Combine 3 planes to form a single plane YUV tensor. 93 * 94 * @param[in] win Region on which to execute the kernel. 95 */ 96 template <bool is_yuyv> 97 void combine_YUV_1p(const Window &win); 98 /** Combine 3 planes to form a two plane YUV tensor. 99 * 100 * @param[in] win Region on which to execute the kernel. 101 */ 102 void combine_YUV_2p(const Window &win); 103 /** Combine 3 planes to form a three plane YUV tensor. 104 * 105 * @param[in] win Region on which to execute the kernel. 106 */ 107 void combine_YUV_3p(const Window &win); 108 /** Copies a full plane to the output tensor. 109 * 110 * @param[in] win Region on which to execute the kernel. 111 */ 112 void copy_plane(const Window &win, uint32_t plane_id); 113 /** Common signature for all the specialised ChannelCombine functions 114 * 115 * @param[in] window Region on which to execute the kernel. 116 */ 117 using ChannelCombineFunction = void (NEChannelCombineKernel::*)(const Window &window); 118 /** ChannelCombine function to use for the particular tensor types passed to configure() */ 119 ChannelCombineFunction _func; 120 std::array<const ITensor *, 4> _planes; 121 ITensor *_output; 122 IMultiImage *_output_multi; 123 std::array<uint32_t, 3> _x_subsampling; 124 std::array<uint32_t, 3> _y_subsampling; 125 unsigned int _num_elems_processed_per_iteration; 126 bool _is_parallelizable; 127 }; 128 } // namespace arm_compute 129 #endif /* ARM_COMPUTE_NECHANNELCOMBINEKERNEL_H */ 130