Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 "helpers.h" |
| 25 | |
| 26 | #ifdef SATURATE |
| 27 | #define CONVERT_DOWN(x, type) CONVERT_SAT(x, type) |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 28 | #else /* SATURATE */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #define CONVERT_DOWN(x, type) CONVERT(x, type) |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 30 | #endif /* SATURATE */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 32 | #define CONVERT_UP(x, type) CONVERT(x, type) |
| 33 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | /** This function performs a down-scaling depth conversion. |
| 35 | * |
| 36 | * @attention The input and output data_types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: |
| 37 | * e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short |
| 38 | * |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 39 | * @param[in] in_ptr Pointer to the source image. Supported data types: U8, U16, S16, U32, S32, F16, F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | * @param[in] in_stride_x Stride of the source image in X dimension (in bytes) |
| 41 | * @param[in] in_step_x in_stride_x * number of elements along X processed per workitem(in bytes) |
| 42 | * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes) |
| 43 | * @param[in] in_step_y in_stride_y * number of elements along Y processed per workitem(in bytes) |
| 44 | * @param[in] in_offset_first_element_in_bytes The offset of the first element in the source image |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame^] | 45 | * @param[out] out_ptr Pointer to the destination image. Supported data types: U8, U16, S16, U32, S32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes) |
| 47 | * @param[in] out_step_x out_stride_x * number of elements along X processed per workitem(in bytes) |
| 48 | * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes) |
| 49 | * @param[in] out_step_y out_stride_y * number of elements along Y processed per workitem(in bytes) |
| 50 | * @param[in] out_offset_first_element_in_bytes The offset of the first element in the destination image |
| 51 | * @param[in] shift The integer shift amount value. Supported data types: S32 |
| 52 | */ |
| 53 | __kernel void convert_depth_down( |
| 54 | IMAGE_DECLARATION(in), |
| 55 | IMAGE_DECLARATION(out), |
| 56 | const int shift) |
| 57 | { |
| 58 | // Get pixels pointer |
| 59 | Image in = CONVERT_TO_IMAGE_STRUCT(in); |
| 60 | Image out = CONVERT_TO_IMAGE_STRUCT(out); |
| 61 | |
| 62 | // Load data |
| 63 | VEC_DATA_TYPE(DATA_TYPE_IN, 16) |
| 64 | in_data = vload16(0, (__global DATA_TYPE_IN *)in.ptr); |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 65 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | vstore16(CONVERT_DOWN(in_data >> shift, VEC_DATA_TYPE(DATA_TYPE_OUT, 16)), 0, (__global DATA_TYPE_OUT *)out.ptr); |
| 67 | } |
| 68 | |
| 69 | /** This function performs a up-scaling depth conversion. |
| 70 | * |
| 71 | * @attention The input and output data_types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: |
| 72 | * e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short |
| 73 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame^] | 74 | * @param[in] in_ptr Pointer to the source image. Supported data types: U8, U16, S16, U32 or S32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | * @param[in] in_stride_x Stride of the source image in X dimension (in bytes) |
| 76 | * @param[in] in_step_x in_stride_x * number of elements along X processed per workitem(in bytes) |
| 77 | * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes) |
| 78 | * @param[in] in_step_y in_stride_y * number of elements along Y processed per workitem(in bytes) |
| 79 | * @param[in] in_offset_first_element_in_bytes The offset of the first element in the source image |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 80 | * @param[out] out_ptr Pointer to the destination image. Supported data types: U8, U16, S16, U32, S32, F16 or F32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes) |
| 82 | * @param[in] out_step_x out_stride_x * number of elements along X processed per workitem(in bytes) |
| 83 | * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes) |
| 84 | * @param[in] out_step_y out_stride_y * number of elements along Y processed per workitem(in bytes) |
| 85 | * @param[in] out_offset_first_element_in_bytes The offset of the first element in the destination image |
| 86 | * @param[in] shift The integer shift amount value. Supported data types: S32 |
| 87 | */ |
| 88 | __kernel void convert_depth_up( |
| 89 | IMAGE_DECLARATION(in), |
| 90 | IMAGE_DECLARATION(out), |
| 91 | const int shift) |
| 92 | { |
| 93 | // Get pixels pointer |
| 94 | Image in = CONVERT_TO_IMAGE_STRUCT(in); |
| 95 | Image out = CONVERT_TO_IMAGE_STRUCT(out); |
| 96 | |
| 97 | // Load data |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 98 | VEC_DATA_TYPE(DATA_TYPE_IN, 16) |
| 99 | in_data = vload16(0, (__global DATA_TYPE_IN *)in.ptr); |
| 100 | |
steniu01 | da37e2f | 2017-06-29 10:14:58 +0100 | [diff] [blame] | 101 | vstore16(CONVERT_UP(in_data, VEC_DATA_TYPE(DATA_TYPE_OUT, 16)) << shift, 0, (__global DATA_TYPE_OUT *)out.ptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | } |