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) */
44 /*******************************************************************************
46 *******************************************************************************/
47 static int BinaryLog ( u32 i );
48 static void MaskToShift ( int *pi_right, int *pi_left, u32 i_mask );
49 static void SetGammaTable ( int *pi_table, double f_gamma );
50 static void SetTables ( vout_thread_t *p_vout );
52 static void ConvertY4Gray16 ( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
53 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
54 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,
55 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
56 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,
57 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
58 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,
59 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
60 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,
61 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
62 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,
63 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
64 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,
65 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
66 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,
67 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
68 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,
69 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
70 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,
71 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
72 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,
73 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
74 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,
75 int i_width, int i_height, int i_eol, int i_pic_eol, int i_scale, int i_matrix_coefficients );
77 /*******************************************************************************
78 * CLIP_BYTE macro: boundary detection
79 *******************************************************************************
80 * Return parameter if between 0 and 255, else return nearest boundary (0 or
81 * 255). This macro is used to build translations tables.
82 *******************************************************************************/
83 #define CLIP_BYTE( i_val ) ( (i_val < 0) ? 0 : ((i_val > 255) ? 255 : i_val) )
85 /*******************************************************************************
86 * LINE_COPY macro: memcopy using 16 pixels blocks
87 *******************************************************************************
89 * p_pic destination pointer
90 * p_pic_src source pointer
93 *******************************************************************************/
95 for( i_x = 0; i_x < i_width; i_x+=16 ) \
97 *p_pic++ = *p_pic_src++; \
98 *p_pic++ = *p_pic_src++; \
99 *p_pic++ = *p_pic_src++; \
100 *p_pic++ = *p_pic_src++; \
101 *p_pic++ = *p_pic_src++; \
102 *p_pic++ = *p_pic_src++; \
103 *p_pic++ = *p_pic_src++; \
104 *p_pic++ = *p_pic_src++; \
105 *p_pic++ = *p_pic_src++; \
106 *p_pic++ = *p_pic_src++; \
107 *p_pic++ = *p_pic_src++; \
108 *p_pic++ = *p_pic_src++; \
109 *p_pic++ = *p_pic_src++; \
110 *p_pic++ = *p_pic_src++; \
111 *p_pic++ = *p_pic_src++; \
112 *p_pic++ = *p_pic_src++; \
115 /*******************************************************************************
116 * CONVERT_YUV_GRAY macro: grayscale YUV convertion
117 *******************************************************************************
119 * ...see vout_convert_t
120 * i_x, i_y coordinates
121 * i_pic_copy same type as p_pic
122 * p_gray gray translation table
123 *******************************************************************************/
124 #define CONVERT_YUV_GRAY \
125 for (i_y = 0; i_y < i_height ; i_y++) \
127 for (i_x = 0; i_x < i_width; i_x += 16) \
129 /* Convert 16 pixels (width is always multiple of 16 */ \
130 *p_pic++ = p_gray[ *p_y++ ]; \
131 *p_pic++ = p_gray[ *p_y++ ]; \
132 *p_pic++ = p_gray[ *p_y++ ]; \
133 *p_pic++ = p_gray[ *p_y++ ]; \
134 *p_pic++ = p_gray[ *p_y++ ]; \
135 *p_pic++ = p_gray[ *p_y++ ]; \
136 *p_pic++ = p_gray[ *p_y++ ]; \
137 *p_pic++ = p_gray[ *p_y++ ]; \
138 *p_pic++ = p_gray[ *p_y++ ]; \
139 *p_pic++ = p_gray[ *p_y++ ]; \
140 *p_pic++ = p_gray[ *p_y++ ]; \
141 *p_pic++ = p_gray[ *p_y++ ]; \
142 *p_pic++ = p_gray[ *p_y++ ]; \
143 *p_pic++ = p_gray[ *p_y++ ]; \
144 *p_pic++ = p_gray[ *p_y++ ]; \
145 *p_pic++ = p_gray[ *p_y++ ]; \
148 /* Handle scale factor */ \
149 if( i_scale && ! (i_y % i_scale) ) \
153 /* Copy previous line */ \
154 p_pic_src = p_pic - i_width; \
155 p_pic += i_pic_eol; \
160 /* Ignore next line */ \
161 p_y += i_eol + i_width; \
166 /* Skip until beginning of next line */ \
167 p_pic += i_pic_eol; \
171 /*******************************************************************************
172 * CONVERT_YUV_RGB: color YUV convertion
173 *******************************************************************************
175 * CHROMA 420, 422 or 444
177 * ...see vout_convert_t
178 * i_x, i_y coordinates
179 * i_uval, i_yval, i_vval samples
180 * p_pic_src same type as p_pic
181 * i_chroma_width chroma width
182 * i_chroma_eol chroma eol
183 * p_red red translation table
184 * p_green green translation table
185 * p_blue blue translation table
186 * i_crv, i_cgu, i_cgv, i_cbu matrix coefficients
187 *******************************************************************************/
188 #define CONVERT_YUV_RGB( CHROMA ) \
189 for (i_y = 0; i_y < i_height ; i_y++) \
191 for (i_x = 0; i_x < i_width; i_x += 2 ) \
193 /* First sample (complete) */ \
194 i_yval = 76309 * *p_y++ - 1188177; \
195 i_uval = *p_u++ - 128; \
196 i_vval = *p_v++ - 128; \
198 p_red [(i_yval+i_crv*i_vval) >>16] | \
199 p_green[(i_yval-i_cgu*i_uval-i_cgv*i_vval) >>16] | \
200 p_blue [(i_yval+i_cbu*i_uval) >>16]; \
201 i_yval = 76309 * *p_y++ - 1188177; \
202 /* Second sample (partial) */ \
203 if( CHROMA == 444 ) \
205 i_uval = *p_u++ - 128; \
206 i_vval = *p_v++ - 128; \
209 p_red [(i_yval+i_crv*i_vval) >>16] | \
210 p_green[(i_yval-i_cgu*i_uval-i_cgv*i_vval) >>16] | \
211 p_blue [(i_yval+i_cbu*i_uval) >>16]; \
214 /* Handle scale factor and rewind in 4:2:0 */ \
215 if( i_scale && ! (i_y % i_scale) ) \
219 /* Copy previous line, rewind if required */ \
220 p_pic_src = p_pic - i_width; \
221 p_pic += i_pic_eol; \
223 if( (CHROMA == 420) && !(i_y & 0x1) ) \
225 p_u -= i_chroma_width; \
226 p_v -= i_chroma_width; \
230 p_u += i_chroma_eol; \
231 p_v += i_chroma_eol; \
236 /* Ignore next line */ \
237 p_y += i_eol + i_width; \
238 p_u += i_chroma_eol; \
239 p_v += i_chroma_eol; \
243 else if( (CHROMA == 420) && !(i_y & 0x1) ) \
245 p_u -= i_chroma_width; \
246 p_v -= i_chroma_width; \
250 p_u += i_chroma_eol; \
251 p_v += i_chroma_eol; \
254 /* Skip until beginning of next line */ \
255 p_pic += i_pic_eol; \
260 /*******************************************************************************
261 * vout_InitTables: allocate and initialize translations tables
262 *******************************************************************************
263 * This function will allocate memory to store translation tables, depending
264 * of the screen depth.
265 *******************************************************************************/
266 int vout_InitTables( vout_thread_t *p_vout )
268 size_t tables_size; /* tables size, in bytes */
270 /* Computes tables size */
271 switch( p_vout->i_screen_depth )
275 tables_size = sizeof( u16 ) * 1024 * (p_vout->b_grayscale ? 1 : 3);
282 tables_size = sizeof( u32 ) * 1024 * (p_vout->b_grayscale ? 1 : 3);
286 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
292 /* Allocate memory */
293 p_vout->tables.p_base = malloc( tables_size );
294 if( p_vout->tables.p_base == NULL )
296 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
300 /* Initialize tables */
305 /*******************************************************************************
306 * vout_ResetTables: re-initialize translations tables
307 *******************************************************************************
308 * This function will initialize the tables allocated by vout_CreateTables and
309 * set functions pointers.
310 *******************************************************************************/
311 int vout_ResetTables( vout_thread_t *p_vout )
313 vout_EndTables( p_vout );
314 return( vout_InitTables( p_vout ) );
317 /*******************************************************************************
318 * vout_EndTables: destroy translations tables
319 *******************************************************************************
320 * Free memory allocated by vout_CreateTables.
321 *******************************************************************************/
322 void vout_EndTables( vout_thread_t *p_vout )
324 free( p_vout->tables.p_base );
327 /* following functions are local */
329 /*******************************************************************************
330 * BinaryLog: computes the base 2 log of a binary value
331 *******************************************************************************
332 * This functions is used by MaskToShift during tables initialisation, to
333 * get a bit index from a binary value.
334 *******************************************************************************/
335 static int BinaryLog(u32 i)
360 if (i != ((u32)1 << i_log))
362 intf_ErrMsg("internal error: binary log overflow\n");
368 /*******************************************************************************
369 * MaskToShift: Transform a color mask into right and left shifts
370 *******************************************************************************
371 * This function is used during table initialisation. It can return a value
372 *******************************************************************************/
373 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
375 u32 i_low, i_high; /* lower hand higher bits of the mask */
378 i_low = i_mask & (- i_mask); /* lower bit of the mask */
379 i_high = i_mask + i_low; /* higher bit of the mask */
381 /* Transform bits into an index */
382 i_low = BinaryLog (i_low);
383 i_high = BinaryLog (i_high);
385 /* Update pointers and return */
387 *pi_right = (8 - i_high + i_low);
390 /*******************************************************************************
391 * SetGammaTable: return intensity table transformed by gamma curve.
392 *******************************************************************************
393 * pi_table is a table of 256 entries from 0 to 255.
394 *******************************************************************************/
395 static void SetGammaTable( int *pi_table, double f_gamma )
397 int i_y; /* base intensity */
399 /* Use exp(gamma) instead of gamma */
400 f_gamma = exp(f_gamma );
402 /* Build gamma table */
403 for( i_y = 0; i_y < 256; i_y++ )
405 pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
409 /*******************************************************************************
410 * SetTables: compute tables and set function pointers
411 + *******************************************************************************/
412 static void SetTables( vout_thread_t *p_vout )
414 int pi_gamma[256]; /* gamma table */
415 int i_index; /* index in tables */
416 int i_red_right, i_red_left; /* red shifts */
417 int i_green_right, i_green_left; /* green shifts */
418 int i_blue_right, i_blue_left; /* blue shifts */
420 /* Build gamma table */
421 SetGammaTable( pi_gamma, p_vout->f_gamma );
424 * Set color masks and shifts
426 switch( p_vout->i_screen_depth )
429 MaskToShift( &i_red_right, &i_red_left, 0x7c00 );
430 MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
431 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
434 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
435 MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
436 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
440 MaskToShift( &i_red_right, &i_red_left, 0x00ff0000 );
441 MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
442 MaskToShift( &i_blue_right, &i_blue_left, 0x000000ff );
446 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
452 * Set pointers and build YUV tables
454 if( p_vout->b_grayscale )
456 /* Grayscale: build gray table */
457 switch( p_vout->i_screen_depth )
461 p_vout->tables.yuv.gray16.p_gray = (u16 *)p_vout->tables.p_base + 384;
462 for( i_index = -384; i_index < 640; i_index++)
464 p_vout->tables.yuv.gray16.p_gray[ i_index ] =
465 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
466 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
467 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
472 p_vout->tables.yuv.gray32.p_gray = (u32 *)p_vout->tables.p_base + 384;
473 for( i_index = -384; i_index < 640; i_index++)
475 p_vout->tables.yuv.gray32.p_gray[ i_index ] =
476 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
477 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
478 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
485 /* Color: build red, green and blue tables */
486 switch( p_vout->i_screen_depth )
490 p_vout->tables.yuv.rgb16.p_red = (u16 *)p_vout->tables.p_base + 384;
491 p_vout->tables.yuv.rgb16.p_green = (u16 *)p_vout->tables.p_base + 1024 + 384;
492 p_vout->tables.yuv.rgb16.p_blue = (u16 *)p_vout->tables.p_base + 2*1024 + 384;
493 for( i_index = -384; i_index < 640; i_index++)
495 p_vout->tables.yuv.rgb16.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
496 p_vout->tables.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
497 p_vout->tables.yuv.rgb16.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
502 p_vout->tables.yuv.rgb32.p_red = (u32 *)p_vout->tables.p_base + 384;
503 p_vout->tables.yuv.rgb32.p_green = (u32 *)p_vout->tables.p_base + 1024 + 384;
504 p_vout->tables.yuv.rgb32.p_blue = (u32 *)p_vout->tables.p_base + 2*1024 + 384;
505 for( i_index = -384; i_index < 640; i_index++)
507 p_vout->tables.yuv.rgb32.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
508 p_vout->tables.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
509 p_vout->tables.yuv.rgb32.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
516 * Set functions pointers
518 if( p_vout->b_grayscale )
521 switch( p_vout->i_screen_depth )
525 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray16;
526 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray16;
527 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray16;
530 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray24;
531 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray24;
532 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray24;
535 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray32;
536 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray32;
537 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertY4Gray32;
544 switch( p_vout->i_screen_depth )
548 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertYUV420RGB16;
549 p_vout->p_ConvertYUV422 = (vout_convert_t *) ConvertYUV422RGB16;
550 p_vout->p_ConvertYUV444 = (vout_convert_t *) ConvertYUV444RGB16;
553 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertYUV420RGB24;
554 p_vout->p_ConvertYUV422 = (vout_convert_t *) ConvertYUV422RGB24;
555 p_vout->p_ConvertYUV444 = (vout_convert_t *) ConvertYUV444RGB24;
558 p_vout->p_ConvertYUV420 = (vout_convert_t *) ConvertYUV420RGB32;
559 p_vout->p_ConvertYUV422 = (vout_convert_t *) ConvertYUV422RGB32;
560 p_vout->p_ConvertYUV444 = (vout_convert_t *) ConvertYUV444RGB32;
566 /*******************************************************************************
567 * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
568 *******************************************************************************/
569 static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic,
570 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
571 int i_width, int i_height, int i_eol, int i_pic_eol,
572 int i_scale, int i_matrix_coefficients )
574 u16 * p_pic_src; /* source pointer in case of copy */
575 u16 * p_gray; /* gray table */
576 int i_x, i_y; /* picture coordinates */
578 p_gray = p_vout->tables.yuv.gray16.p_gray;
582 /*******************************************************************************
583 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
584 *******************************************************************************/
585 static void ConvertY4Gray24( p_vout_thread_t p_vout, void *p_pic,
586 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
587 int i_width, int i_height, int i_eol, int i_pic_eol,
588 int i_scale, int i_matrix_coefficients )
593 /*******************************************************************************
594 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
595 *******************************************************************************/
596 static void ConvertY4Gray32( p_vout_thread_t p_vout, u32 *p_pic,
597 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
598 int i_width, int i_height, int i_eol, int i_pic_eol,
599 int i_scale, int i_matrix_coefficients )
601 u32 * p_pic_src; /* source pointer in case of copy */
602 u32 * p_gray; /* gray table */
603 int i_x, i_y; /* picture coordinates */
605 p_gray = p_vout->tables.yuv.gray32.p_gray;
609 /*******************************************************************************
610 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
611 *******************************************************************************/
612 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic,
613 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
614 int i_width, int i_height, int i_eol, int i_pic_eol,
615 int i_scale, int i_matrix_coefficients )
618 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
620 i_chroma_width = i_width / 2;
621 i_chroma_eol = i_eol / 2;
622 ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height,
623 (i_width + i_eol) * sizeof( yuv_data_t ),
624 (i_chroma_width + i_chroma_eol) * sizeof( yuv_data_t),
625 i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
626 p_vout->i_screen_depth == 15 );
628 u16 * p_pic_src; /* source pointer in case of copy */
629 u16 * p_red; /* red table */
630 u16 * p_green; /* green table */
631 u16 * p_blue; /* blue table */
632 int i_uval, i_yval, i_vval; /* samples */
633 int i_x, i_y; /* picture coordinates */
634 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
635 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
637 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
638 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
639 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
640 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
641 p_red = p_vout->tables.yuv.rgb16.p_red;
642 p_green = p_vout->tables.yuv.rgb16.p_green;
643 p_blue = p_vout->tables.yuv.rgb16.p_blue;
644 i_chroma_width = i_width / 2;
645 i_chroma_eol = i_eol / 2;
646 CONVERT_YUV_RGB( 420 )
650 /*******************************************************************************
651 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
652 *******************************************************************************/
653 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic,
654 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
655 int i_width, int i_height, int i_eol, int i_pic_eol,
656 int i_scale, int i_matrix_coefficients )
658 u16 * p_pic_src; /* source pointer in case of copy */
659 u16 * p_red; /* red table */
660 u16 * p_green; /* green table */
661 u16 * p_blue; /* blue table */
662 int i_uval, i_yval, i_vval; /* samples */
663 int i_x, i_y; /* picture coordinates */
664 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
665 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
667 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
668 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
669 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
670 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
671 p_red = p_vout->tables.yuv.rgb16.p_red;
672 p_green = p_vout->tables.yuv.rgb16.p_green;
673 p_blue = p_vout->tables.yuv.rgb16.p_blue;
674 i_chroma_width = i_width / 2;
675 i_chroma_eol = i_eol / 2;
676 CONVERT_YUV_RGB( 422 )
679 /*******************************************************************************
680 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
681 *******************************************************************************/
682 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic,
683 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
684 int i_width, int i_height, int i_eol, int i_pic_eol,
685 int i_scale, int i_matrix_coefficients )
687 u16 * p_pic_src; /* source pointer in case of copy */
688 u16 * p_red; /* red table */
689 u16 * p_green; /* green table */
690 u16 * p_blue; /* blue table */
691 int i_uval, i_yval, i_vval; /* samples */
692 int i_x, i_y; /* picture coordinates */
693 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
694 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
696 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
697 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
698 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
699 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
700 p_red = p_vout->tables.yuv.rgb16.p_red;
701 p_green = p_vout->tables.yuv.rgb16.p_green;
702 p_blue = p_vout->tables.yuv.rgb16.p_blue;
703 i_chroma_width = i_width;
704 i_chroma_eol = i_eol;
705 CONVERT_YUV_RGB( 444 )
708 /*******************************************************************************
709 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
710 *******************************************************************************/
711 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic,
712 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
713 int i_width, int i_height, int i_eol, int i_pic_eol,
714 int i_scale, int i_matrix_coefficients )
719 /*******************************************************************************
720 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
721 *******************************************************************************/
722 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic,
723 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
724 int i_width, int i_height, int i_eol, int i_pic_eol,
725 int i_scale, int i_matrix_coefficients )
730 /*******************************************************************************
731 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
732 *******************************************************************************/
733 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic,
734 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
735 int i_width, int i_height, int i_eol, int i_pic_eol,
736 int i_scale, int i_matrix_coefficients )
741 /*******************************************************************************
742 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
743 *******************************************************************************/
744 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic,
745 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
746 int i_width, int i_height, int i_eol, int i_pic_eol,
747 int i_scale, int i_matrix_coefficients )
749 u32 * p_pic_src; /* source pointer in case of copy */
750 u32 * p_red; /* red table */
751 u32 * p_green; /* green table */
752 u32 * p_blue; /* blue table */
753 int i_uval, i_yval, i_vval; /* samples */
754 int i_x, i_y; /* picture coordinates */
755 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
756 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
758 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
759 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
760 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
761 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
762 p_red = p_vout->tables.yuv.rgb32.p_red;
763 p_green = p_vout->tables.yuv.rgb32.p_green;
764 p_blue = p_vout->tables.yuv.rgb32.p_blue;
765 i_chroma_width = i_width / 2;
766 i_chroma_eol = i_eol / 2;
767 CONVERT_YUV_RGB( 420 )
770 /*******************************************************************************
771 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
772 *******************************************************************************/
773 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic,
774 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
775 int i_width, int i_height, int i_eol, int i_pic_eol,
776 int i_scale, int i_matrix_coefficients )
778 u32 * p_pic_src; /* source pointer in case of copy */
779 u32 * p_red; /* red table */
780 u32 * p_green; /* green table */
781 u32 * p_blue; /* blue table */
782 int i_uval, i_yval, i_vval; /* samples */
783 int i_x, i_y; /* picture coordinates */
784 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
785 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
787 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
788 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
789 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
790 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
791 p_red = p_vout->tables.yuv.rgb32.p_red;
792 p_green = p_vout->tables.yuv.rgb32.p_green;
793 p_blue = p_vout->tables.yuv.rgb32.p_blue;
794 i_chroma_width = i_width / 2;
795 i_chroma_eol = i_eol / 2;
796 CONVERT_YUV_RGB( 422 )
799 /*******************************************************************************
800 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
801 *******************************************************************************/
802 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic,
803 yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
804 int i_width, int i_height, int i_eol, int i_pic_eol,
805 int i_scale, int i_matrix_coefficients )
807 u32 * p_pic_src; /* source pointer in case of copy */
808 u32 * p_red; /* red table */
809 u32 * p_green; /* green table */
810 u32 * p_blue; /* blue table */
811 int i_uval, i_yval, i_vval; /* samples */
812 int i_x, i_y; /* picture coordinates */
813 int i_chroma_width, i_chroma_eol; /* width and eol for chroma */
814 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
816 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
817 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
818 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
819 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
820 p_red = p_vout->tables.yuv.rgb32.p_red;
821 p_green = p_vout->tables.yuv.rgb32.p_green;
822 p_blue = p_vout->tables.yuv.rgb32.p_blue;
823 i_chroma_width = i_width;
824 i_chroma_eol = i_eol;
825 CONVERT_YUV_RGB( 444 )
828 //-------------------- walken code follow ---------------------------------------
831 * YUV to RGB routines.
833 * these routines calculate r, g and b values from each pixel's y, u and v.
834 * these r, g an b values are then passed thru a table lookup to take the
835 * gamma curve into account and find the corresponding pixel value.
837 * the table must store more than 3*256 values because of the possibility
838 * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
839 * values are in the following intervals :
840 * -176 to 255+176 for red
841 * -133 to 255+133 for green
842 * -222 to 255+222 for blue
844 * If the input y,u,v values are right, the r,g,b results are not expected
845 * to move out of the 0 to 255 interval but who knows what will happen in
848 * the red, green and blue conversion tables are stored in a single 1935-entry
849 * array. The respective positions of each component in the array have been
850 * calculated to minimize the cache interactions of the 3 tables.
853 int rgbTable16 (short table [1935],
854 int redMask, int greenMask, int blueMask,
855 unsigned char gamma[256])
869 MaskToShift (&redRight, &redLeft, redMask);
870 MaskToShift (&greenRight, &greenLeft, greenMask);
871 MaskToShift (&blueRight, &blueLeft, blueMask);
874 * green blue red +- 2 just to be sure
875 * green = 0-525 [151-370]
876 * blue = 594-1297 [834-1053] <834-29>
877 * red = 1323-1934 [1517-1736] <493-712>
880 redTable = table + 1501;
881 greenTable = table + 135;
882 blueTable = table + 818;
884 for (i = 0; i < 178; i++) {
886 redTable[i+256] = redMask;
888 for (i = 0; i < 135; i++) {
889 greenTable[i-135] = 0;
890 greenTable[i+256] = greenMask;
892 for (i = 0; i < 224; i++) {
893 blueTable[i-224] = 0;
894 blueTable[i+256] = blueMask;
897 for (i = 0; i < 256; i++) {
899 redTable[i] = ((y >> redRight) << redLeft);
900 greenTable[i] = ((y >> greenRight) << greenLeft);
901 blueTable[i] = ((y >> blueRight) << blueLeft);
907 static int rgbTable32 (int table [1935],
908 int redMask, int greenMask, int blueMask,
909 unsigned char gamma[256])
923 MaskToShift (&redRight, &redLeft, redMask);
924 MaskToShift (&greenRight, &greenLeft, greenMask);
925 MaskToShift (&blueRight, &blueLeft, blueMask);
929 * green blue red +- 2 just to be sure
930 * green = 0-525 [151-370]
931 * blue = 594-1297 [834-1053] <834-29>
932 * red = 1323-1934 [1517-1736] <493-712>
935 redTable = table + 1501;
936 greenTable = table + 135;
937 blueTable = table + 818;
939 for (i = 0; i < 178; i++) {
941 redTable[i+256] = redMask;
943 for (i = 0; i < 135; i++) {
944 greenTable[i-135] = 0;
945 greenTable[i+256] = greenMask;
947 for (i = 0; i < 224; i++) {
948 blueTable[i-224] = 0;
949 blueTable[i+256] = blueMask;
952 for (i = 0; i < 256; i++) {
954 redTable[i] = ((y >> redRight) << redLeft);
955 greenTable[i] = ((y >> greenRight) << greenLeft);
956 blueTable[i] = ((y >> blueRight) << blueLeft);
963 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
964 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
965 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
966 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
968 void yuvToRgb16 (unsigned char * Y,
969 unsigned char * U, unsigned char * V,
970 short * dest, short table[1935], int width)
984 uvRed = (V_RED_COEF*v) >> SHIFT;
985 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
986 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
988 tableY = table + *(Y++);
989 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
990 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
992 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
994 tableY = table + *(Y++);
995 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
996 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
998 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1002 uvRed = (V_RED_COEF*v) >> SHIFT;
1003 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1004 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1006 tableY = table + *(Y++);
1007 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1008 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1010 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1012 tableY = table + *(Y++);
1013 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1014 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1016 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1020 uvRed = (V_RED_COEF*v) >> SHIFT;
1021 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1022 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1030 tableY = table + *(Y++);
1031 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1032 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1034 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1038 uvRed = (V_RED_COEF*v) >> SHIFT;
1039 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1040 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1048 tableY = table + *(Y++);
1049 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1050 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1052 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1056 uvRed = (V_RED_COEF*v) >> SHIFT;
1057 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1058 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1066 tableY = table + *(Y++);
1067 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1068 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1070 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1074 uvRed = (V_RED_COEF*v) >> SHIFT;
1075 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1076 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1084 tableY = table + *(Y++);
1085 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1086 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1088 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1092 uvRed = (V_RED_COEF*v) >> SHIFT;
1093 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1094 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1102 tableY = table + *(Y++);
1103 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1104 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1106 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1110 uvRed = (V_RED_COEF*v) >> SHIFT;
1111 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1112 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1120 tableY = table + *(Y++);
1121 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1122 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1124 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1127 i = (width & 15) >> 1;
1131 uvRed = (V_RED_COEF*v) >> SHIFT;
1132 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1133 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1141 tableY = table + *(Y++);
1142 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1143 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1145 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1151 uvRed = (V_RED_COEF*v) >> SHIFT;
1152 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1153 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1155 tableY = table + *(Y++);
1156 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1157 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1159 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1163 static void yuvToRgb24 (unsigned char * Y,
1164 unsigned char * U, unsigned char * V,
1165 char * dest, int table[1935], int width)
1180 uvRed = (V_RED_COEF*v) >> SHIFT;
1181 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1182 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1184 tableY = table + *(Y++);
1185 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1186 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1188 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1190 *(dest++) = tmp24 >> 8;
1191 *(dest++) = tmp24 >> 16;
1193 tableY = table + *(Y++);
1194 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1195 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1197 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1199 *(dest++) = tmp24 >> 8;
1200 *(dest++) = tmp24 >> 16;
1204 uvRed = (V_RED_COEF*v) >> SHIFT;
1205 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1206 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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;
1217 tableY = table + *(Y++);
1218 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1219 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1221 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1223 *(dest++) = tmp24 >> 8;
1224 *(dest++) = tmp24 >> 16;
1228 uvRed = (V_RED_COEF*v) >> SHIFT;
1229 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1230 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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;
1241 tableY = table + *(Y++);
1242 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1243 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1245 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1247 *(dest++) = tmp24 >> 8;
1248 *(dest++) = tmp24 >> 16;
1252 uvRed = (V_RED_COEF*v) >> SHIFT;
1253 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1254 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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;
1265 tableY = table + *(Y++);
1266 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1267 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1269 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1271 *(dest++) = tmp24 >> 8;
1272 *(dest++) = tmp24 >> 16;
1275 i = (width & 7) >> 1;
1279 uvRed = (V_RED_COEF*v) >> SHIFT;
1280 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1281 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1283 tableY = table + *(Y++);
1284 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1285 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1287 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1289 *(dest++) = tmp24 >> 8;
1290 *(dest++) = tmp24 >> 16;
1292 tableY = table + *(Y++);
1293 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1294 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1296 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1298 *(dest++) = tmp24 >> 8;
1299 *(dest++) = tmp24 >> 16;
1305 uvRed = (V_RED_COEF*v) >> SHIFT;
1306 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1307 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1309 tableY = table + *(Y++);
1310 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1311 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1313 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1315 *(dest++) = tmp24 >> 8;
1316 *(dest++) = tmp24 >> 16;
1320 static void yuvToRgb32 (unsigned char * Y,
1321 unsigned char * U, unsigned char * V,
1322 int * dest, int table[1935], int width)
1336 uvRed = (V_RED_COEF*v) >> SHIFT;
1337 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1338 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1340 tableY = table + *(Y++);
1341 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1342 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1344 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1346 tableY = table + *(Y++);
1347 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1348 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1350 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1354 uvRed = (V_RED_COEF*v) >> SHIFT;
1355 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1356 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1358 tableY = table + *(Y++);
1359 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1360 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1362 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1364 tableY = table + *(Y++);
1365 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1366 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1368 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1372 uvRed = (V_RED_COEF*v) >> SHIFT;
1373 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1374 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1382 tableY = table + *(Y++);
1383 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1384 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1386 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1390 uvRed = (V_RED_COEF*v) >> SHIFT;
1391 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1392 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1400 tableY = table + *(Y++);
1401 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1402 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1404 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1408 uvRed = (V_RED_COEF*v) >> SHIFT;
1409 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1410 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1418 tableY = table + *(Y++);
1419 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1420 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1422 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1426 uvRed = (V_RED_COEF*v) >> SHIFT;
1427 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1428 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1436 tableY = table + *(Y++);
1437 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1438 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1440 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1444 uvRed = (V_RED_COEF*v) >> SHIFT;
1445 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1446 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1454 tableY = table + *(Y++);
1455 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1456 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1458 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1462 uvRed = (V_RED_COEF*v) >> SHIFT;
1463 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1464 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1472 tableY = table + *(Y++);
1473 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1474 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1476 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1479 i = (width & 15) >> 1;
1483 uvRed = (V_RED_COEF*v) >> SHIFT;
1484 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1485 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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]);
1493 tableY = table + *(Y++);
1494 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1495 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1497 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1503 uvRed = (V_RED_COEF*v) >> SHIFT;
1504 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1505 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1507 tableY = table + *(Y++);
1508 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1509 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1511 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1515 /* yuv routines with scaling */
1516 /* 4:2:2 i, 16 bpp*/
1518 void yuv422ToRgb16_scaled (unsigned char * Y,
1519 unsigned char * U, unsigned char * V,
1520 short * dest, short table[1935], int width , int dest_width,
1521 int height, int dest_height, int skip, int dest_skip,short * buffer)
1523 int i, i_hcount, i_vcount, j, k;
1532 if ( ( width < dest_width ) && ( height < dest_height ) )
1534 i_vcount = dest_height;
1540 i_hcount = dest_width;
1545 uvRed = (V_RED_COEF*v) >> SHIFT;
1546 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1547 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1549 tableY = table + *(Y++);
1550 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1551 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1552 >>SHIFT) + uvGreen] |
1553 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1554 while ( ( i_hcount -= width ) >= 0 )
1558 i_hcount += dest_width;
1560 tableY = table + *(Y++);
1561 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1562 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1563 >>SHIFT) + uvGreen] |
1564 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1565 while ( ( i_hcount -= width ) >= 0 )
1569 i_hcount += dest_width;
1571 while ( ( i_vcount -= height ) >= 0 )
1573 for (j=0; j<dest_width; j+=16)
1576 dest[j+1]=buffer[j+1];
1577 dest[j+2]=buffer[j+2];
1578 dest[j+3]=buffer[j+3];
1579 dest[j+4]=buffer[j+4];
1580 dest[j+6]=buffer[j+7];
1581 dest[j+8]=buffer[j+9];
1582 dest[j+10]=buffer[j+10];
1583 dest[j+11]=buffer[j+11];
1584 dest[j+12]=buffer[j+12];
1585 dest[j+13]=buffer[j+13];
1586 dest[j+14]=buffer[j+14];
1587 dest[j+15]=buffer[j+15];
1591 i_vcount += dest_height;
1594 else if ( ( width > dest_width ) && ( height < dest_height ) )
1596 i_vcount = dest_height;
1607 uvRed = (V_RED_COEF*v) >> SHIFT;
1608 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1609 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1611 if ( ( i_hcount -= dest_width ) >= 0 )
1615 tableY = table + *(Y++);
1616 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1619 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1621 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1625 if ( ( i_hcount -= dest_width ) >= 0 )
1629 tableY = table + *(Y++);
1630 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1633 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1635 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1640 while ( ( i_vcount -= height ) >= 0 )
1642 for (j=0; j<dest_width; j+=16)
1645 dest[j+1]=buffer[j+1];
1646 dest[j+2]=buffer[j+2];
1647 dest[j+3]=buffer[j+3];
1648 dest[j+4]=buffer[j+4];
1649 dest[j+6]=buffer[j+7];
1650 dest[j+8]=buffer[j+9];
1651 dest[j+10]=buffer[j+10];
1652 dest[j+11]=buffer[j+11];
1653 dest[j+12]=buffer[j+12];
1654 dest[j+13]=buffer[j+13];
1655 dest[j+14]=buffer[j+14];
1656 dest[j+15]=buffer[j+15];
1660 i_vcount += dest_height;
1663 else if ( ( width < dest_width ) && ( height > dest_height ) )
1671 i_hcount = dest_width;
1676 uvRed = (V_RED_COEF*v) >> SHIFT;
1677 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1678 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1680 tableY = table + *(Y++);
1681 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1682 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1683 >>SHIFT) + uvGreen] |
1684 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1685 while ( ( i_hcount -= width ) >= 0 )
1689 i_hcount += dest_width;
1691 tableY = table + *(Y++);
1692 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1693 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1694 >>SHIFT) + uvGreen] |
1695 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1696 while ( ( i_hcount -= width ) >= 0 )
1700 i_hcount += dest_width;
1702 while ( ( i_vcount -= height ) >= 0 )
1708 i_vcount += dest_height;
1711 else if ( ( width > dest_width ) && ( height > dest_height ) )
1713 i_vcount = dest_height;
1724 uvRed = (V_RED_COEF*v) >> SHIFT;
1725 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1726 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1728 if ( ( i_hcount -= dest_width ) >= 0 )
1732 tableY = table + *(Y++);
1733 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1736 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1738 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1742 if ( ( i_hcount -= dest_width ) >= 0 )
1746 tableY = table + *(Y++);
1747 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1750 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1752 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1757 while ( ( i_vcount -= height ) >= 0 )
1763 i_vcount += dest_height;
1768 /* yuv routines with scaling */
1769 /* 4:2:0 i, 16 bpp*/
1771 void yuv420ToRgb16_scaled (unsigned char * Y,
1772 unsigned char * U, unsigned char * V,
1773 short * dest, short table[1935], int width , int dest_width,
1774 int height, int dest_height, int skip, int dest_skip,short * buffer)
1776 int i, i_hcount, i_vcount, j, k;
1785 if ( ( width < dest_width ) && ( height < dest_height ) )
1787 i_vcount = dest_height;
1793 i_hcount = dest_width;
1798 uvRed = (V_RED_COEF*v) >> SHIFT;
1799 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1800 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1802 tableY = table + *(Y++);
1803 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1804 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1805 >>SHIFT) + uvGreen] |
1806 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1807 while ( ( i_hcount -= width ) >= 0 )
1811 i_hcount += dest_width;
1813 tableY = table + *(Y++);
1814 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1815 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1816 >>SHIFT) + uvGreen] |
1817 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1818 while ( ( i_hcount -= width ) >= 0 )
1822 i_hcount += dest_width;
1824 while ( ( i_vcount -= height ) >= 0 )
1826 for (j=0; j<dest_width; j+=16)
1829 dest[j+1]=buffer[j+1];
1830 dest[j+2]=buffer[j+2];
1831 dest[j+3]=buffer[j+3];
1832 dest[j+4]=buffer[j+4];
1833 dest[j+6]=buffer[j+7];
1834 dest[j+8]=buffer[j+9];
1835 dest[j+10]=buffer[j+10];
1836 dest[j+11]=buffer[j+11];
1837 dest[j+12]=buffer[j+12];
1838 dest[j+13]=buffer[j+13];
1839 dest[j+14]=buffer[j+14];
1840 dest[j+15]=buffer[j+15];
1844 i_vcount += dest_height;
1849 i_hcount = dest_width;
1854 uvRed = (V_RED_COEF*v) >> SHIFT;
1855 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1856 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1858 tableY = table + *(Y++);
1859 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1860 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1861 >>SHIFT) + uvGreen] |
1862 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1863 while ( ( i_hcount -= width ) >= 0 )
1867 i_hcount += dest_width;
1869 tableY = table + *(Y++);
1870 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1871 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1872 >>SHIFT) + uvGreen] |
1873 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1874 while ( ( i_hcount -= width ) >= 0 )
1878 i_hcount += dest_width;
1880 while ( ( i_vcount -= height ) >= 0 )
1882 for (j=0; j<dest_width; j+=16)
1885 dest[j+1]=buffer[j+1];
1886 dest[j+2]=buffer[j+2];
1887 dest[j+3]=buffer[j+3];
1888 dest[j+4]=buffer[j+4];
1889 dest[j+6]=buffer[j+7];
1890 dest[j+8]=buffer[j+9];
1891 dest[j+10]=buffer[j+10];
1892 dest[j+11]=buffer[j+11];
1893 dest[j+12]=buffer[j+12];
1894 dest[j+13]=buffer[j+13];
1895 dest[j+14]=buffer[j+14];
1896 dest[j+15]=buffer[j+15];
1900 i_vcount += dest_height;
1903 else if ( ( width > dest_width ) && ( height < dest_height ) )
1905 i_vcount = dest_height;
1916 uvRed = (V_RED_COEF*v) >> SHIFT;
1917 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1918 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1920 if ( ( i_hcount -= dest_width ) >= 0 )
1924 tableY = table + *(Y++);
1925 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1928 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1930 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1934 if ( ( i_hcount -= dest_width ) >= 0 )
1938 tableY = table + *(Y++);
1939 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1942 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1944 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1949 while ( ( i_vcount -= height ) >= 0 )
1951 for (j=0; j<dest_width; j+=16)
1954 dest[j+1]=buffer[j+1];
1955 dest[j+2]=buffer[j+2];
1956 dest[j+3]=buffer[j+3];
1957 dest[j+4]=buffer[j+4];
1958 dest[j+6]=buffer[j+7];
1959 dest[j+8]=buffer[j+9];
1960 dest[j+10]=buffer[j+10];
1961 dest[j+11]=buffer[j+11];
1962 dest[j+12]=buffer[j+12];
1963 dest[j+13]=buffer[j+13];
1964 dest[j+14]=buffer[j+14];
1965 dest[j+15]=buffer[j+15];
1969 i_vcount += dest_height;
1979 uvRed = (V_RED_COEF*v) >> SHIFT;
1980 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1981 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1983 if ( ( i_hcount -= dest_width ) >= 0 )
1987 tableY = table + *(Y++);
1988 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1991 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1993 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1997 if ( ( i_hcount -= dest_width ) >= 0 )
2001 tableY = table + *(Y++);
2002 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2005 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2007 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2012 while ( ( i_vcount -= height ) >= 0 )
2014 for (j=0; j<dest_width; j+=16)
2017 dest[j+1]=buffer[j+1];
2018 dest[j+2]=buffer[j+2];
2019 dest[j+3]=buffer[j+3];
2020 dest[j+4]=buffer[j+4];
2021 dest[j+6]=buffer[j+7];
2022 dest[j+8]=buffer[j+9];
2023 dest[j+10]=buffer[j+10];
2024 dest[j+11]=buffer[j+11];
2025 dest[j+12]=buffer[j+12];
2026 dest[j+13]=buffer[j+13];
2027 dest[j+14]=buffer[j+14];
2028 dest[j+15]=buffer[j+15];
2032 i_vcount += dest_height;
2035 else if ( ( width < dest_width ) && ( height > dest_height ) )
2043 i_hcount = dest_width;
2048 uvRed = (V_RED_COEF*v) >> SHIFT;
2049 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2050 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2052 tableY = table + *(Y++);
2053 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2054 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2055 >>SHIFT) + uvGreen] |
2056 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2057 while ( ( i_hcount -= width ) >= 0 )
2061 i_hcount += dest_width;
2063 tableY = table + *(Y++);
2064 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2065 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2066 >>SHIFT) + uvGreen] |
2067 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2068 while ( ( i_hcount -= width ) >= 0 )
2072 i_hcount += dest_width;
2075 while ( ( i_vcount -= height ) >= 0 )
2080 U += skip * ( j >> 1 );
2081 V += skip * ( j >> 1 );
2082 i_vcount += dest_height;
2085 else if ( ( width > dest_width ) && ( height > dest_height ) )
2087 i_vcount = dest_height;
2098 uvRed = (V_RED_COEF*v) >> SHIFT;
2099 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2100 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2102 if ( ( i_hcount -= dest_width ) >= 0 )
2106 tableY = table + *(Y++);
2107 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2110 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2112 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2116 if ( ( i_hcount -= dest_width ) >= 0 )
2120 tableY = table + *(Y++);
2121 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2124 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2126 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2132 while ( ( i_vcount -= height ) >= 0 )
2137 U += skip * ( j >> 1 );
2138 V += skip * ( j >> 1 );
2139 i_vcount += dest_height;