1 /*****************************************************************************
2 * i420_rgb.c : YUV to bitmap RGB conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: i420_rgb.c,v 1.5 2002/02/15 13:32:53 sam Exp $
7 * Authors: Samuel 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <math.h> /* exp(), pow() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
30 #include <stdlib.h> /* malloc(), free() */
32 #include <videolan/vlc.h>
35 #include "video_output.h"
39 /*****************************************************************************
40 * Local and extern prototypes.
41 *****************************************************************************/
42 static void chroma_getfunctions ( function_list_t * p_function_list );
44 static int chroma_Init ( vout_thread_t *p_vout );
45 static void chroma_End ( vout_thread_t *p_vout );
47 /*****************************************************************************
48 * Build configuration tree.
49 *****************************************************************************/
54 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
55 SET_DESCRIPTION( "I420/IYUV/YV12 to RGB 8/15/16/24/32 conversions" )
56 ADD_CAPABILITY( CHROMA, 80 )
57 #elif defined (MODULE_NAME_IS_chroma_i420_rgb_mmx)
58 SET_DESCRIPTION( "MMX I420/IYUV/YV12 to RGB 15/16/24/32 conversions" )
59 ADD_CAPABILITY( CHROMA, 100 )
60 ADD_REQUIREMENT( MMX )
65 chroma_getfunctions( &p_module->p_functions->chroma );
68 MODULE_DEACTIVATE_START
69 MODULE_DEACTIVATE_STOP
71 /*****************************************************************************
72 * Functions exported as capabilities. They are declared as static so that
73 * we don't pollute the namespace too much.
74 *****************************************************************************/
75 static void chroma_getfunctions( function_list_t * p_function_list )
77 p_function_list->functions.chroma.pf_init = chroma_Init;
78 p_function_list->functions.chroma.pf_end = chroma_End;
81 /*****************************************************************************
82 * chroma_Init: allocate a chroma function
83 *****************************************************************************
84 * This function allocates and initializes a chroma function
85 *****************************************************************************/
86 static int chroma_Init( vout_thread_t *p_vout )
88 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
93 switch( p_vout->render.i_chroma )
98 switch( p_vout->output.i_chroma )
100 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
102 p_vout->chroma.pf_convert = _M( I420_RGB8 );
106 p_vout->chroma.pf_convert = _M( I420_RGB15 );
110 p_vout->chroma.pf_convert = _M( I420_RGB16 );
114 p_vout->chroma.pf_convert = _M( I420_RGB32 );
126 p_vout->chroma.p_sys = malloc( sizeof( chroma_sys_t ) );
127 if( p_vout->chroma.p_sys == NULL )
132 switch( p_vout->output.i_chroma )
134 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
136 p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH );
142 p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH * 2 );
146 p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH * 4 );
150 p_vout->chroma.p_sys->p_buffer = NULL;
154 if( p_vout->chroma.p_sys->p_buffer == NULL )
156 free( p_vout->chroma.p_sys );
160 p_vout->chroma.p_sys->p_offset = malloc( p_vout->output.i_width
162 if( p_vout->chroma.p_sys->p_offset == NULL )
164 free( p_vout->chroma.p_sys->p_buffer );
165 free( p_vout->chroma.p_sys );
172 /*****************************************************************************
173 * chroma_End: free the chroma function
174 *****************************************************************************
175 * This function frees the previously allocated chroma function
176 *****************************************************************************/
177 static void chroma_End( vout_thread_t *p_vout )
179 free( p_vout->chroma.p_sys->p_offset );
180 free( p_vout->chroma.p_sys->p_buffer );
181 free( p_vout->chroma.p_sys );