1 /*****************************************************************************
2 * i420_rgb.h : YUV to bitmap RGB conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000 VideoLAN
5 * $Id: i420_rgb.h,v 1.1 2002/08/04 17:23:43 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 /*****************************************************************************
25 * chroma_sys_t: chroma method descriptor
26 *****************************************************************************
27 * This structure is part of the chroma transformation descriptor, it
28 * describes the yuv2rgb specific properties.
29 *****************************************************************************/
35 #ifdef MODULE_NAME_IS_i420_rgb
36 /* Pre-calculated conversion tables */
37 void *p_base; /* base for all conversion tables */
38 u8 *p_rgb8; /* RGB 8 bits table */
39 u16 *p_rgb16; /* RGB 16 bits table */
40 u32 *p_rgb32; /* RGB 32 bits table */
44 /*****************************************************************************
46 *****************************************************************************/
47 #ifdef MODULE_NAME_IS_i420_rgb
48 void E_(I420_RGB8) ( vout_thread_t *, picture_t *, picture_t * );
50 void E_(I420_RGB15)( vout_thread_t *, picture_t *, picture_t * );
51 void E_(I420_RGB16)( vout_thread_t *, picture_t *, picture_t * );
52 void E_(I420_RGB32)( vout_thread_t *, picture_t *, picture_t * );
54 /*****************************************************************************
55 * CONVERT_*_PIXEL: pixel conversion macros
56 *****************************************************************************
57 * These conversion routines are used by YUV conversion functions.
58 * conversion are made from p_y, p_u, p_v, which are modified, to p_buffer,
59 * which is also modified. CONVERT_4YUV_PIXEL is used for 8bpp dithering,
60 * CONVERT_4YUV_PIXEL_SCALE does the same but also scales the output.
61 *****************************************************************************/
62 #define CONVERT_Y_PIXEL( BPP ) \
63 /* Only Y sample is present */ \
64 p_ybase = p_yuv + *p_y++; \
65 *p_buffer++ = p_ybase[RED_OFFSET-((V_RED_COEF*128)>>SHIFT) + i_red] | \
66 p_ybase[GREEN_OFFSET-(((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) \
67 + i_green ] | p_ybase[BLUE_OFFSET-((U_BLUE_COEF*128)>>SHIFT) + i_blue];
69 #define CONVERT_YUV_PIXEL( BPP ) \
70 /* Y, U and V samples are present */ \
73 i_red = (V_RED_COEF * i_vval) >> SHIFT; \
74 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT; \
75 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT; \
76 CONVERT_Y_PIXEL( BPP ) \
78 #define CONVERT_4YUV_PIXEL( CHROMA ) \
79 *p_pic++ = p_lookup[ \
80 (((*p_y++ + dither10[i_real_y]) >> 4) << 7) \
81 + ((*p_u + dither20[i_real_y]) >> 5) * 9 \
82 + ((*p_v + dither20[i_real_y]) >> 5) ]; \
83 *p_pic++ = p_lookup[ \
84 (((*p_y++ + dither11[i_real_y]) >> 4) << 7) \
85 + ((*p_u++ + dither21[i_real_y]) >> 5) * 9 \
86 + ((*p_v++ + dither21[i_real_y]) >> 5) ]; \
87 *p_pic++ = p_lookup[ \
88 (((*p_y++ + dither12[i_real_y]) >> 4) << 7) \
89 + ((*p_u + dither22[i_real_y]) >> 5) * 9 \
90 + ((*p_v + dither22[i_real_y]) >> 5) ]; \
91 *p_pic++ = p_lookup[ \
92 (((*p_y++ + dither13[i_real_y]) >> 4) << 7) \
93 + ((*p_u++ + dither23[i_real_y]) >> 5) * 9 \
94 + ((*p_v++ + dither23[i_real_y]) >> 5) ]; \
96 #define CONVERT_4YUV_PIXEL_SCALE( CHROMA ) \
97 *p_pic++ = p_lookup[ \
98 ( ((*p_y + dither10[i_real_y]) >> 4) << 7) \
99 + ((*p_u + dither20[i_real_y]) >> 5) * 9 \
100 + ((*p_v + dither20[i_real_y]) >> 5) ]; \
101 p_y += *p_offset++; \
103 p_v += *p_offset++; \
104 *p_pic++ = p_lookup[ \
105 ( ((*p_y + dither11[i_real_y]) >> 4) << 7) \
106 + ((*p_u + dither21[i_real_y]) >> 5) * 9 \
107 + ((*p_v + dither21[i_real_y]) >> 5) ]; \
108 p_y += *p_offset++; \
110 p_v += *p_offset++; \
111 *p_pic++ = p_lookup[ \
112 ( ((*p_y + dither12[i_real_y]) >> 4) << 7) \
113 + ((*p_u + dither22[i_real_y]) >> 5) * 9 \
114 + ((*p_v + dither22[i_real_y]) >> 5) ]; \
115 p_y += *p_offset++; \
117 p_v += *p_offset++; \
118 *p_pic++ = p_lookup[ \
119 ( ((*p_y + dither13[i_real_y]) >> 4) << 7) \
120 + ((*p_u + dither23[i_real_y]) >> 5) * 9 \
121 + ((*p_v + dither23[i_real_y]) >> 5) ]; \
122 p_y += *p_offset++; \
124 p_v += *p_offset++; \
126 /*****************************************************************************
127 * SCALE_WIDTH: scale a line horizontally
128 *****************************************************************************
129 * This macro scales a line using rendering buffer and offset array. It works
130 * for 1, 2 and 4 Bpp.
131 *****************************************************************************/
132 #define SCALE_WIDTH \
135 /* Horizontal scaling, conversion has been done to buffer. \
136 * Rewind buffer and offset, then copy and scale line */ \
137 p_buffer = p_buffer_start; \
138 p_offset = p_offset_start; \
139 for( i_x = p_vout->output.i_width / 16; i_x--; ) \
141 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
142 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
143 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
144 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
145 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
146 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
147 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
148 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
149 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
150 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
151 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
152 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
153 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
154 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
155 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
156 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
158 for( i_x = p_vout->output.i_width & 15; i_x--; ) \
160 *p_pic++ = *p_buffer; p_buffer += *p_offset++; \
162 p_pic += i_right_margin; \
166 /* No scaling, conversion has been done directly in picture memory. \
167 * Increment of picture pointer to end of line is still needed */ \
168 (u8*)p_pic += p_dest->p->i_pitch; \
171 /*****************************************************************************
172 * SCALE_WIDTH_DITHER: scale a line horizontally for dithered 8 bpp
173 *****************************************************************************
174 * This macro scales a line using an offset array.
175 *****************************************************************************/
176 #define SCALE_WIDTH_DITHER( CHROMA ) \
179 /* Horizontal scaling - we can't use a buffer due to dithering */ \
180 p_offset = p_offset_start; \
181 for( i_x = p_vout->output.i_width / 16; i_x--; ) \
183 CONVERT_4YUV_PIXEL_SCALE( CHROMA ) \
184 CONVERT_4YUV_PIXEL_SCALE( CHROMA ) \
185 CONVERT_4YUV_PIXEL_SCALE( CHROMA ) \
186 CONVERT_4YUV_PIXEL_SCALE( CHROMA ) \
191 for( i_x = p_vout->render.i_width / 16; i_x--; ) \
193 CONVERT_4YUV_PIXEL( CHROMA ) \
194 CONVERT_4YUV_PIXEL( CHROMA ) \
195 CONVERT_4YUV_PIXEL( CHROMA ) \
196 CONVERT_4YUV_PIXEL( CHROMA ) \
199 /* Increment of picture pointer to end of line is still needed */ \
200 p_pic += i_right_margin; \
202 /* Increment the Y coordinate in the matrix, modulo 4 */ \
203 i_real_y = (i_real_y + 1) & 0x3; \
205 /*****************************************************************************
206 * SCALE_HEIGHT: handle vertical scaling
207 *****************************************************************************
208 * This macro handle vertical scaling for a picture. CHROMA may be 420, 422 or
209 * 444 for RGB conversion, or 400 for gray conversion. It works for 1, 2, 3
211 *****************************************************************************/
212 #define SCALE_HEIGHT( CHROMA, BPP ) \
213 /* If line is odd, rewind 4:2:0 U and V samples */ \
214 if( ((CHROMA == 420) || (CHROMA == 422)) && !(i_y & 0x1) ) \
216 p_u -= i_chroma_width; \
217 p_v -= i_chroma_width; \
221 * Handle vertical scaling. The current line can be copied or next one \
226 case -1: /* vertical scaling factor is < 1 */ \
227 while( (i_scale_count -= p_vout->output.i_height) > 0 ) \
229 /* Height reduction: skip next source line */ \
230 p_y += p_vout->render.i_width; \
232 if( (CHROMA == 420) || (CHROMA == 422) ) \
236 p_u += i_chroma_width; \
237 p_v += i_chroma_width; \
240 else if( CHROMA == 444 ) \
242 p_u += p_vout->render.i_width; \
243 p_v += p_vout->render.i_width; \
246 i_scale_count += p_vout->render.i_height; \
248 case 1: /* vertical scaling factor is > 1 */ \
249 while( (i_scale_count -= p_vout->render.i_height) > 0 ) \
251 /* Height increment: copy previous picture line */ \
252 p_vout->p_vlc->pf_memcpy( p_pic, p_pic_start, \
253 p_vout->output.i_width * BPP ); \
254 (u8*)p_pic += p_dest->p->i_pitch; \
256 i_scale_count += p_vout->output.i_height; \
260 /*****************************************************************************
261 * SCALE_HEIGHT_DITHER: handle vertical scaling for dithered 8 bpp
262 *****************************************************************************
263 * This macro handles vertical scaling for a picture. CHROMA may be 420,
264 * 422 or 444 for RGB conversion, or 400 for gray conversion.
265 *****************************************************************************/
266 #define SCALE_HEIGHT_DITHER( CHROMA ) \
268 /* If line is odd, rewind 4:2:0 U and V samples */ \
269 if( ((CHROMA == 420) || (CHROMA == 422)) && !(i_y & 0x1) ) \
271 p_u -= i_chroma_width; \
272 p_v -= i_chroma_width; \
276 * Handle vertical scaling. The current line can be copied or next one \
282 case -1: /* vertical scaling factor is < 1 */ \
283 while( (i_scale_count -= p_vout->output.i_height) > 0 ) \
285 /* Height reduction: skip next source line */ \
286 p_y += p_vout->render.i_width; \
288 if( (CHROMA == 420) || (CHROMA == 422) ) \
292 p_u += i_chroma_width; \
293 p_v += i_chroma_width; \
296 else if( CHROMA == 444 ) \
298 p_u += p_vout->render.i_width; \
299 p_v += p_vout->render.i_width; \
302 i_scale_count += p_vout->render.i_height; \
304 case 1: /* vertical scaling factor is > 1 */ \
305 while( (i_scale_count -= p_vout->render.i_height) > 0 ) \
307 p_y -= p_vout->render.i_width; \
308 p_u -= i_chroma_width; \
309 p_v -= i_chroma_width; \
310 SCALE_WIDTH_DITHER( CHROMA ); \
312 i_scale_count += p_vout->output.i_height; \