1 /*******************************************************************************
2 * video_yuv.c: YUV transformation functions
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 *******************************************************************************/
10 /*******************************************************************************
12 *******************************************************************************/
21 #include "vlc_thread.h"
23 #include "video_output.h"
24 #include "video_yuv.h"
27 /*******************************************************************************
29 *******************************************************************************/
31 /* RGB/YUV inversion matrix (ISO/IEC 13818-2 section 6.3.6, table 6.9) */
32 const int MATRIX_COEFFICIENTS_TABLE[8][4] =
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) */
45 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
46 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
47 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
48 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
50 /*******************************************************************************
52 *******************************************************************************/
53 static int BinaryLog ( u32 i );
54 static void MaskToShift ( int *pi_right, int *pi_left, u32 i_mask );
55 static void SetGammaTable ( int *pi_table, double f_gamma );
56 static void SetYUV ( vout_thread_t *p_vout );
58 static void ConvertY4Gray16 ( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
59 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
60 int i_matrix_coefficients );
61 static void ConvertY4Gray24 ( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
62 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
63 int i_matrix_coefficients );
64 static void ConvertY4Gray32 ( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
65 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
66 int i_matrix_coefficients );
67 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
68 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
69 int i_matrix_coefficients );
70 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
71 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
72 int i_matrix_coefficients );
73 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
74 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
75 int i_matrix_coefficients );
76 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
77 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
78 int i_matrix_coefficients );
79 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
80 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
81 int i_matrix_coefficients );
82 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
83 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
84 int i_matrix_coefficients );
85 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
86 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
87 int i_matrix_coefficients );
88 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
89 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
90 int i_matrix_coefficients );
91 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
92 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
93 int i_matrix_coefficients );
95 /*******************************************************************************
96 * CLIP_BYTE macro: boundary detection
97 *******************************************************************************
98 * Return parameter if between 0 and 255, else return nearest boundary (0 or
99 * 255). This macro is used to build translations tables.
100 *******************************************************************************/
101 #define CLIP_BYTE( i_val ) ( (i_val < 0) ? 0 : ((i_val > 255) ? 255 : i_val) )
103 /*******************************************************************************
104 * CONVERT_YUV_GRAY macro: grayscale YUV convertion
105 *******************************************************************************
106 * This macro does not perform any scaling, but crops the picture. It is
107 * provided as a temporary way of implementing an YUV convertion function.
108 *******************************************************************************/
109 #define CONVERT_YUV_GRAY \
110 /* Change boundaries according to picture size */ \
111 i_width = MIN( i_width, i_pic_width ); \
112 i_height = MIN( i_height, i_pic_height ); \
113 i_pic_line_width -= i_width; \
116 for (i_y = 0; i_y < i_height ; i_y++) \
118 for (i_x = 0; i_x < i_width; ) \
120 /* Convert 16 pixels (width is always multiple of 16 */ \
121 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
122 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
123 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
124 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
125 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
126 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
127 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
128 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
129 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
130 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
131 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
132 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
133 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
134 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
135 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
136 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
139 /* Skip until beginning of next line */ \
140 p_pic += i_pic_line_width; \
143 /*******************************************************************************
144 * CONVERT_YUV_RGB: color YUV convertion
145 *******************************************************************************
146 * This macro does not perform any scaling, but crops the picture. It is
147 * provided as a temporary way of implementing an YUV convertion function.
148 *******************************************************************************/
149 #define CONVERT_YUV_RGB( CHROMA, CRV, CGV, CBU, CGU ) \
150 /* Change boundaries according to picture size */ \
151 i_width = MIN( i_width, i_pic_width ); \
152 i_height = MIN( i_height, i_pic_height ); \
153 i_chroma_width = (CHROMA == 444) ? i_width : i_width / 2; \
154 i_pic_line_width -= i_width; \
157 for (i_y = 0; i_y < i_height ; i_y++) \
159 for (i_x = 0; i_x < i_width; ) \
161 /* First sample (complete) */ \
162 i_yval = 76309 * p_y[i_x] - 1188177; \
163 i_uval = *p_u++ - 128; \
164 i_vval = *p_v++ - 128; \
166 p_red [(i_yval+CRV*i_vval) >>16] | \
167 p_green[(i_yval-CGU*i_uval-CGV*i_vval) >>16] | \
168 p_blue [(i_yval+CBU*i_uval) >>16]; \
169 i_yval = 76309 * p_y[i_x] - 1188177; \
170 /* Second sample (partial) */ \
171 if( CHROMA == 444 ) \
173 i_uval = *p_u++ - 128; \
174 i_vval = *p_v++ - 128; \
177 p_red [(i_yval+CRV*i_vval) >>16] | \
178 p_green[(i_yval-CGU*i_uval-CGV*i_vval) >>16] | \
179 p_blue [(i_yval+CBU*i_uval) >>16]; \
182 /* Rewind in 4:2:0 */ \
183 if( (CHROMA == 420) && !(i_y & 0x1) ) \
185 p_u -= i_chroma_width; \
186 p_v -= i_chroma_width; \
189 /* Skip until beginning of next line */ \
190 p_pic += i_pic_line_width; \
193 /*******************************************************************************
194 * CONVERT_YUV_PIXEL, CONVERT_Y_PIXEL: pixel convertion blocks
195 *******************************************************************************
196 * These convertion routines are used by YUV convertion functions.
197 * Convertion are made from p_y, p_u, p_v, which are modified, to i_dst. ??
198 *******************************************************************************/
199 #define CONVERT_Y_PIXEL \
200 /* Only Y sample is present */ \
201 p_ybase = p_yuv + *(p_y++); \
202 *p_pic++ = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] | \
203 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] | \
204 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue]; \
206 #define CONVERT_YUV_PIXEL \
207 /* Y, U and V samples are present */ \
210 i_red = (V_RED_COEF * i_vval) >> SHIFT; \
211 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT; \
212 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT; \
216 /* Pixel may be copied, but only once */ \
217 while( (i_width_count -= i_width) > 0 ) \
219 *p_pic++ = *(p_pic - 1); \
221 i_width_count += i_pic_width; \
223 /*******************************************************************************
224 * vout_InitYUV: allocate and initialize translations tables
225 *******************************************************************************
226 * This function will allocate memory to store translation tables, depending
227 * of the screen depth.
228 *******************************************************************************/
229 int vout_InitYUV( vout_thread_t *p_vout )
231 size_t tables_size; /* tables size, in bytes */
233 /* Computes tables size */
234 switch( p_vout->i_screen_depth )
238 tables_size = sizeof( u16 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
245 tables_size = sizeof( u32 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
249 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
255 /* Add conversion buffer size. The conversions functions need one comple line
256 * plus one pixel, so we give them two. */
257 tables_size += p_vout->i_bytes_per_line * 2;
259 /* Allocate memory */
260 p_vout->yuv.p_base = malloc( tables_size );
261 if( p_vout->yuv.p_base == NULL )
263 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
267 /* Initialize tables */
272 /*******************************************************************************
273 * vout_ResetTables: re-initialize translations tables
274 *******************************************************************************
275 * This function will initialize the tables allocated by vout_CreateTables and
276 * set functions pointers.
277 *******************************************************************************/
278 int vout_ResetYUV( vout_thread_t *p_vout )
280 vout_EndYUV( p_vout );
281 return( vout_InitYUV( p_vout ) );
284 /*******************************************************************************
285 * vout_EndYUV: destroy translations tables
286 *******************************************************************************
287 * Free memory allocated by vout_CreateTables.
288 *******************************************************************************/
289 void vout_EndYUV( vout_thread_t *p_vout )
291 free( p_vout->yuv.p_base );
294 /* following functions are local */
296 /*******************************************************************************
297 * BinaryLog: computes the base 2 log of a binary value
298 *******************************************************************************
299 * This functions is used by MaskToShift during tables initialisation, to
300 * get a bit index from a binary value.
301 *******************************************************************************/
302 static int BinaryLog(u32 i)
327 if (i != ((u32)1 << i_log))
329 intf_ErrMsg("internal error: binary log overflow\n");
335 /*******************************************************************************
336 * MaskToShift: Transform a color mask into right and left shifts
337 *******************************************************************************
338 * This function is used during table initialisation. It can return a value
339 *******************************************************************************/
340 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
342 u32 i_low, i_high; /* lower hand higher bits of the mask */
345 i_low = i_mask & (- i_mask); /* lower bit of the mask */
346 i_high = i_mask + i_low; /* higher bit of the mask */
348 /* Transform bits into an index */
349 i_low = BinaryLog (i_low);
350 i_high = BinaryLog (i_high);
352 /* Update pointers and return */
354 *pi_right = (8 - i_high + i_low);
357 /*******************************************************************************
358 * SetGammaTable: return intensity table transformed by gamma curve.
359 *******************************************************************************
360 * pi_table is a table of 256 entries from 0 to 255.
361 *******************************************************************************/
362 static void SetGammaTable( int *pi_table, double f_gamma )
364 int i_y; /* base intensity */
366 /* Use exp(gamma) instead of gamma */
367 f_gamma = exp(f_gamma );
369 /* Build gamma table */
370 for( i_y = 0; i_y < 256; i_y++ )
372 pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
376 /*******************************************************************************
377 * SetYUV: compute tables and set function pointers
378 + *******************************************************************************/
379 static void SetYUV( vout_thread_t *p_vout )
381 int pi_gamma[256]; /* gamma table */
382 int i_index; /* index in tables */
383 int i_red_right, i_red_left; /* red shifts */
384 int i_green_right, i_green_left; /* green shifts */
385 int i_blue_right, i_blue_left; /* blue shifts */
387 /* Build gamma table */
388 SetGammaTable( pi_gamma, p_vout->f_gamma );
391 * Set color masks and shifts
393 switch( p_vout->i_screen_depth )
396 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
397 MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
398 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
401 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
402 MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
403 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
407 MaskToShift( &i_red_right, &i_red_left, 0x00ff0000 );
408 MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
409 MaskToShift( &i_blue_right, &i_blue_left, 0x000000ff );
413 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
419 * Set pointers and build YUV tables
421 if( p_vout->b_grayscale )
423 /* Grayscale: build gray table */
424 switch( p_vout->i_screen_depth )
428 p_vout->yuv.yuv.gray16.p_gray = (u16 *)p_vout->yuv.p_base + 384;
429 for( i_index = -384; i_index < 640; i_index++)
431 p_vout->yuv.yuv.gray16.p_gray[ i_index ] =
432 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
433 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
434 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
439 p_vout->yuv.yuv.gray32.p_gray = (u32 *)p_vout->yuv.p_base + 384;
440 for( i_index = -384; i_index < 640; i_index++)
442 p_vout->yuv.yuv.gray32.p_gray[ i_index ] =
443 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
444 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
445 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
452 /* Color: build red, green and blue tables */
453 switch( p_vout->i_screen_depth )
457 p_vout->yuv.yuv.rgb16.p_red = (u16 *)p_vout->yuv.p_base + 384;
458 p_vout->yuv.yuv.rgb16.p_green = (u16 *)p_vout->yuv.p_base + 1024 + 384;
459 p_vout->yuv.yuv.rgb16.p_blue = (u16 *)p_vout->yuv.p_base + 2*1024 + 384;
460 p_vout->yuv.yuv2.p_rgb16 = (u16 *)p_vout->yuv.p_base + 3*1024;
461 p_vout->yuv.p_buffer = (u16 *)p_vout->yuv.p_base + 3*1024 + 1935;
462 for( i_index = -384; i_index < 640; i_index++)
464 p_vout->yuv.yuv.rgb16.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
465 p_vout->yuv.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
466 p_vout->yuv.yuv.rgb16.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
468 for( i_index = 0; i_index < 178; i_index++ )
470 p_vout->yuv.yuv2.p_rgb16[1501 - 178 + i_index] = (pi_gamma[0]>>i_red_right)<<i_red_left;
471 p_vout->yuv.yuv2.p_rgb16[1501 + 256 + i_index] = (pi_gamma[255]>>i_red_right)<<i_red_left;
473 for( i_index = 0; i_index < 135; i_index++ )
475 p_vout->yuv.yuv2.p_rgb16[135 - 135 + i_index] = (pi_gamma[0]>>i_green_right)<<i_green_left;
476 p_vout->yuv.yuv2.p_rgb16[135 + 256 + i_index] = (pi_gamma[255]>>i_green_right)<<i_green_left;
478 for( i_index = 0; i_index < 224; i_index++ )
480 p_vout->yuv.yuv2.p_rgb16[818 - 224 + i_index] = (pi_gamma[0]>>i_blue_right)<<i_blue_left;
481 p_vout->yuv.yuv2.p_rgb16[818 + 256 + i_index] = (pi_gamma[255]>>i_blue_right)<<i_blue_left;
483 for( i_index = 0; i_index < 256; i_index++ )
485 p_vout->yuv.yuv2.p_rgb16[1501 + i_index] = (pi_gamma[i_index]>>i_red_right)<<i_red_left;
486 p_vout->yuv.yuv2.p_rgb16[135 + i_index] = (pi_gamma[i_index]>>i_green_right)<<i_green_left;
487 p_vout->yuv.yuv2.p_rgb16[818 + i_index] = (pi_gamma[i_index]>>i_blue_right)<<i_blue_left;
492 p_vout->yuv.yuv.rgb32.p_red = (u32 *)p_vout->yuv.p_base + 384;
493 p_vout->yuv.yuv.rgb32.p_green = (u32 *)p_vout->yuv.p_base + 1024 + 384;
494 p_vout->yuv.yuv.rgb32.p_blue = (u32 *)p_vout->yuv.p_base + 2*1024 + 384;
495 p_vout->yuv.yuv2.p_rgb32 = (u32 *)p_vout->yuv.p_base + 3*1024;
496 p_vout->yuv.p_buffer = (u32 *)p_vout->yuv.p_base + 3*1024 + 1935;
497 for( i_index = -384; i_index < 640; i_index++)
499 p_vout->yuv.yuv.rgb32.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
500 p_vout->yuv.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
501 p_vout->yuv.yuv.rgb32.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
509 * Set functions pointers
511 if( p_vout->b_grayscale )
514 switch( p_vout->i_screen_depth )
518 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
519 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
520 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
523 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
524 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
525 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
528 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
529 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
530 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
537 switch( p_vout->i_screen_depth )
541 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB16;
542 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB16;
543 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB16;
546 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB24;
547 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB24;
548 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB24;
551 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB32;
552 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB32;
553 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB32;
559 /*******************************************************************************
560 * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
561 *******************************************************************************/
562 static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
563 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
564 int i_matrix_coefficients )
566 u16 * p_gray; /* gray table */
567 int i_x, i_y; /* picture coordinates */
569 p_gray = p_vout->yuv.yuv.gray16.p_gray;
573 /*******************************************************************************
574 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
575 *******************************************************************************/
576 static void ConvertY4Gray24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
577 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
578 int i_matrix_coefficients )
583 /*******************************************************************************
584 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
585 *******************************************************************************/
586 static void ConvertY4Gray32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
587 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
588 int i_matrix_coefficients )
590 u32 * p_gray; /* gray table */
591 int i_x, i_y; /* picture coordinates */
593 p_gray = p_vout->yuv.yuv.gray32.p_gray;
597 /*******************************************************************************
598 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
599 *******************************************************************************/
600 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
601 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
602 int i_matrix_coefficients )
605 // int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
607 i_chroma_width = i_width / 2;
608 i_chroma_skip = i_skip / 2;
609 ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height,
610 (i_width + i_skip) * sizeof( yuv_data_t ),
611 (i_chroma_width + i_chroma_skip) * sizeof( yuv_data_t),
612 i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
613 p_vout->i_screen_depth == 15 );
617 u16 * p_red; /* red table */
618 u16 * p_green; /* green table */
619 u16 * p_blue; /* blue table */
620 int i_uval, i_yval, i_vval; /* samples */
621 int i_x, i_y; /* picture coordinates */
622 int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
623 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
625 p_red = p_vout->yuv.yuv.rgb16.p_red;
626 p_green = p_vout->yuv.yuv.rgb16.p_green;
627 p_blue = p_vout->yuv.yuv.rgb16.p_blue;
628 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
629 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
630 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
631 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
633 CONVERT_YUV_RGB( 420, i_crv, i_cgv, i_cbu, i_cgu );
635 int i_horizontal_scaling; /* horizontal scaling type */
636 int i_vertical_scaling; /* vertical scaling type */
637 int i_x, i_y; /* horizontal and vertical indexes */
638 int i_uval, i_vval; /* U and V samples */
639 int i_red, i_green, i_blue; /* U and V modified samples */
640 int i_chroma_width; /* chroma width */
641 int i_width_count; /* width modulo counter */
642 int i_height_count; /* height modulo counter */
643 u16 * p_yuv; /* base convertion table */
644 u16 * p_ybase; /* Y dependant convertion table */
645 u16 * p_pic_start; /* beginning of the current line */
647 /* Initialize values */
648 i_height_count = i_pic_height;
649 i_chroma_width = i_width / 2;
650 p_yuv = p_vout->yuv.yuv2.p_rgb16;
653 if( i_pic_width - i_width > 0 )
655 i_horizontal_scaling = 1;
657 else if( i_pic_width - i_width < 0 )
659 i_horizontal_scaling = -1;
663 i_horizontal_scaling = 0;
665 if( i_pic_height - i_height > 0 )
667 i_vertical_scaling = 1;
669 else if( i_pic_height - i_height < 0 )
671 i_vertical_scaling = -1;
675 i_vertical_scaling = 0;
681 i_height_count = i_pic_height;
682 for( i_y = 0; i_y < i_height; i_y++ )
684 /* Mark beginnning of line */
687 /* Convert line using 16 pixels blocks, since picture come from 16 pixels
688 * width macroblocks - several loops will be used, depending of the
690 switch( i_horizontal_scaling )
692 case 1: /* horizontal scaling is > 1 */
693 i_width_count = i_pic_width;
694 for( i_x = i_width / 16; i_x--; )
731 for( i_x = i_width / 16; i_x--; )
752 i_width_count = i_width;
754 while( (i_width_count -= i_pic_width) > 0)
759 i_width_count += i_width;
762 while( (i_width_count -= i_width) > 0)
764 *p_pic++ = *(p_pic - 1);
766 i_width_count += i_pic_width;
772 /* If line is odd, rewind U and V samples */
775 p_u -= i_chroma_width;
776 p_v -= i_chroma_width;
779 /* End of line: skip picture to reach beginning of next line */
780 p_pic += i_pic_line_width - i_pic_width;
783 * Handle vertical scaling. The current line is copied or next one
786 switch( i_vertical_scaling )
788 case -1: /* vertical scaling factor is < 1 */
789 while( (i_height_count -= i_pic_height) >= 0 )
791 /* Height reduction: skip next source line */
793 if( ! (++i_y & 0x1) )
795 p_u += i_chroma_width;
796 p_v += i_chroma_width;
799 i_height_count += i_height;
801 case 1: /* vertical scaling factor is > 1 */
802 while( (i_height_count -= i_height) > 0 )
804 /* Height increment: copy previous picture line */
805 for( i_x = i_pic_width / 16; i_x--; )
807 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
808 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
809 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
810 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
812 p_pic += i_pic_line_width - i_pic_width;
813 p_pic_start += i_pic_line_width - i_pic_width;
815 i_height_count += i_pic_height;
822 /*******************************************************************************
823 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
824 *******************************************************************************/
825 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
826 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
827 int i_matrix_coefficients )
832 /*******************************************************************************
833 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
834 *******************************************************************************/
835 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
836 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
837 int i_matrix_coefficients )
842 /*******************************************************************************
843 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
844 *******************************************************************************/
845 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
846 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
847 int i_matrix_coefficients )
852 /*******************************************************************************
853 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
854 *******************************************************************************/
855 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
856 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
857 int i_matrix_coefficients )
862 /*******************************************************************************
863 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
864 *******************************************************************************/
865 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
866 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
867 int i_matrix_coefficients )
872 /*******************************************************************************
873 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
874 *******************************************************************************/
875 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
876 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
877 int i_matrix_coefficients )
882 /*******************************************************************************
883 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
884 *******************************************************************************/
885 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
886 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
887 int i_matrix_coefficients )
892 /*******************************************************************************
893 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
894 *******************************************************************************/
895 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
896 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
897 int i_matrix_coefficients )
902 //-------------------- walken code follow ---------------------------------------
905 * YUV to RGB routines.
907 * these routines calculate r, g and b values from each pixel's y, u and v.
908 * these r, g an b values are then passed thru a table lookup to take the
909 * gamma curve into account and find the corresponding pixel value.
911 * the table must store more than 3*256 values because of the possibility
912 * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
913 * values are in the following intervals :
914 * -176 to 255+176 for red
915 * -133 to 255+133 for green
916 * -222 to 255+222 for blue
918 * If the input y,u,v values are right, the r,g,b results are not expected
919 * to move out of the 0 to 255 interval but who knows what will happen in
922 * the red, green and blue conversion tables are stored in a single 1935-entry
923 * array. The respective positions of each component in the array have been
924 * calculated to minimize the cache interactions of the 3 tables.
927 static int rgbTable32 (int table [1935],
928 int redMask, int greenMask, int blueMask,
929 unsigned char gamma[256])
943 MaskToShift (&redRight, &redLeft, redMask);
944 MaskToShift (&greenRight, &greenLeft, greenMask);
945 MaskToShift (&blueRight, &blueLeft, blueMask);
949 * green blue red +- 2 just to be sure
950 * green = 0-525 [151-370]
951 * blue = 594-1297 [834-1053] <834-29>
952 * red = 1323-1934 [1517-1736] <493-712>
955 redTable = table + 1501;
956 greenTable = table + 135;
957 blueTable = table + 818;
959 for (i = 0; i < 178; i++) {
961 redTable[i+256] = redMask;
963 for (i = 0; i < 135; i++) {
964 greenTable[i-135] = 0;
965 greenTable[i+256] = greenMask;
967 for (i = 0; i < 224; i++) {
968 blueTable[i-224] = 0;
969 blueTable[i+256] = blueMask;
972 for (i = 0; i < 256; i++) {
974 redTable[i] = ((y >> redRight) << redLeft);
975 greenTable[i] = ((y >> greenRight) << greenLeft);
976 blueTable[i] = ((y >> blueRight) << blueLeft);
983 void yuvToRgb16 (unsigned char * Y,
984 unsigned char * U, unsigned char * V,
985 short * dest, short table[1935], int width)
999 uvRed = (V_RED_COEF*v) >> SHIFT;
1000 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1001 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1003 tableY = table + *(Y++);
1004 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1005 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1007 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1009 tableY = table + *(Y++);
1010 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1011 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1013 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1017 uvRed = (V_RED_COEF*v) >> SHIFT;
1018 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1019 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1021 tableY = table + *(Y++);
1022 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1023 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1025 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1027 tableY = table + *(Y++);
1028 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1029 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1031 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1035 uvRed = (V_RED_COEF*v) >> SHIFT;
1036 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1037 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1039 tableY = table + *(Y++);
1040 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1041 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1043 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1045 tableY = table + *(Y++);
1046 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1047 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1049 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1053 uvRed = (V_RED_COEF*v) >> SHIFT;
1054 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1055 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1057 tableY = table + *(Y++);
1058 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1059 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1061 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1063 tableY = table + *(Y++);
1064 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1065 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1067 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1071 uvRed = (V_RED_COEF*v) >> SHIFT;
1072 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1073 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1075 tableY = table + *(Y++);
1076 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1077 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1079 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1081 tableY = table + *(Y++);
1082 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1083 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1085 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1089 uvRed = (V_RED_COEF*v) >> SHIFT;
1090 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1091 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1093 tableY = table + *(Y++);
1094 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1095 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1097 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1099 tableY = table + *(Y++);
1100 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1101 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1103 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
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;
1111 tableY = table + *(Y++);
1112 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1113 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1115 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1117 tableY = table + *(Y++);
1118 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1119 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1121 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1125 uvRed = (V_RED_COEF*v) >> SHIFT;
1126 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1127 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1129 tableY = table + *(Y++);
1130 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1131 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1133 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1135 tableY = table + *(Y++);
1136 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1137 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1139 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1142 i = (width & 15) >> 1;
1146 uvRed = (V_RED_COEF*v) >> SHIFT;
1147 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1148 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1150 tableY = table + *(Y++);
1151 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1152 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1154 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1156 tableY = table + *(Y++);
1157 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1158 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1160 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1166 uvRed = (V_RED_COEF*v) >> SHIFT;
1167 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1168 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1170 tableY = table + *(Y++);
1171 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1172 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1174 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1178 static void yuvToRgb24 (unsigned char * Y,
1179 unsigned char * U, unsigned char * V,
1180 char * dest, int table[1935], int width)
1195 uvRed = (V_RED_COEF*v) >> SHIFT;
1196 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1197 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1199 tableY = table + *(Y++);
1200 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1201 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1203 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1205 *(dest++) = tmp24 >> 8;
1206 *(dest++) = tmp24 >> 16;
1208 tableY = table + *(Y++);
1209 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1210 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1212 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1214 *(dest++) = tmp24 >> 8;
1215 *(dest++) = tmp24 >> 16;
1219 uvRed = (V_RED_COEF*v) >> SHIFT;
1220 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1221 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1223 tableY = table + *(Y++);
1224 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1225 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1227 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1229 *(dest++) = tmp24 >> 8;
1230 *(dest++) = tmp24 >> 16;
1232 tableY = table + *(Y++);
1233 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1234 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1236 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1238 *(dest++) = tmp24 >> 8;
1239 *(dest++) = tmp24 >> 16;
1243 uvRed = (V_RED_COEF*v) >> SHIFT;
1244 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1245 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1247 tableY = table + *(Y++);
1248 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1249 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1251 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1253 *(dest++) = tmp24 >> 8;
1254 *(dest++) = tmp24 >> 16;
1256 tableY = table + *(Y++);
1257 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1258 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1260 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1262 *(dest++) = tmp24 >> 8;
1263 *(dest++) = tmp24 >> 16;
1267 uvRed = (V_RED_COEF*v) >> SHIFT;
1268 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1269 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1271 tableY = table + *(Y++);
1272 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1273 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1275 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1277 *(dest++) = tmp24 >> 8;
1278 *(dest++) = tmp24 >> 16;
1280 tableY = table + *(Y++);
1281 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1282 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1284 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1286 *(dest++) = tmp24 >> 8;
1287 *(dest++) = tmp24 >> 16;
1290 i = (width & 7) >> 1;
1294 uvRed = (V_RED_COEF*v) >> SHIFT;
1295 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1296 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1298 tableY = table + *(Y++);
1299 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1300 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1302 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1304 *(dest++) = tmp24 >> 8;
1305 *(dest++) = tmp24 >> 16;
1307 tableY = table + *(Y++);
1308 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1309 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1311 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1313 *(dest++) = tmp24 >> 8;
1314 *(dest++) = tmp24 >> 16;
1320 uvRed = (V_RED_COEF*v) >> SHIFT;
1321 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1322 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1324 tableY = table + *(Y++);
1325 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1326 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1328 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1330 *(dest++) = tmp24 >> 8;
1331 *(dest++) = tmp24 >> 16;
1335 static void yuvToRgb32 (unsigned char * Y,
1336 unsigned char * U, unsigned char * V,
1337 int * dest, int table[1935], int width)
1351 uvRed = (V_RED_COEF*v) >> SHIFT;
1352 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1353 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1355 tableY = table + *(Y++);
1356 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1357 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1359 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1361 tableY = table + *(Y++);
1362 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1363 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1365 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1369 uvRed = (V_RED_COEF*v) >> SHIFT;
1370 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1371 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1373 tableY = table + *(Y++);
1374 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1375 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1377 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1379 tableY = table + *(Y++);
1380 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1381 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1383 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1387 uvRed = (V_RED_COEF*v) >> SHIFT;
1388 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1389 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1391 tableY = table + *(Y++);
1392 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1393 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1395 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1397 tableY = table + *(Y++);
1398 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1399 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1401 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1405 uvRed = (V_RED_COEF*v) >> SHIFT;
1406 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1407 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1409 tableY = table + *(Y++);
1410 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1411 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1413 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1415 tableY = table + *(Y++);
1416 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1417 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1419 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1423 uvRed = (V_RED_COEF*v) >> SHIFT;
1424 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1425 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1427 tableY = table + *(Y++);
1428 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1429 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1431 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1433 tableY = table + *(Y++);
1434 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1435 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1437 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1441 uvRed = (V_RED_COEF*v) >> SHIFT;
1442 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1443 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1445 tableY = table + *(Y++);
1446 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1447 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1449 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1451 tableY = table + *(Y++);
1452 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1453 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1455 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1459 uvRed = (V_RED_COEF*v) >> SHIFT;
1460 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1461 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1463 tableY = table + *(Y++);
1464 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1465 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1467 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1469 tableY = table + *(Y++);
1470 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1471 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1473 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1477 uvRed = (V_RED_COEF*v) >> SHIFT;
1478 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1479 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1481 tableY = table + *(Y++);
1482 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1483 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1485 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1487 tableY = table + *(Y++);
1488 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1489 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1491 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1494 i = (width & 15) >> 1;
1498 uvRed = (V_RED_COEF*v) >> SHIFT;
1499 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1500 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1502 tableY = table + *(Y++);
1503 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1504 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1506 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1508 tableY = table + *(Y++);
1509 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1510 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1512 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1518 uvRed = (V_RED_COEF*v) >> SHIFT;
1519 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1520 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1522 tableY = table + *(Y++);
1523 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1524 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1526 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1530 /* yuv routines with scaling */
1531 /* 4:2:2 i, 16 bpp*/
1533 void yuv422ToRgb16_scaled (unsigned char * Y,
1534 unsigned char * U, unsigned char * V,
1535 short * dest, short table[1935], int width , int dest_width,
1536 int height, int dest_height, int skip, int dest_skip,short * buffer)
1538 int i, i_hcount, i_vcount, j, k;
1547 if ( ( width < dest_width ) && ( height < dest_height ) )
1549 i_vcount = dest_height;
1555 i_hcount = dest_width;
1560 uvRed = (V_RED_COEF*v) >> SHIFT;
1561 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1562 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1564 tableY = table + *(Y++);
1565 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1566 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1567 >>SHIFT) + uvGreen] |
1568 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1569 while ( ( i_hcount -= width ) >= 0 )
1573 i_hcount += dest_width;
1575 tableY = table + *(Y++);
1576 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1577 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1578 >>SHIFT) + uvGreen] |
1579 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1580 while ( ( i_hcount -= width ) >= 0 )
1584 i_hcount += dest_width;
1586 while ( ( i_vcount -= height ) >= 0 )
1588 for (j=0; j<dest_width; j+=16)
1591 dest[j+1]=buffer[j+1];
1592 dest[j+2]=buffer[j+2];
1593 dest[j+3]=buffer[j+3];
1594 dest[j+4]=buffer[j+4];
1595 dest[j+6]=buffer[j+7];
1596 dest[j+8]=buffer[j+9];
1597 dest[j+10]=buffer[j+10];
1598 dest[j+11]=buffer[j+11];
1599 dest[j+12]=buffer[j+12];
1600 dest[j+13]=buffer[j+13];
1601 dest[j+14]=buffer[j+14];
1602 dest[j+15]=buffer[j+15];
1606 i_vcount += dest_height;
1609 else if ( ( width > dest_width ) && ( height < dest_height ) )
1611 i_vcount = dest_height;
1622 uvRed = (V_RED_COEF*v) >> SHIFT;
1623 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1624 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1626 if ( ( i_hcount -= dest_width ) >= 0 )
1630 tableY = table + *(Y++);
1631 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1634 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1636 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1640 if ( ( i_hcount -= dest_width ) >= 0 )
1644 tableY = table + *(Y++);
1645 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1648 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1650 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1655 while ( ( i_vcount -= height ) >= 0 )
1657 for (j=0; j<dest_width; j+=16)
1660 dest[j+1]=buffer[j+1];
1661 dest[j+2]=buffer[j+2];
1662 dest[j+3]=buffer[j+3];
1663 dest[j+4]=buffer[j+4];
1664 dest[j+6]=buffer[j+7];
1665 dest[j+8]=buffer[j+9];
1666 dest[j+10]=buffer[j+10];
1667 dest[j+11]=buffer[j+11];
1668 dest[j+12]=buffer[j+12];
1669 dest[j+13]=buffer[j+13];
1670 dest[j+14]=buffer[j+14];
1671 dest[j+15]=buffer[j+15];
1675 i_vcount += dest_height;
1678 else if ( ( width < dest_width ) && ( height > dest_height ) )
1686 i_hcount = dest_width;
1691 uvRed = (V_RED_COEF*v) >> SHIFT;
1692 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1693 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1695 tableY = table + *(Y++);
1696 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1697 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1698 >>SHIFT) + uvGreen] |
1699 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1700 while ( ( i_hcount -= width ) >= 0 )
1704 i_hcount += dest_width;
1706 tableY = table + *(Y++);
1707 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1708 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1709 >>SHIFT) + uvGreen] |
1710 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1711 while ( ( i_hcount -= width ) >= 0 )
1715 i_hcount += dest_width;
1717 while ( ( i_vcount -= height ) >= 0 )
1723 i_vcount += dest_height;
1726 else if ( ( width > dest_width ) && ( height > dest_height ) )
1728 i_vcount = dest_height;
1739 uvRed = (V_RED_COEF*v) >> SHIFT;
1740 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1741 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1743 if ( ( i_hcount -= dest_width ) >= 0 )
1747 tableY = table + *(Y++);
1748 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1751 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1753 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1757 if ( ( i_hcount -= dest_width ) >= 0 )
1761 tableY = table + *(Y++);
1762 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1765 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1767 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1772 while ( ( i_vcount -= height ) >= 0 )
1778 i_vcount += dest_height;
1783 /* yuv routines with scaling */
1784 /* 4:2:0 i, 16 bpp*/
1786 void yuv420ToRgb16_scaled (unsigned char * Y,
1787 unsigned char * U, unsigned char * V,
1788 short * dest, short table[1935], int width , int dest_width,
1789 int height, int dest_height, int skip, int dest_skip,short * buffer)
1791 int i, i_hcount, i_vcount, j, k;
1800 if ( ( width < dest_width ) && ( height < dest_height ) )
1802 i_vcount = dest_height;
1808 i_hcount = dest_width;
1813 uvRed = (V_RED_COEF*v) >> SHIFT;
1814 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1815 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1817 tableY = table + *(Y++);
1818 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1819 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1820 >>SHIFT) + uvGreen] |
1821 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1822 while ( ( i_hcount -= width ) >= 0 )
1826 i_hcount += dest_width;
1828 tableY = table + *(Y++);
1829 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1830 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1831 >>SHIFT) + uvGreen] |
1832 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1833 while ( ( i_hcount -= width ) >= 0 )
1837 i_hcount += dest_width;
1839 while ( ( i_vcount -= height ) >= 0 )
1841 for (j=0; j<dest_width; j+=16)
1844 dest[j+1]=buffer[j+1];
1845 dest[j+2]=buffer[j+2];
1846 dest[j+3]=buffer[j+3];
1847 dest[j+4]=buffer[j+4];
1848 dest[j+6]=buffer[j+7];
1849 dest[j+8]=buffer[j+9];
1850 dest[j+10]=buffer[j+10];
1851 dest[j+11]=buffer[j+11];
1852 dest[j+12]=buffer[j+12];
1853 dest[j+13]=buffer[j+13];
1854 dest[j+14]=buffer[j+14];
1855 dest[j+15]=buffer[j+15];
1859 i_vcount += dest_height;
1864 i_hcount = dest_width;
1869 uvRed = (V_RED_COEF*v) >> SHIFT;
1870 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1871 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1873 tableY = table + *(Y++);
1874 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1875 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1876 >>SHIFT) + uvGreen] |
1877 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1878 while ( ( i_hcount -= width ) >= 0 )
1882 i_hcount += dest_width;
1884 tableY = table + *(Y++);
1885 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1886 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1887 >>SHIFT) + uvGreen] |
1888 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1889 while ( ( i_hcount -= width ) >= 0 )
1893 i_hcount += dest_width;
1895 while ( ( i_vcount -= height ) >= 0 )
1897 for (j=0; j<dest_width; j+=16)
1900 dest[j+1]=buffer[j+1];
1901 dest[j+2]=buffer[j+2];
1902 dest[j+3]=buffer[j+3];
1903 dest[j+4]=buffer[j+4];
1904 dest[j+6]=buffer[j+7];
1905 dest[j+8]=buffer[j+9];
1906 dest[j+10]=buffer[j+10];
1907 dest[j+11]=buffer[j+11];
1908 dest[j+12]=buffer[j+12];
1909 dest[j+13]=buffer[j+13];
1910 dest[j+14]=buffer[j+14];
1911 dest[j+15]=buffer[j+15];
1915 i_vcount += dest_height;
1918 else if ( ( width > dest_width ) && ( height < dest_height ) )
1920 i_vcount = dest_height;
1931 uvRed = (V_RED_COEF*v) >> SHIFT;
1932 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1933 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1935 if ( ( i_hcount -= dest_width ) >= 0 )
1939 tableY = table + *(Y++);
1940 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1943 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1945 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1949 if ( ( i_hcount -= dest_width ) >= 0 )
1953 tableY = table + *(Y++);
1954 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1957 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1959 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1964 while ( ( i_vcount -= height ) >= 0 )
1966 for (j=0; j<dest_width; j+=16)
1969 dest[j+1]=buffer[j+1];
1970 dest[j+2]=buffer[j+2];
1971 dest[j+3]=buffer[j+3];
1972 dest[j+4]=buffer[j+4];
1973 dest[j+6]=buffer[j+7];
1974 dest[j+8]=buffer[j+9];
1975 dest[j+10]=buffer[j+10];
1976 dest[j+11]=buffer[j+11];
1977 dest[j+12]=buffer[j+12];
1978 dest[j+13]=buffer[j+13];
1979 dest[j+14]=buffer[j+14];
1980 dest[j+15]=buffer[j+15];
1984 i_vcount += dest_height;
1994 uvRed = (V_RED_COEF*v) >> SHIFT;
1995 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1996 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1998 if ( ( i_hcount -= dest_width ) >= 0 )
2002 tableY = table + *(Y++);
2003 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2006 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2008 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2012 if ( ( i_hcount -= dest_width ) >= 0 )
2016 tableY = table + *(Y++);
2017 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2020 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2022 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2027 while ( ( i_vcount -= height ) >= 0 )
2029 for (j=0; j<dest_width; j+=16)
2032 dest[j+1]=buffer[j+1];
2033 dest[j+2]=buffer[j+2];
2034 dest[j+3]=buffer[j+3];
2035 dest[j+4]=buffer[j+4];
2036 dest[j+6]=buffer[j+7];
2037 dest[j+8]=buffer[j+9];
2038 dest[j+10]=buffer[j+10];
2039 dest[j+11]=buffer[j+11];
2040 dest[j+12]=buffer[j+12];
2041 dest[j+13]=buffer[j+13];
2042 dest[j+14]=buffer[j+14];
2043 dest[j+15]=buffer[j+15];
2047 i_vcount += dest_height;
2050 else if ( ( width < dest_width ) && ( height > dest_height ) )
2058 i_hcount = dest_width;
2063 uvRed = (V_RED_COEF*v) >> SHIFT;
2064 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2065 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2067 tableY = table + *(Y++);
2068 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2069 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2070 >>SHIFT) + uvGreen] |
2071 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2072 while ( ( i_hcount -= width ) >= 0 )
2076 i_hcount += dest_width;
2078 tableY = table + *(Y++);
2079 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2080 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2081 >>SHIFT) + uvGreen] |
2082 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2083 while ( ( i_hcount -= width ) >= 0 )
2087 i_hcount += dest_width;
2090 while ( ( i_vcount -= height ) >= 0 )
2095 U += skip * ( j >> 1 );
2096 V += skip * ( j >> 1 );
2097 i_vcount += dest_height;
2100 else if ( ( width > dest_width ) && ( height > dest_height ) )
2102 i_vcount = dest_height;
2113 uvRed = (V_RED_COEF*v) >> SHIFT;
2114 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2115 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2117 if ( ( i_hcount -= dest_width ) >= 0 )
2121 tableY = table + *(Y++);
2122 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2125 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2127 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2131 if ( ( i_hcount -= dest_width ) >= 0 )
2135 tableY = table + *(Y++);
2136 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2139 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2141 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2147 while ( ( i_vcount -= height ) >= 0 )
2152 U += skip * ( j >> 1 );
2153 V += skip * ( j >> 1 );
2154 i_vcount += dest_height;