input: add input_SetProgramId
[vlc.git] / modules / arm_neon / chroma_yuv.c
blobbf72154a76b31ecddf23e9b7bea531a0ee61481d
1 /*****************************************************************************
2 * chroma_yuv.c : ARM NEONv1 YUV 4:2:0 to YUV 4:2:2 chroma conversion for VLC
3 *****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_filter.h>
28 #include <vlc_picture.h>
29 #include <vlc_cpu.h>
30 #include "arm_neon/chroma_neon.h"
32 static int Open (filter_t *);
34 vlc_module_begin ()
35 set_description (N_("ARM NEON video chroma conversions"))
36 set_callback_video_converter(Open, 250)
37 vlc_module_end ()
39 #define DEFINE_PACK(pack, pict) \
40 struct yuv_pack pack = { (pict)->Y_PIXELS, (pict)->Y_PITCH }
41 #define DEFINE_PLANES(planes, pict) \
42 struct yuv_planes planes = { \
43 (pict)->Y_PIXELS, (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->Y_PITCH }
44 #define DEFINE_PLANES_SWAP(planes, pict) \
45 struct yuv_planes planes = { \
46 (pict)->Y_PIXELS, (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->Y_PITCH }
48 #define DEFINE_UV_PLANES(planes, pict) \
49 struct uv_planes planes = { \
50 (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->U_PITCH }
51 #define DEFINE_UV_PLANES_SWAP(planes, pict) \
52 struct uv_planes planes = { \
53 (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->U_PITCH }
54 #define DEFINE_UV_PACK(pack, pict) \
55 struct yuv_pack pack = { (pict)->U_PIXELS, (pict)->U_PITCH }
57 /* Planar YUV420 to packed YUV422 */
58 static void I420_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
60 DEFINE_PACK(out, dst);
61 DEFINE_PLANES(in, src);
62 i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
63 filter->fmt_in.video.i_height);
65 VIDEO_FILTER_WRAPPER (I420_YUYV)
67 static void I420_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
69 DEFINE_PACK(out, dst);
70 DEFINE_PLANES_SWAP(in, src);
71 i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
72 filter->fmt_in.video.i_height);
74 VIDEO_FILTER_WRAPPER (I420_YVYU)
76 static void I420_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
78 DEFINE_PACK(out, dst);
79 DEFINE_PLANES(in, src);
80 i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
81 filter->fmt_in.video.i_height);
83 VIDEO_FILTER_WRAPPER (I420_UYVY)
85 static void I420_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
87 DEFINE_PACK(out, dst);
88 DEFINE_PLANES_SWAP(in, src);
89 i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
90 filter->fmt_in.video.i_height);
92 VIDEO_FILTER_WRAPPER (I420_VYUY)
95 /* Semiplanar NV12/21/16/24 to planar I420/YV12/I422/I444 */
96 static void copy_y_plane(filter_t *filter, picture_t *src, picture_t *dst)
98 uint8_t *src_y = src->Y_PIXELS;
99 uint8_t *dst_y = dst->Y_PIXELS;
100 if (src->Y_PITCH == dst->Y_PITCH) {
101 memcpy(dst_y, src_y, dst->Y_PITCH * filter->fmt_in.video.i_height);
102 } else {
103 for (unsigned y = 0; y < filter->fmt_in.video.i_height;
104 y++, dst_y += dst->Y_PITCH, src_y += src->Y_PITCH)
105 memcpy(dst_y, src_y, filter->fmt_in.video.i_width);
109 #define SEMIPLANAR_FILTERS(name, h_subsamp, v_subsamp) \
110 static void name (filter_t *filter, picture_t *src, \
111 picture_t *dst) \
113 DEFINE_UV_PLANES(out, dst); \
114 DEFINE_UV_PACK(in, src); \
115 copy_y_plane (filter, src, dst); \
116 deinterleave_chroma_neon (&out, &in, \
117 filter->fmt_in.video.i_width / h_subsamp, \
118 filter->fmt_in.video.i_height / v_subsamp); \
120 VIDEO_FILTER_WRAPPER (name) \
122 #define SEMIPLANAR_FILTERS_SWAP(name, h_subsamp, v_subsamp) \
123 static void name (filter_t *filter, picture_t *src, \
124 picture_t *dst) \
126 DEFINE_UV_PLANES_SWAP(out, dst); \
127 DEFINE_UV_PACK(in, src); \
128 copy_y_plane (filter, src, dst); \
129 deinterleave_chroma_neon (&out, &in, \
130 filter->fmt_in.video.i_width / h_subsamp, \
131 filter->fmt_in.video.i_height / v_subsamp); \
133 VIDEO_FILTER_WRAPPER (name) \
135 SEMIPLANAR_FILTERS (Semiplanar_Planar_420, 2, 2)
136 SEMIPLANAR_FILTERS_SWAP (Semiplanar_Planar_420_Swap, 2, 2)
137 SEMIPLANAR_FILTERS (Semiplanar_Planar_422, 2, 1)
138 SEMIPLANAR_FILTERS (Semiplanar_Planar_444, 1, 1)
141 /* Planar YUV422 to packed YUV422 */
142 static void I422_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
144 DEFINE_PACK(out, dst);
145 DEFINE_PLANES(in, src);
146 i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
147 filter->fmt_in.video.i_height);
149 VIDEO_FILTER_WRAPPER (I422_YUYV)
151 static void I422_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
153 DEFINE_PACK(out, dst);
154 DEFINE_PLANES_SWAP(in, src);
155 i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
156 filter->fmt_in.video.i_height);
158 VIDEO_FILTER_WRAPPER (I422_YVYU)
160 static void I422_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
162 DEFINE_PACK(out, dst);
163 DEFINE_PLANES(in, src);
164 i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
165 filter->fmt_in.video.i_height);
167 VIDEO_FILTER_WRAPPER (I422_UYVY)
169 static void I422_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
171 DEFINE_PACK(out, dst);
172 DEFINE_PLANES_SWAP(in, src);
173 i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
174 filter->fmt_in.video.i_height);
176 VIDEO_FILTER_WRAPPER (I422_VYUY)
179 /* Packed YUV422 to planar YUV422 */
180 static void YUYV_I422 (filter_t *filter, picture_t *src, picture_t *dst)
182 DEFINE_PLANES(out, dst);
183 DEFINE_PACK(in, src);
184 yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
185 filter->fmt_in.video.i_height);
187 VIDEO_FILTER_WRAPPER (YUYV_I422)
189 static void YVYU_I422 (filter_t *filter, picture_t *src, picture_t *dst)
191 DEFINE_PLANES_SWAP(out, dst);
192 DEFINE_PACK(in, src);
193 yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
194 filter->fmt_in.video.i_height);
196 VIDEO_FILTER_WRAPPER (YVYU_I422)
198 static void UYVY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
200 DEFINE_PLANES(out, dst);
201 DEFINE_PACK(in, src);
202 uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
203 filter->fmt_in.video.i_height);
205 VIDEO_FILTER_WRAPPER (UYVY_I422)
207 static void VYUY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
209 DEFINE_PLANES_SWAP(out, dst);
210 DEFINE_PACK(in, src);
211 uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
212 filter->fmt_in.video.i_height);
214 VIDEO_FILTER_WRAPPER (VYUY_I422)
216 static int Open (filter_t *filter)
218 if (!vlc_CPU_ARM_NEON())
219 return VLC_EGENERIC;
220 if ((filter->fmt_in.video.i_width != filter->fmt_out.video.i_width)
221 || (filter->fmt_in.video.i_height != filter->fmt_out.video.i_height))
222 return VLC_EGENERIC;
224 switch (filter->fmt_in.video.i_chroma)
226 /* Planar to packed */
227 case VLC_CODEC_I420:
228 switch (filter->fmt_out.video.i_chroma)
230 case VLC_CODEC_YUYV:
231 filter->ops = &I420_YUYV_ops;
232 break;
233 case VLC_CODEC_UYVY:
234 filter->ops = &I420_UYVY_ops;
235 break;
236 case VLC_CODEC_YVYU:
237 filter->ops = &I420_YVYU_ops;
238 break;
239 case VLC_CODEC_VYUY:
240 filter->ops = &I420_VYUY_ops;
241 break;
242 default:
243 return VLC_EGENERIC;
245 break;
247 case VLC_CODEC_YV12:
248 switch (filter->fmt_out.video.i_chroma)
250 case VLC_CODEC_YUYV:
251 filter->ops = &I420_YVYU_ops;
252 break;
253 case VLC_CODEC_UYVY:
254 filter->ops = &I420_VYUY_ops;
255 break;
256 case VLC_CODEC_YVYU:
257 filter->ops = &I420_YUYV_ops;
258 break;
259 case VLC_CODEC_VYUY:
260 filter->ops = &I420_UYVY_ops;
261 break;
262 default:
263 return VLC_EGENERIC;
265 break;
267 case VLC_CODEC_I422:
268 switch (filter->fmt_out.video.i_chroma)
270 case VLC_CODEC_YUYV:
271 filter->ops = &I422_YUYV_ops;
272 break;
273 case VLC_CODEC_UYVY:
274 filter->ops = &I422_UYVY_ops;
275 break;
276 case VLC_CODEC_YVYU:
277 filter->ops = &I422_YVYU_ops;
278 break;
279 case VLC_CODEC_VYUY:
280 filter->ops = &I422_VYUY_ops;
281 break;
282 default:
283 return VLC_EGENERIC;
285 break;
287 /* Semiplanar to planar */
288 case VLC_CODEC_NV12:
289 switch (filter->fmt_out.video.i_chroma)
291 case VLC_CODEC_I420:
292 filter->ops = &Semiplanar_Planar_420_ops;
293 break;
294 case VLC_CODEC_YV12:
295 filter->ops = &Semiplanar_Planar_420_Swap_ops;
296 break;
297 default:
298 return VLC_EGENERIC;
300 break;
302 case VLC_CODEC_NV21:
303 switch (filter->fmt_out.video.i_chroma)
305 case VLC_CODEC_I420:
306 filter->ops = &Semiplanar_Planar_420_Swap_ops;
307 break;
308 case VLC_CODEC_YV12:
309 filter->ops = &Semiplanar_Planar_420_ops;
310 break;
311 default:
312 return VLC_EGENERIC;
314 break;
316 case VLC_CODEC_NV16:
317 switch (filter->fmt_out.video.i_chroma)
319 case VLC_CODEC_I422:
320 filter->ops = &Semiplanar_Planar_422_ops;
321 break;
322 default:
323 return VLC_EGENERIC;
325 break;
327 case VLC_CODEC_NV24:
328 switch (filter->fmt_out.video.i_chroma)
330 case VLC_CODEC_I444:
331 filter->ops = &Semiplanar_Planar_444_ops;
332 break;
333 default:
334 return VLC_EGENERIC;
336 break;
338 /* Packed to planar */
339 case VLC_CODEC_YUYV:
340 switch (filter->fmt_out.video.i_chroma)
342 case VLC_CODEC_I422:
343 filter->ops = &YUYV_I422_ops;
344 break;
345 default:
346 return VLC_EGENERIC;
349 case VLC_CODEC_UYVY:
350 switch (filter->fmt_out.video.i_chroma)
352 case VLC_CODEC_I422:
353 filter->ops = &UYVY_I422_ops;
354 break;
355 default:
356 return VLC_EGENERIC;
359 case VLC_CODEC_YVYU:
360 switch (filter->fmt_out.video.i_chroma)
362 case VLC_CODEC_I422:
363 filter->ops = &YVYU_I422_ops;
364 break;
365 default:
366 return VLC_EGENERIC;
370 case VLC_CODEC_VYUY:
371 switch (filter->fmt_out.video.i_chroma)
373 case VLC_CODEC_I422:
374 filter->ops = &VYUY_I422_ops;
375 break;
376 default:
377 return VLC_EGENERIC;
380 default:
381 return VLC_EGENERIC;
383 return VLC_SUCCESS;