]> git.sesse.net Git - vlc/blob - plugins/chroma/i420_rgb.c
* ALL: got rid of *_Probe functions because most of them were duplicates
[vlc] / plugins / chroma / i420_rgb.c
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 $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <math.h>                                            /* exp(), pow() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdlib.h>                                      /* malloc(), free() */
31
32 #include <videolan/vlc.h>
33
34 #include "video.h"
35 #include "video_output.h"
36
37 #include "i420_rgb.h"
38
39 /*****************************************************************************
40  * Local and extern prototypes.
41  *****************************************************************************/
42 static void chroma_getfunctions ( function_list_t * p_function_list );
43
44 static int  chroma_Init         ( vout_thread_t *p_vout );
45 static void chroma_End          ( vout_thread_t *p_vout );
46
47 /*****************************************************************************
48  * Build configuration tree.
49  *****************************************************************************/
50 MODULE_CONFIG_START
51 MODULE_CONFIG_STOP
52
53 MODULE_INIT_START
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 )
61 #endif
62 MODULE_INIT_STOP
63
64 MODULE_ACTIVATE_START
65     chroma_getfunctions( &p_module->p_functions->chroma );
66 MODULE_ACTIVATE_STOP
67
68 MODULE_DEACTIVATE_START
69 MODULE_DEACTIVATE_STOP
70
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 )
76 {
77     p_function_list->functions.chroma.pf_init = chroma_Init;
78     p_function_list->functions.chroma.pf_end  = chroma_End;
79 }
80
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 )
87 {
88     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
89     {
90         return -1;
91     }
92
93     switch( p_vout->render.i_chroma )
94     {
95         case FOURCC_YV12:
96         case FOURCC_I420:
97         case FOURCC_IYUV:
98             switch( p_vout->output.i_chroma )
99             {
100 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
101                 case FOURCC_BI_RGB:
102                     p_vout->chroma.pf_convert = _M( I420_RGB8 );
103                     break;
104 #endif
105                 case FOURCC_RV15:
106                     p_vout->chroma.pf_convert = _M( I420_RGB15 );
107                     break;
108
109                 case FOURCC_RV16:
110                     p_vout->chroma.pf_convert = _M( I420_RGB16 );
111                     break;
112
113                 case FOURCC_RV32:
114                     p_vout->chroma.pf_convert = _M( I420_RGB32 );
115                     break;
116
117                 default:
118                     return -1;
119             }
120             break;
121
122         default:
123             return -1;
124     }
125     
126     p_vout->chroma.p_sys = malloc( sizeof( chroma_sys_t ) );
127     if( p_vout->chroma.p_sys == NULL )
128     {
129         return -1;
130     }
131
132     switch( p_vout->output.i_chroma )
133     {
134 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
135         case FOURCC_BI_RGB:
136             p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH );
137             break;
138 #endif
139
140         case FOURCC_RV15:
141         case FOURCC_RV16:
142             p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH * 2 );
143             break;
144
145         case FOURCC_RV32:
146             p_vout->chroma.p_sys->p_buffer = malloc( VOUT_MAX_WIDTH * 4 );
147             break;
148
149         default:
150             p_vout->chroma.p_sys->p_buffer = NULL;
151             break;
152     }
153
154     if( p_vout->chroma.p_sys->p_buffer == NULL )
155     {
156         free( p_vout->chroma.p_sys );
157         return -1;
158     }
159
160     p_vout->chroma.p_sys->p_offset = malloc( p_vout->output.i_width
161                                               * sizeof( int ) );
162     if( p_vout->chroma.p_sys->p_offset == NULL )
163     {
164         free( p_vout->chroma.p_sys->p_buffer );
165         free( p_vout->chroma.p_sys );
166         return -1;
167     }
168
169     return 0; 
170 }
171
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 )
178 {
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 );
182 }
183