]> git.sesse.net Git - vlc/blob - modules/video_chroma/i420_ymga.c
Merge branch 1.0-bugfix
[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
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <errno.h>                                                 /* ENOMEM */
33
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_filter.h>
37
38 #define SRC_FOURCC  "I420,IYUV,YV12"
39 #define DEST_FOURCC "YMGA"
40
41 /*****************************************************************************
42  * Local and extern prototypes.
43  *****************************************************************************/
44 static int  Activate   ( vlc_object_t * );
45 static void I420_YMGA  ( filter_t *, picture_t *, picture_t * );
46 static picture_t *I420_YMGA_Filter( filter_t *, picture_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 vlc_module_begin ()
52 #if defined (MODULE_NAME_IS_i420_ymga)
53     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
54     set_capability( "video filter2", 80 )
55 #elif defined (MODULE_NAME_IS_i420_ymga_mmx)
56     set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
57     set_capability( "video filter2", 100 )
58     add_requirement( MMX )
59 #endif
60     set_callbacks( Activate, NULL )
61 vlc_module_end ()
62
63 /*****************************************************************************
64  * Activate: allocate a chroma function
65  *****************************************************************************
66  * This function allocates and initializes a chroma function
67  *****************************************************************************/
68 static int Activate( vlc_object_t *p_this )
69 {
70     filter_t *p_filter = (filter_t *)p_this;
71
72     if( p_filter->fmt_in.video.i_width & 1
73      || p_filter->fmt_in.video.i_height & 1 )
74     {
75         return -1;
76     }
77
78     if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
79      || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
80         return -1;
81
82     switch( p_filter->fmt_in.video.i_chroma )
83     {
84         case VLC_CODEC_YV12:
85         case VLC_CODEC_I420:
86             switch( p_filter->fmt_out.video.i_chroma )
87             {
88                 case VLC_CODEC_YMGA:
89                     p_filter->pf_video_filter = I420_YMGA_Filter;
90                     break;
91
92                 default:
93                     return -1;
94             }
95             break;
96
97         default:
98             return -1;
99     }
100
101     return 0;
102 }
103
104 /* Following functions are local */
105
106 VIDEO_FILTER_WRAPPER( I420_YMGA )
107
108 /*****************************************************************************
109  * I420_YMGA: planar YUV 4:2:0 to Matrox's planar/packed YUV 4:2:0
110  *****************************************************************************/
111 static void I420_YMGA( filter_t *p_filter, picture_t *p_source,
112                                            picture_t *p_dest )
113 {
114     uint8_t *p_uv = p_dest->U_PIXELS;
115     uint8_t *p_u = p_source->U_PIXELS;
116     uint8_t *p_v = p_source->V_PIXELS;
117
118     int i_x;
119
120     /* Copy the Y part */
121     vlc_memcpy( p_dest->Y_PIXELS, p_source->Y_PIXELS,
122                 p_dest->p[Y_PLANE].i_pitch * p_dest->p[Y_PLANE].i_visible_lines );
123
124     /* Copy the U:V part */
125     for( i_x = p_dest->p[U_PLANE].i_pitch * p_dest->p[U_PLANE].i_visible_lines / 64;
126          i_x--; )
127     {
128 #if defined (MODULE_NAME_IS_i420_ymga)
129         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
130         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
131         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
132         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
133         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
134         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
135         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
136         *p_uv++ = *p_u++; *p_uv++ = *p_v++; *p_uv++ = *p_u++; *p_uv++ = *p_v++;
137 #else
138         __asm__( ".p2align 5 \n\
139         movd       (%0), %%mm0  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
140         movd      4(%0), %%mm2  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
141         movd      8(%0), %%mm4  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
142         movd     12(%0), %%mm6  # Load 4 Cr   00 00 00 00 v3 v2 v1 v0     \n\
143         movd       (%1), %%mm1  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
144         movd      4(%1), %%mm3  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
145         movd      8(%1), %%mm5  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
146         movd     12(%1), %%mm7  # Load 4 Cb   00 00 00 00 u3 u2 u1 u0     \n\
147         punpcklbw %%mm1, %%mm0  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
148         punpcklbw %%mm3, %%mm2  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
149         punpcklbw %%mm5, %%mm4  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
150         punpcklbw %%mm7, %%mm6  #             u3 v3 u2 v2 u1 v1 u0 v0     \n\
151         movq      %%mm0, (%2)   # Store CrCb                              \n\
152         movq      %%mm2, 8(%2)  # Store CrCb                              \n\
153         movq      %%mm4, 16(%2) # Store CrCb                              \n\
154         movq      %%mm6, 24(%2) # Store CrCb"
155         : : "r" (p_v), "r" (p_u), "r" (p_uv) );
156
157         p_v += 16; p_u += 16; p_uv += 32;
158 #endif
159     }
160 }
161