]> git.sesse.net Git - vlc/blob - modules/video_chroma/i420_ymga.c
A bit of headers cleanup
[vlc] / modules / video_chroma / i420_ymga.c
1 /*****************************************************************************
2  * i420_ymga.c : YUV to 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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <string.h>                                            /* strerror() */
29 #include <stdlib.h>                                      /* malloc(), free() */
30
31 #include <vlc/vlc.h>
32 #include <vlc_vout.h>
33
34 #define SRC_FOURCC  "I420,IYUV,YV12"
35 #define DEST_FOURCC "YMGA"
36
37 /*****************************************************************************
38  * Local and extern prototypes.
39  *****************************************************************************/
40 static int  Activate   ( vlc_object_t * );
41 static void I420_YMGA  ( vout_thread_t *, picture_t *, picture_t * );
42
43 /*****************************************************************************
44  * Module descriptor
45  *****************************************************************************/
46 vlc_module_begin();
47 #if defined (MODULE_NAME_IS_i420_ymga)
48     set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
49     set_capability( "chroma", 80 );
50 #elif defined (MODULE_NAME_IS_i420_ymga_mmx)
51     set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
52     set_capability( "chroma", 100 );
53     add_requirement( MMX );
54 #endif
55     set_callbacks( Activate, NULL );
56 vlc_module_end();
57
58 /*****************************************************************************
59  * Activate: allocate a chroma function
60  *****************************************************************************
61  * This function allocates and initializes a chroma function
62  *****************************************************************************/
63 static int Activate( vlc_object_t *p_this )
64 {
65     vout_thread_t *p_vout = (vout_thread_t *)p_this;
66
67     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
68     {
69         return -1;
70     }
71
72     switch( p_vout->render.i_chroma )
73     {
74         case VLC_FOURCC('Y','V','1','2'):
75         case VLC_FOURCC('I','4','2','0'):
76         case VLC_FOURCC('I','Y','U','V'):
77             switch( p_vout->output.i_chroma )
78             {
79                 case VLC_FOURCC('Y','M','G','A'):
80                     p_vout->chroma.pf_convert = I420_YMGA;
81                     break;
82
83                 default:
84                     return -1;
85             }
86             break;
87
88         default:
89             return -1;
90     }
91
92     return 0;
93 }
94
95 /* Following functions are local */
96
97 /*****************************************************************************
98  * I420_YMGA: planar YUV 4:2:0 to Matrox's planar/packed YUV 4:2:0
99  *****************************************************************************/
100 static void I420_YMGA( vout_thread_t *p_vout, picture_t *p_source,
101                                               picture_t *p_dest )
102 {
103     uint8_t *p_uv = p_dest->U_PIXELS;
104     uint8_t *p_u = p_source->U_PIXELS;
105     uint8_t *p_v = p_source->V_PIXELS;
106
107     int i_x;
108
109     /* Copy the Y part */
110     p_vout->p_libvlc->pf_memcpy( p_dest->Y_PIXELS, p_source->Y_PIXELS,
111                  p_dest->p[Y_PLANE].i_pitch * p_dest->p[Y_PLANE].i_visible_lines );
112
113     /* Copy the U:V part */
114     for( i_x = p_dest->p[U_PLANE].i_pitch * p_dest->p[U_PLANE].i_visible_lines / 64;
115          i_x--; )
116     {
117 #if defined (MODULE_NAME_IS_i420_ymga)
118         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
119         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
120         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
121         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
122         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
123         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
124         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
125         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
126 #else
127         __asm__( ".p2align 5 \n\
128         movd       (%0), %%mm0  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
129         movd      4(%0), %%mm2  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
130         movd      8(%0), %%mm4  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
131         movd     12(%0), %%mm6  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
132         movd       (%1), %%mm1  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
133         movd      4(%1), %%mm3  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
134         movd      8(%1), %%mm5  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
135         movd     12(%1), %%mm7  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
136         punpcklbw %%mm1, %%mm0  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
137         punpcklbw %%mm3, %%mm2  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
138         punpcklbw %%mm5, %%mm4  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
139         punpcklbw %%mm7, %%mm6  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
140         movq      %%mm0, (%2)   # Store CrCb                              \n\
141         movq      %%mm2, 8(%2)  # Store CrCb                              \n\
142         movq      %%mm4, 16(%2) # Store CrCb                              \n\
143         movq      %%mm6, 24(%2) # Store CrCb"
144         : : "r" (p_v), "r" (p_u), "r" (p_uv) );
145
146         p_v += 16; p_u += 16; p_uv += 32;
147 #endif
148     }
149 }
150