]> git.sesse.net Git - vlc/blob - modules/video_chroma/yuy2_i422.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[vlc] / modules / video_chroma / yuy2_i422.c
1 /*****************************************************************************
2  * yuy2_i422.c : Packed YUV 4:2:2 to Planar YUV conversion module for vlc
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan dot 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 <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35 #include <vlc_vout.h>
36
37 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
38 #define DEST_FOURCC  "I422"
39
40 /*****************************************************************************
41  * Local and extern prototypes.
42  *****************************************************************************/
43 static int  Activate ( vlc_object_t * );
44
45 static void YUY2_I422           ( filter_t *, picture_t *, picture_t * );
46 static void YVYU_I422           ( filter_t *, picture_t *, picture_t * );
47 static void UYVY_I422           ( filter_t *, picture_t *, picture_t * );
48 static void cyuv_I422           ( filter_t *, picture_t *, picture_t * );
49 static picture_t *YUY2_I422_Filter    ( filter_t *, picture_t * );
50 static picture_t *YVYU_I422_Filter    ( filter_t *, picture_t * );
51 static picture_t *UYVY_I422_Filter    ( filter_t *, picture_t * );
52 static picture_t *cyuv_I422_Filter    ( filter_t *, picture_t * );
53
54 /*****************************************************************************
55  * Module descriptor
56  *****************************************************************************/
57 vlc_module_begin ()
58     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
59     set_capability( "video filter2", 80 )
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_out.video.i_chroma )
83     {
84         case VLC_FOURCC('I','4','2','2'):
85             switch( p_filter->fmt_in.video.i_chroma )
86             {
87                 case VLC_FOURCC('Y','U','Y','2'):
88                 case VLC_FOURCC('Y','U','N','V'):
89                     p_filter->pf_video_filter = YUY2_I422_Filter;
90                     break;
91
92                 case VLC_FOURCC('Y','V','Y','U'):
93                     p_filter->pf_video_filter = YVYU_I422_Filter;
94                     break;
95
96                 case VLC_FOURCC('U','Y','V','Y'):
97                 case VLC_FOURCC('U','Y','N','V'):
98                 case VLC_FOURCC('Y','4','2','2'):
99                     p_filter->pf_video_filter = UYVY_I422_Filter;
100                     break;
101
102                 case VLC_FOURCC('c','y','u','v'):
103                     p_filter->pf_video_filter = cyuv_I422_Filter;
104                     break;
105
106                 default:
107                     return -1;
108             }
109             break;
110
111         default:
112             return -1;
113     }
114     return 0;
115 }
116
117 /* Following functions are local */
118
119 VIDEO_FILTER_WRAPPER( YUY2_I422 )
120 VIDEO_FILTER_WRAPPER( YVYU_I422 )
121 VIDEO_FILTER_WRAPPER( UYVY_I422 )
122 VIDEO_FILTER_WRAPPER( cyuv_I422 )
123
124 /*****************************************************************************
125  * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
126  *****************************************************************************/
127 static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
128                                            picture_t *p_dest )
129 {
130     uint8_t *p_line = p_source->p->p_pixels;
131
132     uint8_t *p_y = p_dest->Y_PIXELS;
133     uint8_t *p_u = p_dest->U_PIXELS;
134     uint8_t *p_v = p_dest->V_PIXELS;
135
136     int i_x, i_y;
137
138     const int i_dest_margin = p_dest->p[0].i_pitch
139                                  - p_dest->p[0].i_visible_pitch;
140     const int i_dest_margin_c = p_dest->p[1].i_pitch
141                                  - p_dest->p[1].i_visible_pitch;
142     const int i_source_margin = p_source->p->i_pitch
143                                - p_source->p->i_visible_pitch;
144
145     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
146     {
147         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
148         {
149 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v )      \
150             *p_y++ = *p_line++; *p_u++ = *p_line++; \
151             *p_y++ = *p_line++; *p_v++ = *p_line++
152             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
153             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
154             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
155             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
156         }
157         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
158         {
159             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
160         }
161         p_line += i_source_margin;
162         p_y += i_dest_margin;
163         p_u += i_dest_margin_c;
164         p_v += i_dest_margin_c;
165     }
166 }
167
168 /*****************************************************************************
169  * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
170  *****************************************************************************/
171 static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
172                                            picture_t *p_dest )
173 {
174     uint8_t *p_line = p_source->p->p_pixels;
175
176     uint8_t *p_y = p_dest->Y_PIXELS;
177     uint8_t *p_u = p_dest->U_PIXELS;
178     uint8_t *p_v = p_dest->V_PIXELS;
179
180     int i_x, i_y;
181
182     const int i_dest_margin = p_dest->p[0].i_pitch
183                                  - p_dest->p[0].i_visible_pitch;
184     const int i_dest_margin_c = p_dest->p[1].i_pitch
185                                  - p_dest->p[1].i_visible_pitch;
186     const int i_source_margin = p_source->p->i_pitch
187                                - p_source->p->i_visible_pitch;
188
189     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
190     {
191         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
192         {
193 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v )      \
194             *p_y++ = *p_line++; *p_v++ = *p_line++; \
195             *p_y++ = *p_line++; *p_u++ = *p_line++
196             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
197             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
198             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
199             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
200         }
201         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
202         {
203             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
204         }
205         p_line += i_source_margin;
206         p_y += i_dest_margin;
207         p_u += i_dest_margin_c;
208         p_v += i_dest_margin_c;
209     }
210 }
211
212 /*****************************************************************************
213  * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
214  *****************************************************************************/
215 static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
216                                            picture_t *p_dest )
217 {
218     uint8_t *p_line = p_source->p->p_pixels;
219
220     uint8_t *p_y = p_dest->Y_PIXELS;
221     uint8_t *p_u = p_dest->U_PIXELS;
222     uint8_t *p_v = p_dest->V_PIXELS;
223
224     int i_x, i_y;
225
226     const int i_dest_margin = p_dest->p[0].i_pitch
227                                  - p_dest->p[0].i_visible_pitch;
228     const int i_dest_margin_c = p_dest->p[1].i_pitch
229                                  - p_dest->p[1].i_visible_pitch;
230     const int i_source_margin = p_source->p->i_pitch
231                                - p_source->p->i_visible_pitch;
232
233     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
234     {
235         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
236         {
237 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v )      \
238             *p_u++ = *p_line++; *p_y++ = *p_line++; \
239             *p_v++ = *p_line++; *p_y++ = *p_line++
240             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
241             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
242             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
243             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
244         }
245         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
246         {
247             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
248         }
249         p_line += i_source_margin;
250         p_y += i_dest_margin;
251         p_u += i_dest_margin_c;
252         p_v += i_dest_margin_c;
253     }
254 }
255
256 /*****************************************************************************
257  * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
258  * FIXME
259  *****************************************************************************/
260 static void cyuv_I422( filter_t *p_filter, picture_t *p_source,
261                                            picture_t *p_dest )
262 {
263     uint8_t *p_line = p_source->p->p_pixels;
264
265     uint8_t *p_y = p_dest->Y_PIXELS;
266     uint8_t *p_u = p_dest->U_PIXELS;
267     uint8_t *p_v = p_dest->V_PIXELS;
268
269     int i_x, i_y;
270
271     const int i_dest_margin = p_dest->p[0].i_pitch
272                                  - p_dest->p[0].i_visible_pitch;
273     const int i_dest_margin_c = p_dest->p[1].i_pitch
274                                  - p_dest->p[1].i_visible_pitch;
275     const int i_source_margin = p_source->p->i_pitch
276                                - p_source->p->i_visible_pitch;
277
278     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
279     {
280         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
281         {
282 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v )      \
283             *p_y++ = *p_line++; *p_v++ = *p_line++; \
284             *p_y++ = *p_line++; *p_u++ = *p_line++
285             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
286             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
287             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
288             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
289         }
290         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
291         {
292             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
293         }
294         p_line += i_source_margin;
295         p_y += i_dest_margin;
296         p_u += i_dest_margin_c;
297         p_v += i_dest_margin_c;
298     }
299 }