1 /*****************************************************************************
2 * grey_yuv.c : grayscale to others conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #define SRC_FOURCC "GREY"
36 #define DEST_FOURCC "I420,YUY2"
38 /*****************************************************************************
39 * Local and extern prototypes.
40 *****************************************************************************/
41 static int Activate ( vlc_object_t * );
43 static void GREY_I420 ( vout_thread_t *, picture_t *, picture_t * );
44 static void GREY_YUY2 ( vout_thread_t *, picture_t *, picture_t * );
46 /*****************************************************************************
48 *****************************************************************************/
50 set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
51 set_capability( "chroma", 80 );
52 set_callbacks( Activate, NULL );
55 /*****************************************************************************
56 * Activate: allocate a chroma function
57 *****************************************************************************
58 * This function allocates and initializes a chroma function
59 *****************************************************************************/
60 static int Activate( vlc_object_t *p_this )
62 vout_thread_t *p_vout = (vout_thread_t *)p_this;
64 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
69 switch( p_vout->render.i_chroma )
71 case VLC_FOURCC('Y','8','0','0'):
72 p_vout->render.i_chroma = VLC_FOURCC('G','R','E','Y');
73 case VLC_FOURCC('G','R','E','Y'):
74 switch( p_vout->output.i_chroma )
76 case VLC_FOURCC('I','4','2','0'):
77 p_vout->chroma.pf_convert = GREY_I420;
79 case VLC_FOURCC('Y','U','Y','2'):
80 p_vout->chroma.pf_convert = GREY_YUY2;
94 /* Following functions are local */
96 /*****************************************************************************
97 * GREY_I420: 8-bit grayscale to planar YUV 4:2:0
98 *****************************************************************************/
99 static void GREY_I420( vout_thread_t *p_vout, picture_t *p_source,
102 uint8_t *p_line = p_source->p->p_pixels;
103 uint8_t *p_y = p_dest->Y_PIXELS;
104 uint8_t *p_u = p_dest->U_PIXELS;
105 uint8_t *p_v = p_dest->V_PIXELS;
109 const int i_source_margin = p_source->p->i_pitch
110 - p_source->p->i_visible_pitch;
111 const int i_dest_margin = p_dest->p[0].i_pitch
112 - p_dest->p[0].i_visible_pitch;
113 const int i_dest_margin_c = p_dest->p[1].i_pitch
114 - p_dest->p[1].i_visible_pitch;
116 for( i_y = p_vout->render.i_height / 2; i_y-- ; )
118 memset(p_u, 0x80, p_dest->p[1].i_visible_pitch);
119 p_u += i_dest_margin_c;
121 memset(p_v, 0x80, p_dest->p[1].i_visible_pitch);
122 p_v += i_dest_margin_c;
125 for( i_y = p_vout->render.i_height; i_y-- ; )
127 for( i_x = p_vout->render.i_width / 8; i_x-- ; )
129 *p_y++ = *p_line++; *p_y++ = *p_line++;
130 *p_y++ = *p_line++; *p_y++ = *p_line++;
131 *p_y++ = *p_line++; *p_y++ = *p_line++;
132 *p_y++ = *p_line++; *p_y++ = *p_line++;
135 for( i_x = p_vout->render.i_width % 8; i_x-- ; )
140 p_line += i_source_margin;
141 p_y += i_dest_margin;
145 /*****************************************************************************
146 * GREY_YUY2: 8-bit grayscale to packed YUY2
147 *****************************************************************************/
148 static void GREY_YUY2( vout_thread_t *p_vout, picture_t *p_source,
151 uint8_t *p_in = p_source->p->p_pixels;
152 uint8_t *p_out = p_dest->p->p_pixels;
156 const int i_source_margin = p_source->p->i_pitch
157 - p_source->p->i_visible_pitch;
158 const int i_dest_margin = p_dest->p->i_pitch
159 - p_dest->p->i_visible_pitch;
161 for( i_y = p_vout->render.i_height; i_y-- ; )
163 for( i_x = p_vout->render.i_width / 8; i_x-- ; )
165 *p_out++ = *p_in++; *p_out++ = 0x80;
166 *p_out++ = *p_in++; *p_out++ = 0x80;
167 *p_out++ = *p_in++; *p_out++ = 0x80;
168 *p_out++ = *p_in++; *p_out++ = 0x80;
169 *p_out++ = *p_in++; *p_out++ = 0x80;
170 *p_out++ = *p_in++; *p_out++ = 0x80;
171 *p_out++ = *p_in++; *p_out++ = 0x80;
172 *p_out++ = *p_in++; *p_out++ = 0x80;
175 for( i_x = (p_vout->render.i_width % 8) / 2; i_x-- ; )
177 *p_out++ = *p_in++; *p_out++ = 0x80;
178 *p_out++ = *p_in++; *p_out++ = 0x80;
181 p_in += i_source_margin;
182 p_out += i_dest_margin;