]> git.sesse.net Git - vlc/blob - modules/video_chroma/grey_yuv.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[vlc] / modules / video_chroma / grey_yuv.c
1 /*****************************************************************************
2  * grey_yuv.c : grayscale to others conversion module for vlc
3  *****************************************************************************
4  * Copyright (C) 2007, 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sam 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 <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35 #include <vlc_vout.h>
36
37 #define SRC_FOURCC  "GREY"
38 #define DEST_FOURCC "I420,YUY2"
39
40 /*****************************************************************************
41  * Local and extern prototypes.
42  *****************************************************************************/
43 static int  Activate ( vlc_object_t * );
44
45 static void GREY_I420( filter_t *, picture_t *, picture_t * );
46 static void GREY_YUY2( filter_t *, picture_t *, picture_t * );
47
48 static picture_t *GREY_I420_Filter( filter_t *, picture_t * );
49 static picture_t *GREY_YUY2_Filter( filter_t *, picture_t * );
50
51 /*****************************************************************************
52  * Module descriptor.
53  *****************************************************************************/
54 vlc_module_begin ()
55     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
56     set_capability( "video filter2", 80 )
57     set_callbacks( Activate, NULL )
58 vlc_module_end ()
59
60 /*****************************************************************************
61  * Activate: allocate a chroma function
62  *****************************************************************************
63  * This function allocates and initializes a chroma function
64  *****************************************************************************/
65 static int Activate( vlc_object_t *p_this )
66 {
67     filter_t *p_filter = (filter_t *)p_this;
68
69     if( p_filter->fmt_out.video.i_width & 1
70      || p_filter->fmt_out.video.i_height & 1 )
71     {
72         return -1;
73     }
74
75     if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
76      || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
77         return -1;
78
79     switch( p_filter->fmt_in.video.i_chroma )
80     {
81         case VLC_FOURCC('Y','8','0','0'):
82             p_filter->fmt_in.video.i_chroma = VLC_FOURCC('G','R','E','Y');
83         case VLC_FOURCC('G','R','E','Y'):
84             switch( p_filter->fmt_out.video.i_chroma )
85             {
86                 case VLC_FOURCC('I','4','2','0'):
87                     p_filter->pf_video_filter = GREY_I420_Filter;
88                     break;
89                 case VLC_FOURCC('Y','U','Y','2'):
90                     p_filter->pf_video_filter = GREY_YUY2_Filter;
91                     break;
92                 default:
93                     return -1;
94             }
95             break;
96
97         default:
98             return -1;
99     }
100
101     return 0;
102 }
103
104 VIDEO_FILTER_WRAPPER( GREY_I420 )
105 VIDEO_FILTER_WRAPPER( GREY_YUY2 )
106
107 /* Following functions are local */
108
109 /*****************************************************************************
110  * GREY_I420: 8-bit grayscale to planar YUV 4:2:0
111  *****************************************************************************/
112 static void GREY_I420( filter_t *p_filter, picture_t *p_source,
113                                            picture_t *p_dest )
114 {
115     uint8_t *p_line = p_source->p->p_pixels;
116     uint8_t *p_y = p_dest->Y_PIXELS;
117     uint8_t *p_u = p_dest->U_PIXELS;
118     uint8_t *p_v = p_dest->V_PIXELS;
119
120     int i_x, i_y;
121
122     const int i_source_margin = p_source->p->i_pitch
123                                  - p_source->p->i_visible_pitch;
124     const int i_dest_margin = p_dest->p[0].i_pitch
125                                - p_dest->p[0].i_visible_pitch;
126     const int i_dest_margin_c = p_dest->p[1].i_pitch
127                                  - p_dest->p[1].i_visible_pitch;
128
129     for( i_y = p_filter->fmt_in.video.i_height / 2; i_y-- ; )
130     {
131         memset(p_u, 0x80, p_dest->p[1].i_visible_pitch);
132         p_u += i_dest_margin_c;
133
134         memset(p_v, 0x80, p_dest->p[1].i_visible_pitch);
135         p_v += i_dest_margin_c;
136     }
137
138     for( i_y = p_filter->fmt_in.video.i_height; i_y-- ; )
139     {
140         for( i_x = p_filter->fmt_in.video.i_width / 8; i_x-- ; )
141         {
142             *p_y++ = *p_line++; *p_y++ = *p_line++;
143             *p_y++ = *p_line++; *p_y++ = *p_line++;
144             *p_y++ = *p_line++; *p_y++ = *p_line++;
145             *p_y++ = *p_line++; *p_y++ = *p_line++;
146         }
147
148         for( i_x = p_filter->fmt_in.video.i_width % 8; i_x-- ; )
149         {
150             *p_y++ = *p_line++;
151         }
152
153         p_line += i_source_margin;
154         p_y += i_dest_margin;
155     }
156 }
157
158 /*****************************************************************************
159  * GREY_YUY2: 8-bit grayscale to packed YUY2
160  *****************************************************************************/
161 static void GREY_YUY2( filter_t *p_filter, picture_t *p_source,
162                                            picture_t *p_dest )
163 {
164     uint8_t *p_in = p_source->p->p_pixels;
165     uint8_t *p_out = p_dest->p->p_pixels;
166
167     int i_x, i_y;
168
169     const int i_source_margin = p_source->p->i_pitch
170                                  - p_source->p->i_visible_pitch;
171     const int i_dest_margin = p_dest->p->i_pitch
172                                - p_dest->p->i_visible_pitch;
173
174     for( i_y = p_filter->fmt_out.video.i_height; i_y-- ; )
175     {
176         for( i_x = p_filter->fmt_out.video.i_width / 8; i_x-- ; )
177         {
178             *p_out++ = *p_in++; *p_out++ = 0x80;
179             *p_out++ = *p_in++; *p_out++ = 0x80;
180             *p_out++ = *p_in++; *p_out++ = 0x80;
181             *p_out++ = *p_in++; *p_out++ = 0x80;
182             *p_out++ = *p_in++; *p_out++ = 0x80;
183             *p_out++ = *p_in++; *p_out++ = 0x80;
184             *p_out++ = *p_in++; *p_out++ = 0x80;
185             *p_out++ = *p_in++; *p_out++ = 0x80;
186         }
187
188         for( i_x = (p_filter->fmt_out.video.i_width % 8) / 2; i_x-- ; )
189         {
190             *p_out++ = *p_in++; *p_out++ = 0x80;
191             *p_out++ = *p_in++; *p_out++ = 0x80;
192         }
193
194         p_in += i_source_margin;
195         p_out += i_dest_margin;
196     }
197 }
198