1 /*****************************************************************************
2 * i420_rgb16.c : YUV to bitmap RGB conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000 VideoLAN
5 * $Id: i420_rgb16.c,v 1.1 2002/01/04 14:01:34 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"
38 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
39 # include "i420_rgb_c.h"
40 #elif defined (MODULE_NAME_IS_chroma_i420_rgb_mmx)
41 # include "i420_rgb_mmx.h"
44 static void SetOffset( int, int, int, int, boolean_t *, int *, int * );
46 /*****************************************************************************
47 * I420_RGB16: color YUV 4:2:0 to RGB 16 bpp
48 *****************************************************************************
49 * Horizontal alignment needed:
50 * - input: 8 pixels (8 Y bytes, 4 U/V bytes), margins not allowed
51 * - output: 1 pixel (2 bytes), margins allowed
52 * Vertical alignment needed:
53 * - input: 2 lines (2 Y lines, 1 U/V line)
55 *****************************************************************************/
56 void _M( I420_RGB16 )( vout_thread_t *p_vout, picture_t *p_src,
59 /* We got this one from the old arguments */
60 u16 *p_pic = (u16*)p_dest->p->p_pixels;
61 u8 *p_y = p_src->Y_PIXELS;
62 u8 *p_u = p_src->U_PIXELS;
63 u8 *p_v = p_src->V_PIXELS;
65 boolean_t b_hscale; /* horizontal scaling type */
66 int i_vscale; /* vertical scaling type */
67 int i_x, i_y; /* horizontal and vertical indexes */
70 int i_scale_count; /* scale modulo counter */
71 int i_chroma_width = p_vout->render.i_width / 2; /* chroma width */
72 u16 * p_pic_start; /* beginning of the current line for copy */
74 /* Conversion buffer pointer */
75 u16 * p_buffer_start = (u16*)p_vout->chroma.p_sys->p_buffer;
78 /* Offset array pointer */
79 int * p_offset_start = p_vout->chroma.p_sys->p_offset;
82 if( p_dest->p->b_margin )
84 i_right_margin = (p_dest->p->i_pitch - p_dest->p->i_visible_bytes) / 2;
91 if( p_vout->render.i_width & 7 )
93 i_rewind = 8 - ( p_vout->render.i_width & 7 );
100 /* Rule: when a picture of size (x1,y1) with aspect ratio r1 is rendered
101 * on a picture of size (x2,y2) with aspect ratio r2, if x1 grows to x1'
102 * then y1 grows to y1' = x1' * y2/x2 * r2/r1 */
103 SetOffset( p_vout->render.i_width, p_vout->render.i_height,
104 p_vout->output.i_width, p_vout->output.i_height,
105 &b_hscale, &i_vscale, p_offset_start );
107 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
108 intf_ErrMsg( "vout error: I420_RGB16 unimplemented, "
109 "please harass sam@zoy.org" );
115 i_scale_count = ( i_vscale == 1 ) ?
116 p_vout->output.i_height : p_vout->render.i_height;
117 for( i_y = 0; i_y < p_vout->render.i_height; i_y++ )
120 p_buffer = b_hscale ? p_buffer_start : p_pic;
122 for ( i_x = p_vout->render.i_width / 8; i_x--; )
124 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
126 #elif defined (MODULE_NAME_IS_chroma_i420_rgb_mmx)
128 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
134 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
143 /* Here we do some unaligned reads and duplicate conversions, but
144 * at least we have all the pixels */
148 p_u -= i_rewind >> 1;
149 p_v -= i_rewind >> 1;
150 p_buffer -= i_rewind;
151 #if defined (MODULE_NAME_IS_chroma_i420_rgb)
153 #elif defined (MODULE_NAME_IS_chroma_i420_rgb_mmx)
155 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
161 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
170 SCALE_HEIGHT( 420, 2 );
174 /*****************************************************************************
175 * I420_RGB24: color YUV 4:2:0 to RGB 24 bpp
176 *****************************************************************************/
177 void _M( I420_RGB24 )( vout_thread_t *p_vout, picture_t *p_src,
180 intf_ErrMsg( "vout error: I420_RGB24 unimplemented, "
181 "please harass sam@zoy.org" );
184 /*****************************************************************************
185 * I420_RGB32: color YUV 4:2:0 to RGB 32 bpp
186 *****************************************************************************/
187 void _M( I420_RGB32 )( vout_thread_t *p_vout, picture_t *p_src,
190 intf_ErrMsg( "vout error: I420_RGB32 unimplemented, "
191 "please harass sam@zoy.org" );
194 /* Following functions are local */
196 /*****************************************************************************
197 * SetOffset: build offset array for conversion functions
198 *****************************************************************************
199 * This function will build an offset array used in later conversion functions.
200 * It will also set horizontal and vertical scaling indicators.
201 *****************************************************************************/
202 static void SetOffset( int i_width, int i_height, int i_pic_width,
203 int i_pic_height, boolean_t *pb_hscale,
204 int *pi_vscale, int *p_offset )
206 int i_x; /* x position in destination */
207 int i_scale_count; /* modulo counter */
210 * Prepare horizontal offset array
212 if( i_pic_width - i_width == 0 )
214 /* No horizontal scaling: YUV conversion is done directly to picture */
217 else if( i_pic_width - i_width > 0 )
219 /* Prepare scaling array for horizontal extension */
221 i_scale_count = i_pic_width;
222 for( i_x = i_width; i_x--; )
224 while( (i_scale_count -= i_width) > 0 )
229 i_scale_count += i_pic_width;
232 else /* if( i_pic_width - i_width < 0 ) */
234 /* Prepare scaling array for horizontal reduction */
236 i_scale_count = i_width;
237 for( i_x = i_pic_width; i_x--; )
240 while( (i_scale_count -= i_pic_width) > 0 )
245 i_scale_count += i_width;
250 * Set vertical scaling indicator
252 if( i_pic_height - i_height == 0 )
256 else if( i_pic_height - i_height > 0 )
260 else /* if( i_pic_height - i_height < 0 ) */