]> git.sesse.net Git - vlc/blob - plugins/sdl/video_yuv.c
* Reverted something that wasn't supposed to go into the cvs :p
[vlc] / plugins / sdl / video_yuv.c
1 /*****************************************************************************
2  * video_yuv.c: YUV transformation functions
3  * Provides functions to perform the YUV conversion. The functions provided here
4  * are a complete and portable C implementation, and may be replaced in certain
5  * case by optimized functions.
6  *****************************************************************************
7  * Copyright (C) 1999, 2000 VideoLAN
8  *
9  * Authors:
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this program; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <math.h>                                            /* exp(), pow() */
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36
37 #include "config.h"
38 #include "common.h"
39 #include "threads.h"
40 #include "mtime.h"
41 #include "plugins.h"
42 #include "video.h"
43 #include "video_output.h"
44 #include "video_yuv.h"
45
46 #include "intf_msg.h"
47
48 /*****************************************************************************
49  * vout_InitYUV: allocate and initialize translations tables
50  *****************************************************************************
51  * This function will allocate memory to store translation tables, depending
52  * of the screen depth.
53  *****************************************************************************/
54 int yuv_CInit( vout_thread_t *p_vout )
55 {
56
57     /* Initialize tables */
58     SetSDLYUV( p_vout );
59     return( 0 );
60 }
61
62 /*****************************************************************************
63  * yuv_CEnd: destroy translations tables
64  *****************************************************************************
65  * Free memory allocated by yuv_CCreate.
66  *****************************************************************************/
67 void yuv_CEnd( vout_thread_t *p_vout )
68 {
69     free( p_vout->yuv.p_base );
70     free( p_vout->yuv.p_buffer );
71     free( p_vout->yuv.p_offset );
72 }
73
74 /*****************************************************************************
75  * yuv_CReset: re-initialize translations tables
76  *****************************************************************************
77  * This function will initialize the tables allocated by vout_CreateTables and
78  * set functions pointers.
79  *****************************************************************************/
80 int yuv_CReset( vout_thread_t *p_vout )
81 {
82     yuv_CEnd( p_vout );
83     return( yuv_CInit( p_vout ) );
84 }
85
86 /* following functions are local */
87
88 /*****************************************************************************
89  * SetYUV: compute tables and set function pointers
90 + *****************************************************************************/
91 void SetSDLYUV( vout_thread_t *p_vout )
92 {
93     /*
94      * Set functions pointers
95      */
96     if( p_vout->b_grayscale )
97     {
98         /* Grayscale */
99         switch( p_vout->i_bytes_per_pixel )
100         {
101         case 1:
102             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert8;
103             p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert8;
104             p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert8;
105             break;
106         case 2:
107             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert16;
108             p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert16;
109             p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert16;
110             break;
111         case 3:
112             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert24;
113             p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert24;
114             p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert24;
115             break;
116         case 4:
117             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert32;
118             p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert32;
119             p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert32;
120             break;
121         }
122     }
123     else
124     {
125         /* Color */
126         switch( p_vout->i_bytes_per_pixel )
127         {
128         case 1:
129             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertRGB8;
130             p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertRGB8;
131             p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertRGB8;
132             break;
133         case 2:
134             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertRGB16;
135             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertRGB16;
136             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertRGB16;
137             break;
138         case 3:
139             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertRGB24;
140             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertRGB24;
141             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertRGB24;
142             break;
143         case 4:
144             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertRGB32;
145             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertRGB32;
146             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertRGB32;
147             break;
148         }
149     }
150 }