blob: fab88a168261b0652156a7fcb93fe686ea5e77e6 [file] [log] [blame]
Adnan AlSinan7075fe22021-07-05 13:12:52 +01001/*
2 * Copyright (c) 2017-2021 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 "helpers.h"
25#include "warp_helpers.h"
26
27#ifndef DEPTH_OUT
28/** Performs a remapping of an input image to an output given two remapping image using nearest neighbor as interpolation.
29 *
30 * This kernel performs remapping with this method of pixel coordinate translation:
31 * out(x,y) = in(mapx(x,y), mapy(x,y));
32 *
33 * @param[in] in_ptr Pointer to the source image. Supported data types: U8.
34 * @param[in] in_stride_x Stride of the source image in X dimension (in bytes)
35 * @param[in] in_step_x in_stride_x * number of elements along X processed per work item (in bytes)
36 * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes)
37 * @param[in] in_step_y in_stride_y * number of elements along Y processed per work item (in bytes)
38 * @param[in] in_offset_first_element_in_bytes Offset of the first element in the source image
39 * @param[out] out_ptr Pointer to the destination image. Supported data types: U8.
40 * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes)
41 * @param[in] out_step_x out_stride_x * number of elements along X processed per work item (in bytes)
42 * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes)
43 * @param[in] out_step_y out_stride_y * number of elements along Y processed per work item (in bytes)
44 * @param[in] out_offset_first_element_in_bytes Offset of the first element in the destination image
45 * @param[in] mapx_ptr Pointer to the x remapping image. Supported data types: F32.
46 * @param[in] mapx_stride_x Stride of the remapping image in X dimension (in bytes)
47 * @param[in] mapx_step_x mapx_stride_x * number of elements along X processed per work item (in bytes)
48 * @param[in] mapx_stride_y Stride of the remapping image in Y dimension (in bytes)
49 * @param[in] mapx_step_y mapy_stride_y * number of elements along Y processed per work item (in bytes)
50 * @param[in] mapx_offset_first_element_in_bytes Offset of the first element in the remapping image
51 * @param[in] mapy_ptr Pointer to the x remapping image. Supported data types: F32.
52 * @param[in] mapy_stride_x Stride of the remapping image in X dimension (in bytes)
53 * @param[in] mapy_step_x mapy_stride_x * number of elements along X processed per work item (in bytes)
54 * @param[in] mapy_stride_y Stride of the remapping image in Y dimension (in bytes)
55 * @param[in] mapy_step_y mapy_stride_y * number of elements along Y processed per work item (in bytes)
56 * @param[in] mapy_offset_first_element_in_bytes Offset of the first element in the remapping image
57 * @param[in] width Width of the input image
58 * @param[in] height Height of the input image
59 */
60__kernel void remap_nearest_neighbour_nchw(
61 IMAGE_DECLARATION(in),
62 IMAGE_DECLARATION(out),
63 IMAGE_DECLARATION(mapx),
64 IMAGE_DECLARATION(mapy),
65 const float width,
66 const float height)
67{
68 Image in = CONVERT_TO_IMAGE_STRUCT_NO_STEP(in);
69 Image out = CONVERT_TO_IMAGE_STRUCT(out);
70 Image mapx = CONVERT_TO_IMAGE_STRUCT(mapx);
71 Image mapy = CONVERT_TO_IMAGE_STRUCT(mapy);
72
73 float4 mapx_coords = vload4(0, (__global float *)mapx.ptr);
74 float4 mapy_coords = vload4(0, (__global float *)mapy.ptr);
75 float8 map_coords = (float8)(mapx_coords.s0, mapy_coords.s0, mapx_coords.s1, mapy_coords.s1,
76 mapx_coords.s2, mapy_coords.s2, mapx_coords.s3, mapy_coords.s3);
77
78 vstore4(read_texels4(&in, convert_int8(clamp_to_border(map_coords, width, height))), 0, out.ptr);
79}
80
81/** Performs a remapping of an input image to an output given two remapping image using bilinear as interpolation.
82 *
83 * This kernel performs remapping with this method of pixel coordinate translation:
84 * out(x,y) = in(mapx(x,y), mapy(x,y));
85 *
86 * @param[in] in_ptr Pointer to the source image. Supported data types: U8.
87 * @param[in] in_stride_x Stride of the source image in X dimension (in bytes)
88 * @param[in] in_step_x in_stride_x * number of elements along X processed per work item (in bytes)
89 * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes)
90 * @param[in] in_step_y in_stride_y * number of elements along Y processed per work item (in bytes)
91 * @param[in] in_offset_first_element_in_bytes Offset of the first element in the source image
92 * @param[out] out_ptr Pointer to the destination image. Supported data types: U8.
93 * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes)
94 * @param[in] out_step_x out_stride_x * number of elements along X processed per work item (in bytes)
95 * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes)
96 * @param[in] out_step_y out_stride_y * number of elements along Y processed per work item (in bytes)
97 * @param[in] out_offset_first_element_in_bytes Offset of the first element in the destination image
98 * @param[in] mapx_ptr Pointer to the x remapping image. Supported data types: F32.
99 * @param[in] mapx_stride_x Stride of the remapping image in X dimension (in bytes)
100 * @param[in] mapx_step_x mapx_stride_x * number of elements along X processed per work item (in bytes)
101 * @param[in] mapx_stride_y Stride of the remapping image in Y dimension (in bytes)
102 * @param[in] mapx_step_y mapy_stride_y * number of elements along Y processed per work item (in bytes)
103 * @param[in] mapx_offset_first_element_in_bytes Offset of the first element in the remapping image
104 * @param[in] mapy_ptr Pointer to the x remapping image. Supported data types: F32.
105 * @param[in] mapy_stride_x Stride of the remapping image in X dimension (in bytes)
106 * @param[in] mapy_step_x mapy_stride_x * number of elements along X processed per work item (in bytes)
107 * @param[in] mapy_stride_y Stride of the remapping image in Y dimension (in bytes)
108 * @param[in] mapy_step_y mapy_stride_y * number of elements along Y processed per work item (in bytes)
109 * @param[in] mapy_offset_first_element_in_bytes Offset of the first element in the remapping image
110 * @param[in] width Width of the input image
111 * @param[in] height Height of the input image
112 */
113__kernel void remap_bilinear_nchw(
114 IMAGE_DECLARATION(in),
115 IMAGE_DECLARATION(out),
116 IMAGE_DECLARATION(mapx),
117 IMAGE_DECLARATION(mapy),
118 const float width,
119 const float height)
120{
121 Image in = CONVERT_TO_IMAGE_STRUCT_NO_STEP(in);
122 Image out = CONVERT_TO_IMAGE_STRUCT(out);
123 Image mapx = CONVERT_TO_IMAGE_STRUCT(mapx);
124 Image mapy = CONVERT_TO_IMAGE_STRUCT(mapy);
125
126 float4 mapx_coords = vload4(0, (__global float *)mapx.ptr);
127 float4 mapy_coords = vload4(0, (__global float *)mapy.ptr);
128 float8 map_coords = (float8)(mapx_coords.s0, mapy_coords.s0, mapx_coords.s1, mapy_coords.s1,
129 mapx_coords.s2, mapy_coords.s2, mapx_coords.s3, mapy_coords.s3);
130
131 vstore4(bilinear_interpolate(&in, clamp_to_border(map_coords, width, height), width, height), 0, out.ptr);
132}
133#endif // DEPTH_OUT