blob: 2c4cb55e3c694df6032f48f7d5757c8fa3609ce7 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEWARPKERNEL_H
25#define ARM_COMPUTE_NEWARPKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010028#include "src/core/NEON/INEKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
Pablo Tellod8b03dd2018-08-07 11:23:54 +010030#include <array>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include <cstdint>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032namespace arm_compute
33{
34class ITensor;
35
36/** Common interface for warp affine and warp perspective */
37class INEWarpKernel : public INEKernel
38{
39public:
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;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010050 /** Default destructor */
51 ~INEWarpKernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052 /** Initialise the kernel's input, output and border mode.
53 *
54 * @param[in] input Source tensor. Data type supported: U8.
55 * @param[out] output Destination tensor. Data type supported: U8.
56 * @param[in] matrix The perspective or affine matrix to use. Must be 2x3 for affine and 3x3 for perspective of type float.
Pablo Tellod8b03dd2018-08-07 11:23:54 +010057 * The matrix argument requires 9 values, for the affine case the last 3 values are ignored.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 * @param[in] border_mode Strategy to use for borders
59 * @param[in] constant_border_value Constant value used for filling the border.
60 */
Pablo Tellod8b03dd2018-08-07 11:23:54 +010061 virtual void configure(const ITensor *input, ITensor *output, const std::array<float, 9> &matrix, BorderMode border_mode, uint8_t constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062
63 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010064 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065
Isabella Gottardif9bae2e2017-07-28 17:24:08 +010066 // Inherited methods overridden:
67 BorderSize border_size() const override;
68
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069protected:
70 /** function to perform warp affine or warp perspective on the given window when border mode == UNDEFINED
71 *
Anthony Barbierf202e502017-11-23 18:02:04 +000072 * @param[in] window Region on which to execute the kernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 */
74 virtual void warp_undefined(const Window &window) = 0;
75 /** function to perform warp affine or warp perspective on the given window when border mode == CONSTANT
76 *
Anthony Barbierf202e502017-11-23 18:02:04 +000077 * @param[in] window Region on which to execute the kernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 */
79 virtual void warp_constant(const Window &window) = 0;
80 /** function to perform warp affine or warp perspective on the given window when border mode == REPLICATE
81 *
Anthony Barbierf202e502017-11-23 18:02:04 +000082 * @param[in] window Region on which to execute the kernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083 */
84 virtual void warp_replicate(const Window &window) = 0;
85 /** Common signature for all the specialised warp functions
86 *
87 * @param[in] window Region on which to execute the kernel.
88 */
89 void (INEWarpKernel::*_func)(const Window &window);
90
91 const ITensor *_input; /**< Input Tensor */
92 ITensor *_output; /**< Output Tensor */
93 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 */
Pablo Tellod8b03dd2018-08-07 11:23:54 +010094 std::array<float, 9> _matrix; /**< The affine or perspective matrix. Must be 2x3 for warp affine or 3x3 for warp perspective of type float. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095};
96
97/** Template interface for the kernel to compute warp affine
98 *
99 */
100template <InterpolationPolicy interpolation>
101class NEWarpAffineKernel : public INEWarpKernel
102{
103private:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000104 const char *name() const override
105 {
106 return "NEWarpAffineKernel";
107 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100108 // Inherited methods overridden:
109 void warp_undefined(const Window &window) override;
110 void warp_constant(const Window &window) override;
111 void warp_replicate(const Window &window) override;
112};
113
114/** Template interface for the kernel to compute warp perspective
115 *
116 */
117template <InterpolationPolicy interpolation>
118class NEWarpPerspectiveKernel : public INEWarpKernel
119{
120private:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000121 const char *name() const override
122 {
123 return "NEWarpPerspectiveKernel";
124 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100125 // Inherited methods overridden:
126 void warp_undefined(const Window &window) override;
127 void warp_constant(const Window &window) override;
128 void warp_replicate(const Window &window) override;
129};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100130} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000131#endif /*ARM_COMPUTE_NEWARPKERNEL_H */