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 SetYUV ( 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_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
54 int i_matrix_coefficients );
55 static void ConvertY4Gray24 ( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
56 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
57 int i_matrix_coefficients );
58 static void ConvertY4Gray32 ( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
59 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
60 int i_matrix_coefficients );
61 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
62 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
63 int i_matrix_coefficients );
64 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
65 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
66 int i_matrix_coefficients );
67 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
68 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
69 int i_matrix_coefficients );
70 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
71 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
72 int i_matrix_coefficients );
73 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
74 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
75 int i_matrix_coefficients );
76 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
77 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
78 int i_matrix_coefficients );
79 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
80 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
81 int i_matrix_coefficients );
82 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
83 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
84 int i_matrix_coefficients );
85 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
86 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
87 int i_matrix_coefficients );
89 //?? temporary prototypes, will be integrated to normal ones */
90 void yuv420ToRgb16_scaled (unsigned char * Y, unsigned char * U, unsigned char * V,
91 short * dest, short table[1935], int width , int dest_width,
92 int height, int dest_height, int skip, int dest_skip,short * buffer);
94 /*******************************************************************************
95 * CLIP_BYTE macro: boundary detection
96 *******************************************************************************
97 * Return parameter if between 0 and 255, else return nearest boundary (0 or
98 * 255). This macro is used to build translations tables.
99 *******************************************************************************/
100 #define CLIP_BYTE( i_val ) ( (i_val < 0) ? 0 : ((i_val > 255) ? 255 : i_val) )
102 /*******************************************************************************
103 * LINE_COPY macro: memcopy using 16 pixels blocks
104 *******************************************************************************
106 * p_pic destination pointer
107 * p_pic_src source pointer
110 *******************************************************************************/
112 for( i_x = 0; i_x < i_width; i_x+=16 ) \
114 *p_pic++ = *p_pic_src++; \
115 *p_pic++ = *p_pic_src++; \
116 *p_pic++ = *p_pic_src++; \
117 *p_pic++ = *p_pic_src++; \
118 *p_pic++ = *p_pic_src++; \
119 *p_pic++ = *p_pic_src++; \
120 *p_pic++ = *p_pic_src++; \
121 *p_pic++ = *p_pic_src++; \
122 *p_pic++ = *p_pic_src++; \
123 *p_pic++ = *p_pic_src++; \
124 *p_pic++ = *p_pic_src++; \
125 *p_pic++ = *p_pic_src++; \
126 *p_pic++ = *p_pic_src++; \
127 *p_pic++ = *p_pic_src++; \
128 *p_pic++ = *p_pic_src++; \
129 *p_pic++ = *p_pic_src++; \
132 /*******************************************************************************
133 * CONVERT_YUV_GRAY macro: grayscale YUV convertion
134 *******************************************************************************
135 * This macro does not perform any scaling, but crops the picture. It is
136 * provided as a temporary way of implementing an YUV convertion function.
137 *******************************************************************************/
138 #define CONVERT_YUV_GRAY \
139 /* Change boundaries according to picture size */ \
140 i_pic_skip += i_pic_width - MIN( i_width, i_pic_width ); \
141 i_skip += i_width - MIN( i_width, i_pic_width ); \
142 i_width = MIN( i_width, i_pic_width ); \
143 i_height = MIN( i_height, i_pic_height ); \
146 for (i_y = 0; i_y < i_height ; i_y++) \
148 for (i_x = 0; i_x < i_width; i_x += 16) \
150 /* Convert 16 pixels (width is always multiple of 16 */ \
151 *p_pic++ = p_gray[ *p_y++ ]; \
152 *p_pic++ = p_gray[ *p_y++ ]; \
153 *p_pic++ = p_gray[ *p_y++ ]; \
154 *p_pic++ = p_gray[ *p_y++ ]; \
155 *p_pic++ = p_gray[ *p_y++ ]; \
156 *p_pic++ = p_gray[ *p_y++ ]; \
157 *p_pic++ = p_gray[ *p_y++ ]; \
158 *p_pic++ = p_gray[ *p_y++ ]; \
159 *p_pic++ = p_gray[ *p_y++ ]; \
160 *p_pic++ = p_gray[ *p_y++ ]; \
161 *p_pic++ = p_gray[ *p_y++ ]; \
162 *p_pic++ = p_gray[ *p_y++ ]; \
163 *p_pic++ = p_gray[ *p_y++ ]; \
164 *p_pic++ = p_gray[ *p_y++ ]; \
165 *p_pic++ = p_gray[ *p_y++ ]; \
166 *p_pic++ = p_gray[ *p_y++ ]; \
169 /* Skip until beginning of next line */ \
171 p_pic += i_pic_skip; \
174 /*******************************************************************************
175 * CONVERT_YUV_RGB: color YUV convertion
176 *******************************************************************************
177 * This macro does not perform any scaling, but crops the picture. It is
178 * provided as a temporary way of implementing an YUV convertion function.
179 *******************************************************************************/
180 #define CONVERT_YUV_RGB( CHROMA ) \
181 /* Change boundaries according to picture size */ \
182 i_pic_skip += i_pic_width - MIN( i_width, i_pic_width ); \
183 i_skip += i_width - MIN( i_width, i_pic_width ); \
184 i_width = MIN( i_width, i_pic_width ); \
185 i_height = MIN( i_height, i_pic_height ); \
186 i_chroma_skip = (CHROMA == 444) ? i_skip : i_skip / 2; \
187 i_chroma_width = (CHROMA == 444) ? i_width : i_width / 2; \
190 for (i_y = 0; i_y < i_height ; i_y++) \
192 for (i_x = 0; i_x < i_width; i_x += 2 ) \
194 /* First sample (complete) */ \
195 i_yval = 76309 * *p_y++ - 1188177; \
196 i_uval = *p_u++ - 128; \
197 i_vval = *p_v++ - 128; \
199 p_red [(i_yval+i_crv*i_vval) >>16] | \
200 p_green[(i_yval-i_cgu*i_uval-i_cgv*i_vval) >>16] | \
201 p_blue [(i_yval+i_cbu*i_uval) >>16]; \
202 i_yval = 76309 * *p_y++ - 1188177; \
203 /* Second sample (partial) */ \
204 if( CHROMA == 444 ) \
206 i_uval = *p_u++ - 128; \
207 i_vval = *p_v++ - 128; \
210 p_red [(i_yval+i_crv*i_vval) >>16] | \
211 p_green[(i_yval-i_cgu*i_uval-i_cgv*i_vval) >>16] | \
212 p_blue [(i_yval+i_cbu*i_uval) >>16]; \
215 /* Rewind in 4:2:0 */ \
216 if( (CHROMA == 420) && !(i_y & 0x1) ) \
218 p_u -= i_chroma_width; \
219 p_v -= i_chroma_width; \
223 p_u += i_chroma_skip; \
224 p_v += i_chroma_skip; \
227 /* Skip until beginning of next line */ \
229 p_pic += i_pic_skip; \
233 /*******************************************************************************
234 * vout_InitYUV: allocate and initialize translations tables
235 *******************************************************************************
236 * This function will allocate memory to store translation tables, depending
237 * of the screen depth.
238 *******************************************************************************/
239 int vout_InitYUV( vout_thread_t *p_vout )
241 size_t tables_size; /* tables size, in bytes */
243 /* Computes tables size */
244 switch( p_vout->i_screen_depth )
248 tables_size = sizeof( u16 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
255 tables_size = sizeof( u32 ) * (1024 * (p_vout->b_grayscale ? 1 : 3) + 1935);
259 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
265 /* Add conversion buffer size. The conversions functions need one comple line
266 * plus one pixel, so we give them two. */
267 tables_size += p_vout->i_bytes_per_line * 2;
269 /* Allocate memory */
270 p_vout->yuv.p_base = malloc( tables_size );
271 if( p_vout->yuv.p_base == NULL )
273 intf_ErrMsg("error: %s\n", strerror(ENOMEM));
277 /* Initialize tables */
282 /*******************************************************************************
283 * vout_ResetTables: re-initialize translations tables
284 *******************************************************************************
285 * This function will initialize the tables allocated by vout_CreateTables and
286 * set functions pointers.
287 *******************************************************************************/
288 int vout_ResetYUV( vout_thread_t *p_vout )
290 vout_EndYUV( p_vout );
291 return( vout_InitYUV( p_vout ) );
294 /*******************************************************************************
295 * vout_EndYUV: destroy translations tables
296 *******************************************************************************
297 * Free memory allocated by vout_CreateTables.
298 *******************************************************************************/
299 void vout_EndYUV( vout_thread_t *p_vout )
301 free( p_vout->yuv.p_base );
304 /* following functions are local */
306 /*******************************************************************************
307 * BinaryLog: computes the base 2 log of a binary value
308 *******************************************************************************
309 * This functions is used by MaskToShift during tables initialisation, to
310 * get a bit index from a binary value.
311 *******************************************************************************/
312 static int BinaryLog(u32 i)
337 if (i != ((u32)1 << i_log))
339 intf_ErrMsg("internal error: binary log overflow\n");
345 /*******************************************************************************
346 * MaskToShift: Transform a color mask into right and left shifts
347 *******************************************************************************
348 * This function is used during table initialisation. It can return a value
349 *******************************************************************************/
350 static void MaskToShift (int *pi_right, int *pi_left, u32 i_mask)
352 u32 i_low, i_high; /* lower hand higher bits of the mask */
355 i_low = i_mask & (- i_mask); /* lower bit of the mask */
356 i_high = i_mask + i_low; /* higher bit of the mask */
358 /* Transform bits into an index */
359 i_low = BinaryLog (i_low);
360 i_high = BinaryLog (i_high);
362 /* Update pointers and return */
364 *pi_right = (8 - i_high + i_low);
367 /*******************************************************************************
368 * SetGammaTable: return intensity table transformed by gamma curve.
369 *******************************************************************************
370 * pi_table is a table of 256 entries from 0 to 255.
371 *******************************************************************************/
372 static void SetGammaTable( int *pi_table, double f_gamma )
374 int i_y; /* base intensity */
376 /* Use exp(gamma) instead of gamma */
377 f_gamma = exp(f_gamma );
379 /* Build gamma table */
380 for( i_y = 0; i_y < 256; i_y++ )
382 pi_table[ i_y ] = pow( (double)i_y / 256, f_gamma ) * 256;
386 /*******************************************************************************
387 * SetYUV: compute tables and set function pointers
388 + *******************************************************************************/
389 static void SetYUV( vout_thread_t *p_vout )
391 int pi_gamma[256]; /* gamma table */
392 int i_index; /* index in tables */
393 int i_red_right, i_red_left; /* red shifts */
394 int i_green_right, i_green_left; /* green shifts */
395 int i_blue_right, i_blue_left; /* blue shifts */
397 /* Build gamma table */
398 SetGammaTable( pi_gamma, p_vout->f_gamma );
401 * Set color masks and shifts
403 switch( p_vout->i_screen_depth )
406 MaskToShift( &i_red_right, &i_red_left, 0x7c00 );
407 MaskToShift( &i_green_right, &i_green_left, 0x03e0 );
408 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
411 MaskToShift( &i_red_right, &i_red_left, 0xf800 );
412 MaskToShift( &i_green_right, &i_green_left, 0x07e0 );
413 MaskToShift( &i_blue_right, &i_blue_left, 0x001f );
417 MaskToShift( &i_red_right, &i_red_left, 0x00ff0000 );
418 MaskToShift( &i_green_right, &i_green_left, 0x0000ff00 );
419 MaskToShift( &i_blue_right, &i_blue_left, 0x000000ff );
423 intf_DbgMsg("error: invalid screen depth %d\n", p_vout->i_screen_depth );
429 * Set pointers and build YUV tables
431 if( p_vout->b_grayscale )
433 /* Grayscale: build gray table */
434 switch( p_vout->i_screen_depth )
438 p_vout->yuv.yuv.gray16.p_gray = (u16 *)p_vout->yuv.p_base + 384;
439 for( i_index = -384; i_index < 640; i_index++)
441 p_vout->yuv.yuv.gray16.p_gray[ i_index ] =
442 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
443 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
444 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
449 p_vout->yuv.yuv.gray32.p_gray = (u32 *)p_vout->yuv.p_base + 384;
450 for( i_index = -384; i_index < 640; i_index++)
452 p_vout->yuv.yuv.gray32.p_gray[ i_index ] =
453 ((pi_gamma[CLIP_BYTE( i_index )] >> i_red_right) << i_red_left) |
454 ((pi_gamma[CLIP_BYTE( i_index )] >> i_green_right) << i_green_left) |
455 ((pi_gamma[CLIP_BYTE( i_index )] >> i_blue_right) << i_blue_left);
462 /* Color: build red, green and blue tables */
463 switch( p_vout->i_screen_depth )
467 p_vout->yuv.yuv.rgb16.p_red = (u16 *)p_vout->yuv.p_base + 384;
468 p_vout->yuv.yuv.rgb16.p_green = (u16 *)p_vout->yuv.p_base + 1024 + 384;
469 p_vout->yuv.yuv.rgb16.p_blue = (u16 *)p_vout->yuv.p_base + 2*1024 + 384;
470 p_vout->yuv.yuv2.p_rgb16 = (u16 *)p_vout->yuv.p_base + 3*1024;
471 p_vout->yuv.p_buffer = (u16 *)p_vout->yuv.p_base + 3*1024 + 1935;
472 for( i_index = -384; i_index < 640; i_index++)
474 p_vout->yuv.yuv.rgb16.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
475 p_vout->yuv.yuv.rgb16.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
476 p_vout->yuv.yuv.rgb16.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
478 for( i_index = 0; i_index < 178; i_index++ )
480 p_vout->yuv.yuv2.p_rgb16[1501 - 178 + i_index] = (pi_gamma[0]>>i_red_right)<<i_red_left;
481 p_vout->yuv.yuv2.p_rgb16[1501 + 256 + i_index] = (pi_gamma[255]>>i_red_right)<<i_red_left;
483 for( i_index = 0; i_index < 135; i_index++ )
485 p_vout->yuv.yuv2.p_rgb16[135 - 135 + i_index] = (pi_gamma[0]>>i_green_right)<<i_green_left;
486 p_vout->yuv.yuv2.p_rgb16[135 + 256 + i_index] = (pi_gamma[255]>>i_green_right)<<i_green_left;
488 for( i_index = 0; i_index < 224; i_index++ )
490 p_vout->yuv.yuv2.p_rgb16[818 - 224 + i_index] = (pi_gamma[0]>>i_blue_right)<<i_blue_left;
491 p_vout->yuv.yuv2.p_rgb16[818 + 256 + i_index] = (pi_gamma[255]>>i_blue_right)<<i_blue_left;
493 for( i_index = 0; i_index < 256; i_index++ )
495 p_vout->yuv.yuv2.p_rgb16[1501 + i_index] = (pi_gamma[i_index]>>i_red_right)<<i_red_left;
496 p_vout->yuv.yuv2.p_rgb16[135 + i_index] = (pi_gamma[i_index]>>i_green_right)<<i_green_left;
497 p_vout->yuv.yuv2.p_rgb16[818 + i_index] = (pi_gamma[i_index]>>i_blue_right)<<i_blue_left;
502 p_vout->yuv.yuv.rgb32.p_red = (u32 *)p_vout->yuv.p_base + 384;
503 p_vout->yuv.yuv.rgb32.p_green = (u32 *)p_vout->yuv.p_base + 1024 + 384;
504 p_vout->yuv.yuv.rgb32.p_blue = (u32 *)p_vout->yuv.p_base + 2*1024 + 384;
505 p_vout->yuv.yuv2.p_rgb32 = (u32 *)p_vout->yuv.p_base + 3*1024;
506 p_vout->yuv.p_buffer = (u32 *)p_vout->yuv.p_base + 3*1024 + 1935;
507 for( i_index = -384; i_index < 640; i_index++)
509 p_vout->yuv.yuv.rgb32.p_red[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_red_right)<<i_red_left;
510 p_vout->yuv.yuv.rgb32.p_green[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_green_right)<<i_green_left;
511 p_vout->yuv.yuv.rgb32.p_blue[i_index] = (pi_gamma[CLIP_BYTE(i_index)]>>i_blue_right)<<i_blue_left;
519 * Set functions pointers
521 if( p_vout->b_grayscale )
524 switch( p_vout->i_screen_depth )
528 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
529 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
530 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16;
533 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
534 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
535 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24;
538 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
539 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
540 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32;
547 switch( p_vout->i_screen_depth )
551 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB16;
552 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB16;
553 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB16;
556 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB24;
557 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB24;
558 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB24;
561 p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB32;
562 p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB32;
563 p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB32;
569 /*******************************************************************************
570 * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 15 or 16 bpp
571 *******************************************************************************/
572 static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
573 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
574 int i_matrix_coefficients )
576 u16 * p_gray; /* gray table */
577 int i_x, i_y; /* picture coordinates */
579 p_gray = p_vout->yuv.yuv.gray16.p_gray;
583 /*******************************************************************************
584 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 24 bpp
585 *******************************************************************************/
586 static void ConvertY4Gray24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
587 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
588 int i_matrix_coefficients )
593 /*******************************************************************************
594 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 32 bpp
595 *******************************************************************************/
596 static void ConvertY4Gray32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
597 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
598 int i_matrix_coefficients )
600 u32 * p_gray; /* gray table */
601 int i_x, i_y; /* picture coordinates */
603 p_gray = p_vout->yuv.yuv.gray32.p_gray;
607 /*******************************************************************************
608 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 15 or 16 bpp
609 *******************************************************************************/
610 static void ConvertYUV420RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
611 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
612 int i_matrix_coefficients )
614 //?? gloups: find a good one !
616 intf_DbgMsg("%dx%d-%d -> %dx%d-%d\n", i_width, i_height, i_skip, i_pic_width, i_pic_height, i_pic_skip );
617 yuv420ToRgb16_scaled ( p_y, p_u, p_v, p_pic, p_vout->yuv.yuv2.p_rgb16,
618 i_width , i_pic_width, i_height, i_pic_height, i_skip, i_pic_skip,
619 p_vout->yuv.p_buffer);
622 int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
624 i_chroma_width = i_width / 2;
625 i_chroma_skip = i_skip / 2;
626 ConvertYUV420RGB16MMX( p_y, p_u, p_v, i_width, i_height,
627 (i_width + i_skip) * sizeof( yuv_data_t ),
628 (i_chroma_width + i_chroma_skip) * sizeof( yuv_data_t),
629 i_scale, (u8 *)p_pic, 0, 0, (i_width + i_pic_eol) * sizeof( u16 ),
630 p_vout->i_screen_depth == 15 );
632 u16 * p_red; /* red table */
633 u16 * p_green; /* green table */
634 u16 * p_blue; /* blue table */
635 int i_uval, i_yval, i_vval; /* samples */
636 int i_x, i_y; /* picture coordinates */
637 int i_chroma_width, i_chroma_skip; /* width and eol for chroma */
638 int i_crv, i_cbu, i_cgu, i_cgv; /* transformation coefficients */
640 i_crv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][0];
641 i_cbu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][1];
642 i_cgu = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][2];
643 i_cgv = MATRIX_COEFFICIENTS_TABLE[i_matrix_coefficients][3];
644 p_red = p_vout->yuv.yuv.rgb16.p_red;
645 p_green = p_vout->yuv.yuv.rgb16.p_green;
646 p_blue = p_vout->yuv.yuv.rgb16.p_blue;
647 CONVERT_YUV_RGB( 420 )
651 /*******************************************************************************
652 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 15 or 16 bpp
653 *******************************************************************************/
654 static void ConvertYUV422RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
655 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
656 int i_matrix_coefficients )
661 /*******************************************************************************
662 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 15 or 16 bpp
663 *******************************************************************************/
664 static void ConvertYUV444RGB16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
665 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
666 int i_matrix_coefficients )
671 /*******************************************************************************
672 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 24 bpp
673 *******************************************************************************/
674 static void ConvertYUV420RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
675 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
676 int i_matrix_coefficients )
681 /*******************************************************************************
682 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 24 bpp
683 *******************************************************************************/
684 static void ConvertYUV422RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
685 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
686 int i_matrix_coefficients )
691 /*******************************************************************************
692 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 24 bpp
693 *******************************************************************************/
694 static void ConvertYUV444RGB24( p_vout_thread_t p_vout, void *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
695 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
696 int i_matrix_coefficients )
701 /*******************************************************************************
702 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 32 bpp
703 *******************************************************************************/
704 static void ConvertYUV420RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
705 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
706 int i_matrix_coefficients )
711 /*******************************************************************************
712 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 32 bpp
713 *******************************************************************************/
714 static void ConvertYUV422RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
715 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
716 int i_matrix_coefficients )
721 /*******************************************************************************
722 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 32 bpp
723 *******************************************************************************/
724 static void ConvertYUV444RGB32( p_vout_thread_t p_vout, u32 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v,
725 int i_width, int i_height, int i_skip, int i_pic_width, int i_pic_height, int i_pic_skip,
726 int i_matrix_coefficients )
731 //-------------------- walken code follow ---------------------------------------
734 * YUV to RGB routines.
736 * these routines calculate r, g and b values from each pixel's y, u and v.
737 * these r, g an b values are then passed thru a table lookup to take the
738 * gamma curve into account and find the corresponding pixel value.
740 * the table must store more than 3*256 values because of the possibility
741 * of overflow in the yuv->rgb calculation. actually the calculated r,g,b
742 * values are in the following intervals :
743 * -176 to 255+176 for red
744 * -133 to 255+133 for green
745 * -222 to 255+222 for blue
747 * If the input y,u,v values are right, the r,g,b results are not expected
748 * to move out of the 0 to 255 interval but who knows what will happen in
751 * the red, green and blue conversion tables are stored in a single 1935-entry
752 * array. The respective positions of each component in the array have been
753 * calculated to minimize the cache interactions of the 3 tables.
756 int rgbTable16 (short table [1935],
757 int redMask, int greenMask, int blueMask,
758 unsigned char gamma[256])
772 MaskToShift (&redRight, &redLeft, redMask);
773 MaskToShift (&greenRight, &greenLeft, greenMask);
774 MaskToShift (&blueRight, &blueLeft, blueMask);
777 * green blue red +- 2 just to be sure
778 * green = 0-525 [151-370]
779 * blue = 594-1297 [834-1053] <834-29>
780 * red = 1323-1934 [1517-1736] <493-712>
783 redTable = table + 1501;
784 greenTable = table + 135;
785 blueTable = table + 818;
787 for (i = 0; i < 178; i++) {
789 redTable[i+256] = redMask;
791 for (i = 0; i < 135; i++) {
792 greenTable[i-135] = 0;
793 greenTable[i+256] = greenMask;
795 for (i = 0; i < 224; i++) {
796 blueTable[i-224] = 0;
797 blueTable[i+256] = blueMask;
800 for (i = 0; i < 256; i++) {
802 redTable[i] = ((y >> redRight) << redLeft);
803 greenTable[i] = ((y >> greenRight) << greenLeft);
804 blueTable[i] = ((y >> blueRight) << blueLeft);
810 static int rgbTable32 (int table [1935],
811 int redMask, int greenMask, int blueMask,
812 unsigned char gamma[256])
826 MaskToShift (&redRight, &redLeft, redMask);
827 MaskToShift (&greenRight, &greenLeft, greenMask);
828 MaskToShift (&blueRight, &blueLeft, blueMask);
832 * green blue red +- 2 just to be sure
833 * green = 0-525 [151-370]
834 * blue = 594-1297 [834-1053] <834-29>
835 * red = 1323-1934 [1517-1736] <493-712>
838 redTable = table + 1501;
839 greenTable = table + 135;
840 blueTable = table + 818;
842 for (i = 0; i < 178; i++) {
844 redTable[i+256] = redMask;
846 for (i = 0; i < 135; i++) {
847 greenTable[i-135] = 0;
848 greenTable[i+256] = greenMask;
850 for (i = 0; i < 224; i++) {
851 blueTable[i-224] = 0;
852 blueTable[i+256] = blueMask;
855 for (i = 0; i < 256; i++) {
857 redTable[i] = ((y >> redRight) << redLeft);
858 greenTable[i] = ((y >> greenRight) << greenLeft);
859 blueTable[i] = ((y >> blueRight) << blueLeft);
866 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
867 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
868 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
869 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
871 void yuvToRgb16 (unsigned char * Y,
872 unsigned char * U, unsigned char * V,
873 short * dest, short table[1935], int width)
887 uvRed = (V_RED_COEF*v) >> SHIFT;
888 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
889 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
891 tableY = table + *(Y++);
892 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
893 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
895 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
897 tableY = table + *(Y++);
898 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
899 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
901 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
905 uvRed = (V_RED_COEF*v) >> SHIFT;
906 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
907 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
909 tableY = table + *(Y++);
910 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
911 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
913 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
915 tableY = table + *(Y++);
916 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
917 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
919 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
923 uvRed = (V_RED_COEF*v) >> SHIFT;
924 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
925 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
927 tableY = table + *(Y++);
928 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
929 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
931 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
933 tableY = table + *(Y++);
934 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
935 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
937 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
941 uvRed = (V_RED_COEF*v) >> SHIFT;
942 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
943 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
945 tableY = table + *(Y++);
946 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
947 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
949 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
951 tableY = table + *(Y++);
952 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
953 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
955 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
959 uvRed = (V_RED_COEF*v) >> SHIFT;
960 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
961 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
963 tableY = table + *(Y++);
964 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
965 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
967 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
969 tableY = table + *(Y++);
970 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
971 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
973 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
977 uvRed = (V_RED_COEF*v) >> SHIFT;
978 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
979 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
981 tableY = table + *(Y++);
982 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
983 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
985 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
987 tableY = table + *(Y++);
988 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
989 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
991 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
995 uvRed = (V_RED_COEF*v) >> SHIFT;
996 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
997 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
999 tableY = table + *(Y++);
1000 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1001 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1003 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1005 tableY = table + *(Y++);
1006 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1007 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1009 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1013 uvRed = (V_RED_COEF*v) >> SHIFT;
1014 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1015 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1017 tableY = table + *(Y++);
1018 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1019 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1021 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1023 tableY = table + *(Y++);
1024 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1025 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1027 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1030 i = (width & 15) >> 1;
1034 uvRed = (V_RED_COEF*v) >> SHIFT;
1035 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1036 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1038 tableY = table + *(Y++);
1039 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1040 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1042 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1044 tableY = table + *(Y++);
1045 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1046 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1048 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1054 uvRed = (V_RED_COEF*v) >> SHIFT;
1055 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1056 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1058 tableY = table + *(Y++);
1059 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1060 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1062 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1066 static void yuvToRgb24 (unsigned char * Y,
1067 unsigned char * U, unsigned char * V,
1068 char * dest, int table[1935], int width)
1083 uvRed = (V_RED_COEF*v) >> SHIFT;
1084 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1085 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1087 tableY = table + *(Y++);
1088 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1089 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1091 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1093 *(dest++) = tmp24 >> 8;
1094 *(dest++) = tmp24 >> 16;
1096 tableY = table + *(Y++);
1097 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1098 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1100 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1102 *(dest++) = tmp24 >> 8;
1103 *(dest++) = tmp24 >> 16;
1107 uvRed = (V_RED_COEF*v) >> SHIFT;
1108 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1109 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1111 tableY = table + *(Y++);
1112 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1113 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1115 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1117 *(dest++) = tmp24 >> 8;
1118 *(dest++) = tmp24 >> 16;
1120 tableY = table + *(Y++);
1121 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1122 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1124 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1126 *(dest++) = tmp24 >> 8;
1127 *(dest++) = tmp24 >> 16;
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 tmp24 = (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 *(dest++) = tmp24 >> 8;
1142 *(dest++) = tmp24 >> 16;
1144 tableY = table + *(Y++);
1145 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1146 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1148 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1150 *(dest++) = tmp24 >> 8;
1151 *(dest++) = tmp24 >> 16;
1155 uvRed = (V_RED_COEF*v) >> SHIFT;
1156 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1157 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1159 tableY = table + *(Y++);
1160 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1161 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1163 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1165 *(dest++) = tmp24 >> 8;
1166 *(dest++) = tmp24 >> 16;
1168 tableY = table + *(Y++);
1169 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1170 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1172 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1174 *(dest++) = tmp24 >> 8;
1175 *(dest++) = tmp24 >> 16;
1178 i = (width & 7) >> 1;
1182 uvRed = (V_RED_COEF*v) >> SHIFT;
1183 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1184 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1186 tableY = table + *(Y++);
1187 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1188 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1190 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1192 *(dest++) = tmp24 >> 8;
1193 *(dest++) = tmp24 >> 16;
1195 tableY = table + *(Y++);
1196 tmp24 = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1197 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1199 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1201 *(dest++) = tmp24 >> 8;
1202 *(dest++) = tmp24 >> 16;
1208 uvRed = (V_RED_COEF*v) >> SHIFT;
1209 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1210 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
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 static void yuvToRgb32 (unsigned char * Y,
1224 unsigned char * U, unsigned char * V,
1225 int * dest, int table[1935], int width)
1239 uvRed = (V_RED_COEF*v) >> SHIFT;
1240 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1241 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1243 tableY = table + *(Y++);
1244 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1245 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1247 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1249 tableY = table + *(Y++);
1250 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1251 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1253 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1257 uvRed = (V_RED_COEF*v) >> SHIFT;
1258 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1259 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1261 tableY = table + *(Y++);
1262 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1263 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1265 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1267 tableY = table + *(Y++);
1268 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1269 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1271 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1275 uvRed = (V_RED_COEF*v) >> SHIFT;
1276 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1277 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1279 tableY = table + *(Y++);
1280 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1281 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1283 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1285 tableY = table + *(Y++);
1286 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1287 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1289 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1293 uvRed = (V_RED_COEF*v) >> SHIFT;
1294 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1295 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1297 tableY = table + *(Y++);
1298 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1299 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1301 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1303 tableY = table + *(Y++);
1304 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1305 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1307 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1311 uvRed = (V_RED_COEF*v) >> SHIFT;
1312 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1313 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1315 tableY = table + *(Y++);
1316 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1317 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1319 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1321 tableY = table + *(Y++);
1322 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1323 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1325 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1329 uvRed = (V_RED_COEF*v) >> SHIFT;
1330 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1331 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1333 tableY = table + *(Y++);
1334 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1335 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1337 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1339 tableY = table + *(Y++);
1340 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1341 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1343 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1347 uvRed = (V_RED_COEF*v) >> SHIFT;
1348 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1349 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1351 tableY = table + *(Y++);
1352 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1353 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1355 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1357 tableY = table + *(Y++);
1358 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1359 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1361 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1365 uvRed = (V_RED_COEF*v) >> SHIFT;
1366 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1367 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1369 tableY = table + *(Y++);
1370 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1371 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1373 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1375 tableY = table + *(Y++);
1376 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1377 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1379 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1382 i = (width & 15) >> 1;
1386 uvRed = (V_RED_COEF*v) >> SHIFT;
1387 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1388 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1390 tableY = table + *(Y++);
1391 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1392 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1394 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1396 tableY = table + *(Y++);
1397 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1398 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1400 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1406 uvRed = (V_RED_COEF*v) >> SHIFT;
1407 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1408 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1410 tableY = table + *(Y++);
1411 *(dest++) = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1412 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1414 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1418 /* yuv routines with scaling */
1419 /* 4:2:2 i, 16 bpp*/
1421 void yuv422ToRgb16_scaled (unsigned char * Y,
1422 unsigned char * U, unsigned char * V,
1423 short * dest, short table[1935], int width , int dest_width,
1424 int height, int dest_height, int skip, int dest_skip,short * buffer)
1426 int i, i_hcount, i_vcount, j, k;
1435 if ( ( width < dest_width ) && ( height < dest_height ) )
1437 i_vcount = dest_height;
1443 i_hcount = dest_width;
1448 uvRed = (V_RED_COEF*v) >> SHIFT;
1449 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1450 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1452 tableY = table + *(Y++);
1453 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1454 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1455 >>SHIFT) + uvGreen] |
1456 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1457 while ( ( i_hcount -= width ) >= 0 )
1461 i_hcount += dest_width;
1463 tableY = table + *(Y++);
1464 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1465 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1466 >>SHIFT) + uvGreen] |
1467 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1468 while ( ( i_hcount -= width ) >= 0 )
1472 i_hcount += dest_width;
1474 while ( ( i_vcount -= height ) >= 0 )
1476 for (j=0; j<dest_width; j+=16)
1479 dest[j+1]=buffer[j+1];
1480 dest[j+2]=buffer[j+2];
1481 dest[j+3]=buffer[j+3];
1482 dest[j+4]=buffer[j+4];
1483 dest[j+6]=buffer[j+7];
1484 dest[j+8]=buffer[j+9];
1485 dest[j+10]=buffer[j+10];
1486 dest[j+11]=buffer[j+11];
1487 dest[j+12]=buffer[j+12];
1488 dest[j+13]=buffer[j+13];
1489 dest[j+14]=buffer[j+14];
1490 dest[j+15]=buffer[j+15];
1494 i_vcount += dest_height;
1497 else if ( ( width > dest_width ) && ( height < dest_height ) )
1499 i_vcount = dest_height;
1510 uvRed = (V_RED_COEF*v) >> SHIFT;
1511 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1512 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1514 if ( ( i_hcount -= dest_width ) >= 0 )
1518 tableY = table + *(Y++);
1519 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1522 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1524 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1528 if ( ( i_hcount -= dest_width ) >= 0 )
1532 tableY = table + *(Y++);
1533 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1536 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1538 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1543 while ( ( i_vcount -= height ) >= 0 )
1545 for (j=0; j<dest_width; j+=16)
1548 dest[j+1]=buffer[j+1];
1549 dest[j+2]=buffer[j+2];
1550 dest[j+3]=buffer[j+3];
1551 dest[j+4]=buffer[j+4];
1552 dest[j+6]=buffer[j+7];
1553 dest[j+8]=buffer[j+9];
1554 dest[j+10]=buffer[j+10];
1555 dest[j+11]=buffer[j+11];
1556 dest[j+12]=buffer[j+12];
1557 dest[j+13]=buffer[j+13];
1558 dest[j+14]=buffer[j+14];
1559 dest[j+15]=buffer[j+15];
1563 i_vcount += dest_height;
1566 else if ( ( width < dest_width ) && ( height > dest_height ) )
1574 i_hcount = dest_width;
1579 uvRed = (V_RED_COEF*v) >> SHIFT;
1580 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1581 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1583 tableY = table + *(Y++);
1584 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1585 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1586 >>SHIFT) + uvGreen] |
1587 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1588 while ( ( i_hcount -= width ) >= 0 )
1592 i_hcount += dest_width;
1594 tableY = table + *(Y++);
1595 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1596 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1597 >>SHIFT) + uvGreen] |
1598 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1599 while ( ( i_hcount -= width ) >= 0 )
1603 i_hcount += dest_width;
1605 while ( ( i_vcount -= height ) >= 0 )
1611 i_vcount += dest_height;
1614 else if ( ( width > dest_width ) && ( height > dest_height ) )
1616 i_vcount = dest_height;
1627 uvRed = (V_RED_COEF*v) >> SHIFT;
1628 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1629 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1631 if ( ( i_hcount -= dest_width ) >= 0 )
1635 tableY = table + *(Y++);
1636 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1639 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1641 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1645 if ( ( i_hcount -= dest_width ) >= 0 )
1649 tableY = table + *(Y++);
1650 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1653 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1655 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1660 while ( ( i_vcount -= height ) >= 0 )
1666 i_vcount += dest_height;
1671 /* yuv routines with scaling */
1672 /* 4:2:0 i, 16 bpp*/
1674 void yuv420ToRgb16_scaled (unsigned char * Y,
1675 unsigned char * U, unsigned char * V,
1676 short * dest, short table[1935], int width , int dest_width,
1677 int height, int dest_height, int skip, int dest_skip,short * buffer)
1679 int i, i_hcount, i_vcount, j, k;
1688 if ( ( width < dest_width ) && ( height < dest_height ) )
1690 i_vcount = dest_height;
1696 i_hcount = dest_width;
1701 uvRed = (V_RED_COEF*v) >> SHIFT;
1702 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1703 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1705 tableY = table + *(Y++);
1706 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1707 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1708 >>SHIFT) + uvGreen] |
1709 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1710 while ( ( i_hcount -= width ) >= 0 )
1714 i_hcount += dest_width;
1716 tableY = table + *(Y++);
1717 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1718 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1719 >>SHIFT) + uvGreen] |
1720 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1721 while ( ( i_hcount -= width ) >= 0 )
1725 i_hcount += dest_width;
1727 while ( ( i_vcount -= height ) >= 0 )
1729 for (j=0; j<dest_width; j+=16)
1732 dest[j+1]=buffer[j+1];
1733 dest[j+2]=buffer[j+2];
1734 dest[j+3]=buffer[j+3];
1735 dest[j+4]=buffer[j+4];
1736 dest[j+6]=buffer[j+7];
1737 dest[j+8]=buffer[j+9];
1738 dest[j+10]=buffer[j+10];
1739 dest[j+11]=buffer[j+11];
1740 dest[j+12]=buffer[j+12];
1741 dest[j+13]=buffer[j+13];
1742 dest[j+14]=buffer[j+14];
1743 dest[j+15]=buffer[j+15];
1747 i_vcount += dest_height;
1752 i_hcount = dest_width;
1757 uvRed = (V_RED_COEF*v) >> SHIFT;
1758 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1759 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1761 tableY = table + *(Y++);
1762 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1763 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1764 >>SHIFT) + uvGreen] |
1765 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1766 while ( ( i_hcount -= width ) >= 0 )
1770 i_hcount += dest_width;
1772 tableY = table + *(Y++);
1773 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1774 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1775 >>SHIFT) + uvGreen] |
1776 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1777 while ( ( i_hcount -= width ) >= 0 )
1781 i_hcount += dest_width;
1783 while ( ( i_vcount -= height ) >= 0 )
1785 for (j=0; j<dest_width; j+=16)
1788 dest[j+1]=buffer[j+1];
1789 dest[j+2]=buffer[j+2];
1790 dest[j+3]=buffer[j+3];
1791 dest[j+4]=buffer[j+4];
1792 dest[j+6]=buffer[j+7];
1793 dest[j+8]=buffer[j+9];
1794 dest[j+10]=buffer[j+10];
1795 dest[j+11]=buffer[j+11];
1796 dest[j+12]=buffer[j+12];
1797 dest[j+13]=buffer[j+13];
1798 dest[j+14]=buffer[j+14];
1799 dest[j+15]=buffer[j+15];
1803 i_vcount += dest_height;
1806 else if ( ( width > dest_width ) && ( height < dest_height ) )
1808 i_vcount = dest_height;
1819 uvRed = (V_RED_COEF*v) >> SHIFT;
1820 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1821 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1823 if ( ( i_hcount -= dest_width ) >= 0 )
1827 tableY = table + *(Y++);
1828 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1831 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1833 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1837 if ( ( i_hcount -= dest_width ) >= 0 )
1841 tableY = table + *(Y++);
1842 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1845 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1847 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1852 while ( ( i_vcount -= height ) >= 0 )
1854 for (j=0; j<dest_width; j+=16)
1857 dest[j+1]=buffer[j+1];
1858 dest[j+2]=buffer[j+2];
1859 dest[j+3]=buffer[j+3];
1860 dest[j+4]=buffer[j+4];
1861 dest[j+6]=buffer[j+7];
1862 dest[j+8]=buffer[j+9];
1863 dest[j+10]=buffer[j+10];
1864 dest[j+11]=buffer[j+11];
1865 dest[j+12]=buffer[j+12];
1866 dest[j+13]=buffer[j+13];
1867 dest[j+14]=buffer[j+14];
1868 dest[j+15]=buffer[j+15];
1872 i_vcount += dest_height;
1882 uvRed = (V_RED_COEF*v) >> SHIFT;
1883 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1884 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1886 if ( ( i_hcount -= dest_width ) >= 0 )
1890 tableY = table + *(Y++);
1891 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1894 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1896 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1900 if ( ( i_hcount -= dest_width ) >= 0 )
1904 tableY = table + *(Y++);
1905 buffer[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
1908 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
1910 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
1915 while ( ( i_vcount -= height ) >= 0 )
1917 for (j=0; j<dest_width; j+=16)
1920 dest[j+1]=buffer[j+1];
1921 dest[j+2]=buffer[j+2];
1922 dest[j+3]=buffer[j+3];
1923 dest[j+4]=buffer[j+4];
1924 dest[j+6]=buffer[j+7];
1925 dest[j+8]=buffer[j+9];
1926 dest[j+10]=buffer[j+10];
1927 dest[j+11]=buffer[j+11];
1928 dest[j+12]=buffer[j+12];
1929 dest[j+13]=buffer[j+13];
1930 dest[j+14]=buffer[j+14];
1931 dest[j+15]=buffer[j+15];
1935 i_vcount += dest_height;
1938 else if ( ( width < dest_width ) && ( height > dest_height ) )
1946 i_hcount = dest_width;
1951 uvRed = (V_RED_COEF*v) >> SHIFT;
1952 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
1953 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
1955 tableY = table + *(Y++);
1956 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1957 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1958 >>SHIFT) + uvGreen] |
1959 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1960 while ( ( i_hcount -= width ) >= 0 )
1964 i_hcount += dest_width;
1966 tableY = table + *(Y++);
1967 pix = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) + uvRed] |
1968 tableY [135 - (((U_GREEN_COEF+V_GREEN_COEF)*128)
1969 >>SHIFT) + uvGreen] |
1970 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) + uvBlue]);
1971 while ( ( i_hcount -= width ) >= 0 )
1975 i_hcount += dest_width;
1978 while ( ( i_vcount -= height ) >= 0 )
1983 U += skip * ( j >> 1 );
1984 V += skip * ( j >> 1 );
1985 i_vcount += dest_height;
1988 else if ( ( width > dest_width ) && ( height > dest_height ) )
1990 i_vcount = dest_height;
2001 uvRed = (V_RED_COEF*v) >> SHIFT;
2002 uvGreen = (U_GREEN_COEF*u + V_GREEN_COEF*v) >> SHIFT;
2003 uvBlue = (U_BLUE_COEF*u) >> SHIFT;
2005 if ( ( i_hcount -= dest_width ) >= 0 )
2009 tableY = table + *(Y++);
2010 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2013 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2015 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2019 if ( ( i_hcount -= dest_width ) >= 0 )
2023 tableY = table + *(Y++);
2024 dest[j++] = (tableY [1501 - ((V_RED_COEF*128)>>SHIFT) +
2027 (((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) +
2029 tableY [818 - ((U_BLUE_COEF*128)>>SHIFT) +
2035 while ( ( i_vcount -= height ) >= 0 )
2040 U += skip * ( j >> 1 );
2041 V += skip * ( j >> 1 );
2042 i_vcount += dest_height;