1 /*****************************************************************************
2 * i422_yuy2.c : Planar YUV 4:2:2 to Packed YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Damien Fouilleul <damienf@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_filter.h>
38 #include "i422_yuy2.h"
40 #define SRC_FOURCC "I422"
41 #if defined (MODULE_NAME_IS_i422_yuy2)
42 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
44 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
47 /*****************************************************************************
48 * Local and extern prototypes.
49 *****************************************************************************/
50 static int Activate ( vlc_object_t * );
52 static void I422_YUY2 ( filter_t *, picture_t *, picture_t * );
53 static void I422_YVYU ( filter_t *, picture_t *, picture_t * );
54 static void I422_UYVY ( filter_t *, picture_t *, picture_t * );
55 static void I422_IUYV ( filter_t *, picture_t *, picture_t * );
56 static void I422_cyuv ( filter_t *, picture_t *, picture_t * );
57 static picture_t *I422_YUY2_Filter ( filter_t *, picture_t * );
58 static picture_t *I422_YVYU_Filter ( filter_t *, picture_t * );
59 static picture_t *I422_UYVY_Filter ( filter_t *, picture_t * );
60 static picture_t *I422_IUYV_Filter ( filter_t *, picture_t * );
61 static picture_t *I422_cyuv_Filter ( filter_t *, picture_t * );
62 #if defined (MODULE_NAME_IS_i422_yuy2)
63 static void I422_Y211 ( filter_t *, picture_t *, picture_t * );
64 static picture_t *I422_Y211_Filter ( filter_t *, picture_t * );
67 /*****************************************************************************
69 *****************************************************************************/
71 #if defined (MODULE_NAME_IS_i422_yuy2)
72 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
73 set_capability( "video filter2", 80 )
74 # define CPU_CAPABILITY 0
76 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
77 set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
78 set_capability( "video filter2", 100 )
79 # define CPU_CAPABILITY CPU_CAPABILITY_MMX
80 # define VLC_TARGET VLC_MMX
81 #elif defined (MODULE_NAME_IS_i422_yuy2_sse2)
82 set_description( N_("SSE2 conversions from " SRC_FOURCC " to " DEST_FOURCC) )
83 set_capability( "video filter2", 120 )
84 # define CPU_CAPABILITY CPU_CAPABILITY_SSE2
85 # define VLC_TARGET VLC_SSE
87 set_callbacks( Activate, NULL )
90 /*****************************************************************************
91 * Activate: allocate a chroma function
92 *****************************************************************************
93 * This function allocates and initializes a chroma function
94 *****************************************************************************/
95 static int Activate( vlc_object_t *p_this )
97 filter_t *p_filter = (filter_t *)p_this;
100 if( !(vlc_CPU() & CPU_CAPABILITY) )
103 if( p_filter->fmt_in.video.i_width & 1
104 || p_filter->fmt_in.video.i_height & 1 )
109 switch( p_filter->fmt_in.video.i_chroma )
112 switch( p_filter->fmt_out.video.i_chroma )
115 p_filter->pf_video_filter = I422_YUY2_Filter;
119 p_filter->pf_video_filter = I422_YVYU_Filter;
123 p_filter->pf_video_filter = I422_UYVY_Filter;
126 case VLC_FOURCC('I','U','Y','V'):
127 p_filter->pf_video_filter = I422_IUYV_Filter;
131 p_filter->pf_video_filter = I422_cyuv_Filter;
134 #if defined (MODULE_NAME_IS_i422_yuy2)
136 p_filter->pf_video_filter = I422_Y211_Filter;
151 /* Following functions are local */
153 VIDEO_FILTER_WRAPPER( I422_YUY2 )
154 VIDEO_FILTER_WRAPPER( I422_YVYU )
155 VIDEO_FILTER_WRAPPER( I422_UYVY )
156 VIDEO_FILTER_WRAPPER( I422_IUYV )
157 VIDEO_FILTER_WRAPPER( I422_cyuv )
158 #if defined (MODULE_NAME_IS_i422_yuy2)
159 VIDEO_FILTER_WRAPPER( I422_Y211 )
162 /*****************************************************************************
163 * I422_YUY2: planar YUV 4:2:2 to packed YUY2 4:2:2
164 *****************************************************************************/
166 static void I422_YUY2( filter_t *p_filter, picture_t *p_source,
169 uint8_t *p_line = p_dest->p->p_pixels;
170 uint8_t *p_y = p_source->Y_PIXELS;
171 uint8_t *p_u = p_source->U_PIXELS;
172 uint8_t *p_v = p_source->V_PIXELS;
176 const int i_source_margin = p_source->p[0].i_pitch
177 - p_source->p[0].i_visible_pitch;
178 const int i_source_margin_c = p_source->p[1].i_pitch
179 - p_source->p[1].i_visible_pitch;
180 const int i_dest_margin = p_dest->p->i_pitch
181 - p_dest->p->i_visible_pitch;
183 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
185 if( 0 == (15 & (p_source->p[Y_PLANE].i_pitch|p_dest->p->i_pitch|
186 ((intptr_t)p_line|(intptr_t)p_y))) )
188 /* use faster SSE2 aligned fetch and store */
189 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
191 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
193 SSE2_CALL( SSE2_YUV422_YUYV_ALIGNED );
195 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
197 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
199 p_y += i_source_margin;
200 p_u += i_source_margin_c;
201 p_v += i_source_margin_c;
202 p_line += i_dest_margin;
206 /* use slower SSE2 unaligned fetch and store */
207 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
209 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
211 SSE2_CALL( SSE2_YUV422_YUYV_UNALIGNED );
213 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
215 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
217 p_y += i_source_margin;
218 p_u += i_source_margin_c;
219 p_v += i_source_margin_c;
220 p_line += i_dest_margin;
227 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
229 for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
231 #if defined (MODULE_NAME_IS_i422_yuy2)
232 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
233 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
234 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
235 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
236 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
237 MMX_CALL( MMX_YUV422_YUYV );
240 for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
242 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
244 p_y += i_source_margin;
245 p_u += i_source_margin_c;
246 p_v += i_source_margin_c;
247 p_line += i_dest_margin;
249 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
256 /*****************************************************************************
257 * I422_YVYU: planar YUV 4:2:2 to packed YVYU 4:2:2
258 *****************************************************************************/
260 static void I422_YVYU( filter_t *p_filter, picture_t *p_source,
263 uint8_t *p_line = p_dest->p->p_pixels;
264 uint8_t *p_y = p_source->Y_PIXELS;
265 uint8_t *p_u = p_source->U_PIXELS;
266 uint8_t *p_v = p_source->V_PIXELS;
270 const int i_source_margin = p_source->p[0].i_pitch
271 - p_source->p[0].i_visible_pitch;
272 const int i_source_margin_c = p_source->p[1].i_pitch
273 - p_source->p[1].i_visible_pitch;
274 const int i_dest_margin = p_dest->p->i_pitch
275 - p_dest->p->i_visible_pitch;
277 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
279 if( 0 == (15 & (p_source->p[Y_PLANE].i_pitch|p_dest->p->i_pitch|
280 ((intptr_t)p_line|(intptr_t)p_y))) )
282 /* use faster SSE2 aligned fetch and store */
283 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
285 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
287 SSE2_CALL( SSE2_YUV422_YVYU_ALIGNED );
289 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
291 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
293 p_y += i_source_margin;
294 p_u += i_source_margin_c;
295 p_v += i_source_margin_c;
296 p_line += i_dest_margin;
300 /* use slower SSE2 unaligned fetch and store */
301 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
303 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
305 SSE2_CALL( SSE2_YUV422_YVYU_UNALIGNED );
307 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
309 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
311 p_y += i_source_margin;
312 p_u += i_source_margin_c;
313 p_v += i_source_margin_c;
314 p_line += i_dest_margin;
321 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
323 for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
325 #if defined (MODULE_NAME_IS_i422_yuy2)
326 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
327 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
328 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
329 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
330 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
331 MMX_CALL( MMX_YUV422_YVYU );
334 for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
336 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
338 p_y += i_source_margin;
339 p_u += i_source_margin_c;
340 p_v += i_source_margin_c;
341 p_line += i_dest_margin;
343 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
350 /*****************************************************************************
351 * I422_UYVY: planar YUV 4:2:2 to packed UYVY 4:2:2
352 *****************************************************************************/
354 static void I422_UYVY( filter_t *p_filter, picture_t *p_source,
357 uint8_t *p_line = p_dest->p->p_pixels;
358 uint8_t *p_y = p_source->Y_PIXELS;
359 uint8_t *p_u = p_source->U_PIXELS;
360 uint8_t *p_v = p_source->V_PIXELS;
364 const int i_source_margin = p_source->p[0].i_pitch
365 - p_source->p[0].i_visible_pitch;
366 const int i_source_margin_c = p_source->p[1].i_pitch
367 - p_source->p[1].i_visible_pitch;
368 const int i_dest_margin = p_dest->p->i_pitch
369 - p_dest->p->i_visible_pitch;
371 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
373 if( 0 == (15 & (p_source->p[Y_PLANE].i_pitch|p_dest->p->i_pitch|
374 ((intptr_t)p_line|(intptr_t)p_y))) )
376 /* use faster SSE2 aligned fetch and store */
377 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
379 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
381 SSE2_CALL( SSE2_YUV422_UYVY_ALIGNED );
383 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
385 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
387 p_y += i_source_margin;
388 p_u += i_source_margin_c;
389 p_v += i_source_margin_c;
390 p_line += i_dest_margin;
394 /* use slower SSE2 unaligned fetch and store */
395 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
397 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
399 SSE2_CALL( SSE2_YUV422_UYVY_UNALIGNED );
401 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
403 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
405 p_y += i_source_margin;
406 p_u += i_source_margin_c;
407 p_v += i_source_margin_c;
408 p_line += i_dest_margin;
415 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
417 for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
419 #if defined (MODULE_NAME_IS_i422_yuy2)
420 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
421 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
422 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
423 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
424 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
425 MMX_CALL( MMX_YUV422_UYVY );
428 for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
430 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
432 p_y += i_source_margin;
433 p_u += i_source_margin_c;
434 p_v += i_source_margin_c;
435 p_line += i_dest_margin;
437 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
444 /*****************************************************************************
445 * I422_IUYV: planar YUV 4:2:2 to interleaved packed IUYV 4:2:2
446 *****************************************************************************/
447 static void I422_IUYV( filter_t *p_filter, picture_t *p_source,
450 VLC_UNUSED(p_source); VLC_UNUSED(p_dest);
452 msg_Err( p_filter, "I422_IUYV unimplemented, please harass <sam@zoy.org>" );
455 /*****************************************************************************
456 * I422_cyuv: planar YUV 4:2:2 to upside-down packed UYVY 4:2:2
457 *****************************************************************************/
459 static void I422_cyuv( filter_t *p_filter, picture_t *p_source,
462 uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_visible_lines * p_dest->p->i_pitch;
463 uint8_t *p_y = p_source->Y_PIXELS;
464 uint8_t *p_u = p_source->U_PIXELS;
465 uint8_t *p_v = p_source->V_PIXELS;
469 const int i_source_margin = p_source->p[0].i_pitch
470 - p_source->p[0].i_visible_pitch;
471 const int i_source_margin_c = p_source->p[1].i_pitch
472 - p_source->p[1].i_visible_pitch;
473 const int i_dest_margin = p_dest->p->i_pitch
474 - p_dest->p->i_visible_pitch;
476 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
478 if( 0 == (15 & (p_source->p[Y_PLANE].i_pitch|p_dest->p->i_pitch|
479 ((intptr_t)p_line|(intptr_t)p_y))) )
481 /* use faster SSE2 aligned fetch and store */
482 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
484 p_line -= 2 * p_dest->p->i_pitch;
486 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
488 SSE2_CALL( SSE2_YUV422_UYVY_ALIGNED );
490 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
492 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
494 p_y += i_source_margin;
495 p_u += i_source_margin_c;
496 p_v += i_source_margin_c;
497 p_line += i_dest_margin;
501 /* use slower SSE2 unaligned fetch and store */
502 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
504 p_line -= 2 * p_dest->p->i_pitch;
506 for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
508 SSE2_CALL( SSE2_YUV422_UYVY_UNALIGNED );
510 for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
512 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
514 p_y += i_source_margin;
515 p_u += i_source_margin_c;
516 p_v += i_source_margin_c;
517 p_line += i_dest_margin;
524 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
526 for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
528 p_line -= 2 * p_dest->p->i_pitch;
530 #if defined (MODULE_NAME_IS_i422_yuy2)
531 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
532 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
533 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
534 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
535 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
536 MMX_CALL( MMX_YUV422_UYVY );
539 p_y += i_source_margin;
540 p_u += i_source_margin_c;
541 p_v += i_source_margin_c;
542 p_line += i_dest_margin;
544 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
546 #elif defined (MODULE_NAME_IS_i422_yuy2_sse2)
553 /*****************************************************************************
554 * I422_Y211: planar YUV 4:2:2 to packed YUYV 2:1:1
555 *****************************************************************************/
556 #if defined (MODULE_NAME_IS_i422_yuy2)
557 static void I422_Y211( filter_t *p_filter, picture_t *p_source,
560 uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_visible_lines * p_dest->p->i_pitch;
561 uint8_t *p_y = p_source->Y_PIXELS;
562 uint8_t *p_u = p_source->U_PIXELS;
563 uint8_t *p_v = p_source->V_PIXELS;
567 for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
569 for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
571 C_YUV422_Y211( p_line, p_y, p_u, p_v );
572 C_YUV422_Y211( p_line, p_y, p_u, p_v );