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