blob: e99e9ebb2538718473d2e20d5f752a92b07c0a3a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +01002 * Copyright (c) 2016-2018 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 */
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 Barbierac69aa12017-07-03 17:39:37 +010054#ifdef CHANNEL_R
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 vstore4(data.s0369, 0, dst.ptr);
56 vstore4((uchar4)(data.sCF, data2.s25), 0, dst.ptr + 4);
Anthony Barbierac69aa12017-07-03 17:39:37 +010057#elif defined(CHANNEL_G)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 vstore4(data.s147A, 0, dst.ptr);
59 vstore4((uchar4)(data.sD, data2.s036), 0, dst.ptr + 4);
Anthony Barbierac69aa12017-07-03 17:39:37 +010060#elif defined(CHANNEL_B)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 vstore4(data.s258B, 0, dst.ptr);
62 vstore4((uchar4)(data.sE, data2.s147), 0, dst.ptr + 4);
Anthony Barbierac69aa12017-07-03 17:39:37 +010063#endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064}
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 Barbierac69aa12017-07-03 17:39:37 +010094#ifdef CHANNEL_R
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095 vstore8((uchar8)(data.s048C, data2.s048C), 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +010096#elif defined(CHANNEL_G)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 vstore8((uchar8)(data.s159D, data2.s159D), 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +010098#elif defined(CHANNEL_B)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099 vstore8((uchar8)(data.s26AE, data2.s26AE), 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100100#elif defined(CHANNEL_A)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 vstore8((uchar8)(data.s37BF, data2.s37BF), 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100102#endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B or CHANNEL_A */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103}
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 Barbierac69aa12017-07-03 17:39:37 +0100132#ifdef CHANNEL_Y
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133 vstore8(data.s02468ACE, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100134#elif defined(CHANNEL_U)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135 vstore4(data.s159D, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100136#elif defined(CHANNEL_V)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137 vstore4(data.s37BF, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100138#endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139}
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 Barbierac69aa12017-07-03 17:39:37 +0100168#ifdef CHANNEL_Y
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169 vstore8(data.s13579BDF, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100170#elif defined(CHANNEL_U)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100171 vstore4(data.s048C, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100172#elif defined(CHANNEL_V)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100173 vstore4(data.s26AE, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100174#endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100175}
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 Barbierac69aa12017-07-03 17:39:37 +0100205#ifdef CHANNEL_U
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100206 vstore8(data.s02468ACE, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100207#elif defined(CHANNEL_V)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208 vstore8(data.s13579BDF, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100209#endif /* CHANNEL_U or CHANNEL_V */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100210}
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 Barbierac69aa12017-07-03 17:39:37 +0100240#ifdef CHANNEL_U
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100241 vstore8(data.s13579BDF, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100242#elif defined(CHANNEL_V)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100243 vstore8(data.s02468ACE, 0, dst.ptr);
Anthony Barbierac69aa12017-07-03 17:39:37 +0100244#endif /* CHANNEL_U or CHANNEL_V */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245}
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
Ioan-Cristian Szabo9414f642017-10-27 17:35:40 +0100271 vstore8(vload8(0, src.ptr), 0, dst.ptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100272}