]> git.sesse.net Git - vlc/blob - src/video_output/video_yuv.c
A few new things:
[vlc] / src / video_output / video_yuv.c
1 /*****************************************************************************
2  * video_yuv.c: YUV transformation functions
3  * These functions set up YUV tables for colorspace conversion
4  *****************************************************************************
5  * Copyright (C) 1999, 2000 VideoLAN
6  *
7  * Authors:
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 GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this program; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <math.h>                                            /* exp(), pow() */
31 #include <errno.h>                                                 /* ENOMEM */
32 #include <stdlib.h>                                                /* free() */
33 #include <string.h>                                            /* strerror() */
34
35 #include "config.h"
36 #include "common.h"
37 #include "threads.h"
38 #include "mtime.h"
39 #include "plugins.h"
40 #include "video.h"
41 #include "video_output.h"
42 #include "video_yuv.h"
43
44 #include "intf_msg.h"
45
46 #include "main.h"
47
48 /*****************************************************************************
49  * vout_InitYUV: allocate and initialize translation tables
50  *****************************************************************************
51  * This function will allocate memory to store translation tables, depending
52  * on the screen depth.
53  *****************************************************************************/
54 int vout_InitYUV( vout_thread_t *p_vout )
55 {
56     typedef void ( yuv_getplugin_t ) ( vout_thread_t * p_vout );
57     
58     int          i_index;
59     int          i_best_index = 0, i_best_score = 0;
60
61     /* Get a suitable YUV plugin */
62     for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
63     {
64         /* If there's a plugin in p_info ... */
65         if( p_main->p_bank->p_info[ i_index ] != NULL )
66         {
67             /* ... and if this plugin provides the functions we want ... */
68             if( p_main->p_bank->p_info[ i_index ]->yuv_GetPlugin != NULL )
69             {
70                 /* ... and if this plugin has a good score ... */
71                 if(  p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
72                 {
73                     /* ... then take it */
74                     i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
75                     i_best_index = i_index;
76                 }
77             }
78         }
79     }
80
81     if( i_best_score == 0 )
82     {
83         /* this should NEVER happen ! */
84         free( p_vout );
85         return( 12 ); 
86     }
87
88     /* Get the plugin functions */
89     ( ( yuv_getplugin_t * ) p_main->p_bank->p_info[ i_best_index ]->yuv_GetPlugin)( p_vout );
90  
91     
92     return p_vout->p_yuv_init( p_vout );
93 }
94
95 /*****************************************************************************
96  * vout_ResetYUV: re-initialize translation tables
97  *****************************************************************************
98  * This function will initialize the tables allocated by vout_InitYUV and
99  * set functions pointers.
100  *****************************************************************************/
101 int vout_ResetYUV( vout_thread_t *p_vout )
102 {
103     p_vout->p_yuv_end( p_vout );
104     return( p_vout->p_yuv_init( p_vout ) );
105 }
106
107 /*****************************************************************************
108  * vout_EndYUV: destroy translation tables
109  *****************************************************************************
110  * Free memory allocated by vout_InitYUV
111  *****************************************************************************/
112 void vout_EndYUV( vout_thread_t *p_vout )
113 {
114     p_vout->p_yuv_end( p_vout );
115 }
116