2 * Copyright (c) 2016-2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
26 /** This function extracts a given channel from an RGB image.
28 * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_B will extract the B channel.
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
43 __kernel void channel_extract_RGB888(
44 IMAGE_DECLARATION(src),
45 IMAGE_DECLARATION(dst))
48 Image src = CONVERT_TO_IMAGE_STRUCT(src);
49 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
51 uchar16 data = vload16(0, src.ptr);
52 uchar8 data2 = vload8(0, src.ptr + 16);
55 vstore4(data.s0369, 0, dst.ptr);
56 vstore4((uchar4)(data.sCF, data2.s25), 0, dst.ptr + 4);
57 #elif defined(CHANNEL_G)
58 vstore4(data.s147A, 0, dst.ptr);
59 vstore4((uchar4)(data.sD, data2.s036), 0, dst.ptr + 4);
60 #elif defined(CHANNEL_B)
61 vstore4(data.s258B, 0, dst.ptr);
62 vstore4((uchar4)(data.sE, data2.s147), 0, dst.ptr + 4);
63 #endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B */
66 /** This function extracts a given channel from an RGBA image.
68 * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_B will extract the B channel.
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
83 __kernel void channel_extract_RGBA8888(
84 IMAGE_DECLARATION(src),
85 IMAGE_DECLARATION(dst))
88 Image src = CONVERT_TO_IMAGE_STRUCT(src);
89 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
91 uchar16 data = vload16(0, src.ptr);
92 uchar16 data2 = vload16(0, src.ptr + 16);
95 vstore8((uchar8)(data.s048C, data2.s048C), 0, dst.ptr);
96 #elif defined(CHANNEL_G)
97 vstore8((uchar8)(data.s159D, data2.s159D), 0, dst.ptr);
98 #elif defined(CHANNEL_B)
99 vstore8((uchar8)(data.s26AE, data2.s26AE), 0, dst.ptr);
100 #elif defined(CHANNEL_A)
101 vstore8((uchar8)(data.s37BF, data2.s37BF), 0, dst.ptr);
102 #endif /* CHANNEL_R or CHANNEL_G or CHANNEL_B or CHANNEL_A */
105 /** This function extracts a given channel from an YUYV image.
107 * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel.
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
122 __kernel void channel_extract_YUYV422(
123 IMAGE_DECLARATION(src),
124 IMAGE_DECLARATION(dst))
126 // Get pixels pointer
127 Image src = CONVERT_TO_IMAGE_STRUCT(src);
128 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
130 uchar16 data = vload16(0, src.ptr);
133 vstore8(data.s02468ACE, 0, dst.ptr);
134 #elif defined(CHANNEL_U)
135 vstore4(data.s159D, 0, dst.ptr);
136 #elif defined(CHANNEL_V)
137 vstore4(data.s37BF, 0, dst.ptr);
138 #endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */
141 /** This function extracts a given channel from an UYUV image.
143 * @note Channel to be extracted should be passed as a pre-processor argument, e.g. -DCHANNEL_U will extract the U channel.
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
158 __kernel void channel_extract_UYVY422(
159 IMAGE_DECLARATION(src),
160 IMAGE_DECLARATION(dst))
162 // Get pixels pointer
163 Image src = CONVERT_TO_IMAGE_STRUCT(src);
164 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
166 uchar16 data = vload16(0, src.ptr);
169 vstore8(data.s13579BDF, 0, dst.ptr);
170 #elif defined(CHANNEL_U)
171 vstore4(data.s048C, 0, dst.ptr);
172 #elif defined(CHANNEL_V)
173 vstore4(data.s26AE, 0, dst.ptr);
174 #endif /* CHANNEL_Y or CHANNEL_U or CHANNEL_V */
177 /** This function extracts a given channel from an NV12 image.
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.
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
195 __kernel void channel_extract_NV12(
196 IMAGE_DECLARATION(src),
197 IMAGE_DECLARATION(dst))
199 // Get pixels pointer
200 Image src = CONVERT_TO_IMAGE_STRUCT(src);
201 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
203 uchar16 data = vload16(0, src.ptr);
206 vstore8(data.s02468ACE, 0, dst.ptr);
207 #elif defined(CHANNEL_V)
208 vstore8(data.s13579BDF, 0, dst.ptr);
209 #endif /* CHANNEL_U or CHANNEL_V */
212 /** This function extracts a given channel from an NV21 image.
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.
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
230 __kernel void channel_extract_NV21(
231 IMAGE_DECLARATION(src),
232 IMAGE_DECLARATION(dst))
234 // Get pixels pointer
235 Image src = CONVERT_TO_IMAGE_STRUCT(src);
236 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
238 uchar16 data = vload16(0, src.ptr);
241 vstore8(data.s13579BDF, 0, dst.ptr);
242 #elif defined(CHANNEL_V)
243 vstore8(data.s02468ACE, 0, dst.ptr);
244 #endif /* CHANNEL_U or CHANNEL_V */
247 /** This function extracts a given plane from an multi-planar image.
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
262 __kernel void copy_plane(
263 IMAGE_DECLARATION(src),
264 IMAGE_DECLARATION(dst))
266 // Get pixels pointer
267 Image src = CONVERT_TO_IMAGE_STRUCT(src);
268 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
271 vstore8(vload8(0, src.ptr), 0, dst.ptr);