]> git.sesse.net Git - vlc/blob - modules/video_chroma/i422_yuy2.c
I422_YUY2: clobber lists for MMX and SSE2
[vlc] / modules / video_chroma / i422_yuy2.c
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
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Damien Fouilleul <damienf@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_filter.h>
36 #include <vlc_cpu.h>
37
38 #include "i422_yuy2.h"
39
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"
43 #else
44 #    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
45 #endif
46
47 /*****************************************************************************
48  * Local and extern prototypes.
49  *****************************************************************************/
50 static int  Activate ( vlc_object_t * );
51
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 * );
65 #endif
66
67 /*****************************************************************************
68  * Module descriptor
69  *****************************************************************************/
70 vlc_module_begin ()
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
75 # define VLC_TARGET
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
86 #endif
87     set_callbacks( Activate, NULL )
88 vlc_module_end ()
89
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 )
96 {
97     filter_t *p_filter = (filter_t *)p_this;
98
99 #if CPU_CAPABILITY
100     if( !(vlc_CPU() & CPU_CAPABILITY) )
101         return VLC_EGENERIC;
102 #endif
103     if( p_filter->fmt_in.video.i_width & 1
104      || p_filter->fmt_in.video.i_height & 1 )
105     {
106         return -1;
107     }
108
109     switch( p_filter->fmt_in.video.i_chroma )
110     {
111         case VLC_CODEC_I422:
112             switch( p_filter->fmt_out.video.i_chroma )
113             {
114                 case VLC_CODEC_YUYV:
115                     p_filter->pf_video_filter = I422_YUY2_Filter;
116                     break;
117
118                 case VLC_CODEC_YVYU:
119                     p_filter->pf_video_filter = I422_YVYU_Filter;
120                     break;
121
122                 case VLC_CODEC_UYVY:
123                     p_filter->pf_video_filter = I422_UYVY_Filter;
124                     break;
125
126                 case VLC_FOURCC('I','U','Y','V'):
127                     p_filter->pf_video_filter = I422_IUYV_Filter;
128                     break;
129
130                 case VLC_CODEC_CYUV:
131                     p_filter->pf_video_filter = I422_cyuv_Filter;
132                     break;
133
134 #if defined (MODULE_NAME_IS_i422_yuy2)
135                 case VLC_CODEC_Y211:
136                     p_filter->pf_video_filter = I422_Y211_Filter;
137                     break;
138 #endif
139
140                 default:
141                     return -1;
142             }
143             break;
144
145         default:
146             return -1;
147     }
148     return 0;
149 }
150
151 /* Following functions are local */
152
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 )
160 #endif
161
162 /*****************************************************************************
163  * I422_YUY2: planar YUV 4:2:2 to packed YUY2 4:2:2
164  *****************************************************************************/
165 VLC_TARGET
166 static void I422_YUY2( filter_t *p_filter, picture_t *p_source,
167                                            picture_t *p_dest )
168 {
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;
173
174     int i_x, i_y;
175
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;
182
183 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
184
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))) )
187     {
188         /* use faster SSE2 aligned fetch and store */
189         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
190         {
191             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
192             {
193                 SSE2_CALL( SSE2_YUV422_YUYV_ALIGNED );
194             }
195             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
196             {
197                 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
198             }
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;
203         }
204     }
205     else {
206         /* use slower SSE2 unaligned fetch and store */
207         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
208         {
209             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
210             {
211                 SSE2_CALL( SSE2_YUV422_YUYV_UNALIGNED );
212             }
213             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
214             {
215                 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
216             }
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;
221         }
222     }
223     SSE2_END;
224
225 #else
226
227     for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
228     {
229         for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
230         {
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 );
238 #endif
239         }
240         for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
241         {
242             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
243         }
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;
248     }
249 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
250     MMX_END;
251 #endif
252
253 #endif
254 }
255
256 /*****************************************************************************
257  * I422_YVYU: planar YUV 4:2:2 to packed YVYU 4:2:2
258  *****************************************************************************/
259 VLC_TARGET
260 static void I422_YVYU( filter_t *p_filter, picture_t *p_source,
261                                            picture_t *p_dest )
262 {
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;
267
268     int i_x, i_y;
269
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;
276
277 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
278
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))) )
281     {
282         /* use faster SSE2 aligned fetch and store */
283         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
284         {
285             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
286             {
287                 SSE2_CALL( SSE2_YUV422_YVYU_ALIGNED );
288             }
289             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
290             {
291                 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
292             }
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;
297         }
298     }
299     else {
300         /* use slower SSE2 unaligned fetch and store */
301         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
302         {
303             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
304             {
305                 SSE2_CALL( SSE2_YUV422_YVYU_UNALIGNED );
306             }
307             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
308             {
309                 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
310             }
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;
315         }
316     }
317     SSE2_END;
318
319 #else
320
321     for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
322     {
323         for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
324         {
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 );
332 #endif
333         }
334         for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
335         {
336             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
337         }
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;
342     }
343 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
344     MMX_END;
345 #endif
346
347 #endif
348 }
349
350 /*****************************************************************************
351  * I422_UYVY: planar YUV 4:2:2 to packed UYVY 4:2:2
352  *****************************************************************************/
353 VLC_TARGET
354 static void I422_UYVY( filter_t *p_filter, picture_t *p_source,
355                                            picture_t *p_dest )
356 {
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;
361
362     int i_x, i_y;
363
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;
370
371 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
372
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))) )
375     {
376         /* use faster SSE2 aligned fetch and store */
377         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
378         {
379             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
380             {
381                 SSE2_CALL( SSE2_YUV422_UYVY_ALIGNED );
382             }
383             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
384             {
385                 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
386             }
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;
391         }
392     }
393     else {
394         /* use slower SSE2 unaligned fetch and store */
395         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
396         {
397             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
398             {
399                 SSE2_CALL( SSE2_YUV422_UYVY_UNALIGNED );
400             }
401             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
402             {
403                 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
404             }
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;
409         }
410     }
411     SSE2_END;
412
413 #else
414
415     for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
416     {
417         for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
418         {
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 );
426 #endif
427         }
428         for( i_x = ( p_filter->fmt_in.video.i_width % 8 ) / 2; i_x-- ; )
429         {
430             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
431         }
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;
436     }
437 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
438     MMX_END;
439 #endif
440
441 #endif
442 }
443
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,
448                                            picture_t *p_dest )
449 {
450     VLC_UNUSED(p_source); VLC_UNUSED(p_dest);
451     /* FIXME: TODO ! */
452     msg_Err( p_filter, "I422_IUYV unimplemented, please harass <sam@zoy.org>" );
453 }
454
455 /*****************************************************************************
456  * I422_cyuv: planar YUV 4:2:2 to upside-down packed UYVY 4:2:2
457  *****************************************************************************/
458 VLC_TARGET
459 static void I422_cyuv( filter_t *p_filter, picture_t *p_source,
460                                            picture_t *p_dest )
461 {
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;
466
467     int i_x, i_y;
468
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;
475
476 #if defined (MODULE_NAME_IS_i422_yuy2_sse2)
477
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))) )
480     {
481         /* use faster SSE2 aligned fetch and store */
482         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
483         {
484             p_line -= 2 * p_dest->p->i_pitch;
485
486             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
487             {
488                 SSE2_CALL( SSE2_YUV422_UYVY_ALIGNED );
489             }
490             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
491             {
492                 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
493             }
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;
498         }
499     }
500     else {
501         /* use slower SSE2 unaligned fetch and store */
502         for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
503         {
504             p_line -= 2 * p_dest->p->i_pitch;
505
506             for( i_x = p_filter->fmt_in.video.i_width / 16 ; i_x-- ; )
507             {
508                 SSE2_CALL( SSE2_YUV422_UYVY_UNALIGNED );
509             }
510             for( i_x = ( p_filter->fmt_in.video.i_width % 16 ) / 2; i_x-- ; )
511             {
512                 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
513             }
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;
518         }
519     }
520     SSE2_END;
521
522 #else
523
524     for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
525     {
526         for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
527         {
528             p_line -= 2 * p_dest->p->i_pitch;
529
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 );
537 #endif
538         }
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;
543     }
544 #if defined (MODULE_NAME_IS_i422_yuy2_mmx)
545     MMX_END;
546 #elif defined (MODULE_NAME_IS_i422_yuy2_sse2)
547     SSE2_END;
548 #endif
549
550 #endif
551 }
552
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,
558                                            picture_t *p_dest )
559 {
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;
564
565     int i_x, i_y;
566
567     for( i_y = p_filter->fmt_in.video.i_height ; i_y-- ; )
568     {
569         for( i_x = p_filter->fmt_in.video.i_width / 8 ; i_x-- ; )
570         {
571             C_YUV422_Y211( p_line, p_y, p_u, p_v );
572             C_YUV422_Y211( p_line, p_y, p_u, p_v );
573         }
574     }
575 }
576 #endif