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 * vout_InitYUV: allocate and initialize translations tables
195 *******************************************************************************
196 * This function will allocate memory to store translation tables, depending
197 * of the screen depth.
198 *******************************************************************************/
199 int vout_InitYUV( vout_thread_t *p_vout )
201 size_t tables_size; /* tables size, in bytes */
203 /* Computes tables size */
204 switch( p_vout->i_screen_depth )
208 tables_size = sizeof( u16 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
215 tables_size = sizeof( u32 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
219 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
225 /* Add conversion buffer size. The conversions functions need one comple line
226 * plus one pixel, so we give them two. */
227 tables_size += p_vout->i_bytes_per_line * 2;
229 /* Allocate memory */
230 p_vout->yuv.p_base = malloc( tables_size );
231 if( p_vout->yuv.p_base == NULL )
233 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
237 /* Initialize tables */
242 /*******************************************************************************
243 * vout_ResetTables: re-initialize translations tables
244 *******************************************************************************
245 * This function will initialize the tables allocated by vout_CreateTables and
246 * set functions pointers.
247 *******************************************************************************/
248 int vout_ResetYUV( vout_thread_t *p_vout )
250 vout_EndYUV( p_vout );
251 return( vout_InitYUV( p_vout ) );
254 /*******************************************************************************
255 * vout_EndYUV: destroy translations tables
256 *******************************************************************************
257 * Free memory allocated by vout_CreateTables.
258 *******************************************************************************/
259 void vout_EndYUV( vout_thread_t *p_vout )
261 free( p_vout->yuv.p_base );
264 /* following functions are local */
266 /*******************************************************************************
267 * BinaryLog: computes the base 2 log of a binary value
268 *******************************************************************************
269 * This functions is used by MaskToShift during tables initialisation, to
270 * get a bit index from a binary value.
271 *******************************************************************************/
272 static int BinaryLog(u32 i)
297 if (i != ((u32)1 << i_log))
299 intf_ErrMsg("internal error: binary log overflow\n");
305 /*******************************************************************************
306 * MaskToShift: Transform a color mask into right and left shifts
307 *******************************************************************************
308 * This function is used during table initialisation. It can return a value
309 *******************************************************************************/
310 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
312 u32 i_low, i_high; /* lower hand higher bits of the mask */
315 i_low = i_mask & (- i_mask); /* lower bit of the mask */
316 i_high = i_mask + i_low; /* higher bit of the mask */
318 /* Transform bits into an index */
319 i_low = BinaryLog (i_low);
320 i_high = BinaryLog (i_high);
322 /* Update pointers and return */
324 *pi_right = (8 - i_high + i_low);
327 /*******************************************************************************
328 * SetGammaTable: return intensity table transformed by gamma curve.
329 *******************************************************************************
330 * pi_table is a table of 256 entries from 0 to 255.
331 *******************************************************************************/
332 static void SetGammaTable( int *pi_table, double f_gamma )
334 int i_y; /* base intensity */
336 /* Use exp(gamma) instead of gamma */
337 f_gamma = exp(f_gamma );
339 /* Build gamma table */
340 for( i_y = 0; i_y < 256; i_y++ )
342 pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
346 /*******************************************************************************
347 * SetYUV: compute tables and set function pointers
348 + *******************************************************************************/
349 static void SetYUV( vout_thread_t *p_vout )
351 int pi_gamma[256]; /* gamma table */
352 int i_index; /* index in tables */
353 int i_red_right, i_red_left; /* red shifts */
354 int i_green_right, i_green_left; /* green shifts */
355 int i_blue_right, i_blue_left; /* blue shifts */
357 /* Build gamma table */
358 SetGammaTable( pi_gamma, p_vout->f_gamma );
361 * Set color masks and shifts
363 switch( p_vout->i_screen_depth )
366 MaskToShift( &i_red_right, &i_red_left, 0x7c00 );
367 MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
368 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
371 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
372 MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
373 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
377 MaskToShift( &i_red_right, &i_red_left, 0x00ff0000 );
378 MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
379 MaskToShift( &i_blue_right, &i_blue_left, 0x000000ff );
383 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
389 * Set pointers and build YUV tables
391 if( p_vout->b_grayscale )
393 /* Grayscale: build gray table */
394 switch( p_vout->i_screen_depth )
398 p_vout->yuv.yuv.gray16.p_gray = (u16 *)p_vout->yuv.p_base + 384;
399 for( i_index = -384; i_index < 640; i_index++)
401 p_vout->yuv.yuv.gray16.p_gray[ i_index ] =
402 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
403 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
404 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
409 p_vout->yuv.yuv.gray32.p_gray = (u32 *)p_vout->yuv.p_base + 384;
410 for( i_index = -384; i_index < 640; i_index++)
412 p_vout->yuv.yuv.gray32.p_gray[ i_index ] =
413 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
414 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
415 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
422 /* Color: build red, green and blue tables */
423 switch( p_vout->i_screen_depth )
427 p_vout->yuv.yuv.rgb16.p_red = (u16 *)p_vout->yuv.p_base + 384;
428 p_vout->yuv.yuv.rgb16.p_green = (u16 *)p_vout->yuv.p_base + 1024 + 384;
429 p_vout->yuv.yuv.rgb16.p_blue = (u16 *)p_vout->yuv.p_base + 2*1024 + 384;
430 p_vout->yuv.yuv2.p_rgb16 = (u16 *)p_vout->yuv.p_base + 3*1024;
431 p_vout->yuv.p_buffer = (u16 *)p_vout->yuv.p_base + 3*1024 + 1935;
432 for( i_index = -384; i_index < 640; i_index++)
434 p_vout->yuv.yuv.rgb16.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
435 p_vout->yuv.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
436 p_vout->yuv.yuv.rgb16.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
438 for( i_index = 0; i_index < 178; i_index++ )
440 p_vout->yuv.yuv2.p_rgb16[1501 - 178 + i_index] = (pi_gamma[0]>>i_red_right)<<i_red_left;
441 p_vout->yuv.yuv2.p_rgb16[1501 + 256 + i_index] = (pi_gamma[255]>>i_red_right)<<i_red_left;
443 for( i_index = 0; i_index < 135; i_index++ )
445 p_vout->yuv.yuv2.p_rgb16[135 - 135 + i_index] = (pi_gamma[0]>>i_green_right)<<i_green_left;
446 p_vout->yuv.yuv2.p_rgb16[135 + 256 + i_index] = (pi_gamma[255]>>i_green_right)<<i_green_left;
448 for( i_index = 0; i_index < 224; i_index++ )
450 p_vout->yuv.yuv2.p_rgb16[818 - 224 + i_index] = (pi_gamma[0]>>i_blue_right)<<i_blue_left;
451 p_vout->yuv.yuv2.p_rgb16[818 + 256 + i_index] = (pi_gamma[255]>>i_blue_right)<<i_blue_left;
453 for( i_index = 0; i_index < 256; i_index++ )
455 p_vout->yuv.yuv2.p_rgb16[1501 + i_index] = (pi_gamma[i_index]>>i_red_right)<<i_red_left;
456 p_vout->yuv.yuv2.p_rgb16[135 + i_index] = (pi_gamma[i_index]>>i_green_right)<<i_green_left;
457 p_vout->yuv.yuv2.p_rgb16[818 + i_index] = (pi_gamma[i_index]>>i_blue_right)<<i_blue_left;
462 p_vout->yuv.yuv.rgb32.p_red = (u32 *)p_vout->yuv.p_base + 384;
463 p_vout->yuv.yuv.rgb32.p_green = (u32 *)p_vout->yuv.p_base + 1024 + 384;
464 p_vout->yuv.yuv.rgb32.p_blue = (u32 *)p_vout->yuv.p_base + 2*1024 + 384;
465 p_vout->yuv.yuv2.p_rgb32 = (u32 *)p_vout->yuv.p_base + 3*1024;
466 p_vout->yuv.p_buffer = (u32 *)p_vout->yuv.p_base + 3*1024 + 1935;
467 for( i_index = -384; i_index < 640; i_index++)
469 p_vout->yuv.yuv.rgb32.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
470 p_vout->yuv.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
471 p_vout->yuv.yuv.rgb32.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
479 * Set functions pointers
481 if( p_vout->b_grayscale )
484 switch( p_vout->i_screen_depth )
488 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
489 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
490 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
493 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
494 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
495 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
498 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
499 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
500 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
507 switch( p_vout->i_screen_depth )
511 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB16;
512 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB16;
513 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB16;
516 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB24;
517 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB24;
518 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB24;
521 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB32;
522 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB32;
523 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB32;
529 /*******************************************************************************
530 * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
531 *******************************************************************************/
532 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,
533 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
534 int i_matrix_coefficients )
536 u16 * p_gray; /* gray table */
537 int i_x, i_y; /* picture coordinates */
539 p_gray = p_vout->yuv.yuv.gray16.p_gray;
543 /*******************************************************************************
544 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
545 *******************************************************************************/
546 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,
547 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
548 int i_matrix_coefficients )
553 /*******************************************************************************
554 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
555 *******************************************************************************/
556 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,
557 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
558 int i_matrix_coefficients )
560 u32 * p_gray; /* gray table */
561 int i_x, i_y; /* picture coordinates */
563 p_gray = p_vout->yuv.yuv.gray32.p_gray;
567 /*******************************************************************************
568 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
569 *******************************************************************************/
570 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,
571 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
572 int i_matrix_coefficients )
575 // int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
577 i_chroma_width = i_width / 2;
578 i_chroma_skip = i_skip / 2;
579 ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height,
580 (i_width + i_skip) * sizeof( yuv_data_t ),
581 (i_chroma_width + i_chroma_skip) * sizeof( yuv_data_t),
582 i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
583 p_vout->i_screen_depth == 15 );
587 u16 * p_red; /* red table */
588 u16 * p_green; /* green table */
589 u16 * p_blue; /* blue table */
590 int i_uval, i_yval, i_vval; /* samples */
591 int i_x, i_y; /* picture coordinates */
592 int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
593 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
595 p_red = p_vout->yuv.yuv.rgb16.p_red;
596 p_green = p_vout->yuv.yuv.rgb16.p_green;
597 p_blue = p_vout->yuv.yuv.rgb16.p_blue;
598 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
599 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
600 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
601 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
603 CONVERT_YUV_RGB( 420, i_crv, i_cgv, i_cbu, i_cgu );
605 int i_x, i_y; /* horizontal and vertical indexes */
606 int i_uval, i_vval; /* U and V samples */
607 int i_red, i_green, i_blue; /* U and V modified samples */
608 int i_chroma_width; /* chroma width */
609 int i_height_count; /* height modulo counter */
610 u16 * p_yuv; /* base convertion table */
611 u16 * p_ybase; /* Y dependant convertion table */
614 /* Initialize values */
615 i_height_count = i_pic_height;
616 i_chroma_width = i_width / 2;
617 p_yuv = p_vout->yuv.yuv2.p_rgb16;
619 /*?? temporary kludge to protect from segfault at startup */
620 i_height = MIN( i_height, i_pic_height );
625 for( i_y = 0; i_y < i_height; i_y++ )
627 /* Mark beginnning of line */
630 /* Convert line using 16 pixels blocks, since picture come from 16 pixels width
632 for( i_x = i_width / 16; i_x--; )
636 i_red = (V_RED_COEF * i_vval) >> SHIFT;
637 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
638 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
640 p_ybase = p_yuv + *(p_y++);
641 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
642 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
643 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
644 p_ybase = p_yuv + *(p_y++);
645 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
646 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
647 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
651 i_red = (V_RED_COEF * i_vval) >> SHIFT;
652 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
653 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
655 p_ybase = p_yuv + *(p_y++);
656 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
657 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
658 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
659 p_ybase = p_yuv + *(p_y++);
660 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
661 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
662 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
666 i_red = (V_RED_COEF * i_vval) >> SHIFT;
667 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
668 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
670 p_ybase = p_yuv + *(p_y++);
671 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
672 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
673 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
674 p_ybase = p_yuv + *(p_y++);
675 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
676 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
677 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
681 i_red = (V_RED_COEF * i_vval) >> SHIFT;
682 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
683 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
685 p_ybase = p_yuv + *(p_y++);
686 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
687 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
688 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
689 p_ybase = p_yuv + *(p_y++);
690 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
691 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
692 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
696 i_red = (V_RED_COEF * i_vval) >> SHIFT;
697 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
698 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
700 p_ybase = p_yuv + *(p_y++);
701 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
702 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
703 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
704 p_ybase = p_yuv + *(p_y++);
705 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
706 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
707 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
711 i_red = (V_RED_COEF * i_vval) >> SHIFT;
712 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
713 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
715 p_ybase = p_yuv + *(p_y++);
716 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
717 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
718 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
719 p_ybase = p_yuv + *(p_y++);
720 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
721 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
722 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
726 i_red = (V_RED_COEF * i_vval) >> SHIFT;
727 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
728 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
730 p_ybase = p_yuv + *(p_y++);
731 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
732 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
733 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
734 p_ybase = p_yuv + *(p_y++);
735 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
736 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
737 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
741 i_red = (V_RED_COEF * i_vval) >> SHIFT;
742 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;
743 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT;
745 p_ybase = p_yuv + *(p_y++);
746 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
747 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
748 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
749 p_ybase = p_yuv + *(p_y++);
750 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] |
751 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] |
752 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue];
755 /* If line is odd, rewind U and V samples */
758 p_u -= i_chroma_width;
759 p_v -= i_chroma_width;
762 /* End of line: skip picture to reach beginning of next line */
763 p_pic += i_pic_line_width - i_pic_width;
765 /* Copy line if needed */
766 while( (i_height_count -= i_height) >= 0 )
768 for( i_x = i_pic_width / 16; i_x--; )
770 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
771 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
772 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
773 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
775 p_pic += i_pic_line_width - i_pic_width;
776 p_pic_start += i_pic_line_width - i_pic_width;
778 i_height_count += i_pic_height;
783 /*******************************************************************************
784 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
785 *******************************************************************************/
786 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,
787 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
788 int i_matrix_coefficients )
793 /*******************************************************************************
794 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
795 *******************************************************************************/
796 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,
797 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
798 int i_matrix_coefficients )
803 /*******************************************************************************
804 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
805 *******************************************************************************/
806 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,
807 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
808 int i_matrix_coefficients )
813 /*******************************************************************************
814 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
815 *******************************************************************************/
816 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,
817 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
818 int i_matrix_coefficients )
823 /*******************************************************************************
824 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
825 *******************************************************************************/
826 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,
827 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
828 int i_matrix_coefficients )
833 /*******************************************************************************
834 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
835 *******************************************************************************/
836 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,
837 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
838 int i_matrix_coefficients )
843 /*******************************************************************************
844 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
845 *******************************************************************************/
846 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,
847 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
848 int i_matrix_coefficients )
853 /*******************************************************************************
854 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
855 *******************************************************************************/
856 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,
857 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
858 int i_matrix_coefficients )
863 //-------------------- walken code follow ---------------------------------------
866 * YUV to RGB routines.
868 * these routines calculate r, g and b values from each pixel's y, u and v.
869 * these r, g an b values are then passed thru a table lookup to take the
870 * gamma curve into account and find the corresponding pixel value.
872 * the table must store more than 3*256 values because of the possibility
873 * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
874 * values are in the following intervals :
875 * -176 to 255+176 for red
876 * -133 to 255+133 for green
877 * -222 to 255+222 for blue
879 * If the input y,u,v values are right, the r,g,b results are not expected
880 * to move out of the 0 to 255 interval but who knows what will happen in
883 * the red, green and blue conversion tables are stored in a single 1935-entry
884 * array. The respective positions of each component in the array have been
885 * calculated to minimize the cache interactions of the 3 tables.
888 int rgbTable16 (short table [1935],
889 int redMask, int greenMask, int blueMask,
890 unsigned char gamma[256])
904 MaskToShift (&redRight, &redLeft, redMask);
905 MaskToShift (&greenRight, &greenLeft, greenMask);
906 MaskToShift (&blueRight, &blueLeft, blueMask);
909 * green blue red +- 2 just to be sure
910 * green = 0-525 [151-370]
911 * blue = 594-1297 [834-1053] <834-29>
912 * red = 1323-1934 [1517-1736] <493-712>
915 redTable = table + 1501;
916 greenTable = table + 135;
917 blueTable = table + 818;
919 for (i = 0; i < 178; i++) {
921 redTable[i+256] = redMask;
923 for (i = 0; i < 135; i++) {
924 greenTable[i-135] = 0;
925 greenTable[i+256] = greenMask;
927 for (i = 0; i < 224; i++) {
928 blueTable[i-224] = 0;
929 blueTable[i+256] = blueMask;
932 for (i = 0; i < 256; i++) {
934 redTable[i] = ((y >> redRight) << redLeft);
935 greenTable[i] = ((y >> greenRight) << greenLeft);
936 blueTable[i] = ((y >> blueRight) << blueLeft);
942 static int rgbTable32 (int table [1935],
943 int redMask, int greenMask, int blueMask,
944 unsigned char gamma[256])
958 MaskToShift (&redRight, &redLeft, redMask);
959 MaskToShift (&greenRight, &greenLeft, greenMask);
960 MaskToShift (&blueRight, &blueLeft, blueMask);
964 * green blue red +- 2 just to be sure
965 * green = 0-525 [151-370]
966 * blue = 594-1297 [834-1053] <834-29>
967 * red = 1323-1934 [1517-1736] <493-712>
970 redTable = table + 1501;
971 greenTable = table + 135;
972 blueTable = table + 818;
974 for (i = 0; i < 178; i++) {
976 redTable[i+256] = redMask;
978 for (i = 0; i < 135; i++) {
979 greenTable[i-135] = 0;
980 greenTable[i+256] = greenMask;
982 for (i = 0; i < 224; i++) {
983 blueTable[i-224] = 0;
984 blueTable[i+256] = blueMask;
987 for (i = 0; i < 256; i++) {
989 redTable[i] = ((y >> redRight) << redLeft);
990 greenTable[i] = ((y >> greenRight) << greenLeft);
991 blueTable[i] = ((y >> blueRight) << blueLeft);
998 void yuvToRgb16 (unsigned char * Y,
999 unsigned char * U, unsigned char * V,
1000 short * dest, short table[1935], int width)
1014 uvRed = (V_RED_COEF*v) >> SHIFT;
1015 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1016 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1018 tableY = table + *(Y++);
1019 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1020 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1022 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1024 tableY = table + *(Y++);
1025 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1026 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1028 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1032 uvRed = (V_RED_COEF*v) >> SHIFT;
1033 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1034 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1036 tableY = table + *(Y++);
1037 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1038 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1040 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1042 tableY = table + *(Y++);
1043 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1044 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1046 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1050 uvRed = (V_RED_COEF*v) >> SHIFT;
1051 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1052 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1054 tableY = table + *(Y++);
1055 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1056 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1058 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1060 tableY = table + *(Y++);
1061 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1062 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1064 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1068 uvRed = (V_RED_COEF*v) >> SHIFT;
1069 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1070 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1072 tableY = table + *(Y++);
1073 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1074 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1076 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1078 tableY = table + *(Y++);
1079 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1080 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1082 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1086 uvRed = (V_RED_COEF*v) >> SHIFT;
1087 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1088 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1090 tableY = table + *(Y++);
1091 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1092 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1094 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1096 tableY = table + *(Y++);
1097 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1098 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1100 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1104 uvRed = (V_RED_COEF*v) >> SHIFT;
1105 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1106 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1108 tableY = table + *(Y++);
1109 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1110 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1112 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1114 tableY = table + *(Y++);
1115 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1116 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1118 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1122 uvRed = (V_RED_COEF*v) >> SHIFT;
1123 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1124 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1126 tableY = table + *(Y++);
1127 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1128 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1130 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1132 tableY = table + *(Y++);
1133 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1134 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1136 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1140 uvRed = (V_RED_COEF*v) >> SHIFT;
1141 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1142 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1144 tableY = table + *(Y++);
1145 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1146 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1148 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
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]);
1157 i = (width & 15) >> 1;
1161 uvRed = (V_RED_COEF*v) >> SHIFT;
1162 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1163 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1165 tableY = table + *(Y++);
1166 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1167 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1169 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1171 tableY = table + *(Y++);
1172 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1173 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1175 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1181 uvRed = (V_RED_COEF*v) >> SHIFT;
1182 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1183 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1185 tableY = table + *(Y++);
1186 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1187 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1189 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1193 static void yuvToRgb24 (unsigned char * Y,
1194 unsigned char * U, unsigned char * V,
1195 char * dest, int table[1935], int width)
1210 uvRed = (V_RED_COEF*v) >> SHIFT;
1211 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1212 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1214 tableY = table + *(Y++);
1215 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1216 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1218 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1220 *(dest++) = tmp24 >> 8;
1221 *(dest++) = tmp24 >> 16;
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;
1234 uvRed = (V_RED_COEF*v) >> SHIFT;
1235 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1236 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1238 tableY = table + *(Y++);
1239 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1240 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1242 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1244 *(dest++) = tmp24 >> 8;
1245 *(dest++) = tmp24 >> 16;
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;
1258 uvRed = (V_RED_COEF*v) >> SHIFT;
1259 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1260 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1262 tableY = table + *(Y++);
1263 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1264 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1266 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1268 *(dest++) = tmp24 >> 8;
1269 *(dest++) = tmp24 >> 16;
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;
1282 uvRed = (V_RED_COEF*v) >> SHIFT;
1283 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1284 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1286 tableY = table + *(Y++);
1287 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1288 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1290 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1292 *(dest++) = tmp24 >> 8;
1293 *(dest++) = tmp24 >> 16;
1295 tableY = table + *(Y++);
1296 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1297 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1299 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1301 *(dest++) = tmp24 >> 8;
1302 *(dest++) = tmp24 >> 16;
1305 i = (width & 7) >> 1;
1309 uvRed = (V_RED_COEF*v) >> SHIFT;
1310 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1311 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1313 tableY = table + *(Y++);
1314 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1315 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1317 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1319 *(dest++) = tmp24 >> 8;
1320 *(dest++) = tmp24 >> 16;
1322 tableY = table + *(Y++);
1323 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1324 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1326 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1328 *(dest++) = tmp24 >> 8;
1329 *(dest++) = tmp24 >> 16;
1335 uvRed = (V_RED_COEF*v) >> SHIFT;
1336 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1337 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1339 tableY = table + *(Y++);
1340 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1341 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1343 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1345 *(dest++) = tmp24 >> 8;
1346 *(dest++) = tmp24 >> 16;
1350 static void yuvToRgb32 (unsigned char * Y,
1351 unsigned char * U, unsigned char * V,
1352 int * dest, int table[1935], int width)
1366 uvRed = (V_RED_COEF*v) >> SHIFT;
1367 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1368 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1370 tableY = table + *(Y++);
1371 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1372 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1374 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1376 tableY = table + *(Y++);
1377 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1378 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1380 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1384 uvRed = (V_RED_COEF*v) >> SHIFT;
1385 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1386 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1388 tableY = table + *(Y++);
1389 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1390 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1392 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1394 tableY = table + *(Y++);
1395 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1396 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1398 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1402 uvRed = (V_RED_COEF*v) >> SHIFT;
1403 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1404 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1406 tableY = table + *(Y++);
1407 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1408 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1410 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1412 tableY = table + *(Y++);
1413 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1414 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1416 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1420 uvRed = (V_RED_COEF*v) >> SHIFT;
1421 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1422 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1424 tableY = table + *(Y++);
1425 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1426 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1428 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1430 tableY = table + *(Y++);
1431 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1432 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1434 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1438 uvRed = (V_RED_COEF*v) >> SHIFT;
1439 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1440 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1442 tableY = table + *(Y++);
1443 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1444 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1446 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1448 tableY = table + *(Y++);
1449 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1450 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1452 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1456 uvRed = (V_RED_COEF*v) >> SHIFT;
1457 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1458 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1460 tableY = table + *(Y++);
1461 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1462 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1464 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1466 tableY = table + *(Y++);
1467 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1468 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1470 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1474 uvRed = (V_RED_COEF*v) >> SHIFT;
1475 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1476 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1478 tableY = table + *(Y++);
1479 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1480 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1482 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1484 tableY = table + *(Y++);
1485 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1486 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1488 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1492 uvRed = (V_RED_COEF*v) >> SHIFT;
1493 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1494 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1496 tableY = table + *(Y++);
1497 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1498 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1500 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
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]);
1509 i = (width & 15) >> 1;
1513 uvRed = (V_RED_COEF*v) >> SHIFT;
1514 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1515 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1517 tableY = table + *(Y++);
1518 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1519 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1521 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1523 tableY = table + *(Y++);
1524 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1525 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1527 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1533 uvRed = (V_RED_COEF*v) >> SHIFT;
1534 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1535 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1537 tableY = table + *(Y++);
1538 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1539 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1541 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1545 /* yuv routines with scaling */
1546 /* 4:2:2 i, 16 bpp*/
1548 void yuv422ToRgb16_scaled (unsigned char * Y,
1549 unsigned char * U, unsigned char * V,
1550 short * dest, short table[1935], int width , int dest_width,
1551 int height, int dest_height, int skip, int dest_skip,short * buffer)
1553 int i, i_hcount, i_vcount, j, k;
1562 if ( ( width < dest_width ) && ( height < dest_height ) )
1564 i_vcount = dest_height;
1570 i_hcount = dest_width;
1575 uvRed = (V_RED_COEF*v) >> SHIFT;
1576 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1577 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1579 tableY = table + *(Y++);
1580 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1581 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1582 >>SHIFT) + uvGreen] |
1583 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1584 while ( ( i_hcount -= width ) >= 0 )
1588 i_hcount += dest_width;
1590 tableY = table + *(Y++);
1591 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1592 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1593 >>SHIFT) + uvGreen] |
1594 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1595 while ( ( i_hcount -= width ) >= 0 )
1599 i_hcount += dest_width;
1601 while ( ( i_vcount -= height ) >= 0 )
1603 for (j=0; j<dest_width; j+=16)
1606 dest[j+1]=buffer[j+1];
1607 dest[j+2]=buffer[j+2];
1608 dest[j+3]=buffer[j+3];
1609 dest[j+4]=buffer[j+4];
1610 dest[j+6]=buffer[j+7];
1611 dest[j+8]=buffer[j+9];
1612 dest[j+10]=buffer[j+10];
1613 dest[j+11]=buffer[j+11];
1614 dest[j+12]=buffer[j+12];
1615 dest[j+13]=buffer[j+13];
1616 dest[j+14]=buffer[j+14];
1617 dest[j+15]=buffer[j+15];
1621 i_vcount += dest_height;
1624 else if ( ( width > dest_width ) && ( height < dest_height ) )
1626 i_vcount = dest_height;
1637 uvRed = (V_RED_COEF*v) >> SHIFT;
1638 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1639 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1641 if ( ( i_hcount -= dest_width ) >= 0 )
1645 tableY = table + *(Y++);
1646 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1649 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1651 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1655 if ( ( i_hcount -= dest_width ) >= 0 )
1659 tableY = table + *(Y++);
1660 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1663 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1665 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1670 while ( ( i_vcount -= height ) >= 0 )
1672 for (j=0; j<dest_width; j+=16)
1675 dest[j+1]=buffer[j+1];
1676 dest[j+2]=buffer[j+2];
1677 dest[j+3]=buffer[j+3];
1678 dest[j+4]=buffer[j+4];
1679 dest[j+6]=buffer[j+7];
1680 dest[j+8]=buffer[j+9];
1681 dest[j+10]=buffer[j+10];
1682 dest[j+11]=buffer[j+11];
1683 dest[j+12]=buffer[j+12];
1684 dest[j+13]=buffer[j+13];
1685 dest[j+14]=buffer[j+14];
1686 dest[j+15]=buffer[j+15];
1690 i_vcount += dest_height;
1693 else if ( ( width < dest_width ) && ( height > dest_height ) )
1701 i_hcount = dest_width;
1706 uvRed = (V_RED_COEF*v) >> SHIFT;
1707 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1708 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1710 tableY = table + *(Y++);
1711 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1712 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1713 >>SHIFT) + uvGreen] |
1714 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1715 while ( ( i_hcount -= width ) >= 0 )
1719 i_hcount += dest_width;
1721 tableY = table + *(Y++);
1722 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1723 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1724 >>SHIFT) + uvGreen] |
1725 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1726 while ( ( i_hcount -= width ) >= 0 )
1730 i_hcount += dest_width;
1732 while ( ( i_vcount -= height ) >= 0 )
1738 i_vcount += dest_height;
1741 else if ( ( width > dest_width ) && ( height > dest_height ) )
1743 i_vcount = dest_height;
1754 uvRed = (V_RED_COEF*v) >> SHIFT;
1755 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1756 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1758 if ( ( i_hcount -= dest_width ) >= 0 )
1762 tableY = table + *(Y++);
1763 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1766 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1768 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1772 if ( ( i_hcount -= dest_width ) >= 0 )
1776 tableY = table + *(Y++);
1777 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1780 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1782 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1787 while ( ( i_vcount -= height ) >= 0 )
1793 i_vcount += dest_height;
1798 /* yuv routines with scaling */
1799 /* 4:2:0 i, 16 bpp*/
1801 void yuv420ToRgb16_scaled (unsigned char * Y,
1802 unsigned char * U, unsigned char * V,
1803 short * dest, short table[1935], int width , int dest_width,
1804 int height, int dest_height, int skip, int dest_skip,short * buffer)
1806 int i, i_hcount, i_vcount, j, k;
1815 if ( ( width < dest_width ) && ( height < dest_height ) )
1817 i_vcount = dest_height;
1823 i_hcount = dest_width;
1828 uvRed = (V_RED_COEF*v) >> SHIFT;
1829 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1830 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1832 tableY = table + *(Y++);
1833 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1834 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1835 >>SHIFT) + uvGreen] |
1836 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1837 while ( ( i_hcount -= width ) >= 0 )
1841 i_hcount += dest_width;
1843 tableY = table + *(Y++);
1844 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1845 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1846 >>SHIFT) + uvGreen] |
1847 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1848 while ( ( i_hcount -= width ) >= 0 )
1852 i_hcount += dest_width;
1854 while ( ( i_vcount -= height ) >= 0 )
1856 for (j=0; j<dest_width; j+=16)
1859 dest[j+1]=buffer[j+1];
1860 dest[j+2]=buffer[j+2];
1861 dest[j+3]=buffer[j+3];
1862 dest[j+4]=buffer[j+4];
1863 dest[j+6]=buffer[j+7];
1864 dest[j+8]=buffer[j+9];
1865 dest[j+10]=buffer[j+10];
1866 dest[j+11]=buffer[j+11];
1867 dest[j+12]=buffer[j+12];
1868 dest[j+13]=buffer[j+13];
1869 dest[j+14]=buffer[j+14];
1870 dest[j+15]=buffer[j+15];
1874 i_vcount += dest_height;
1879 i_hcount = dest_width;
1884 uvRed = (V_RED_COEF*v) >> SHIFT;
1885 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1886 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1888 tableY = table + *(Y++);
1889 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1890 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1891 >>SHIFT) + uvGreen] |
1892 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1893 while ( ( i_hcount -= width ) >= 0 )
1897 i_hcount += dest_width;
1899 tableY = table + *(Y++);
1900 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1901 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1902 >>SHIFT) + uvGreen] |
1903 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1904 while ( ( i_hcount -= width ) >= 0 )
1908 i_hcount += dest_width;
1910 while ( ( i_vcount -= height ) >= 0 )
1912 for (j=0; j<dest_width; j+=16)
1915 dest[j+1]=buffer[j+1];
1916 dest[j+2]=buffer[j+2];
1917 dest[j+3]=buffer[j+3];
1918 dest[j+4]=buffer[j+4];
1919 dest[j+6]=buffer[j+7];
1920 dest[j+8]=buffer[j+9];
1921 dest[j+10]=buffer[j+10];
1922 dest[j+11]=buffer[j+11];
1923 dest[j+12]=buffer[j+12];
1924 dest[j+13]=buffer[j+13];
1925 dest[j+14]=buffer[j+14];
1926 dest[j+15]=buffer[j+15];
1930 i_vcount += dest_height;
1933 else if ( ( width > dest_width ) && ( height < dest_height ) )
1935 i_vcount = dest_height;
1946 uvRed = (V_RED_COEF*v) >> SHIFT;
1947 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1948 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1950 if ( ( i_hcount -= dest_width ) >= 0 )
1954 tableY = table + *(Y++);
1955 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1958 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1960 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1964 if ( ( i_hcount -= dest_width ) >= 0 )
1968 tableY = table + *(Y++);
1969 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1972 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1974 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1979 while ( ( i_vcount -= height ) >= 0 )
1981 for (j=0; j<dest_width; j+=16)
1984 dest[j+1]=buffer[j+1];
1985 dest[j+2]=buffer[j+2];
1986 dest[j+3]=buffer[j+3];
1987 dest[j+4]=buffer[j+4];
1988 dest[j+6]=buffer[j+7];
1989 dest[j+8]=buffer[j+9];
1990 dest[j+10]=buffer[j+10];
1991 dest[j+11]=buffer[j+11];
1992 dest[j+12]=buffer[j+12];
1993 dest[j+13]=buffer[j+13];
1994 dest[j+14]=buffer[j+14];
1995 dest[j+15]=buffer[j+15];
1999 i_vcount += dest_height;
2009 uvRed = (V_RED_COEF*v) >> SHIFT;
2010 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2011 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2013 if ( ( i_hcount -= dest_width ) >= 0 )
2017 tableY = table + *(Y++);
2018 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2021 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2023 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2027 if ( ( i_hcount -= dest_width ) >= 0 )
2031 tableY = table + *(Y++);
2032 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2035 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2037 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2042 while ( ( i_vcount -= height ) >= 0 )
2044 for (j=0; j<dest_width; j+=16)
2047 dest[j+1]=buffer[j+1];
2048 dest[j+2]=buffer[j+2];
2049 dest[j+3]=buffer[j+3];
2050 dest[j+4]=buffer[j+4];
2051 dest[j+6]=buffer[j+7];
2052 dest[j+8]=buffer[j+9];
2053 dest[j+10]=buffer[j+10];
2054 dest[j+11]=buffer[j+11];
2055 dest[j+12]=buffer[j+12];
2056 dest[j+13]=buffer[j+13];
2057 dest[j+14]=buffer[j+14];
2058 dest[j+15]=buffer[j+15];
2062 i_vcount += dest_height;
2065 else if ( ( width < dest_width ) && ( height > dest_height ) )
2073 i_hcount = dest_width;
2078 uvRed = (V_RED_COEF*v) >> SHIFT;
2079 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2080 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2082 tableY = table + *(Y++);
2083 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2084 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2085 >>SHIFT) + uvGreen] |
2086 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2087 while ( ( i_hcount -= width ) >= 0 )
2091 i_hcount += dest_width;
2093 tableY = table + *(Y++);
2094 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2095 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2096 >>SHIFT) + uvGreen] |
2097 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2098 while ( ( i_hcount -= width ) >= 0 )
2102 i_hcount += dest_width;
2105 while ( ( i_vcount -= height ) >= 0 )
2110 U += skip * ( j >> 1 );
2111 V += skip * ( j >> 1 );
2112 i_vcount += dest_height;
2115 else if ( ( width > dest_width ) && ( height > dest_height ) )
2117 i_vcount = dest_height;
2128 uvRed = (V_RED_COEF*v) >> SHIFT;
2129 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2130 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2132 if ( ( i_hcount -= dest_width ) >= 0 )
2136 tableY = table + *(Y++);
2137 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2140 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2142 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2146 if ( ( i_hcount -= dest_width ) >= 0 )
2150 tableY = table + *(Y++);
2151 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2154 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2156 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2162 while ( ( i_vcount -= height ) >= 0 )
2167 U += skip * ( j >> 1 );
2168 V += skip * ( j >> 1 );
2169 i_vcount += dest_height;