Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016, 2017 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 | /** Perform binary thresholding on an image. |
| 27 | * |
| 28 | * @param[in] in_ptr Pointer to the source image |
| 29 | * @param[in] in_stride_x Stride of the source image in X dimension (in bytes) |
| 30 | * @param[in] in_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 31 | * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes) |
| 32 | * @param[in] in_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 33 | * @param[in] in_offset_first_element_in_bytes The offset of the first element in the first source image |
| 34 | * @param[out] out_ptr Pointer to the destination image |
| 35 | * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes) |
| 36 | * @param[in] out_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 37 | * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes) |
| 38 | * @param[in] out_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 39 | * @param[in] out_offset_first_element_in_bytes The offset of the first element in the destination image |
| 40 | * @param[in] false_val False value |
| 41 | * @param[in] true_val True value |
| 42 | * @param[in] threshold The thresold value |
| 43 | */ |
| 44 | __kernel void threshold_binary( |
| 45 | IMAGE_DECLARATION(in), |
| 46 | IMAGE_DECLARATION(out), |
| 47 | const uchar false_val, |
| 48 | const uchar true_val, |
| 49 | const uchar threshold) |
| 50 | { |
| 51 | // Get pixels pointer |
| 52 | Image in = CONVERT_TO_IMAGE_STRUCT(in); |
| 53 | Image out = CONVERT_TO_IMAGE_STRUCT(out); |
| 54 | |
| 55 | // Load data |
| 56 | uchar16 in_data = vload16(0, in.ptr); |
| 57 | |
| 58 | // Perform binary thresholding |
| 59 | in_data = select((uchar16)false_val, (uchar16)true_val, in_data > (uchar16)threshold); |
| 60 | |
| 61 | // Store result |
| 62 | vstore16(in_data, 0, out.ptr); |
| 63 | } |
| 64 | |
| 65 | /** Perform range thresholding on an image. |
| 66 | * |
| 67 | * @param[in] in_ptr Pointer to the source image |
| 68 | * @param[in] in_stride_x Stride of the source image in X dimension (in bytes) |
| 69 | * @param[in] in_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 70 | * @param[in] in_stride_y Stride of the source image in Y dimension (in bytes) |
| 71 | * @param[in] in_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 72 | * @param[in] in_offset_first_element_in_bytes The offset of the first element in the first source image |
| 73 | * @param[out] out_ptr Pointer to the destination image |
| 74 | * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes) |
| 75 | * @param[in] out_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 76 | * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes) |
| 77 | * @param[in] out_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 78 | * @param[in] out_offset_first_element_in_bytes The offset of the first element in the destination image |
| 79 | * @param[in] false_val False value |
| 80 | * @param[in] true_val True value |
| 81 | * @param[in] lower Lower threshold |
| 82 | * @param[in] upper Upper threshold |
| 83 | */ |
| 84 | __kernel void threshold_range( |
| 85 | IMAGE_DECLARATION(in), |
| 86 | IMAGE_DECLARATION(out), |
| 87 | const uchar false_val, |
| 88 | const uchar true_val, |
| 89 | const uchar lower, |
| 90 | const uchar upper) |
| 91 | { |
| 92 | // Get pixels pointer |
| 93 | Image in = CONVERT_TO_IMAGE_STRUCT(in); |
| 94 | Image out = CONVERT_TO_IMAGE_STRUCT(out); |
| 95 | |
| 96 | // Load data |
| 97 | uchar16 in_data = vload16(0, in.ptr); |
| 98 | |
| 99 | // Perform range thresholding |
| 100 | in_data = select((uchar16)true_val, (uchar16)false_val, in_data > (uchar16)upper || in_data < (uchar16)lower); |
| 101 | |
| 102 | // Store result |
| 103 | vstore16(in_data, 0, out.ptr); |
| 104 | } |