]> git.sesse.net Git - vlc/blob - src/video_output/video_yuv.c
Scaling horizontal >=1
[vlc] / src / video_output / video_yuv.c
1 /*******************************************************************************
2  * video_yuv.c: YUV transformation functions
3  * (c)1999 VideoLAN
4  *******************************************************************************
5  * Provides functions to perform the YUV conversion. The functions provided here
6  * are a complete and portable C implementation, and may be replaced in certain
7  * case by optimized functions.
8  *******************************************************************************/
9
10 /*******************************************************************************
11  * Preamble
12  *******************************************************************************/
13 #include <math.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <stdlib.h>
17
18 #include "common.h"
19 #include "config.h"
20 #include "mtime.h"
21 #include "vlc_thread.h"
22 #include "video.h"
23 #include "video_output.h"
24 #include "video_yuv.h"
25 #include "intf_msg.h"
26
27 /*******************************************************************************
28  * Constants
29  *******************************************************************************/
30
31 /* RGB/YUV inversion matrix (ISO/IEC 13818-2 section 6.3.6, table 6.9) */
32 const int MATRIX_COEFFICIENTS_TABLE[8][4] =
33 {
34   {117504, 138453, 13954, 34903},       /* no sequence_display_extension */
35   {117504, 138453, 13954, 34903},       /* ITU-R Rec. 709 (1990) */
36   {104597, 132201, 25675, 53279},       /* unspecified */
37   {104597, 132201, 25675, 53279},       /* reserved */
38   {104448, 132798, 24759, 53109},       /* FCC */
39   {104597, 132201, 25675, 53279},       /* ITU-R Rec. 624-4 System B, G */
40   {104597, 132201, 25675, 53279},       /* SMPTE 170M */
41   {117579, 136230, 16907, 35559}        /* SMPTE 240M (1987) */
42 };
43
44 #define SHIFT 20
45 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
46 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
47 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
48 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
49
50 /*******************************************************************************
51  * Local prototypes
52  *******************************************************************************/
53 static int      BinaryLog         ( u32 i );
54 static void     MaskToShift       ( int *pi_right, int *pi_left, u32 i_mask );
55 static void     SetGammaTable     ( int *pi_table, double f_gamma );
56 static void     SetYUV            ( vout_thread_t *p_vout );
57
58 static void     ConvertY4Gray16   ( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
59                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
60                                     int i_matrix_coefficients );
61 static void     ConvertY4Gray24   ( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
62                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
63                                     int i_matrix_coefficients );
64 static void     ConvertY4Gray32   ( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
65                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
66                                     int i_matrix_coefficients );
67 static void     ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
68                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
69                                     int i_matrix_coefficients );
70 static void     ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
71                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
72                                     int i_matrix_coefficients );
73 static void     ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
74                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
75                                     int i_matrix_coefficients );
76 static void     ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
77                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
78                                     int i_matrix_coefficients );
79 static void     ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
80                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
81                                     int i_matrix_coefficients );
82 static void     ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
83                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
84                                     int i_matrix_coefficients );
85 static void     ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
86                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
87                                     int i_matrix_coefficients );
88 static void     ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
89                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
90                                     int i_matrix_coefficients );
91 static void     ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
92                                     int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
93                                     int i_matrix_coefficients );
94
95 /*******************************************************************************
96  * CLIP_BYTE macro: boundary detection
97  *******************************************************************************
98  * Return parameter if between 0 and 255, else return nearest boundary (0 or 
99  * 255). This macro is used to build translations tables.
100  *******************************************************************************/
101 #define CLIP_BYTE( i_val ) ( (i_val < 0) ? 0 : ((i_val > 255) ? 255 : i_val) )
102
103 /*******************************************************************************
104  * CONVERT_YUV_GRAY macro: grayscale YUV convertion
105  *******************************************************************************
106  * This macro does not perform any scaling, but crops the picture. It is
107  * provided as a temporary way of implementing an YUV convertion function.
108  *******************************************************************************/
109 #define CONVERT_YUV_GRAY                                                \
110 /* Change boundaries according to picture size */                       \
111 i_width =               MIN( i_width, i_pic_width );                    \
112 i_height =              MIN( i_height, i_pic_height );                  \
113 i_pic_line_width -=     i_width;                                        \
114                                                                         \
115 /* Loop */                                                              \
116 for (i_y = 0; i_y < i_height ; i_y++)                                   \
117 {                                                                       \
118     for (i_x = 0; i_x < i_width; )                                      \
119     {                                                                   \
120         /* Convert 16 pixels (width is always multiple of 16 */         \
121         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
122         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
123         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
124         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
125         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
126         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
127         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
128         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
129         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
130         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
131         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
132         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
133         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
134         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
135         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
136         p_pic[i_x++] = p_gray[ p_y[i_x] ];                              \
137     }                                                                   \
138                                                                         \
139     /* Skip until beginning of next line */                             \
140     p_pic += i_pic_line_width;                                          \
141 }
142
143 /*******************************************************************************
144  * CONVERT_YUV_RGB: color YUV convertion
145  *******************************************************************************
146  * This macro does not perform any scaling, but crops the picture. It is
147  * provided as a temporary way of implementing an YUV convertion function.
148  *******************************************************************************/
149 #define CONVERT_YUV_RGB( CHROMA, CRV, CGV, CBU, CGU )                   \
150 /* Change boundaries according to picture size */                       \
151 i_width =               MIN( i_width, i_pic_width );                    \
152 i_height =              MIN( i_height, i_pic_height );                  \
153 i_chroma_width =        (CHROMA == 444) ? i_width : i_width / 2;        \
154 i_pic_line_width -=     i_width;                                        \
155                                                                         \
156 /* Loop */                                                              \
157 for (i_y = 0; i_y < i_height ; i_y++)                                   \
158 {                                                                       \
159     for (i_x = 0; i_x < i_width; )                                      \
160     {                                                                   \
161         /* First sample (complete) */                                   \
162         i_yval = 76309 * p_y[i_x] - 1188177;                            \
163         i_uval = *p_u++ - 128;                                          \
164         i_vval = *p_v++ - 128;                                          \
165         p_pic[i_x++] =                                                  \
166             p_red  [(i_yval+CRV*i_vval)              >>16] |            \
167             p_green[(i_yval-CGU*i_uval-CGV*i_vval)   >>16] |            \
168             p_blue [(i_yval+CBU*i_uval)              >>16];             \
169         i_yval = 76309 * p_y[i_x] - 1188177;                            \
170         /* Second sample (partial) */                                   \
171         if( CHROMA == 444 )                                             \
172         {                                                               \
173             i_uval = *p_u++ - 128;                                      \
174             i_vval = *p_v++ - 128;                                      \
175         }                                                               \
176         p_pic[i_x++] =                                                  \
177             p_red  [(i_yval+CRV*i_vval)              >>16] |            \
178             p_green[(i_yval-CGU*i_uval-CGV*i_vval)   >>16] |            \
179             p_blue [(i_yval+CBU*i_uval)              >>16];             \
180     }                                                                   \
181                                                                         \
182     /* Rewind in 4:2:0 */                                               \
183     if( (CHROMA == 420) && !(i_y & 0x1) )                               \
184     {                                                                   \
185         p_u -= i_chroma_width;                                          \
186         p_v -= i_chroma_width;                                          \
187     }                                                                   \
188                                                                         \
189     /* Skip until beginning of next line */                             \
190     p_pic += i_pic_line_width;                                          \
191 }
192
193 /*******************************************************************************
194  * CONVERT_YUV_PIXEL, CONVERT_Y_PIXEL: pixel convertion blocks
195  *******************************************************************************
196  * These convertion routines are used by YUV convertion functions.
197  * Convertion are made from p_y, p_u, p_v, which are modified, to i_dst. ??
198  *******************************************************************************/
199 #define CONVERT_Y_PIXEL                                                         \
200     /* Only Y sample is present */                                              \
201     p_ybase = p_yuv + *(p_y++);                                                 \
202     *p_pic++ = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |              \
203         p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |  \
204         p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];                     \
205
206 #define CONVERT_YUV_PIXEL                                                       \
207     /* Y, U and V samples are present */                                        \
208     i_uval =    *p_u++;                                                         \
209     i_vval =    *p_v++;                                                         \
210     i_red =     (V_RED_COEF * i_vval) >> SHIFT;                                 \
211     i_green =   (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;       \
212     i_blue =    (U_BLUE_COEF * i_uval) >> SHIFT;                                \
213     CONVERT_Y_PIXEL                                                             \
214
215 #define COPY_PIXEL                                                              \
216     /* Pixel may be copied, but only once */                                    \
217     while( (i_width_count -= i_width) > 0 )                                     \
218     {                                                                           \
219         *p_pic++ = *(p_pic - 1);                                                \
220     }                                                                           \
221     i_width_count += i_pic_width;                                               \
222
223 /*******************************************************************************
224  * vout_InitYUV: allocate and initialize translations tables
225  *******************************************************************************
226  * This function will allocate memory to store translation tables, depending
227  * of the screen depth.
228  *******************************************************************************/
229 int vout_InitYUV( vout_thread_t *p_vout )
230 {
231     size_t      tables_size;                          /* tables size, in bytes */
232     
233     /* Computes tables size */
234     switch( p_vout->i_screen_depth )
235     {
236     case 15:
237     case 16:
238         tables_size = sizeof( u16 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
239         break;        
240     case 24:        
241     case 32:
242 #ifndef DEBUG
243     default:        
244 #endif
245         tables_size = sizeof( u32 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);        
246         break;        
247 #ifdef DEBUG
248     default:
249         intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
250         tables_size = 0;
251         break;        
252 #endif      
253     }
254
255     /* Add conversion buffer size. The conversions functions need one comple line
256      * plus one pixel, so we give them two. */
257     tables_size += p_vout->i_bytes_per_line * 2;    
258     
259     /* Allocate memory */
260     p_vout->yuv.p_base = malloc( tables_size );
261     if( p_vout->yuv.p_base == NULL )
262     {
263         intf_ErrMsg("error: %s\n", strerror(ENOMEM));
264         return( 1 );                
265     }
266
267     /* Initialize tables */
268     SetYUV( p_vout );    
269     return( 0 );    
270 }
271
272 /*******************************************************************************
273  * vout_ResetTables: re-initialize translations tables
274  *******************************************************************************
275  * This function will initialize the tables allocated by vout_CreateTables and
276  * set functions pointers.
277  *******************************************************************************/
278 int vout_ResetYUV( vout_thread_t *p_vout )
279 {
280     vout_EndYUV( p_vout );    
281     return( vout_InitYUV( p_vout ) );    
282 }
283
284 /*******************************************************************************
285  * vout_EndYUV: destroy translations tables
286  *******************************************************************************
287  * Free memory allocated by vout_CreateTables.
288  *******************************************************************************/
289 void vout_EndYUV( vout_thread_t *p_vout )
290 {
291     free( p_vout->yuv.p_base );
292 }
293
294 /* following functions are local */
295
296 /*******************************************************************************
297  * BinaryLog: computes the base 2 log of a binary value
298  *******************************************************************************
299  * This functions is used by MaskToShift during tables initialisation, to
300  * get a bit index from a binary value.
301  *******************************************************************************/
302 static int BinaryLog(u32 i)
303 {
304     int i_log;
305
306     i_log = 0;
307     if (i & 0xffff0000) 
308     {        
309         i_log = 16;
310     }    
311     if (i & 0xff00ff00) 
312     {        
313         i_log += 8;
314     }    
315     if (i & 0xf0f0f0f0) 
316     {        
317         i_log += 4;
318     }    
319     if (i & 0xcccccccc) 
320     {        
321         i_log += 2;
322     }    
323     if (i & 0xaaaaaaaa) 
324     {        
325         i_log++;
326     }    
327     if (i != ((u32)1 << i_log))
328     {        
329         intf_ErrMsg("internal error: binary log overflow\n");        
330     }    
331
332     return( i_log );
333 }
334
335 /*******************************************************************************
336  * MaskToShift: Transform a color mask into right and left shifts
337  *******************************************************************************
338  * This function is used during table initialisation. It can return a value
339  *******************************************************************************/
340 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
341 {
342     u32 i_low, i_high;                   /* lower hand higher bits of the mask */
343
344     /* Get bits */
345     i_low =  i_mask & (- i_mask);                     /* lower bit of the mask */
346     i_high = i_mask + i_low;                         /* higher bit of the mask */
347
348     /* Transform bits into an index */
349     i_low =  BinaryLog (i_low);
350     i_high = BinaryLog (i_high);
351
352     /* Update pointers and return */
353     *pi_left =   i_low;
354     *pi_right = (8 - i_high + i_low);
355 }
356
357 /*******************************************************************************
358  * SetGammaTable: return intensity table transformed by gamma curve.
359  *******************************************************************************
360  * pi_table is a table of 256 entries from 0 to 255.
361  *******************************************************************************/
362 static void SetGammaTable( int *pi_table, double f_gamma )
363 {
364     int         i_y;                                         /* base intensity */
365
366     /* Use exp(gamma) instead of gamma */
367     f_gamma = exp(f_gamma );
368
369     /* Build gamma table */
370     for( i_y = 0; i_y < 256; i_y++ )
371     {
372         pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
373     }
374  }
375
376 /*******************************************************************************
377  * SetYUV: compute tables and set function pointers
378 + *******************************************************************************/
379 static void SetYUV( vout_thread_t *p_vout )
380 {
381     int         pi_gamma[256];                                  /* gamma table */    
382     int         i_index;                                    /* index in tables */
383     int         i_red_right, i_red_left;                         /* red shifts */
384     int         i_green_right, i_green_left;                   /* green shifts */
385     int         i_blue_right, i_blue_left;                      /* blue shifts */
386
387     /* Build gamma table */    
388     SetGammaTable( pi_gamma, p_vout->f_gamma );
389     
390     /*          
391      * Set color masks and shifts
392      */
393     switch( p_vout->i_screen_depth )
394     {
395     case 15:
396         MaskToShift( &i_red_right,   &i_red_left,   0xf800 );
397         MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
398         MaskToShift( &i_blue_right,  &i_blue_left,  0x001f );        
399         break;        
400     case 16:
401         MaskToShift( &i_red_right,   &i_red_left,   0xf800 );
402         MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
403         MaskToShift( &i_blue_right,  &i_blue_left,  0x001f );
404         break;        
405     case 24:
406     case 32:        
407         MaskToShift( &i_red_right,   &i_red_left,   0x00ff0000 );
408         MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
409         MaskToShift( &i_blue_right,  &i_blue_left,  0x000000ff );
410         break;
411 #ifdef DEBUG
412     default:
413         intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
414         break;        
415 #endif      
416     }
417
418     /*
419      * Set pointers and build YUV tables
420      */        
421     if( p_vout->b_grayscale )
422     {
423         /* Grayscale: build gray table */
424         switch( p_vout->i_screen_depth )
425         {
426         case 15:
427         case 16:         
428             p_vout->yuv.yuv.gray16.p_gray =  (u16 *)p_vout->yuv.p_base + 384;
429             for( i_index = -384; i_index < 640; i_index++) 
430             {
431                 p_vout->yuv.yuv.gray16.p_gray[ i_index ] = 
432                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right)   << i_red_left)   |
433                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
434                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right)  << i_blue_left);
435             }
436             break;        
437         case 24:
438         case 32:        
439             p_vout->yuv.yuv.gray32.p_gray =  (u32 *)p_vout->yuv.p_base + 384;
440             for( i_index = -384; i_index < 640; i_index++) 
441             {
442                 p_vout->yuv.yuv.gray32.p_gray[ i_index ] = 
443                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right)   << i_red_left)   |
444                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
445                     ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right)  << i_blue_left);
446             }        
447             break;        
448         }
449     }
450     else
451     {
452         /* Color: build red, green and blue tables */
453         switch( p_vout->i_screen_depth )
454         {
455         case 15:
456         case 16:            
457             p_vout->yuv.yuv.rgb16.p_red =    (u16 *)p_vout->yuv.p_base +          384;
458             p_vout->yuv.yuv.rgb16.p_green =  (u16 *)p_vout->yuv.p_base +   1024 + 384;
459             p_vout->yuv.yuv.rgb16.p_blue =   (u16 *)p_vout->yuv.p_base + 2*1024 + 384;
460             p_vout->yuv.yuv2.p_rgb16 =       (u16 *)p_vout->yuv.p_base + 3*1024;
461             p_vout->yuv.p_buffer =           (u16 *)p_vout->yuv.p_base + 3*1024 + 1935;            
462             for( i_index = -384; i_index < 640; i_index++) 
463             {
464                 p_vout->yuv.yuv.rgb16.p_red[i_index] =   (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
465                 p_vout->yuv.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
466                 p_vout->yuv.yuv.rgb16.p_blue[i_index] =  (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
467             }
468             for( i_index = 0; i_index < 178; i_index++ )
469             {
470                 p_vout->yuv.yuv2.p_rgb16[1501 - 178 + i_index] = (pi_gamma[0]>>i_red_right)<<i_red_left;
471                 p_vout->yuv.yuv2.p_rgb16[1501 + 256 + i_index] = (pi_gamma[255]>>i_red_right)<<i_red_left;                
472             }
473             for( i_index = 0; i_index < 135; i_index++ )
474             {
475                 p_vout->yuv.yuv2.p_rgb16[135 - 135 + i_index] = (pi_gamma[0]>>i_green_right)<<i_green_left;
476                 p_vout->yuv.yuv2.p_rgb16[135 + 256 + i_index] = (pi_gamma[255]>>i_green_right)<<i_green_left;
477             }
478             for( i_index = 0; i_index < 224; i_index++ )
479             {
480                 p_vout->yuv.yuv2.p_rgb16[818 - 224 + i_index] = (pi_gamma[0]>>i_blue_right)<<i_blue_left;
481                 p_vout->yuv.yuv2.p_rgb16[818 + 256 + i_index] = (pi_gamma[255]>>i_blue_right)<<i_blue_left;                
482             }
483             for( i_index = 0; i_index < 256; i_index++ )
484             {
485                 p_vout->yuv.yuv2.p_rgb16[1501 + i_index] = (pi_gamma[i_index]>>i_red_right)<<i_red_left;
486                 p_vout->yuv.yuv2.p_rgb16[135 + i_index] = (pi_gamma[i_index]>>i_green_right)<<i_green_left;
487                 p_vout->yuv.yuv2.p_rgb16[818 + i_index] = (pi_gamma[i_index]>>i_blue_right)<<i_blue_left;
488             }            
489             break;        
490         case 24:
491         case 32:
492             p_vout->yuv.yuv.rgb32.p_red =    (u32 *)p_vout->yuv.p_base +          384;
493             p_vout->yuv.yuv.rgb32.p_green =  (u32 *)p_vout->yuv.p_base +   1024 + 384;
494             p_vout->yuv.yuv.rgb32.p_blue =   (u32 *)p_vout->yuv.p_base + 2*1024 + 384;
495             p_vout->yuv.yuv2.p_rgb32 =       (u32 *)p_vout->yuv.p_base + 3*1024;
496             p_vout->yuv.p_buffer =           (u32 *)p_vout->yuv.p_base + 3*1024 + 1935;            
497             for( i_index = -384; i_index < 640; i_index++) 
498             {
499                 p_vout->yuv.yuv.rgb32.p_red[i_index] =   (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
500                 p_vout->yuv.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
501                 p_vout->yuv.yuv.rgb32.p_blue[i_index] =  (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
502             }
503             //?? walken's yuv
504             break;        
505         }
506     }    
507
508     /*
509      * Set functions pointers
510      */
511     if( p_vout->b_grayscale )
512     {
513         /* Grayscale */
514         switch( p_vout->i_screen_depth )
515         {
516         case 15:
517         case 16:  
518             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;        
519             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;        
520             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;        
521             break;        
522         case 24:
523             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;        
524             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;        
525             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;        
526             break;        
527         case 32:        
528             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;        
529             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;        
530             p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;        
531             break;        
532         }        
533     }
534     else
535     {
536         /* Color */
537         switch( p_vout->i_screen_depth )
538         {
539         case 15:
540         case 16:  
541             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertYUV420RGB16;        
542             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertYUV422RGB16;        
543             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertYUV444RGB16;        
544             break;        
545         case 24:
546             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertYUV420RGB24;        
547             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertYUV422RGB24;        
548             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertYUV444RGB24;        
549             break;        
550         case 32:        
551             p_vout->yuv.p_Convert420 =   (vout_yuv_convert_t *) ConvertYUV420RGB32;        
552             p_vout->yuv.p_Convert422 =   (vout_yuv_convert_t *) ConvertYUV422RGB32;        
553             p_vout->yuv.p_Convert444 =   (vout_yuv_convert_t *) ConvertYUV444RGB32;        
554             break;        
555         }
556     }        
557 }
558
559 /*******************************************************************************
560  * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
561  *******************************************************************************/
562 static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
563                              int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
564                              int i_matrix_coefficients )
565 {
566     u16 *       p_gray;                                          /* gray table */    
567     int         i_x, i_y;                               /* picture coordinates */
568     
569     p_gray = p_vout->yuv.yuv.gray16.p_gray;
570     CONVERT_YUV_GRAY
571 }
572
573 /*******************************************************************************
574  * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
575  *******************************************************************************/
576 static void ConvertY4Gray24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
577                              int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
578                              int i_matrix_coefficients )
579 {
580     //??
581 }
582
583 /*******************************************************************************
584  * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
585  *******************************************************************************/
586 static void ConvertY4Gray32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
587                              int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
588                              int i_matrix_coefficients )
589 {
590     u32 *       p_gray;                                          /* gray table */    
591     int         i_x, i_y;                               /* picture coordinates */
592     
593     p_gray = p_vout->yuv.yuv.gray32.p_gray;
594     CONVERT_YUV_GRAY
595 }
596
597 /*******************************************************************************
598  * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
599  *******************************************************************************/
600 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
601                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
602                                 int i_matrix_coefficients )
603 {
604 /* MMX version */
605   //  int                 i_chroma_width, i_chroma_skip;      /* width and eol for chroma */
606 /*
607     i_chroma_width =    i_width / 2;
608     i_chroma_skip =     i_skip / 2;
609     ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height, 
610                            (i_width + i_skip) * sizeof( yuv_data_t ), 
611                            (i_chroma_width + i_chroma_skip) * sizeof( yuv_data_t),
612                            i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
613                            p_vout->i_screen_depth == 15 );    
614 */
615
616 #if 0
617     u16 *       p_red;                                            /* red table */
618     u16 *       p_green;                                        /* green table */
619     u16 *       p_blue;                                          /* blue table */
620     int         i_uval, i_yval, i_vval;                             /* samples */   
621     int         i_x, i_y;                               /* picture coordinates */
622     int         i_chroma_width, i_chroma_skip;     /* width and eol for chroma */
623     int         i_crv, i_cbu, i_cgu, i_cgv;     /* transformation coefficients */
624
625     p_red   = p_vout->yuv.yuv.rgb16.p_red;
626     p_green = p_vout->yuv.yuv.rgb16.p_green;
627     p_blue  = p_vout->yuv.yuv.rgb16.p_blue;
628     i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
629     i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
630     i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
631     i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
632     
633     CONVERT_YUV_RGB( 420, i_crv, i_cgv, i_cbu, i_cgu );        
634 #else
635     int         i_horizontal_scaling;               /* horizontal scaling type */
636     int         i_vertical_scaling;                   /* vertical scaling type */
637     int         i_x, i_y;                   /* horizontal and vertical indexes */
638     int         i_uval, i_vval;                             /* U and V samples */
639     int         i_red, i_green, i_blue;            /* U and V modified samples */
640     int         i_chroma_width;                                /* chroma width */
641     int         i_width_count;                         /* width modulo counter */    
642     int         i_height_count;                       /* height modulo counter */
643     u16 *       p_yuv;                                /* base convertion table */
644     u16 *       p_ybase;                       /* Y dependant convertion table */   
645     u16 *       p_pic_start;                  /* beginning of the current line */
646     
647     /* Initialize values */
648     i_height_count =    i_pic_height;
649     i_chroma_width =    i_width / 2;
650     p_yuv =             p_vout->yuv.yuv2.p_rgb16;
651
652     /* Set scalings */
653     if( i_pic_width - i_width > 0 )
654     {
655         i_horizontal_scaling = 1;        
656     }
657     else if( i_pic_width - i_width < 0 )
658     {
659         i_horizontal_scaling = -1;        
660     }
661     else
662     {
663         i_horizontal_scaling = 0;        
664     }
665     if( i_pic_height - i_height > 0 )
666     {
667         i_vertical_scaling = 1;        
668     }
669     else if( i_pic_height - i_height < 0 )
670     {
671         i_vertical_scaling = -1;        
672     }
673     else
674     {
675         i_vertical_scaling = 0;        
676     }
677
678     /*
679      * Perform convertion
680      */
681     i_height_count = i_pic_height;
682     for( i_y = 0; i_y < i_height; i_y++ )
683     {
684         /* Mark beginnning of line */
685         p_pic_start = p_pic;        
686
687         /* Convert line using 16 pixels blocks, since picture come from 16 pixels 
688          * width macroblocks - several loops will be used, depending of the 
689          * scaling type */
690         switch( i_horizontal_scaling )
691         {
692         case 1:                                   /* horizontal scaling is > 1 */
693             i_width_count = i_pic_width;
694             for( i_x = i_width / 16; i_x--; )
695             {
696                 CONVERT_YUV_PIXEL;            
697                 COPY_PIXEL;
698                 CONVERT_Y_PIXEL;
699                 COPY_PIXEL;
700                 CONVERT_YUV_PIXEL;            
701                 COPY_PIXEL;
702                 CONVERT_Y_PIXEL;
703                 COPY_PIXEL;
704                 CONVERT_YUV_PIXEL;            
705                 COPY_PIXEL;
706                 CONVERT_Y_PIXEL;
707                 COPY_PIXEL;
708                 CONVERT_YUV_PIXEL;            
709                 COPY_PIXEL;
710                 CONVERT_Y_PIXEL;
711                 COPY_PIXEL;
712                 CONVERT_YUV_PIXEL;            
713                 COPY_PIXEL;
714                 CONVERT_Y_PIXEL;
715                 COPY_PIXEL;
716                 CONVERT_YUV_PIXEL;            
717                 COPY_PIXEL;
718                 CONVERT_Y_PIXEL;
719                 COPY_PIXEL;
720                 CONVERT_YUV_PIXEL;            
721                 COPY_PIXEL;
722                 CONVERT_Y_PIXEL;
723                 COPY_PIXEL;
724                 CONVERT_YUV_PIXEL;            
725                 COPY_PIXEL;
726                 CONVERT_Y_PIXEL;
727                 COPY_PIXEL;
728             }            
729             break;            
730         case 0:
731             for( i_x = i_width / 16; i_x--;  )
732             {
733                 CONVERT_YUV_PIXEL;            
734                 CONVERT_Y_PIXEL;
735                 CONVERT_YUV_PIXEL;            
736                 CONVERT_Y_PIXEL;
737                 CONVERT_YUV_PIXEL;            
738                 CONVERT_Y_PIXEL;
739                 CONVERT_YUV_PIXEL;            
740                 CONVERT_Y_PIXEL;
741                 CONVERT_YUV_PIXEL;            
742                 CONVERT_Y_PIXEL;
743                 CONVERT_YUV_PIXEL;            
744                 CONVERT_Y_PIXEL;
745                 CONVERT_YUV_PIXEL;            
746                 CONVERT_Y_PIXEL;
747                 CONVERT_YUV_PIXEL;            
748                 CONVERT_Y_PIXEL;
749             }
750             break;            
751         case -1:
752             i_width_count = i_width;            
753 /*            {
754                 while( (i_width_count -= i_pic_width) > 0)
755                 {
756                     p_y++;
757                     p_u++;                    
758                 }
759                 i_width_count += i_width;            
760             }            
761             CONVERT_Y_PIXEL;
762             while( (i_width_count -= i_width) > 0)
763             {
764                 *p_pic++ = *(p_pic - 1);                
765             }
766             i_width_count += i_pic_width;
767             break;            
768   */
769             break;
770         }
771
772         /* If line is odd, rewind U and V samples */
773         if( i_y & 0x1 )
774         {
775             p_u -= i_chroma_width;
776             p_v -= i_chroma_width;
777         }
778
779         /* End of line: skip picture to reach beginning of next line */
780         p_pic += i_pic_line_width - i_pic_width;
781  
782         /* 
783          * Handle vertical scaling. The current line is copied or next one
784          * is ignored.
785          */
786         switch( i_vertical_scaling )
787         {
788         case -1:                         /* vertical scaling factor is < 1 */
789             while( (i_height_count -= i_pic_height) >= 0 )
790             {                
791                 /* Height reduction: skip next source line */
792                 p_y += i_width;
793                 if( ! (++i_y & 0x1) )
794                 {
795                     p_u += i_chroma_width;
796                     p_v += i_chroma_width;
797                 }                
798             }            
799             i_height_count += i_height;
800             break;            
801         case 1:                          /* vertical scaling factor is > 1 */
802             while( (i_height_count -= i_height) > 0 )
803             {                
804                 /* Height increment: copy previous picture line */
805                 for( i_x = i_pic_width / 16; i_x--; )
806                 {
807                     *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
808                     *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
809                     *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
810                     *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
811                 }
812                 p_pic +=        i_pic_line_width - i_pic_width;
813                 p_pic_start +=  i_pic_line_width - i_pic_width;
814             }
815             i_height_count += i_pic_height; 
816             break;
817         }
818     }    
819 #endif
820 }
821
822 /*******************************************************************************
823  * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
824  *******************************************************************************/
825 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
826                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
827                                 int i_matrix_coefficients )
828 {
829     //??
830 }
831
832 /*******************************************************************************
833  * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
834  *******************************************************************************/
835 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
836                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
837                                 int i_matrix_coefficients )
838 {
839     //??
840 }
841
842 /*******************************************************************************
843  * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
844  *******************************************************************************/
845 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
846                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
847                                 int i_matrix_coefficients )
848 {
849     //???
850 }
851
852 /*******************************************************************************
853  * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
854  *******************************************************************************/
855 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
856                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
857                                 int i_matrix_coefficients )
858 {
859     //???
860 }
861
862 /*******************************************************************************
863  * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
864  *******************************************************************************/
865 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
866                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
867                                 int i_matrix_coefficients )
868 {    
869     //???
870 }
871
872 /*******************************************************************************
873  * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
874  *******************************************************************************/
875 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
876                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
877                                 int i_matrix_coefficients )
878 {
879     //??
880 }
881
882 /*******************************************************************************
883  * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
884  *******************************************************************************/
885 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
886                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
887                                 int i_matrix_coefficients )
888 {
889     //??
890 }
891
892 /*******************************************************************************
893  * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
894  *******************************************************************************/
895 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
896                                 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
897                                 int i_matrix_coefficients )
898 {
899     //??
900 }
901
902 //-------------------- walken code follow ---------------------------------------
903
904 /*
905  * YUV to RGB routines.
906  *
907  * these routines calculate r, g and b values from each pixel's y, u and v.
908  * these r, g an b values are then passed thru a table lookup to take the
909  * gamma curve into account and find the corresponding pixel value.
910  *
911  * the table must store more than 3*256 values because of the possibility
912  * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
913  * values are in the following intervals :
914  * -176 to 255+176 for red
915  * -133 to 255+133 for green
916  * -222 to 255+222 for blue
917  *
918  * If the input y,u,v values are right, the r,g,b results are not expected
919  * to move out of the 0 to 255 interval but who knows what will happen in
920  * real use...
921  *
922  * the red, green and blue conversion tables are stored in a single 1935-entry
923  * array. The respective positions of each component in the array have been
924  * calculated to minimize the cache interactions of the 3 tables.
925  */
926
927 static int rgbTable32 (int table [1935],
928                        int redMask, int greenMask, int blueMask,
929                        unsigned char gamma[256])
930 {
931     int redRight;
932     int redLeft;
933     int greenRight;
934     int greenLeft;
935     int blueRight;
936     int blueLeft;
937     int * redTable;
938     int * greenTable;
939     int * blueTable;
940     int i;
941     int y;
942
943     MaskToShift (&redRight, &redLeft, redMask);
944     MaskToShift (&greenRight, &greenLeft, greenMask);
945     MaskToShift (&blueRight, &blueLeft, blueMask);
946     
947
948     /*
949      * green blue red +- 2 just to be sure
950      * green = 0-525 [151-370]
951      * blue = 594-1297 [834-1053] <834-29>
952      * red = 1323-1934 [1517-1736] <493-712>
953      */
954
955     redTable = table + 1501;
956     greenTable = table + 135;
957     blueTable = table + 818;
958
959     for (i = 0; i < 178; i++) {
960         redTable[i-178] = 0;
961         redTable[i+256] = redMask;
962     }
963     for (i = 0; i < 135; i++) {
964         greenTable[i-135] = 0;
965         greenTable[i+256] = greenMask;
966     }
967     for (i = 0; i < 224; i++) {
968         blueTable[i-224] = 0;
969         blueTable[i+256] = blueMask;
970     }
971
972     for (i = 0; i < 256; i++) {
973         y = gamma[i];
974         redTable[i] = ((y >> redRight) << redLeft);
975         greenTable[i] = ((y >> greenRight) << greenLeft);
976         blueTable[i] = ((y >> blueRight) << blueLeft);
977     }
978
979     return 0;
980 }
981
982
983  void yuvToRgb16 (unsigned char * Y,
984                         unsigned char * U, unsigned char * V,
985                         short * dest, short table[1935], int width)
986 {
987     int i;
988     int u;
989     int v;
990     int uvRed;
991     int uvGreen;
992     int uvBlue;
993     short * tableY;
994
995     i = width >> 4;
996     while (i--) {
997         u = *(U++);
998         v = *(V++);
999         uvRed = (V_RED_COEF*v) >> SHIFT;
1000         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1001         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1002
1003         tableY = table + *(Y++);
1004         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1005                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1006                             uvGreen] |
1007                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1008
1009         tableY = table + *(Y++);
1010         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1011                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1012                             uvGreen] |
1013                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1014
1015         u = *(U++);
1016         v = *(V++);
1017         uvRed = (V_RED_COEF*v) >> SHIFT;
1018         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1019         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1020
1021         tableY = table + *(Y++);
1022         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1023                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1024                             uvGreen] |
1025                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1026
1027         tableY = table + *(Y++);
1028         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1029                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1030                             uvGreen] |
1031                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1032
1033         u = *(U++);
1034         v = *(V++);
1035         uvRed = (V_RED_COEF*v) >> SHIFT;
1036         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1037         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1038
1039         tableY = table + *(Y++);
1040         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1041                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1042                             uvGreen] |
1043                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1044
1045         tableY = table + *(Y++);
1046         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1047                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1048                             uvGreen] |
1049                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1050
1051         u = *(U++);
1052         v = *(V++);
1053         uvRed = (V_RED_COEF*v) >> SHIFT;
1054         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1055         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1056
1057         tableY = table + *(Y++);
1058         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1059                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1060                             uvGreen] |
1061                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1062
1063         tableY = table + *(Y++);
1064         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1065                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1066                             uvGreen] |
1067                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1068
1069         u = *(U++);
1070         v = *(V++);
1071         uvRed = (V_RED_COEF*v) >> SHIFT;
1072         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1073         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1074
1075         tableY = table + *(Y++);
1076         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1077                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1078                             uvGreen] |
1079                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1080
1081         tableY = table + *(Y++);
1082         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1083                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1084                             uvGreen] |
1085                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1086
1087         u = *(U++);
1088         v = *(V++);
1089         uvRed = (V_RED_COEF*v) >> SHIFT;
1090         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1091         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1092
1093         tableY = table + *(Y++);
1094         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1095                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1096                             uvGreen] |
1097                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1098
1099         tableY = table + *(Y++);
1100         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1101                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1102                             uvGreen] |
1103                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1104
1105         u = *(U++);
1106         v = *(V++);
1107         uvRed = (V_RED_COEF*v) >> SHIFT;
1108         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1109         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1110
1111         tableY = table + *(Y++);
1112         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1113                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1114                             uvGreen] |
1115                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1116
1117         tableY = table + *(Y++);
1118         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1119                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1120                             uvGreen] |
1121                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1122
1123         u = *(U++);
1124         v = *(V++);
1125         uvRed = (V_RED_COEF*v) >> SHIFT;
1126         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1127         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1128
1129         tableY = table + *(Y++);
1130         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1131                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1132                             uvGreen] |
1133                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1134
1135         tableY = table + *(Y++);
1136         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1137                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1138                             uvGreen] |
1139                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1140     }
1141
1142     i = (width & 15) >> 1;
1143     while (i--) {
1144         u = *(U++);
1145         v = *(V++);
1146         uvRed = (V_RED_COEF*v) >> SHIFT;
1147         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1148         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1149
1150         tableY = table + *(Y++);
1151         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1152                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1153                             uvGreen] |
1154                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1155
1156         tableY = table + *(Y++);
1157         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1158                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1159                             uvGreen] |
1160                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1161     }
1162
1163     if (width & 1) {
1164         u = *(U++);
1165         v = *(V++);
1166         uvRed = (V_RED_COEF*v) >> SHIFT;
1167         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1168         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1169
1170         tableY = table + *(Y++);
1171         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1172                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1173                             uvGreen] |
1174                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1175     }
1176 }
1177
1178 static void yuvToRgb24 (unsigned char * Y,
1179                         unsigned char * U, unsigned char * V,
1180                         char * dest, int table[1935], int width)
1181 {
1182     int i;
1183     int u;
1184     int v;
1185     int uvRed;
1186     int uvGreen;
1187     int uvBlue;
1188     int * tableY;
1189     int tmp24;
1190
1191     i = width >> 3;
1192     while (i--) {
1193         u = *(U++);
1194         v = *(V++);
1195         uvRed = (V_RED_COEF*v) >> SHIFT;
1196         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1197         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1198
1199         tableY = table + *(Y++);
1200         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1201                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1202                         uvGreen] |
1203                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1204         *(dest++) = tmp24;
1205         *(dest++) = tmp24 >> 8;
1206         *(dest++) = tmp24 >> 16;
1207
1208         tableY = table + *(Y++);
1209         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1210                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1211                         uvGreen] |
1212                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1213         *(dest++) = tmp24;
1214         *(dest++) = tmp24 >> 8;
1215         *(dest++) = tmp24 >> 16;
1216
1217         u = *(U++);
1218         v = *(V++);
1219         uvRed = (V_RED_COEF*v) >> SHIFT;
1220         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1221         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1222
1223         tableY = table + *(Y++);
1224         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1225                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1226                         uvGreen] |
1227                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1228         *(dest++) = tmp24;
1229         *(dest++) = tmp24 >> 8;
1230         *(dest++) = tmp24 >> 16;
1231
1232         tableY = table + *(Y++);
1233         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1234                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1235                         uvGreen] |
1236                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1237         *(dest++) = tmp24;
1238         *(dest++) = tmp24 >> 8;
1239         *(dest++) = tmp24 >> 16;
1240
1241         u = *(U++);
1242         v = *(V++);
1243         uvRed = (V_RED_COEF*v) >> SHIFT;
1244         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1245         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1246
1247         tableY = table + *(Y++);
1248         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1249                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1250                         uvGreen] |
1251                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1252         *(dest++) = tmp24;
1253         *(dest++) = tmp24 >> 8;
1254         *(dest++) = tmp24 >> 16;
1255
1256         tableY = table + *(Y++);
1257         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1258                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1259                         uvGreen] |
1260                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1261         *(dest++) = tmp24;
1262         *(dest++) = tmp24 >> 8;
1263         *(dest++) = tmp24 >> 16;
1264
1265         u = *(U++);
1266         v = *(V++);
1267         uvRed = (V_RED_COEF*v) >> SHIFT;
1268         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1269         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1270
1271         tableY = table + *(Y++);
1272         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1273                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1274                         uvGreen] |
1275                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1276         *(dest++) = tmp24;
1277         *(dest++) = tmp24 >> 8;
1278         *(dest++) = tmp24 >> 16;
1279
1280         tableY = table + *(Y++);
1281         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1282                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1283                         uvGreen] |
1284                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1285         *(dest++) = tmp24;
1286         *(dest++) = tmp24 >> 8;
1287         *(dest++) = tmp24 >> 16;
1288     }
1289
1290     i = (width & 7) >> 1;
1291     while (i--) {
1292         u = *(U++);
1293         v = *(V++);
1294         uvRed = (V_RED_COEF*v) >> SHIFT;
1295         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1296         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1297
1298         tableY = table + *(Y++);
1299         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1300                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1301                         uvGreen] |
1302                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1303         *(dest++) = tmp24;
1304         *(dest++) = tmp24 >> 8;
1305         *(dest++) = tmp24 >> 16;
1306
1307         tableY = table + *(Y++);
1308         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1309                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1310                         uvGreen] |
1311                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1312         *(dest++) = tmp24;
1313         *(dest++) = tmp24 >> 8;
1314         *(dest++) = tmp24 >> 16;
1315     }
1316
1317     if (width & 1) {
1318         u = *(U++);
1319         v = *(V++);
1320         uvRed = (V_RED_COEF*v) >> SHIFT;
1321         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1322         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1323
1324         tableY = table + *(Y++);
1325         tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1326                  tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1327                         uvGreen] |
1328                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1329         *(dest++) = tmp24;
1330         *(dest++) = tmp24 >> 8;
1331         *(dest++) = tmp24 >> 16;
1332     }
1333 }
1334
1335 static void yuvToRgb32 (unsigned char * Y,
1336                         unsigned char * U, unsigned char * V,
1337                         int * dest, int table[1935], int width)
1338 {
1339     int i;
1340     int u;
1341     int v;
1342     int uvRed;
1343     int uvGreen;
1344     int uvBlue;
1345     int * tableY;
1346
1347     i = width >> 4;
1348     while (i--) {
1349         u = *(U++);
1350         v = *(V++);
1351         uvRed = (V_RED_COEF*v) >> SHIFT;
1352         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1353         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1354
1355         tableY = table + *(Y++);
1356         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1357                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1358                             uvGreen] |
1359                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1360
1361         tableY = table + *(Y++);
1362         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1363                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1364                             uvGreen] |
1365                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1366
1367         u = *(U++);
1368         v = *(V++);
1369         uvRed = (V_RED_COEF*v) >> SHIFT;
1370         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1371         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1372
1373         tableY = table + *(Y++);
1374         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1375                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1376                             uvGreen] |
1377                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1378
1379         tableY = table + *(Y++);
1380         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1381                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1382                             uvGreen] |
1383                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1384
1385         u = *(U++);
1386         v = *(V++);
1387         uvRed = (V_RED_COEF*v) >> SHIFT;
1388         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1389         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1390
1391         tableY = table + *(Y++);
1392         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1393                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1394                             uvGreen] |
1395                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1396
1397         tableY = table + *(Y++);
1398         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1399                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1400                             uvGreen] |
1401                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1402
1403         u = *(U++);
1404         v = *(V++);
1405         uvRed = (V_RED_COEF*v) >> SHIFT;
1406         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1407         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1408
1409         tableY = table + *(Y++);
1410         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1411                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1412                             uvGreen] |
1413                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1414
1415         tableY = table + *(Y++);
1416         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1417                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1418                             uvGreen] |
1419                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1420
1421         u = *(U++);
1422         v = *(V++);
1423         uvRed = (V_RED_COEF*v) >> SHIFT;
1424         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1425         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1426
1427         tableY = table + *(Y++);
1428         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1429                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1430                             uvGreen] |
1431                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1432
1433         tableY = table + *(Y++);
1434         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1435                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1436                             uvGreen] |
1437                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1438
1439         u = *(U++);
1440         v = *(V++);
1441         uvRed = (V_RED_COEF*v) >> SHIFT;
1442         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1443         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1444
1445         tableY = table + *(Y++);
1446         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1447                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1448                             uvGreen] |
1449                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1450
1451         tableY = table + *(Y++);
1452         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1453                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1454                             uvGreen] |
1455                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1456
1457         u = *(U++);
1458         v = *(V++);
1459         uvRed = (V_RED_COEF*v) >> SHIFT;
1460         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1461         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1462
1463         tableY = table + *(Y++);
1464         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1465                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1466                             uvGreen] |
1467                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1468
1469         tableY = table + *(Y++);
1470         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1471                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1472                             uvGreen] |
1473                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1474
1475         u = *(U++);
1476         v = *(V++);
1477         uvRed = (V_RED_COEF*v) >> SHIFT;
1478         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1479         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1480
1481         tableY = table + *(Y++);
1482         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1483                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1484                             uvGreen] |
1485                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1486
1487         tableY = table + *(Y++);
1488         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1489                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1490                             uvGreen] |
1491                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1492     }
1493
1494     i = (width & 15) >> 1;
1495     while (i--) {
1496         u = *(U++);
1497         v = *(V++);
1498         uvRed = (V_RED_COEF*v) >> SHIFT;
1499         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1500         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1501
1502         tableY = table + *(Y++);
1503         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1504                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1505                             uvGreen] |
1506                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1507
1508         tableY = table + *(Y++);
1509         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1510                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1511                             uvGreen] |
1512                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1513     }
1514
1515     if (width & 1) {
1516         u = *(U++);
1517         v = *(V++);
1518         uvRed = (V_RED_COEF*v) >> SHIFT;
1519         uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1520         uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1521
1522         tableY = table + *(Y++);
1523         *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1524                      tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1525                             uvGreen] |
1526                      tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1527     }
1528 }
1529
1530 /* yuv routines with scaling */
1531 /* 4:2:2 i, 16 bpp*/
1532
1533 void yuv422ToRgb16_scaled (unsigned char * Y,
1534                         unsigned char * U, unsigned char * V,
1535                         short * dest, short table[1935], int width , int dest_width,
1536             int height, int dest_height, int skip, int dest_skip,short * buffer)
1537 {
1538     int i, i_hcount, i_vcount, j, k;
1539     int u;
1540     int v;
1541     int uvRed;
1542     int uvGreen;
1543     int uvBlue;
1544     short * tableY;
1545     short pix;
1546
1547     if ( ( width < dest_width ) && ( height < dest_height ) )
1548     {
1549         i_vcount = dest_height;
1550         k = height;
1551         while ( k-- )
1552         {
1553             j = 0;
1554             i = width >> 1;
1555             i_hcount = dest_width;
1556             while ( i-- ) 
1557             {
1558                     u = *(U++);
1559                     v = *(V++);
1560                     uvRed = (V_RED_COEF*v) >> SHIFT;
1561                     uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1562                     uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1563
1564                     tableY = table + *(Y++);
1565                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1566                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1567                        >>SHIFT) + uvGreen] |
1568                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1569                 while ( ( i_hcount -= width ) >= 0 )
1570                 {
1571                     buffer[j++] = pix;
1572                 }
1573                 i_hcount += dest_width;
1574             
1575                     tableY = table + *(Y++);
1576                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1577                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1578                        >>SHIFT) + uvGreen] |
1579                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1580                 while ( ( i_hcount -= width ) >= 0 )
1581                 {
1582                     buffer[j++] = pix;
1583                 }
1584                 i_hcount += dest_width;
1585             }
1586             while ( ( i_vcount -= height ) >= 0 )
1587             {
1588             for (j=0; j<dest_width; j+=16)
1589                 {
1590                     dest[j]=buffer[j];
1591                     dest[j+1]=buffer[j+1];
1592                     dest[j+2]=buffer[j+2];
1593                     dest[j+3]=buffer[j+3];
1594                     dest[j+4]=buffer[j+4];
1595                     dest[j+6]=buffer[j+7];
1596                     dest[j+8]=buffer[j+9];
1597                     dest[j+10]=buffer[j+10];
1598                     dest[j+11]=buffer[j+11];
1599                     dest[j+12]=buffer[j+12];
1600                     dest[j+13]=buffer[j+13];
1601                     dest[j+14]=buffer[j+14];
1602                     dest[j+15]=buffer[j+15];
1603                 }
1604                 dest += dest_skip;
1605             }
1606         i_vcount += dest_height;
1607         }
1608     }
1609     else if ( ( width > dest_width ) && ( height < dest_height ) )
1610     {
1611         i_vcount = dest_height;
1612         k = height;
1613         while ( k-- )
1614         {
1615             j = 0;
1616             i_hcount = 0;
1617             i = width >> 1;
1618             while ( i-- ) 
1619             {
1620                 u = *(U++);
1621                 v = *(V++);
1622                 uvRed = (V_RED_COEF*v) >> SHIFT;
1623                 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1624                 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1625                                                                         
1626                     if ( ( i_hcount -= dest_width ) >= 0 )
1627                     Y++;
1628                 else
1629                 {
1630                     tableY = table + *(Y++);
1631                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1632                                    uvRed] | 
1633                                    tableY [135 - 
1634                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1635                                    uvGreen] |
1636                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1637                                    uvBlue]);
1638                     i_hcount += width;
1639                 }
1640                 if ( ( i_hcount -= dest_width ) >= 0 )
1641                     Y++;
1642                 else
1643                 {     
1644                     tableY = table + *(Y++);
1645                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1646                                    uvRed] |
1647                                    tableY [135 - 
1648                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1649                                    uvGreen] |
1650                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1651                                    uvBlue]);
1652                                    i_hcount += width;
1653                 }
1654             }
1655             while ( ( i_vcount -= height ) >= 0 )
1656             {
1657                 for (j=0; j<dest_width; j+=16)
1658                  {
1659                     dest[j]=buffer[j];
1660                     dest[j+1]=buffer[j+1];
1661                     dest[j+2]=buffer[j+2];
1662                     dest[j+3]=buffer[j+3];
1663                     dest[j+4]=buffer[j+4];
1664                     dest[j+6]=buffer[j+7];
1665                     dest[j+8]=buffer[j+9];
1666                     dest[j+10]=buffer[j+10];
1667                     dest[j+11]=buffer[j+11];
1668                     dest[j+12]=buffer[j+12];
1669                     dest[j+13]=buffer[j+13];
1670                     dest[j+14]=buffer[j+14];
1671                     dest[j+15]=buffer[j+15];
1672                 }
1673                 dest += dest_skip;
1674             }
1675             i_vcount += dest_height;
1676         }
1677     }
1678     else if ( ( width < dest_width ) && ( height > dest_height ) )
1679     {
1680         i_vcount = 0;
1681         k = height;
1682         while ( k-- )
1683         {
1684             j = 0;
1685             i = width >> 1;
1686             i_hcount = dest_width;
1687             while ( i-- ) 
1688             {
1689                     u = *(U++);
1690                     v = *(V++);
1691                     uvRed = (V_RED_COEF*v) >> SHIFT;
1692                     uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1693                     uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1694
1695                     tableY = table + *(Y++);
1696                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1697                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1698                        >>SHIFT) + uvGreen] |
1699                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1700                 while ( ( i_hcount -= width ) >= 0 )
1701                 {
1702                     dest[j++] = pix;
1703                 }
1704                 i_hcount += dest_width;
1705             
1706                     tableY = table + *(Y++);
1707                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1708                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1709                        >>SHIFT) + uvGreen] |
1710                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1711                 while ( ( i_hcount -= width ) >= 0 )
1712                 {
1713                     dest[j++] = pix;
1714                 }
1715                 i_hcount += dest_width;
1716             }
1717             while ( ( i_vcount -= height ) >= 0 )
1718             {
1719                 Y += skip;
1720                 U += skip >> 1;
1721                 V += skip >> 1;
1722             }
1723             i_vcount += dest_height;
1724         }
1725     }
1726     else if ( ( width > dest_width ) && ( height > dest_height ) )
1727     {
1728         i_vcount = dest_height;
1729         k = height;
1730         while ( k-- )
1731         {
1732             j = 0;
1733             i_hcount = 0;
1734             i = width >> 1;
1735             while ( i-- ) 
1736             {
1737                 u = *(U++);
1738                 v = *(V++);
1739                 uvRed = (V_RED_COEF*v) >> SHIFT;
1740                 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1741                 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1742                                                                         
1743                     if ( ( i_hcount -= dest_width ) >= 0 )
1744                     Y++;
1745                 else
1746                 {
1747                     tableY = table + *(Y++);
1748                     dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1749                                  uvRed] | 
1750                                  tableY [135 - 
1751                                  (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1752                                  uvGreen] |
1753                                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1754                                  uvBlue]);
1755                     i_hcount += width;
1756                 }
1757                 if ( ( i_hcount -= dest_width ) >= 0 )
1758                     Y++;
1759                 else
1760                 {     
1761                     tableY = table + *(Y++);
1762                     dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1763                                  uvRed] |
1764                                  tableY [135 - 
1765                                  (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1766                                  uvGreen] |
1767                                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1768                                  uvBlue]);
1769                                  i_hcount += width;
1770                 }
1771             }
1772             while ( ( i_vcount -= height ) >= 0 )
1773             {
1774                 Y += skip;
1775                 U += skip >> 1;
1776                 V += skip >> 1;
1777             }
1778             i_vcount += dest_height;
1779         }
1780     }
1781 }
1782
1783 /* yuv routines with scaling */
1784 /* 4:2:0 i, 16 bpp*/
1785
1786 void yuv420ToRgb16_scaled (unsigned char * Y,
1787                         unsigned char * U, unsigned char * V,
1788                         short * dest, short table[1935], int width , int dest_width,
1789             int height, int dest_height, int skip, int dest_skip,short * buffer)
1790 {
1791     int i, i_hcount, i_vcount, j, k;
1792     int u;
1793     int v;
1794     int uvRed;
1795     int uvGreen;
1796     int uvBlue;
1797     short * tableY;
1798     short pix;
1799
1800     if ( ( width < dest_width ) && ( height < dest_height ) )
1801     {
1802         i_vcount = dest_height;
1803         k = height >> 1;
1804         while ( k-- )
1805         {
1806             j = 0;
1807             i = width >> 1;
1808             i_hcount = dest_width;
1809             while ( i-- ) 
1810             {
1811                     u = *(U++);
1812                     v = *(V++);
1813                     uvRed = (V_RED_COEF*v) >> SHIFT;
1814                     uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1815                     uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1816
1817                     tableY = table + *(Y++);
1818                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1819                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1820                        >>SHIFT) + uvGreen] |
1821                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1822                 while ( ( i_hcount -= width ) >= 0 )
1823                 {
1824                     buffer[j++] = pix;
1825                 }
1826                 i_hcount += dest_width;
1827             
1828                     tableY = table + *(Y++);
1829                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1830                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1831                        >>SHIFT) + uvGreen] |
1832                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1833                 while ( ( i_hcount -= width ) >= 0 )
1834                 {
1835                     buffer[j++] = pix;
1836                 }
1837                 i_hcount += dest_width;
1838             }
1839             while ( ( i_vcount -= height ) >= 0 )
1840             {
1841                 for (j=0; j<dest_width; j+=16)
1842                     {
1843                         dest[j]=buffer[j];
1844                         dest[j+1]=buffer[j+1];
1845                         dest[j+2]=buffer[j+2];
1846                         dest[j+3]=buffer[j+3];
1847                         dest[j+4]=buffer[j+4];
1848                         dest[j+6]=buffer[j+7];
1849                         dest[j+8]=buffer[j+9];
1850                         dest[j+10]=buffer[j+10];
1851                         dest[j+11]=buffer[j+11];
1852                         dest[j+12]=buffer[j+12];
1853                         dest[j+13]=buffer[j+13];
1854                         dest[j+14]=buffer[j+14];
1855                         dest[j+15]=buffer[j+15];
1856                     }
1857                 dest += dest_skip;
1858             }
1859             i_vcount += dest_height;
1860             U -= skip >> 1;
1861             V -= skip >> 1;
1862             j = 0;
1863             i = width >> 1;
1864             i_hcount = dest_width;
1865             while ( i-- ) 
1866             {
1867                     u = *(U++);
1868                     v = *(V++);
1869                     uvRed = (V_RED_COEF*v) >> SHIFT;
1870                     uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1871                     uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1872
1873                     tableY = table + *(Y++);
1874                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1875                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1876                        >>SHIFT) + uvGreen] |
1877                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1878                 while ( ( i_hcount -= width ) >= 0 )
1879                 {
1880                     buffer[j++] = pix;
1881                 }
1882                 i_hcount += dest_width;
1883             
1884                     tableY = table + *(Y++);
1885                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1886                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1887                        >>SHIFT) + uvGreen] |
1888                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1889                 while ( ( i_hcount -= width ) >= 0 )
1890                 {
1891                     buffer[j++] = pix;
1892                 }
1893                 i_hcount += dest_width;
1894             }
1895             while ( ( i_vcount -= height ) >= 0 )
1896             {
1897                 for (j=0; j<dest_width; j+=16)
1898                     {
1899                         dest[j]=buffer[j];
1900                         dest[j+1]=buffer[j+1];
1901                         dest[j+2]=buffer[j+2];
1902                         dest[j+3]=buffer[j+3];
1903                         dest[j+4]=buffer[j+4];
1904                         dest[j+6]=buffer[j+7];
1905                         dest[j+8]=buffer[j+9];
1906                         dest[j+10]=buffer[j+10];
1907                         dest[j+11]=buffer[j+11];
1908                         dest[j+12]=buffer[j+12];
1909                         dest[j+13]=buffer[j+13];
1910                         dest[j+14]=buffer[j+14];
1911                         dest[j+15]=buffer[j+15];
1912                     }
1913                 dest += dest_skip;
1914             }
1915             i_vcount += dest_height;
1916         }
1917     }
1918     else if ( ( width > dest_width ) && ( height < dest_height ) )
1919     {
1920         i_vcount = dest_height;
1921         k = height;
1922         while ( k-- )
1923         {
1924             j = 0;
1925             i_hcount = 0;
1926             i = width >> 1;
1927             while ( i-- ) 
1928             {
1929                 u = *(U++);
1930                 v = *(V++);
1931                 uvRed = (V_RED_COEF*v) >> SHIFT;
1932                 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1933                 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1934                                                                         
1935                     if ( ( i_hcount -= dest_width ) >= 0 )
1936                     Y++;
1937                 else
1938                 {
1939                     tableY = table + *(Y++);
1940                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1941                                    uvRed] | 
1942                                    tableY [135 - 
1943                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1944                                    uvGreen] |
1945                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1946                                    uvBlue]);
1947                     i_hcount += width;
1948                 }
1949                 if ( ( i_hcount -= dest_width ) >= 0 )
1950                     Y++;
1951                 else
1952                 {     
1953                     tableY = table + *(Y++);
1954                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
1955                                    uvRed] |
1956                                    tableY [135 - 
1957                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1958                                    uvGreen] |
1959                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
1960                                    uvBlue]);
1961                                    i_hcount += width;
1962                 }
1963             }
1964             while ( ( i_vcount -= height ) >= 0 )
1965             {
1966                 for (j=0; j<dest_width; j+=16)
1967                  {
1968                     dest[j]=buffer[j];
1969                     dest[j+1]=buffer[j+1];
1970                     dest[j+2]=buffer[j+2];
1971                     dest[j+3]=buffer[j+3];
1972                     dest[j+4]=buffer[j+4];
1973                     dest[j+6]=buffer[j+7];
1974                     dest[j+8]=buffer[j+9];
1975                     dest[j+10]=buffer[j+10];
1976                     dest[j+11]=buffer[j+11];
1977                     dest[j+12]=buffer[j+12];
1978                     dest[j+13]=buffer[j+13];
1979                     dest[j+14]=buffer[j+14];
1980                     dest[j+15]=buffer[j+15];
1981                 }
1982                 dest += dest_skip;
1983             }
1984             i_vcount += dest_height;
1985             U -= skip >> 1;
1986             V -= skip >> 1;
1987             j = 0;
1988             i_hcount = 0;
1989             i = width >> 1;
1990             while ( i-- ) 
1991             {
1992                 u = *(U++);
1993                 v = *(V++);
1994                 uvRed = (V_RED_COEF*v) >> SHIFT;
1995                 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1996                 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1997                                                                         
1998                     if ( ( i_hcount -= dest_width ) >= 0 )
1999                     Y++;
2000                 else
2001                 {
2002                     tableY = table + *(Y++);
2003                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
2004                                    uvRed] | 
2005                                    tableY [135 - 
2006                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2007                                    uvGreen] |
2008                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
2009                                    uvBlue]);
2010                     i_hcount += width;
2011                 }
2012                 if ( ( i_hcount -= dest_width ) >= 0 )
2013                     Y++;
2014                 else
2015                 {     
2016                     tableY = table + *(Y++);
2017                     buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
2018                                    uvRed] |
2019                                    tableY [135 - 
2020                                    (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2021                                    uvGreen] |
2022                                    tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
2023                                    uvBlue]);
2024                                    i_hcount += width;
2025                 }
2026             }
2027             while ( ( i_vcount -= height ) >= 0 )
2028             {
2029                 for (j=0; j<dest_width; j+=16)
2030                  {
2031                     dest[j]=buffer[j];
2032                     dest[j+1]=buffer[j+1];
2033                     dest[j+2]=buffer[j+2];
2034                     dest[j+3]=buffer[j+3];
2035                     dest[j+4]=buffer[j+4];
2036                     dest[j+6]=buffer[j+7];
2037                     dest[j+8]=buffer[j+9];
2038                     dest[j+10]=buffer[j+10];
2039                     dest[j+11]=buffer[j+11];
2040                     dest[j+12]=buffer[j+12];
2041                     dest[j+13]=buffer[j+13];
2042                     dest[j+14]=buffer[j+14];
2043                     dest[j+15]=buffer[j+15];
2044                 }
2045                 dest += dest_skip;
2046             }
2047             i_vcount += dest_height;
2048         }
2049     }
2050     else if ( ( width < dest_width ) && ( height > dest_height ) )
2051     {
2052         i_vcount = 0;
2053         k = height;
2054         while ( k-- )
2055         {
2056             j = 0;
2057             i = width >> 1;
2058             i_hcount = dest_width;
2059             while ( i-- ) 
2060             {
2061                     u = *(U++);
2062                     v = *(V++);
2063                     uvRed = (V_RED_COEF*v) >> SHIFT;
2064                     uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2065                     uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2066
2067                     tableY = table + *(Y++);
2068                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2069                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2070                        >>SHIFT) + uvGreen] |
2071                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2072                 while ( ( i_hcount -= width ) >= 0 )
2073                 {
2074                     dest[j++] = pix;
2075                 }
2076                 i_hcount += dest_width;
2077             
2078                     tableY = table + *(Y++);
2079                     pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2080                                tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2081                        >>SHIFT) + uvGreen] |
2082                                tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2083                 while ( ( i_hcount -= width ) >= 0 )
2084                 {
2085                     dest[j++] = pix;
2086                 }
2087                 i_hcount += dest_width;
2088             }
2089             j = 0;
2090             while ( ( i_vcount -= height ) >= 0 )
2091             {
2092                 Y += skip;
2093                 j++;
2094             }
2095             U += skip * ( j >> 1 );
2096             V += skip * ( j >> 1 );
2097             i_vcount += dest_height;
2098         }
2099     }
2100     else if ( ( width > dest_width ) && ( height > dest_height ) )
2101     {
2102         i_vcount = dest_height;
2103         k = height;
2104         while ( k-- )
2105         {
2106             j = 0;
2107             i_hcount = 0;
2108             i = width >> 1;
2109             while ( i-- ) 
2110             {
2111                 u = *(U++);
2112                 v = *(V++);
2113                 uvRed = (V_RED_COEF*v) >> SHIFT;
2114                 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2115                 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2116                                                                         
2117                     if ( ( i_hcount -= dest_width ) >= 0 )
2118                     Y++;
2119                 else
2120                 {
2121                     tableY = table + *(Y++);
2122                     dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
2123                                  uvRed] | 
2124                                  tableY [135 - 
2125                                  (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2126                                  uvGreen] |
2127                                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
2128                                  uvBlue]);
2129                     i_hcount += width;
2130                 }
2131                 if ( ( i_hcount -= dest_width ) >= 0 )
2132                     Y++;
2133                 else
2134                 {     
2135                     tableY = table + *(Y++);
2136                     dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + 
2137                                  uvRed] |
2138                                  tableY [135 - 
2139                                  (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2140                                  uvGreen] |
2141                                  tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + 
2142                                  uvBlue]);
2143                                  i_hcount += width;
2144                 }
2145             }
2146             j = 0;
2147             while ( ( i_vcount -= height ) >= 0 )
2148             {
2149                 Y += skip;
2150                 j++;
2151             }
2152             U += skip * ( j >> 1 );
2153             V += skip * ( j >> 1 );
2154             i_vcount += dest_height;
2155         }
2156     }
2157 }
2158