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