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
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.
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.
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 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <math.h> /* exp(), pow() */
33 #include <errno.h> /* ENOMEM */
34 #include <stdlib.h> /* free() */
35 #include <string.h> /* strerror() */
43 #include "video_output.h"
44 #include "video_yuv.h"
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 )
57 /* Initialize tables */
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 )
69 free( p_vout->yuv.p_base );
70 free( p_vout->yuv.p_buffer );
71 free( p_vout->yuv.p_offset );
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 )
83 return( yuv_CInit( p_vout ) );
86 /* following functions are local */
88 /*****************************************************************************
89 * SetYUV: compute tables and set function pointers
90 + *****************************************************************************/
91 void SetSDLYUV( vout_thread_t *p_vout )
94 * Set functions pointers
96 if( p_vout->b_grayscale )
99 switch( p_vout->i_bytes_per_pixel )
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;
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;
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;
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;
126 switch( p_vout->i_bytes_per_pixel )
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;
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;
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;
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;