Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 2017 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_NEWARPKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NEWARPKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | |
| 30 | #include <cstdint> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | class ITensor; |
| 35 | |
| 36 | /** Common interface for warp affine and warp perspective */ |
| 37 | class INEWarpKernel : public INEKernel |
| 38 | { |
| 39 | public: |
| 40 | /** Default constructor */ |
| 41 | INEWarpKernel(); |
| 42 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 43 | INEWarpKernel(const INEWarpKernel &) = delete; |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 45 | INEWarpKernel &operator=(const INEWarpKernel &) = delete; |
| 46 | /** Allow instances of this class to be moved */ |
| 47 | INEWarpKernel(INEWarpKernel &&) = default; |
| 48 | /** Allow instances of this class to be moved */ |
| 49 | INEWarpKernel &operator=(INEWarpKernel &&) = default; |
| 50 | /** Initialise the kernel's input, output and border mode. |
| 51 | * |
| 52 | * @param[in] input Source tensor. Data type supported: U8. |
| 53 | * @param[out] output Destination tensor. Data type supported: U8. |
| 54 | * @param[in] matrix The perspective or affine matrix to use. Must be 2x3 for affine and 3x3 for perspective of type float. |
| 55 | * @param[in] border_mode Strategy to use for borders |
| 56 | * @param[in] constant_border_value Constant value used for filling the border. |
| 57 | */ |
| 58 | virtual void configure(const ITensor *input, ITensor *output, const float *matrix, BorderMode border_mode, uint8_t constant_border_value); |
| 59 | |
| 60 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 61 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | |
Isabella Gottardi | f9bae2e | 2017-07-28 17:24:08 +0100 | [diff] [blame] | 63 | // Inherited methods overridden: |
| 64 | BorderSize border_size() const override; |
| 65 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | protected: |
| 67 | /** function to perform warp affine or warp perspective on the given window when border mode == UNDEFINED |
| 68 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 69 | * @param[in] window Region on which to execute the kernel |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | */ |
| 71 | virtual void warp_undefined(const Window &window) = 0; |
| 72 | /** function to perform warp affine or warp perspective on the given window when border mode == CONSTANT |
| 73 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 74 | * @param[in] window Region on which to execute the kernel |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | */ |
| 76 | virtual void warp_constant(const Window &window) = 0; |
| 77 | /** function to perform warp affine or warp perspective on the given window when border mode == REPLICATE |
| 78 | * |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 79 | * @param[in] window Region on which to execute the kernel |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | */ |
| 81 | virtual void warp_replicate(const Window &window) = 0; |
| 82 | /** Common signature for all the specialised warp functions |
| 83 | * |
| 84 | * @param[in] window Region on which to execute the kernel. |
| 85 | */ |
| 86 | void (INEWarpKernel::*_func)(const Window &window); |
| 87 | |
| 88 | const ITensor *_input; /**< Input Tensor */ |
| 89 | ITensor *_output; /**< Output Tensor */ |
| 90 | uint8_t _constant_border_value; /**< Constant value used for filling the border. This value is used for those pixels out of the ROI when the border mode is CONSTANT */ |
| 91 | const float *_matrix; /**< The affine or perspective matrix. Must be 2x3 for warp affine or 3x3 for warp perspective of type float. */ |
| 92 | }; |
| 93 | |
| 94 | /** Template interface for the kernel to compute warp affine |
| 95 | * |
| 96 | */ |
| 97 | template <InterpolationPolicy interpolation> |
| 98 | class NEWarpAffineKernel : public INEWarpKernel |
| 99 | { |
| 100 | private: |
| 101 | // Inherited methods overridden: |
| 102 | void warp_undefined(const Window &window) override; |
| 103 | void warp_constant(const Window &window) override; |
| 104 | void warp_replicate(const Window &window) override; |
| 105 | }; |
| 106 | |
| 107 | /** Template interface for the kernel to compute warp perspective |
| 108 | * |
| 109 | */ |
| 110 | template <InterpolationPolicy interpolation> |
| 111 | class NEWarpPerspectiveKernel : public INEWarpKernel |
| 112 | { |
| 113 | private: |
| 114 | // Inherited methods overridden: |
| 115 | void warp_undefined(const Window &window) override; |
| 116 | void warp_constant(const Window &window) override; |
| 117 | void warp_replicate(const Window &window) override; |
| 118 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 119 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 120 | #endif /*__ARM_COMPUTE_NEWARPKERNEL_H__ */ |