display: store the actually requested zoom
[vlc.git] / modules / arm_neon / chroma_yuv.c
blobf790770a04e2a15ff47af7775f2927c42a8a8535
1 /*****************************************************************************
2 * chroma_yuv.c : ARM NEONv1 YUV 4:2:0 to YUV :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 (vlc_object_t *);
34 vlc_module_begin ()
35 set_description (N_("ARM NEON video chroma conversions"))
36 set_capability ("video converter", 250)
37 set_callbacks (Open, NULL)
38 vlc_module_end ()
40 #define DEFINE_PACK(pack, pict) \
41 struct yuv_pack pack = { (pict)->Y_PIXELS, (pict)->Y_PITCH }
42 #define DEFINE_PLANES(planes, pict) \
43 struct yuv_planes planes = { \
44 (pict)->Y_PIXELS, (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->Y_PITCH }
45 #define DEFINE_PLANES_SWAP(planes, pict) \
46 struct yuv_planes planes = { \
47 (pict)->Y_PIXELS, (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->Y_PITCH }
49 #define DEFINE_UV_PLANES(planes, pict) \
50 struct uv_planes planes = { \
51 (pict)->U_PIXELS, (pict)->V_PIXELS, (pict)->U_PITCH }
52 #define DEFINE_UV_PLANES_SWAP(planes, pict) \
53 struct uv_planes planes = { \
54 (pict)->V_PIXELS, (pict)->U_PIXELS, (pict)->U_PITCH }
55 #define DEFINE_UV_PACK(pack, pict) \
56 struct yuv_pack pack = { (pict)->U_PIXELS, (pict)->U_PITCH }
58 /* Planar YUV420 to packed YUV422 */
59 static void I420_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
61 DEFINE_PACK(out, dst);
62 DEFINE_PLANES(in, src);
63 i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
64 filter->fmt_in.video.i_height);
66 VIDEO_FILTER_WRAPPER (I420_YUYV)
68 static void I420_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
70 DEFINE_PACK(out, dst);
71 DEFINE_PLANES_SWAP(in, src);
72 i420_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
73 filter->fmt_in.video.i_height);
75 VIDEO_FILTER_WRAPPER (I420_YVYU)
77 static void I420_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
79 DEFINE_PACK(out, dst);
80 DEFINE_PLANES(in, src);
81 i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
82 filter->fmt_in.video.i_height);
84 VIDEO_FILTER_WRAPPER (I420_UYVY)
86 static void I420_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
88 DEFINE_PACK(out, dst);
89 DEFINE_PLANES_SWAP(in, src);
90 i420_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
91 filter->fmt_in.video.i_height);
93 VIDEO_FILTER_WRAPPER (I420_VYUY)
96 /* Semiplanar NV12/21/16/24 to planar I420/YV12/I422/I444 */
97 static void copy_y_plane(filter_t *filter, picture_t *src, picture_t *dst)
99 uint8_t *src_y = src->Y_PIXELS;
100 uint8_t *dst_y = dst->Y_PIXELS;
101 if (src->Y_PITCH == dst->Y_PITCH) {
102 memcpy(dst_y, src_y, dst->Y_PITCH * filter->fmt_in.video.i_height);
103 } else {
104 for (unsigned y = 0; y < filter->fmt_in.video.i_height;
105 y++, dst_y += dst->Y_PITCH, src_y += src->Y_PITCH)
106 memcpy(dst_y, src_y, filter->fmt_in.video.i_width);
110 #define SEMIPLANAR_FILTERS(name, h_subsamp, v_subsamp) \
111 static void name (filter_t *filter, picture_t *src, \
112 picture_t *dst) \
114 DEFINE_UV_PLANES(out, dst); \
115 DEFINE_UV_PACK(in, src); \
116 copy_y_plane (filter, src, dst); \
117 deinterleave_chroma_neon (&out, &in, \
118 filter->fmt_in.video.i_width / h_subsamp, \
119 filter->fmt_in.video.i_height / v_subsamp); \
121 VIDEO_FILTER_WRAPPER (name) \
123 #define SEMIPLANAR_FILTERS_SWAP(name, h_subsamp, v_subsamp) \
124 static void name (filter_t *filter, picture_t *src, \
125 picture_t *dst) \
127 DEFINE_UV_PLANES_SWAP(out, dst); \
128 DEFINE_UV_PACK(in, src); \
129 copy_y_plane (filter, src, dst); \
130 deinterleave_chroma_neon (&out, &in, \
131 filter->fmt_in.video.i_width / h_subsamp, \
132 filter->fmt_in.video.i_height / v_subsamp); \
134 VIDEO_FILTER_WRAPPER (name) \
136 SEMIPLANAR_FILTERS (Semiplanar_Planar_420, 2, 2)
137 SEMIPLANAR_FILTERS_SWAP (Semiplanar_Planar_420_Swap, 2, 2)
138 SEMIPLANAR_FILTERS (Semiplanar_Planar_422, 2, 1)
139 SEMIPLANAR_FILTERS (Semiplanar_Planar_444, 1, 1)
142 /* Planar YUV422 to packed YUV422 */
143 static void I422_YUYV (filter_t *filter, picture_t *src, picture_t *dst)
145 DEFINE_PACK(out, dst);
146 DEFINE_PLANES(in, src);
147 i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
148 filter->fmt_in.video.i_height);
150 VIDEO_FILTER_WRAPPER (I422_YUYV)
152 static void I422_YVYU (filter_t *filter, picture_t *src, picture_t *dst)
154 DEFINE_PACK(out, dst);
155 DEFINE_PLANES_SWAP(in, src);
156 i422_yuyv_neon (&out, &in, filter->fmt_in.video.i_width,
157 filter->fmt_in.video.i_height);
159 VIDEO_FILTER_WRAPPER (I422_YVYU)
161 static void I422_UYVY (filter_t *filter, picture_t *src, picture_t *dst)
163 DEFINE_PACK(out, dst);
164 DEFINE_PLANES(in, src);
165 i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
166 filter->fmt_in.video.i_height);
168 VIDEO_FILTER_WRAPPER (I422_UYVY)
170 static void I422_VYUY (filter_t *filter, picture_t *src, picture_t *dst)
172 DEFINE_PACK(out, dst);
173 DEFINE_PLANES_SWAP(in, src);
174 i422_uyvy_neon (&out, &in, filter->fmt_in.video.i_width,
175 filter->fmt_in.video.i_height);
177 VIDEO_FILTER_WRAPPER (I422_VYUY)
180 /* Packed YUV422 to planar YUV422 */
181 static void YUYV_I422 (filter_t *filter, picture_t *src, picture_t *dst)
183 DEFINE_PLANES(out, dst);
184 DEFINE_PACK(in, src);
185 yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
186 filter->fmt_in.video.i_height);
188 VIDEO_FILTER_WRAPPER (YUYV_I422)
190 static void YVYU_I422 (filter_t *filter, picture_t *src, picture_t *dst)
192 DEFINE_PLANES_SWAP(out, dst);
193 DEFINE_PACK(in, src);
194 yuyv_i422_neon (&out, &in, filter->fmt_in.video.i_width,
195 filter->fmt_in.video.i_height);
197 VIDEO_FILTER_WRAPPER (YVYU_I422)
199 static void UYVY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
201 DEFINE_PLANES(out, dst);
202 DEFINE_PACK(in, src);
203 uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
204 filter->fmt_in.video.i_height);
206 VIDEO_FILTER_WRAPPER (UYVY_I422)
208 static void VYUY_I422 (filter_t *filter, picture_t *src, picture_t *dst)
210 DEFINE_PLANES_SWAP(out, dst);
211 DEFINE_PACK(in, src);
212 uyvy_i422_neon (&out, &in, filter->fmt_in.video.i_width,
213 filter->fmt_in.video.i_height);
215 VIDEO_FILTER_WRAPPER (VYUY_I422)
217 static int Open (vlc_object_t *obj)
219 filter_t *filter = (filter_t *)obj;
221 if (!vlc_CPU_ARM_NEON())
222 return VLC_EGENERIC;
223 if ((filter->fmt_in.video.i_width != filter->fmt_out.video.i_width)
224 || (filter->fmt_in.video.i_height != filter->fmt_out.video.i_height))
225 return VLC_EGENERIC;
227 switch (filter->fmt_in.video.i_chroma)
229 /* Planar to packed */
230 case VLC_CODEC_I420:
231 switch (filter->fmt_out.video.i_chroma)
233 case VLC_CODEC_YUYV:
234 filter->pf_video_filter = I420_YUYV_Filter;
235 break;
236 case VLC_CODEC_UYVY:
237 filter->pf_video_filter = I420_UYVY_Filter;
238 break;
239 case VLC_CODEC_YVYU:
240 filter->pf_video_filter = I420_YVYU_Filter;
241 break;
242 case VLC_CODEC_VYUY:
243 filter->pf_video_filter = I420_VYUY_Filter;
244 break;
245 default:
246 return VLC_EGENERIC;
248 break;
250 case VLC_CODEC_YV12:
251 switch (filter->fmt_out.video.i_chroma)
253 case VLC_CODEC_YUYV:
254 filter->pf_video_filter = I420_YVYU_Filter;
255 break;
256 case VLC_CODEC_UYVY:
257 filter->pf_video_filter = I420_VYUY_Filter;
258 break;
259 case VLC_CODEC_YVYU:
260 filter->pf_video_filter = I420_YUYV_Filter;
261 break;
262 case VLC_CODEC_VYUY:
263 filter->pf_video_filter = I420_UYVY_Filter;
264 break;
265 default:
266 return VLC_EGENERIC;
268 break;
270 case VLC_CODEC_I422:
271 switch (filter->fmt_out.video.i_chroma)
273 case VLC_CODEC_YUYV:
274 filter->pf_video_filter = I422_YUYV_Filter;
275 break;
276 case VLC_CODEC_UYVY:
277 filter->pf_video_filter = I422_UYVY_Filter;
278 break;
279 case VLC_CODEC_YVYU:
280 filter->pf_video_filter = I422_YVYU_Filter;
281 break;
282 case VLC_CODEC_VYUY:
283 filter->pf_video_filter = I422_VYUY_Filter;
284 break;
285 default:
286 return VLC_EGENERIC;
288 break;
290 /* Semiplanar to planar */
291 case VLC_CODEC_NV12:
292 switch (filter->fmt_out.video.i_chroma)
294 case VLC_CODEC_I420:
295 filter->pf_video_filter = Semiplanar_Planar_420_Filter;
296 break;
297 case VLC_CODEC_YV12:
298 filter->pf_video_filter = Semiplanar_Planar_420_Swap_Filter;
299 break;
300 default:
301 return VLC_EGENERIC;
303 break;
305 case VLC_CODEC_NV21:
306 switch (filter->fmt_out.video.i_chroma)
308 case VLC_CODEC_I420:
309 filter->pf_video_filter = Semiplanar_Planar_420_Swap_Filter;
310 break;
311 case VLC_CODEC_YV12:
312 filter->pf_video_filter = Semiplanar_Planar_420_Filter;
313 break;
314 default:
315 return VLC_EGENERIC;
317 break;
319 case VLC_CODEC_NV16:
320 switch (filter->fmt_out.video.i_chroma)
322 case VLC_CODEC_I422:
323 filter->pf_video_filter = Semiplanar_Planar_422_Filter;
324 break;
325 default:
326 return VLC_EGENERIC;
328 break;
330 case VLC_CODEC_NV24:
331 switch (filter->fmt_out.video.i_chroma)
333 case VLC_CODEC_I444:
334 filter->pf_video_filter = Semiplanar_Planar_444_Filter;
335 break;
336 default:
337 return VLC_EGENERIC;
339 break;
341 /* Packed to planar */
342 case VLC_CODEC_YUYV:
343 switch (filter->fmt_out.video.i_chroma)
345 case VLC_CODEC_I422:
346 filter->pf_video_filter = YUYV_I422_Filter;
347 break;
348 default:
349 return VLC_EGENERIC;
352 case VLC_CODEC_UYVY:
353 switch (filter->fmt_out.video.i_chroma)
355 case VLC_CODEC_I422:
356 filter->pf_video_filter = UYVY_I422_Filter;
357 break;
358 default:
359 return VLC_EGENERIC;
362 case VLC_CODEC_YVYU:
363 switch (filter->fmt_out.video.i_chroma)
365 case VLC_CODEC_I422:
366 filter->pf_video_filter = YVYU_I422_Filter;
367 break;
368 default:
369 return VLC_EGENERIC;
373 case VLC_CODEC_VYUY:
374 switch (filter->fmt_out.video.i_chroma)
376 case VLC_CODEC_I422:
377 filter->pf_video_filter = VYUY_I422_Filter;
378 break;
379 default:
380 return VLC_EGENERIC;
383 default:
384 return VLC_EGENERIC;
386 return VLC_SUCCESS;