1 /*******************************************************************************
2 * video_yuv.c: YUV transformation functions
4 *******************************************************************************
5 * Provides functions to perform the YUV conversion. The functions provided here
6 * are a complete and portable C implementation, and may be replaced in certain
7 * case by optimized functions.
8 *******************************************************************************/
10 /*******************************************************************************
12 *******************************************************************************/
21 #include "vlc_thread.h"
23 #include "video_output.h"
24 #include "video_yuv.h"
27 /*******************************************************************************
29 *******************************************************************************/
31 /* RGB/YUV inversion matrix (ISO/IEC 13818-2 section 6.3.6, table 6.9) */
32 const int MATRIX_COEFFICIENTS_TABLE[8][4] =
34 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
35 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
36 {104597, 132201, 25675, 53279}, /* unspecified */
37 {104597, 132201, 25675, 53279}, /* reserved */
38 {104448, 132798, 24759, 53109}, /* FCC */
39 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
40 {104597, 132201, 25675, 53279}, /* SMPTE 170M */
41 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
45 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
46 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
47 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
48 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
50 /*******************************************************************************
52 *******************************************************************************/
53 static int BinaryLog ( u32 i );
54 static void MaskToShift ( int *pi_right, int *pi_left, u32 i_mask );
55 static void SetGammaTable ( int *pi_table, double f_gamma );
56 static void SetYUV ( vout_thread_t *p_vout );
58 static void ConvertY4Gray16 ( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
59 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
60 int i_matrix_coefficients );
61 static void ConvertY4Gray24 ( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
62 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
63 int i_matrix_coefficients );
64 static void ConvertY4Gray32 ( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
65 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
66 int i_matrix_coefficients );
67 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
68 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
69 int i_matrix_coefficients );
70 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
71 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
72 int i_matrix_coefficients );
73 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
74 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
75 int i_matrix_coefficients );
76 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
77 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
78 int i_matrix_coefficients );
79 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
80 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
81 int i_matrix_coefficients );
82 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
83 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
84 int i_matrix_coefficients );
85 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
86 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
87 int i_matrix_coefficients );
88 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
89 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
90 int i_matrix_coefficients );
91 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
92 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
93 int i_matrix_coefficients );
95 /*******************************************************************************
96 * CLIP_BYTE macro: boundary detection
97 *******************************************************************************
98 * Return parameter if between 0 and 255, else return nearest boundary (0 or
99 * 255). This macro is used to build translations tables.
100 *******************************************************************************/
101 #define CLIP_BYTE( i_val ) ( (i_val < 0) ? 0 : ((i_val > 255) ? 255 : i_val) )
103 /*******************************************************************************
104 * CONVERT_YUV_GRAY macro: grayscale YUV convertion
105 *******************************************************************************
106 * This macro does not perform any scaling, but crops the picture. It is
107 * provided as a temporary way of implementing an YUV convertion function.
108 *******************************************************************************/
109 #define CONVERT_YUV_GRAY \
110 /* Change boundaries according to picture size */ \
111 i_width = MIN( i_width, i_pic_width ); \
112 i_height = MIN( i_height, i_pic_height ); \
113 i_pic_line_width -= i_width; \
116 for (i_y = 0; i_y < i_height ; i_y++) \
118 for (i_x = 0; i_x < i_width; ) \
120 /* Convert 16 pixels (width is always multiple of 16 */ \
121 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
122 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
123 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
124 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
125 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
126 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
127 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
128 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
129 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
130 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
131 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
132 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
133 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
134 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
135 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
136 p_pic[i_x++] = p_gray[ p_y[i_x] ]; \
139 /* Skip until beginning of next line */ \
140 p_pic += i_pic_line_width; \
143 /*******************************************************************************
144 * CONVERT_YUV_RGB: color YUV convertion
145 *******************************************************************************
146 * This macro does not perform any scaling, but crops the picture. It is
147 * provided as a temporary way of implementing an YUV convertion function.
148 *******************************************************************************/
149 #define CONVERT_YUV_RGB( CHROMA, CRV, CGV, CBU, CGU ) \
150 /* Change boundaries according to picture size */ \
151 i_width = MIN( i_width, i_pic_width ); \
152 i_height = MIN( i_height, i_pic_height ); \
153 i_chroma_width = (CHROMA == 444) ? i_width : i_width / 2; \
154 i_pic_line_width -= i_width; \
157 for (i_y = 0; i_y < i_height ; i_y++) \
159 for (i_x = 0; i_x < i_width; ) \
161 /* First sample (complete) */ \
162 i_yval = 76309 * p_y[i_x] - 1188177; \
163 i_uval = *p_u++ - 128; \
164 i_vval = *p_v++ - 128; \
166 p_red [(i_yval+CRV*i_vval) >>16] | \
167 p_green[(i_yval-CGU*i_uval-CGV*i_vval) >>16] | \
168 p_blue [(i_yval+CBU*i_uval) >>16]; \
169 i_yval = 76309 * p_y[i_x] - 1188177; \
170 /* Second sample (partial) */ \
171 if( CHROMA == 444 ) \
173 i_uval = *p_u++ - 128; \
174 i_vval = *p_v++ - 128; \
177 p_red [(i_yval+CRV*i_vval) >>16] | \
178 p_green[(i_yval-CGU*i_uval-CGV*i_vval) >>16] | \
179 p_blue [(i_yval+CBU*i_uval) >>16]; \
182 /* Rewind in 4:2:0 */ \
183 if( (CHROMA == 420) && !(i_y & 0x1) ) \
185 p_u -= i_chroma_width; \
186 p_v -= i_chroma_width; \
189 /* Skip until beginning of next line */ \
190 p_pic += i_pic_line_width; \
193 /*******************************************************************************
194 * CONVERT_YUV_PIXEL, CONVERT_Y_PIXEL: pixel convertion blocks
195 *******************************************************************************
196 * These convertion routines are used by YUV convertion functions.
197 * Convertion are made from p_y, p_u, p_v, which are modified, to p_pic, which
199 *******************************************************************************/
200 #define CONVERT_Y_PIXEL \
201 /* Only Y sample is present */ \
202 p_ybase = p_yuv + *(p_y++); \
203 *(p_pic++) = p_ybase[1501 - ((V_RED_COEF*128)>>SHIFT) + i_red] | \
204 p_ybase[135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) + i_green ] | \
205 p_ybase[818 - ((U_BLUE_COEF*128)>>SHIFT) + i_blue]; \
207 #define CONVERT_YUV_PIXEL \
208 /* Y, U and V samples are present */ \
211 i_red = (V_RED_COEF * i_vval) >> SHIFT; \
212 i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT; \
213 i_blue = (U_BLUE_COEF * i_uval) >> SHIFT; \
216 /*******************************************************************************
217 * vout_InitYUV: allocate and initialize translations tables
218 *******************************************************************************
219 * This function will allocate memory to store translation tables, depending
220 * of the screen depth.
221 *******************************************************************************/
222 int vout_InitYUV( vout_thread_t *p_vout )
224 size_t tables_size; /* tables size, in bytes */
226 /* Computes tables size */
227 switch( p_vout->i_screen_depth )
231 tables_size = sizeof( u16 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
238 tables_size = sizeof( u32 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
242 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
248 /* Add conversion buffer size. The conversions functions need one comple line
249 * plus one pixel, so we give them two. */
250 tables_size += p_vout->i_bytes_per_line * 2;
252 /* Allocate memory */
253 p_vout->yuv.p_base = malloc( tables_size );
254 if( p_vout->yuv.p_base == NULL )
256 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
260 /* Initialize tables */
265 /*******************************************************************************
266 * vout_ResetTables: re-initialize translations tables
267 *******************************************************************************
268 * This function will initialize the tables allocated by vout_CreateTables and
269 * set functions pointers.
270 *******************************************************************************/
271 int vout_ResetYUV( vout_thread_t *p_vout )
273 vout_EndYUV( p_vout );
274 return( vout_InitYUV( p_vout ) );
277 /*******************************************************************************
278 * vout_EndYUV: destroy translations tables
279 *******************************************************************************
280 * Free memory allocated by vout_CreateTables.
281 *******************************************************************************/
282 void vout_EndYUV( vout_thread_t *p_vout )
284 free( p_vout->yuv.p_base );
287 /* following functions are local */
289 /*******************************************************************************
290 * BinaryLog: computes the base 2 log of a binary value
291 *******************************************************************************
292 * This functions is used by MaskToShift during tables initialisation, to
293 * get a bit index from a binary value.
294 *******************************************************************************/
295 static int BinaryLog(u32 i)
320 if (i != ((u32)1 << i_log))
322 intf_ErrMsg("internal error: binary log overflow\n");
328 /*******************************************************************************
329 * MaskToShift: Transform a color mask into right and left shifts
330 *******************************************************************************
331 * This function is used during table initialisation. It can return a value
332 *******************************************************************************/
333 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
335 u32 i_low, i_high; /* lower hand higher bits of the mask */
338 i_low = i_mask & (- i_mask); /* lower bit of the mask */
339 i_high = i_mask + i_low; /* higher bit of the mask */
341 /* Transform bits into an index */
342 i_low = BinaryLog (i_low);
343 i_high = BinaryLog (i_high);
345 /* Update pointers and return */
347 *pi_right = (8 - i_high + i_low);
350 /*******************************************************************************
351 * SetGammaTable: return intensity table transformed by gamma curve.
352 *******************************************************************************
353 * pi_table is a table of 256 entries from 0 to 255.
354 *******************************************************************************/
355 static void SetGammaTable( int *pi_table, double f_gamma )
357 int i_y; /* base intensity */
359 /* Use exp(gamma) instead of gamma */
360 f_gamma = exp(f_gamma );
362 /* Build gamma table */
363 for( i_y = 0; i_y < 256; i_y++ )
365 pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
369 /*******************************************************************************
370 * SetYUV: compute tables and set function pointers
371 + *******************************************************************************/
372 static void SetYUV( vout_thread_t *p_vout )
374 int pi_gamma[256]; /* gamma table */
375 int i_index; /* index in tables */
376 int i_red_right, i_red_left; /* red shifts */
377 int i_green_right, i_green_left; /* green shifts */
378 int i_blue_right, i_blue_left; /* blue shifts */
380 /* Build gamma table */
381 SetGammaTable( pi_gamma, p_vout->f_gamma );
384 * Set color masks and shifts
386 switch( p_vout->i_screen_depth )
389 MaskToShift( &i_red_right, &i_red_left, 0x7c00 );
390 MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
391 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
394 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
395 MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
396 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
400 MaskToShift( &i_red_right, &i_red_left, 0x00ff0000 );
401 MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
402 MaskToShift( &i_blue_right, &i_blue_left, 0x000000ff );
406 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
412 * Set pointers and build YUV tables
414 if( p_vout->b_grayscale )
416 /* Grayscale: build gray table */
417 switch( p_vout->i_screen_depth )
421 p_vout->yuv.yuv.gray16.p_gray = (u16 *)p_vout->yuv.p_base + 384;
422 for( i_index = -384; i_index < 640; i_index++)
424 p_vout->yuv.yuv.gray16.p_gray[ i_index ] =
425 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
426 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
427 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
432 p_vout->yuv.yuv.gray32.p_gray = (u32 *)p_vout->yuv.p_base + 384;
433 for( i_index = -384; i_index < 640; i_index++)
435 p_vout->yuv.yuv.gray32.p_gray[ i_index ] =
436 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
437 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
438 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
445 /* Color: build red, green and blue tables */
446 switch( p_vout->i_screen_depth )
450 p_vout->yuv.yuv.rgb16.p_red = (u16 *)p_vout->yuv.p_base + 384;
451 p_vout->yuv.yuv.rgb16.p_green = (u16 *)p_vout->yuv.p_base + 1024 + 384;
452 p_vout->yuv.yuv.rgb16.p_blue = (u16 *)p_vout->yuv.p_base + 2*1024 + 384;
453 p_vout->yuv.yuv2.p_rgb16 = (u16 *)p_vout->yuv.p_base + 3*1024;
454 p_vout->yuv.p_buffer = (u16 *)p_vout->yuv.p_base + 3*1024 + 1935;
455 for( i_index = -384; i_index < 640; i_index++)
457 p_vout->yuv.yuv.rgb16.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
458 p_vout->yuv.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
459 p_vout->yuv.yuv.rgb16.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
461 for( i_index = 0; i_index < 178; i_index++ )
463 p_vout->yuv.yuv2.p_rgb16[1501 - 178 + i_index] = (pi_gamma[0]>>i_red_right)<<i_red_left;
464 p_vout->yuv.yuv2.p_rgb16[1501 + 256 + i_index] = (pi_gamma[255]>>i_red_right)<<i_red_left;
466 for( i_index = 0; i_index < 135; i_index++ )
468 p_vout->yuv.yuv2.p_rgb16[135 - 135 + i_index] = (pi_gamma[0]>>i_green_right)<<i_green_left;
469 p_vout->yuv.yuv2.p_rgb16[135 + 256 + i_index] = (pi_gamma[255]>>i_green_right)<<i_green_left;
471 for( i_index = 0; i_index < 224; i_index++ )
473 p_vout->yuv.yuv2.p_rgb16[818 - 224 + i_index] = (pi_gamma[0]>>i_blue_right)<<i_blue_left;
474 p_vout->yuv.yuv2.p_rgb16[818 + 256 + i_index] = (pi_gamma[255]>>i_blue_right)<<i_blue_left;
476 for( i_index = 0; i_index < 256; i_index++ )
478 p_vout->yuv.yuv2.p_rgb16[1501 + i_index] = (pi_gamma[i_index]>>i_red_right)<<i_red_left;
479 p_vout->yuv.yuv2.p_rgb16[135 + i_index] = (pi_gamma[i_index]>>i_green_right)<<i_green_left;
480 p_vout->yuv.yuv2.p_rgb16[818 + i_index] = (pi_gamma[i_index]>>i_blue_right)<<i_blue_left;
485 p_vout->yuv.yuv.rgb32.p_red = (u32 *)p_vout->yuv.p_base + 384;
486 p_vout->yuv.yuv.rgb32.p_green = (u32 *)p_vout->yuv.p_base + 1024 + 384;
487 p_vout->yuv.yuv.rgb32.p_blue = (u32 *)p_vout->yuv.p_base + 2*1024 + 384;
488 p_vout->yuv.yuv2.p_rgb32 = (u32 *)p_vout->yuv.p_base + 3*1024;
489 p_vout->yuv.p_buffer = (u32 *)p_vout->yuv.p_base + 3*1024 + 1935;
490 for( i_index = -384; i_index < 640; i_index++)
492 p_vout->yuv.yuv.rgb32.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
493 p_vout->yuv.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
494 p_vout->yuv.yuv.rgb32.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
502 * Set functions pointers
504 if( p_vout->b_grayscale )
507 switch( p_vout->i_screen_depth )
511 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
512 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
513 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
516 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
517 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
518 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
521 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
522 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
523 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
530 switch( p_vout->i_screen_depth )
534 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB16;
535 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB16;
536 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB16;
539 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB24;
540 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB24;
541 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB24;
544 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB32;
545 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB32;
546 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB32;
552 /*******************************************************************************
553 * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
554 *******************************************************************************/
555 static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
556 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
557 int i_matrix_coefficients )
559 u16 * p_gray; /* gray table */
560 int i_x, i_y; /* picture coordinates */
562 p_gray = p_vout->yuv.yuv.gray16.p_gray;
566 /*******************************************************************************
567 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
568 *******************************************************************************/
569 static void ConvertY4Gray24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
570 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
571 int i_matrix_coefficients )
576 /*******************************************************************************
577 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
578 *******************************************************************************/
579 static void ConvertY4Gray32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
580 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
581 int i_matrix_coefficients )
583 u32 * p_gray; /* gray table */
584 int i_x, i_y; /* picture coordinates */
586 p_gray = p_vout->yuv.yuv.gray32.p_gray;
590 /*******************************************************************************
591 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
592 *******************************************************************************/
593 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
594 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
595 int i_matrix_coefficients )
598 // int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
600 i_chroma_width = i_width / 2;
601 i_chroma_skip = i_skip / 2;
602 ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height,
603 (i_width + i_skip) * sizeof( yuv_data_t ),
604 (i_chroma_width + i_chroma_skip) * sizeof( yuv_data_t),
605 i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
606 p_vout->i_screen_depth == 15 );
610 u16 * p_red; /* red table */
611 u16 * p_green; /* green table */
612 u16 * p_blue; /* blue table */
613 int i_uval, i_yval, i_vval; /* samples */
614 int i_x, i_y; /* picture coordinates */
615 int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
616 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
618 p_red = p_vout->yuv.yuv.rgb16.p_red;
619 p_green = p_vout->yuv.yuv.rgb16.p_green;
620 p_blue = p_vout->yuv.yuv.rgb16.p_blue;
621 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
622 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
623 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
624 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
626 CONVERT_YUV_RGB( 420, i_crv, i_cgv, i_cbu, i_cgu );
628 boolean_t b_inc_width, b_inc_height; /* width/heidth are increased */
629 int i_x, i_y; /* horizontal and vertical indexes */
630 int i_uval, i_vval; /* U and V samples */
631 int i_red, i_green, i_blue; /* U and V modified samples */
632 int i_chroma_width; /* chroma width */
633 int i_height_count; /* height modulo counter */
634 u16 * p_yuv; /* base convertion table */
635 u16 * p_ybase; /* Y dependant convertion table */
636 u16 * p_pic_start; /* beginning of the current line */
638 /* Initialize values */
639 b_inc_width = i_width < i_pic_width;
640 b_inc_height = i_height < i_pic_height;
641 i_height_count = i_pic_height;
642 i_chroma_width = i_width / 2;
643 p_yuv = p_vout->yuv.yuv2.p_rgb16;
648 for( i_y = 0; i_y < i_height; i_y++ )
650 /* Mark beginnning of line */
653 /* Convert line using 16 pixels blocks, since picture come from 16 pixels width
655 for( i_x = i_width / 16; i_x--; )
675 /* If line is odd, rewind U and V samples */
678 p_u -= i_chroma_width;
679 p_v -= i_chroma_width;
682 /* End of line: skip picture to reach beginning of next line */
683 p_pic += i_pic_line_width - i_pic_width;
686 * Handle vertical scaling. The current line is copied or next one
691 while( (i_height_count -= i_height) > 0 )
693 /* Height increment: copy previous picture line */
694 for( i_x = i_pic_width / 16; i_x--; )
696 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
697 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
698 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
699 *(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ );
701 p_pic += i_pic_line_width - i_pic_width;
702 p_pic_start += i_pic_line_width - i_pic_width;
704 i_height_count += i_pic_height;
708 while( (i_height_count -= i_pic_height) >= 0 )
710 /* Height reduction: skip next source line */
712 if( ! (++i_y & 0x1) )
714 p_u += i_chroma_width;
715 p_v += i_chroma_width;
718 i_height_count += i_height;
724 /*******************************************************************************
725 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
726 *******************************************************************************/
727 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
728 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
729 int i_matrix_coefficients )
734 /*******************************************************************************
735 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
736 *******************************************************************************/
737 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
738 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
739 int i_matrix_coefficients )
744 /*******************************************************************************
745 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
746 *******************************************************************************/
747 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
748 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
749 int i_matrix_coefficients )
754 /*******************************************************************************
755 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
756 *******************************************************************************/
757 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
758 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
759 int i_matrix_coefficients )
764 /*******************************************************************************
765 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
766 *******************************************************************************/
767 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
768 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
769 int i_matrix_coefficients )
774 /*******************************************************************************
775 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
776 *******************************************************************************/
777 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
778 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
779 int i_matrix_coefficients )
784 /*******************************************************************************
785 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
786 *******************************************************************************/
787 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
788 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
789 int i_matrix_coefficients )
794 /*******************************************************************************
795 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
796 *******************************************************************************/
797 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
798 int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width,
799 int i_matrix_coefficients )
804 //-------------------- walken code follow ---------------------------------------
807 * YUV to RGB routines.
809 * these routines calculate r, g and b values from each pixel's y, u and v.
810 * these r, g an b values are then passed thru a table lookup to take the
811 * gamma curve into account and find the corresponding pixel value.
813 * the table must store more than 3*256 values because of the possibility
814 * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
815 * values are in the following intervals :
816 * -176 to 255+176 for red
817 * -133 to 255+133 for green
818 * -222 to 255+222 for blue
820 * If the input y,u,v values are right, the r,g,b results are not expected
821 * to move out of the 0 to 255 interval but who knows what will happen in
824 * the red, green and blue conversion tables are stored in a single 1935-entry
825 * array. The respective positions of each component in the array have been
826 * calculated to minimize the cache interactions of the 3 tables.
829 int rgbTable16 (short table [1935],
830 int redMask, int greenMask, int blueMask,
831 unsigned char gamma[256])
845 MaskToShift (&redRight, &redLeft, redMask);
846 MaskToShift (&greenRight, &greenLeft, greenMask);
847 MaskToShift (&blueRight, &blueLeft, blueMask);
850 * green blue red +- 2 just to be sure
851 * green = 0-525 [151-370]
852 * blue = 594-1297 [834-1053] <834-29>
853 * red = 1323-1934 [1517-1736] <493-712>
856 redTable = table + 1501;
857 greenTable = table + 135;
858 blueTable = table + 818;
860 for (i = 0; i < 178; i++) {
862 redTable[i+256] = redMask;
864 for (i = 0; i < 135; i++) {
865 greenTable[i-135] = 0;
866 greenTable[i+256] = greenMask;
868 for (i = 0; i < 224; i++) {
869 blueTable[i-224] = 0;
870 blueTable[i+256] = blueMask;
873 for (i = 0; i < 256; i++) {
875 redTable[i] = ((y >> redRight) << redLeft);
876 greenTable[i] = ((y >> greenRight) << greenLeft);
877 blueTable[i] = ((y >> blueRight) << blueLeft);
883 static int rgbTable32 (int table [1935],
884 int redMask, int greenMask, int blueMask,
885 unsigned char gamma[256])
899 MaskToShift (&redRight, &redLeft, redMask);
900 MaskToShift (&greenRight, &greenLeft, greenMask);
901 MaskToShift (&blueRight, &blueLeft, blueMask);
905 * green blue red +- 2 just to be sure
906 * green = 0-525 [151-370]
907 * blue = 594-1297 [834-1053] <834-29>
908 * red = 1323-1934 [1517-1736] <493-712>
911 redTable = table + 1501;
912 greenTable = table + 135;
913 blueTable = table + 818;
915 for (i = 0; i < 178; i++) {
917 redTable[i+256] = redMask;
919 for (i = 0; i < 135; i++) {
920 greenTable[i-135] = 0;
921 greenTable[i+256] = greenMask;
923 for (i = 0; i < 224; i++) {
924 blueTable[i-224] = 0;
925 blueTable[i+256] = blueMask;
928 for (i = 0; i < 256; i++) {
930 redTable[i] = ((y >> redRight) << redLeft);
931 greenTable[i] = ((y >> greenRight) << greenLeft);
932 blueTable[i] = ((y >> blueRight) << blueLeft);
939 void yuvToRgb16 (unsigned char * Y,
940 unsigned char * U, unsigned char * V,
941 short * dest, short table[1935], int width)
955 uvRed = (V_RED_COEF*v) >> SHIFT;
956 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
957 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
959 tableY = table + *(Y++);
960 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
961 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
963 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
965 tableY = table + *(Y++);
966 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
967 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
969 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
973 uvRed = (V_RED_COEF*v) >> SHIFT;
974 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
975 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
977 tableY = table + *(Y++);
978 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
979 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
981 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
983 tableY = table + *(Y++);
984 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
985 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
987 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
991 uvRed = (V_RED_COEF*v) >> SHIFT;
992 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
993 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
995 tableY = table + *(Y++);
996 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
997 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
999 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1001 tableY = table + *(Y++);
1002 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1003 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1005 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1009 uvRed = (V_RED_COEF*v) >> SHIFT;
1010 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1011 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1013 tableY = table + *(Y++);
1014 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1015 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1017 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1019 tableY = table + *(Y++);
1020 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1021 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1023 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1027 uvRed = (V_RED_COEF*v) >> SHIFT;
1028 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1029 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1031 tableY = table + *(Y++);
1032 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1033 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1035 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1037 tableY = table + *(Y++);
1038 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1039 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1041 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1045 uvRed = (V_RED_COEF*v) >> SHIFT;
1046 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1047 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1049 tableY = table + *(Y++);
1050 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1051 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1053 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1055 tableY = table + *(Y++);
1056 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1057 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1059 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1063 uvRed = (V_RED_COEF*v) >> SHIFT;
1064 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1065 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1067 tableY = table + *(Y++);
1068 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1069 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1071 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1073 tableY = table + *(Y++);
1074 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1075 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1077 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1081 uvRed = (V_RED_COEF*v) >> SHIFT;
1082 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1083 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1085 tableY = table + *(Y++);
1086 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1087 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1089 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1091 tableY = table + *(Y++);
1092 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1093 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1095 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1098 i = (width & 15) >> 1;
1102 uvRed = (V_RED_COEF*v) >> SHIFT;
1103 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1104 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1106 tableY = table + *(Y++);
1107 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1108 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1110 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1112 tableY = table + *(Y++);
1113 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1114 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1116 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]);
1134 static void yuvToRgb24 (unsigned char * Y,
1135 unsigned char * U, unsigned char * V,
1136 char * dest, int table[1935], int width)
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 tmp24 = (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]);
1161 *(dest++) = tmp24 >> 8;
1162 *(dest++) = tmp24 >> 16;
1164 tableY = table + *(Y++);
1165 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1166 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1168 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1170 *(dest++) = tmp24 >> 8;
1171 *(dest++) = tmp24 >> 16;
1175 uvRed = (V_RED_COEF*v) >> SHIFT;
1176 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1177 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1179 tableY = table + *(Y++);
1180 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1181 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1183 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1185 *(dest++) = tmp24 >> 8;
1186 *(dest++) = tmp24 >> 16;
1188 tableY = table + *(Y++);
1189 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1190 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1192 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1194 *(dest++) = tmp24 >> 8;
1195 *(dest++) = tmp24 >> 16;
1199 uvRed = (V_RED_COEF*v) >> SHIFT;
1200 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1201 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1203 tableY = table + *(Y++);
1204 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1205 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1207 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1209 *(dest++) = tmp24 >> 8;
1210 *(dest++) = tmp24 >> 16;
1212 tableY = table + *(Y++);
1213 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1214 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1216 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1218 *(dest++) = tmp24 >> 8;
1219 *(dest++) = tmp24 >> 16;
1223 uvRed = (V_RED_COEF*v) >> SHIFT;
1224 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1225 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1227 tableY = table + *(Y++);
1228 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1229 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1231 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1233 *(dest++) = tmp24 >> 8;
1234 *(dest++) = tmp24 >> 16;
1236 tableY = table + *(Y++);
1237 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1238 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1240 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1242 *(dest++) = tmp24 >> 8;
1243 *(dest++) = tmp24 >> 16;
1246 i = (width & 7) >> 1;
1250 uvRed = (V_RED_COEF*v) >> SHIFT;
1251 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1252 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1254 tableY = table + *(Y++);
1255 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1256 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1258 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1260 *(dest++) = tmp24 >> 8;
1261 *(dest++) = tmp24 >> 16;
1263 tableY = table + *(Y++);
1264 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1265 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1267 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1269 *(dest++) = tmp24 >> 8;
1270 *(dest++) = tmp24 >> 16;
1276 uvRed = (V_RED_COEF*v) >> SHIFT;
1277 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1278 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1280 tableY = table + *(Y++);
1281 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1282 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1284 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1286 *(dest++) = tmp24 >> 8;
1287 *(dest++) = tmp24 >> 16;
1291 static void yuvToRgb32 (unsigned char * Y,
1292 unsigned char * U, unsigned char * V,
1293 int * dest, int table[1935], int width)
1307 uvRed = (V_RED_COEF*v) >> SHIFT;
1308 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1309 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1311 tableY = table + *(Y++);
1312 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1313 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1315 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1317 tableY = table + *(Y++);
1318 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1319 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1321 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1325 uvRed = (V_RED_COEF*v) >> SHIFT;
1326 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1327 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1329 tableY = table + *(Y++);
1330 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1331 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1333 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1335 tableY = table + *(Y++);
1336 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1337 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1339 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1343 uvRed = (V_RED_COEF*v) >> SHIFT;
1344 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1345 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1347 tableY = table + *(Y++);
1348 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1349 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1351 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1353 tableY = table + *(Y++);
1354 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1355 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1357 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1361 uvRed = (V_RED_COEF*v) >> SHIFT;
1362 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1363 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1365 tableY = table + *(Y++);
1366 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1367 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1369 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1371 tableY = table + *(Y++);
1372 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1373 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1375 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1379 uvRed = (V_RED_COEF*v) >> SHIFT;
1380 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1381 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1383 tableY = table + *(Y++);
1384 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1385 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1387 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1389 tableY = table + *(Y++);
1390 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1391 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1393 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1397 uvRed = (V_RED_COEF*v) >> SHIFT;
1398 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1399 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1401 tableY = table + *(Y++);
1402 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1403 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1405 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1407 tableY = table + *(Y++);
1408 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1409 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1411 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1415 uvRed = (V_RED_COEF*v) >> SHIFT;
1416 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1417 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1419 tableY = table + *(Y++);
1420 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1421 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1423 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1425 tableY = table + *(Y++);
1426 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1427 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1429 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1433 uvRed = (V_RED_COEF*v) >> SHIFT;
1434 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1435 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1437 tableY = table + *(Y++);
1438 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1439 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1441 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1443 tableY = table + *(Y++);
1444 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1445 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1447 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1450 i = (width & 15) >> 1;
1454 uvRed = (V_RED_COEF*v) >> SHIFT;
1455 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1456 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1458 tableY = table + *(Y++);
1459 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1460 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1462 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1464 tableY = table + *(Y++);
1465 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1466 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1468 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]);
1486 /* yuv routines with scaling */
1487 /* 4:2:2 i, 16 bpp*/
1489 void yuv422ToRgb16_scaled (unsigned char * Y,
1490 unsigned char * U, unsigned char * V,
1491 short * dest, short table[1935], int width , int dest_width,
1492 int height, int dest_height, int skip, int dest_skip,short * buffer)
1494 int i, i_hcount, i_vcount, j, k;
1503 if ( ( width < dest_width ) && ( height < dest_height ) )
1505 i_vcount = dest_height;
1511 i_hcount = dest_width;
1516 uvRed = (V_RED_COEF*v) >> SHIFT;
1517 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1518 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1520 tableY = table + *(Y++);
1521 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1522 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1523 >>SHIFT) + uvGreen] |
1524 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1525 while ( ( i_hcount -= width ) >= 0 )
1529 i_hcount += dest_width;
1531 tableY = table + *(Y++);
1532 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1533 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1534 >>SHIFT) + uvGreen] |
1535 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1536 while ( ( i_hcount -= width ) >= 0 )
1540 i_hcount += dest_width;
1542 while ( ( i_vcount -= height ) >= 0 )
1544 for (j=0; j<dest_width; j+=16)
1547 dest[j+1]=buffer[j+1];
1548 dest[j+2]=buffer[j+2];
1549 dest[j+3]=buffer[j+3];
1550 dest[j+4]=buffer[j+4];
1551 dest[j+6]=buffer[j+7];
1552 dest[j+8]=buffer[j+9];
1553 dest[j+10]=buffer[j+10];
1554 dest[j+11]=buffer[j+11];
1555 dest[j+12]=buffer[j+12];
1556 dest[j+13]=buffer[j+13];
1557 dest[j+14]=buffer[j+14];
1558 dest[j+15]=buffer[j+15];
1562 i_vcount += dest_height;
1565 else if ( ( width > dest_width ) && ( height < dest_height ) )
1567 i_vcount = dest_height;
1578 uvRed = (V_RED_COEF*v) >> SHIFT;
1579 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1580 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1582 if ( ( i_hcount -= dest_width ) >= 0 )
1586 tableY = table + *(Y++);
1587 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1590 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1592 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1596 if ( ( i_hcount -= dest_width ) >= 0 )
1600 tableY = table + *(Y++);
1601 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1604 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1606 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1611 while ( ( i_vcount -= height ) >= 0 )
1613 for (j=0; j<dest_width; j+=16)
1616 dest[j+1]=buffer[j+1];
1617 dest[j+2]=buffer[j+2];
1618 dest[j+3]=buffer[j+3];
1619 dest[j+4]=buffer[j+4];
1620 dest[j+6]=buffer[j+7];
1621 dest[j+8]=buffer[j+9];
1622 dest[j+10]=buffer[j+10];
1623 dest[j+11]=buffer[j+11];
1624 dest[j+12]=buffer[j+12];
1625 dest[j+13]=buffer[j+13];
1626 dest[j+14]=buffer[j+14];
1627 dest[j+15]=buffer[j+15];
1631 i_vcount += dest_height;
1634 else if ( ( width < dest_width ) && ( height > dest_height ) )
1642 i_hcount = dest_width;
1647 uvRed = (V_RED_COEF*v) >> SHIFT;
1648 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1649 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1651 tableY = table + *(Y++);
1652 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1653 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1654 >>SHIFT) + uvGreen] |
1655 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1656 while ( ( i_hcount -= width ) >= 0 )
1660 i_hcount += dest_width;
1662 tableY = table + *(Y++);
1663 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1664 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1665 >>SHIFT) + uvGreen] |
1666 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1667 while ( ( i_hcount -= width ) >= 0 )
1671 i_hcount += dest_width;
1673 while ( ( i_vcount -= height ) >= 0 )
1679 i_vcount += dest_height;
1682 else if ( ( width > dest_width ) && ( height > dest_height ) )
1684 i_vcount = dest_height;
1695 uvRed = (V_RED_COEF*v) >> SHIFT;
1696 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1697 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1699 if ( ( i_hcount -= dest_width ) >= 0 )
1703 tableY = table + *(Y++);
1704 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1707 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1709 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1713 if ( ( i_hcount -= dest_width ) >= 0 )
1717 tableY = table + *(Y++);
1718 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1721 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1723 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1728 while ( ( i_vcount -= height ) >= 0 )
1734 i_vcount += dest_height;
1739 /* yuv routines with scaling */
1740 /* 4:2:0 i, 16 bpp*/
1742 void yuv420ToRgb16_scaled (unsigned char * Y,
1743 unsigned char * U, unsigned char * V,
1744 short * dest, short table[1935], int width , int dest_width,
1745 int height, int dest_height, int skip, int dest_skip,short * buffer)
1747 int i, i_hcount, i_vcount, j, k;
1756 if ( ( width < dest_width ) && ( height < dest_height ) )
1758 i_vcount = dest_height;
1764 i_hcount = dest_width;
1769 uvRed = (V_RED_COEF*v) >> SHIFT;
1770 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1771 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1773 tableY = table + *(Y++);
1774 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1775 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1776 >>SHIFT) + uvGreen] |
1777 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1778 while ( ( i_hcount -= width ) >= 0 )
1782 i_hcount += dest_width;
1784 tableY = table + *(Y++);
1785 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1786 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1787 >>SHIFT) + uvGreen] |
1788 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1789 while ( ( i_hcount -= width ) >= 0 )
1793 i_hcount += dest_width;
1795 while ( ( i_vcount -= height ) >= 0 )
1797 for (j=0; j<dest_width; j+=16)
1800 dest[j+1]=buffer[j+1];
1801 dest[j+2]=buffer[j+2];
1802 dest[j+3]=buffer[j+3];
1803 dest[j+4]=buffer[j+4];
1804 dest[j+6]=buffer[j+7];
1805 dest[j+8]=buffer[j+9];
1806 dest[j+10]=buffer[j+10];
1807 dest[j+11]=buffer[j+11];
1808 dest[j+12]=buffer[j+12];
1809 dest[j+13]=buffer[j+13];
1810 dest[j+14]=buffer[j+14];
1811 dest[j+15]=buffer[j+15];
1815 i_vcount += dest_height;
1820 i_hcount = dest_width;
1825 uvRed = (V_RED_COEF*v) >> SHIFT;
1826 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1827 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1829 tableY = table + *(Y++);
1830 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1831 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1832 >>SHIFT) + uvGreen] |
1833 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1834 while ( ( i_hcount -= width ) >= 0 )
1838 i_hcount += dest_width;
1840 tableY = table + *(Y++);
1841 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1842 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1843 >>SHIFT) + uvGreen] |
1844 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1845 while ( ( i_hcount -= width ) >= 0 )
1849 i_hcount += dest_width;
1851 while ( ( i_vcount -= height ) >= 0 )
1853 for (j=0; j<dest_width; j+=16)
1856 dest[j+1]=buffer[j+1];
1857 dest[j+2]=buffer[j+2];
1858 dest[j+3]=buffer[j+3];
1859 dest[j+4]=buffer[j+4];
1860 dest[j+6]=buffer[j+7];
1861 dest[j+8]=buffer[j+9];
1862 dest[j+10]=buffer[j+10];
1863 dest[j+11]=buffer[j+11];
1864 dest[j+12]=buffer[j+12];
1865 dest[j+13]=buffer[j+13];
1866 dest[j+14]=buffer[j+14];
1867 dest[j+15]=buffer[j+15];
1871 i_vcount += dest_height;
1874 else if ( ( width > dest_width ) && ( height < dest_height ) )
1876 i_vcount = dest_height;
1887 uvRed = (V_RED_COEF*v) >> SHIFT;
1888 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1889 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1891 if ( ( i_hcount -= dest_width ) >= 0 )
1895 tableY = table + *(Y++);
1896 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1899 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1901 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1905 if ( ( i_hcount -= dest_width ) >= 0 )
1909 tableY = table + *(Y++);
1910 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1913 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1915 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1920 while ( ( i_vcount -= height ) >= 0 )
1922 for (j=0; j<dest_width; j+=16)
1925 dest[j+1]=buffer[j+1];
1926 dest[j+2]=buffer[j+2];
1927 dest[j+3]=buffer[j+3];
1928 dest[j+4]=buffer[j+4];
1929 dest[j+6]=buffer[j+7];
1930 dest[j+8]=buffer[j+9];
1931 dest[j+10]=buffer[j+10];
1932 dest[j+11]=buffer[j+11];
1933 dest[j+12]=buffer[j+12];
1934 dest[j+13]=buffer[j+13];
1935 dest[j+14]=buffer[j+14];
1936 dest[j+15]=buffer[j+15];
1940 i_vcount += dest_height;
1950 uvRed = (V_RED_COEF*v) >> SHIFT;
1951 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1952 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1954 if ( ( i_hcount -= dest_width ) >= 0 )
1958 tableY = table + *(Y++);
1959 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1962 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1964 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1968 if ( ( i_hcount -= dest_width ) >= 0 )
1972 tableY = table + *(Y++);
1973 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1976 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1978 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1983 while ( ( i_vcount -= height ) >= 0 )
1985 for (j=0; j<dest_width; j+=16)
1988 dest[j+1]=buffer[j+1];
1989 dest[j+2]=buffer[j+2];
1990 dest[j+3]=buffer[j+3];
1991 dest[j+4]=buffer[j+4];
1992 dest[j+6]=buffer[j+7];
1993 dest[j+8]=buffer[j+9];
1994 dest[j+10]=buffer[j+10];
1995 dest[j+11]=buffer[j+11];
1996 dest[j+12]=buffer[j+12];
1997 dest[j+13]=buffer[j+13];
1998 dest[j+14]=buffer[j+14];
1999 dest[j+15]=buffer[j+15];
2003 i_vcount += dest_height;
2006 else if ( ( width < dest_width ) && ( height > dest_height ) )
2014 i_hcount = dest_width;
2019 uvRed = (V_RED_COEF*v) >> SHIFT;
2020 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2021 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2023 tableY = table + *(Y++);
2024 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2025 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2026 >>SHIFT) + uvGreen] |
2027 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2028 while ( ( i_hcount -= width ) >= 0 )
2032 i_hcount += dest_width;
2034 tableY = table + *(Y++);
2035 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
2036 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
2037 >>SHIFT) + uvGreen] |
2038 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
2039 while ( ( i_hcount -= width ) >= 0 )
2043 i_hcount += dest_width;
2046 while ( ( i_vcount -= height ) >= 0 )
2051 U += skip * ( j >> 1 );
2052 V += skip * ( j >> 1 );
2053 i_vcount += dest_height;
2056 else if ( ( width > dest_width ) && ( height > dest_height ) )
2058 i_vcount = dest_height;
2069 uvRed = (V_RED_COEF*v) >> SHIFT;
2070 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2071 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2073 if ( ( i_hcount -= dest_width ) >= 0 )
2077 tableY = table + *(Y++);
2078 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2081 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2083 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2087 if ( ( i_hcount -= dest_width ) >= 0 )
2091 tableY = table + *(Y++);
2092 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2095 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2097 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2103 while ( ( i_vcount -= height ) >= 0 )
2108 U += skip * ( j >> 1 );
2109 V += skip * ( j >> 1 );
2110 i_vcount += dest_height;