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 | #include "helpers.h" |
| 25 | |
| 26 | /** This function extracts a given channel from an RGB image. |
| 27 | * |
| 28 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_B will extract the B channel. |
| 29 | * |
| 30 | * @param[in] src_ptr Pointer to the source image. Supported Format: RGB |
| 31 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 32 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 33 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 34 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 35 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 36 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 37 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 38 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 39 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 40 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 41 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 42 | */ |
| 43 | __kernel void channel_extract_RGB888( |
| 44 | IMAGE_DECLARATION(src), |
| 45 | IMAGE_DECLARATION(dst)) |
| 46 | { |
| 47 | // Get pixels pointer |
| 48 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 49 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 50 | |
| 51 | uchar16 data = vload16(0, src.ptr); |
| 52 | uchar8 data2 = vload8(0, src.ptr + 16); |
| 53 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 54 | #ifdef CHANNEL_R |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | vstore4(data.s0369, 0, dst.ptr); |
| 56 | vstore4((uchar4)(data.sCF, data2.s25), 0, dst.ptr + 4); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 57 | #elif defined(CHANNEL_G) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | vstore4(data.s147A, 0, dst.ptr); |
| 59 | vstore4((uchar4)(data.sD, data2.s036), 0, dst.ptr + 4); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 60 | #elif defined(CHANNEL_B) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | vstore4(data.s258B, 0, dst.ptr); |
| 62 | vstore4((uchar4)(data.sE, data2.s147), 0, dst.ptr + 4); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 63 | #endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** This function extracts a given channel from an RGBA image. |
| 67 | * |
| 68 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_B will extract the B channel. |
| 69 | * |
| 70 | * @param[in] src_ptr Pointer to the source image. Supported Format: RGBA |
| 71 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 72 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 73 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 74 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 75 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 76 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 77 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 78 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 79 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 80 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 81 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 82 | */ |
| 83 | __kernel void channel_extract_RGBA8888( |
| 84 | IMAGE_DECLARATION(src), |
| 85 | IMAGE_DECLARATION(dst)) |
| 86 | { |
| 87 | // Get pixels pointer |
| 88 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 89 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 90 | |
| 91 | uchar16 data = vload16(0, src.ptr); |
| 92 | uchar16 data2 = vload16(0, src.ptr + 16); |
| 93 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 94 | #ifdef CHANNEL_R |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 95 | vstore8((uchar8)(data.s048C, data2.s048C), 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 96 | #elif defined(CHANNEL_G) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | vstore8((uchar8)(data.s159D, data2.s159D), 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 98 | #elif defined(CHANNEL_B) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 99 | vstore8((uchar8)(data.s26AE, data2.s26AE), 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 100 | #elif defined(CHANNEL_A) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | vstore8((uchar8)(data.s37BF, data2.s37BF), 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 102 | #endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B or CHANNEL_A */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** This function extracts a given channel from an YUYV image. |
| 106 | * |
| 107 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel. |
| 108 | * |
| 109 | * @param[in] src_ptr Pointer to the source image. Supported Format: YUYV |
| 110 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 111 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 112 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 113 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 114 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 115 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 116 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 117 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 118 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 119 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 120 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 121 | */ |
| 122 | __kernel void channel_extract_YUYV422( |
| 123 | IMAGE_DECLARATION(src), |
| 124 | IMAGE_DECLARATION(dst)) |
| 125 | { |
| 126 | // Get pixels pointer |
| 127 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 128 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 129 | |
| 130 | uchar16 data = vload16(0, src.ptr); |
| 131 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 132 | #ifdef CHANNEL_Y |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 133 | vstore8(data.s02468ACE, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 134 | #elif defined(CHANNEL_U) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 135 | vstore4(data.s159D, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 136 | #elif defined(CHANNEL_V) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 137 | vstore4(data.s37BF, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 138 | #endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** This function extracts a given channel from an UYUV image. |
| 142 | * |
| 143 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel. |
| 144 | * |
| 145 | * @param[in] src_ptr Pointer to the source image. Supported Format: UYUV |
| 146 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 147 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 148 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 149 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 150 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 151 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 152 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 153 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 154 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 155 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 156 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 157 | */ |
| 158 | __kernel void channel_extract_UYVY422( |
| 159 | IMAGE_DECLARATION(src), |
| 160 | IMAGE_DECLARATION(dst)) |
| 161 | { |
| 162 | // Get pixels pointer |
| 163 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 164 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 165 | |
| 166 | uchar16 data = vload16(0, src.ptr); |
| 167 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 168 | #ifdef CHANNEL_Y |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 169 | vstore8(data.s13579BDF, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 170 | #elif defined(CHANNEL_U) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 171 | vstore4(data.s048C, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 172 | #elif defined(CHANNEL_V) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 173 | vstore4(data.s26AE, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 174 | #endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** This function extracts a given channel from an NV12 image. |
| 178 | * |
| 179 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel. |
| 180 | * @warning Only channels UV can be extracted using this kernel. |
| 181 | * |
| 182 | * @param[in] src_ptr Pointer to the source image. Supported Format: NV12 (UV88) |
| 183 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 184 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 185 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 186 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 187 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 188 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 189 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 190 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 191 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 192 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 193 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 194 | */ |
| 195 | __kernel void channel_extract_NV12( |
| 196 | IMAGE_DECLARATION(src), |
| 197 | IMAGE_DECLARATION(dst)) |
| 198 | { |
| 199 | // Get pixels pointer |
| 200 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 201 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 202 | |
| 203 | uchar16 data = vload16(0, src.ptr); |
| 204 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 205 | #ifdef CHANNEL_U |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | vstore8(data.s02468ACE, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 207 | #elif defined(CHANNEL_V) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 208 | vstore8(data.s13579BDF, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 209 | #endif /* CHANNEL_U or CHANNEL_V */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** This function extracts a given channel from an NV21 image. |
| 213 | * |
| 214 | * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel. |
| 215 | * @warning Only channels UV can be extracted using this kernel. |
| 216 | * |
| 217 | * @param[in] src_ptr Pointer to the source image. Supported Format: NV21 (UV88) |
| 218 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 219 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 220 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 221 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 222 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 223 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 224 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 225 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 226 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 227 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 228 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 229 | */ |
| 230 | __kernel void channel_extract_NV21( |
| 231 | IMAGE_DECLARATION(src), |
| 232 | IMAGE_DECLARATION(dst)) |
| 233 | { |
| 234 | // Get pixels pointer |
| 235 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 236 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 237 | |
| 238 | uchar16 data = vload16(0, src.ptr); |
| 239 | |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 240 | #ifdef CHANNEL_U |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 241 | vstore8(data.s13579BDF, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 242 | #elif defined(CHANNEL_V) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 243 | vstore8(data.s02468ACE, 0, dst.ptr); |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 244 | #endif /* CHANNEL_U or CHANNEL_V */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** This function extracts a given plane from an multi-planar image. |
| 248 | * |
| 249 | * @param[in] src_ptr Pointer to the source image. Supported Format: U8 |
| 250 | * @param[in] src_stride_x Stride of the source image in X dimension (in bytes) |
| 251 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 252 | * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes) |
| 253 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 254 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image |
| 255 | * @param[out] dst_ptr Pointer to the destination image. Supported Format: U8 |
| 256 | * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes) |
| 257 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 258 | * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes) |
| 259 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 260 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image |
| 261 | */ |
| 262 | __kernel void copy_plane( |
| 263 | IMAGE_DECLARATION(src), |
| 264 | IMAGE_DECLARATION(dst)) |
| 265 | { |
| 266 | // Get pixels pointer |
| 267 | Image src = CONVERT_TO_IMAGE_STRUCT(src); |
| 268 | Image dst = CONVERT_TO_IMAGE_STRUCT(dst); |
| 269 | |
| 270 | // Copy plane data |
| 271 | vstore16(vload16(0, src.ptr), 0, dst.ptr); |
| 272 | } |