2 * software YUV to RGB converter
4 * Copyright (C) 2009 Konstantin Shishkov
6 * 1,4,8bpp support and context / deglobalize stuff
7 * by Michael Niedermayer (michaelni@gmx.at)
9 * This file is part of FFmpeg.
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "swscale_internal.h"
35 #include "libavutil/x86_cpu.h"
37 extern const uint8_t dither_8x8_32
[8][8];
38 extern const uint8_t dither_8x8_73
[8][8];
39 extern const uint8_t dither_8x8_220
[8][8];
41 const int32_t ff_yuv2rgb_coeffs
[8][4] = {
42 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
43 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
44 {104597, 132201, 25675, 53279}, /* unspecified */
45 {104597, 132201, 25675, 53279}, /* reserved */
46 {104448, 132798, 24759, 53109}, /* FCC */
47 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
48 {104597, 132201, 25675, 53279}, /* SMPTE 170M */
49 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */
52 #define LOADCHROMA(i) \
55 r = (void *)c->table_rV[V]; \
56 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
57 b = (void *)c->table_bU[U];
59 #define PUTRGB(dst,src,i) \
61 dst[2*i ] = r[Y] + g[Y] + b[Y]; \
63 dst[2*i+1] = r[Y] + g[Y] + b[Y];
65 #define PUTRGB24(dst,src,i) \
67 dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \
69 dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y];
71 #define PUTBGR24(dst,src,i) \
73 dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
75 dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
77 #define PUTRGBA(dst,ysrc,asrc,i,s) \
79 dst[2*i ] = r[Y] + g[Y] + b[Y] + (asrc[2*i ]<<s); \
81 dst[2*i+1] = r[Y] + g[Y] + b[Y] + (asrc[2*i+1]<<s);
83 #define PUTRGB48(dst,src,i) \
85 dst[12*i+ 0] = dst[12*i+ 1] = r[Y]; \
86 dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \
87 dst[12*i+ 4] = dst[12*i+ 5] = b[Y]; \
89 dst[12*i+ 6] = dst[12*i+ 7] = r[Y]; \
90 dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \
91 dst[12*i+10] = dst[12*i+11] = b[Y];
93 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
94 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
95 int srcSliceH, uint8_t* dst[], int dstStride[]) \
99 if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
103 for (y=0; y<srcSliceH; y+=2) {\
104 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
105 dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
106 dst_type av_unused *r, *b;\
108 uint8_t *py_1 = src[0] + y*srcStride[0];\
109 uint8_t *py_2 = py_1 + srcStride[0];\
110 uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
111 uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
112 uint8_t av_unused *pa_1, *pa_2;\
113 unsigned int h_size = c->dstW>>3;\
115 pa_1 = src[3] + y*srcStride[3];\
116 pa_2 = pa_1 + srcStride[3];\
122 #define ENDYUV2RGBLINE(dst_delta)\
131 int av_unused Y, U, V;\
133 #define ENDYUV2RGBFUNC()\
139 #define CLOSEYUV2RGBFUNC(dst_delta)\
140 ENDYUV2RGBLINE(dst_delta)\
143 YUV2RGBFUNC(yuv2rgb_c_48
, uint8_t, 0)
145 PUTRGB48(dst_1
,py_1
,0);
146 PUTRGB48(dst_2
,py_2
,0);
149 PUTRGB48(dst_2
,py_2
,1);
150 PUTRGB48(dst_1
,py_1
,1);
153 PUTRGB48(dst_1
,py_1
,2);
154 PUTRGB48(dst_2
,py_2
,2);
157 PUTRGB48(dst_2
,py_2
,3);
158 PUTRGB48(dst_1
,py_1
,3);
161 PUTRGB48(dst_1
,py_1
,0);
162 PUTRGB48(dst_2
,py_2
,0);
165 PUTRGB48(dst_2
,py_2
,1);
166 PUTRGB48(dst_1
,py_1
,1);
169 YUV2RGBFUNC(yuv2rgb_c_32
, uint32_t, 0)
171 PUTRGB(dst_1
,py_1
,0);
172 PUTRGB(dst_2
,py_2
,0);
175 PUTRGB(dst_2
,py_2
,1);
176 PUTRGB(dst_1
,py_1
,1);
179 PUTRGB(dst_1
,py_1
,2);
180 PUTRGB(dst_2
,py_2
,2);
183 PUTRGB(dst_2
,py_2
,3);
184 PUTRGB(dst_1
,py_1
,3);
187 PUTRGB(dst_1
,py_1
,0);
188 PUTRGB(dst_2
,py_2
,0);
191 PUTRGB(dst_2
,py_2
,1);
192 PUTRGB(dst_1
,py_1
,1);
195 YUV2RGBFUNC(yuva2rgba_c
, uint32_t, 1)
197 PUTRGBA(dst_1
,py_1
,pa_1
,0,24);
198 PUTRGBA(dst_2
,py_2
,pa_2
,0,24);
201 PUTRGBA(dst_2
,py_2
,pa_1
,1,24);
202 PUTRGBA(dst_1
,py_1
,pa_2
,1,24);
205 PUTRGBA(dst_1
,py_1
,pa_1
,2,24);
206 PUTRGBA(dst_2
,py_2
,pa_2
,2,24);
209 PUTRGBA(dst_2
,py_2
,pa_1
,3,24);
210 PUTRGBA(dst_1
,py_1
,pa_2
,3,24);
215 PUTRGBA(dst_1
,py_1
,pa_1
,0,24);
216 PUTRGBA(dst_2
,py_2
,pa_2
,0,24);
219 PUTRGBA(dst_2
,py_2
,pa_1
,1,24);
220 PUTRGBA(dst_1
,py_1
,pa_2
,1,24);
223 YUV2RGBFUNC(yuva2argb_c
, uint32_t, 1)
225 PUTRGBA(dst_1
,py_1
,pa_1
,0,0);
226 PUTRGBA(dst_2
,py_2
,pa_2
,0,0);
229 PUTRGBA(dst_2
,py_2
,pa_2
,1,0);
230 PUTRGBA(dst_1
,py_1
,pa_1
,1,0);
233 PUTRGBA(dst_1
,py_1
,pa_1
,2,0);
234 PUTRGBA(dst_2
,py_2
,pa_2
,2,0);
237 PUTRGBA(dst_2
,py_2
,pa_2
,3,0);
238 PUTRGBA(dst_1
,py_1
,pa_1
,3,0);
243 PUTRGBA(dst_1
,py_1
,pa_1
,0,0);
244 PUTRGBA(dst_2
,py_2
,pa_2
,0,0);
247 PUTRGBA(dst_2
,py_2
,pa_2
,1,0);
248 PUTRGBA(dst_1
,py_1
,pa_1
,1,0);
251 YUV2RGBFUNC(yuv2rgb_c_24_rgb
, uint8_t, 0)
253 PUTRGB24(dst_1
,py_1
,0);
254 PUTRGB24(dst_2
,py_2
,0);
257 PUTRGB24(dst_2
,py_2
,1);
258 PUTRGB24(dst_1
,py_1
,1);
261 PUTRGB24(dst_1
,py_1
,2);
262 PUTRGB24(dst_2
,py_2
,2);
265 PUTRGB24(dst_2
,py_2
,3);
266 PUTRGB24(dst_1
,py_1
,3);
269 PUTRGB24(dst_1
,py_1
,0);
270 PUTRGB24(dst_2
,py_2
,0);
273 PUTRGB24(dst_2
,py_2
,1);
274 PUTRGB24(dst_1
,py_1
,1);
277 // only trivial mods from yuv2rgb_c_24_rgb
278 YUV2RGBFUNC(yuv2rgb_c_24_bgr
, uint8_t, 0)
280 PUTBGR24(dst_1
,py_1
,0);
281 PUTBGR24(dst_2
,py_2
,0);
284 PUTBGR24(dst_2
,py_2
,1);
285 PUTBGR24(dst_1
,py_1
,1);
288 PUTBGR24(dst_1
,py_1
,2);
289 PUTBGR24(dst_2
,py_2
,2);
292 PUTBGR24(dst_2
,py_2
,3);
293 PUTBGR24(dst_1
,py_1
,3);
296 PUTBGR24(dst_1
,py_1
,0);
297 PUTBGR24(dst_2
,py_2
,0);
300 PUTBGR24(dst_2
,py_2
,1);
301 PUTBGR24(dst_1
,py_1
,1);
304 // This is exactly the same code as yuv2rgb_c_32 except for the types of
305 // r, g, b, dst_1, dst_2
306 YUV2RGBFUNC(yuv2rgb_c_16
, uint16_t, 0)
308 PUTRGB(dst_1
,py_1
,0);
309 PUTRGB(dst_2
,py_2
,0);
312 PUTRGB(dst_2
,py_2
,1);
313 PUTRGB(dst_1
,py_1
,1);
316 PUTRGB(dst_1
,py_1
,2);
317 PUTRGB(dst_2
,py_2
,2);
320 PUTRGB(dst_2
,py_2
,3);
321 PUTRGB(dst_1
,py_1
,3);
324 // This is exactly the same code as yuv2rgb_c_32 except for the types of
325 // r, g, b, dst_1, dst_2
326 YUV2RGBFUNC(yuv2rgb_c_8
, uint8_t, 0)
328 PUTRGB(dst_1
,py_1
,0);
329 PUTRGB(dst_2
,py_2
,0);
332 PUTRGB(dst_2
,py_2
,1);
333 PUTRGB(dst_1
,py_1
,1);
336 PUTRGB(dst_1
,py_1
,2);
337 PUTRGB(dst_2
,py_2
,2);
340 PUTRGB(dst_2
,py_2
,3);
341 PUTRGB(dst_1
,py_1
,3);
344 // r, g, b, dst_1, dst_2
345 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither
, uint8_t, 0)
346 const uint8_t *d32
= dither_8x8_32
[y
&7];
347 const uint8_t *d64
= dither_8x8_73
[y
&7];
348 #define PUTRGB8(dst,src,i,o) \
350 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
352 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
355 PUTRGB8(dst_1
,py_1
,0,0);
356 PUTRGB8(dst_2
,py_2
,0,0+8);
359 PUTRGB8(dst_2
,py_2
,1,2+8);
360 PUTRGB8(dst_1
,py_1
,1,2);
363 PUTRGB8(dst_1
,py_1
,2,4);
364 PUTRGB8(dst_2
,py_2
,2,4+8);
367 PUTRGB8(dst_2
,py_2
,3,6+8);
368 PUTRGB8(dst_1
,py_1
,3,6);
372 // This is exactly the same code as yuv2rgb_c_32 except for the types of
373 // r, g, b, dst_1, dst_2
374 YUV2RGBFUNC(yuv2rgb_c_4
, uint8_t, 0)
376 #define PUTRGB4(dst,src,i) \
378 acc = r[Y] + g[Y] + b[Y]; \
380 acc |= (r[Y] + g[Y] + b[Y])<<4; \
384 PUTRGB4(dst_1
,py_1
,0);
385 PUTRGB4(dst_2
,py_2
,0);
388 PUTRGB4(dst_2
,py_2
,1);
389 PUTRGB4(dst_1
,py_1
,1);
392 PUTRGB4(dst_1
,py_1
,2);
393 PUTRGB4(dst_2
,py_2
,2);
396 PUTRGB4(dst_2
,py_2
,3);
397 PUTRGB4(dst_1
,py_1
,3);
400 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither
, uint8_t, 0)
401 const uint8_t *d64
= dither_8x8_73
[y
&7];
402 const uint8_t *d128
= dither_8x8_220
[y
&7];
405 #define PUTRGB4D(dst,src,i,o) \
407 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
409 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
413 PUTRGB4D(dst_1
,py_1
,0,0);
414 PUTRGB4D(dst_2
,py_2
,0,0+8);
417 PUTRGB4D(dst_2
,py_2
,1,2+8);
418 PUTRGB4D(dst_1
,py_1
,1,2);
421 PUTRGB4D(dst_1
,py_1
,2,4);
422 PUTRGB4D(dst_2
,py_2
,2,4+8);
425 PUTRGB4D(dst_2
,py_2
,3,6+8);
426 PUTRGB4D(dst_1
,py_1
,3,6);
429 // This is exactly the same code as yuv2rgb_c_32 except for the types of
430 // r, g, b, dst_1, dst_2
431 YUV2RGBFUNC(yuv2rgb_c_4b
, uint8_t, 0)
433 PUTRGB(dst_1
,py_1
,0);
434 PUTRGB(dst_2
,py_2
,0);
437 PUTRGB(dst_2
,py_2
,1);
438 PUTRGB(dst_1
,py_1
,1);
441 PUTRGB(dst_1
,py_1
,2);
442 PUTRGB(dst_2
,py_2
,2);
445 PUTRGB(dst_2
,py_2
,3);
446 PUTRGB(dst_1
,py_1
,3);
449 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither
, uint8_t, 0)
450 const uint8_t *d64
= dither_8x8_73
[y
&7];
451 const uint8_t *d128
= dither_8x8_220
[y
&7];
453 #define PUTRGB4DB(dst,src,i,o) \
455 dst[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
457 dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
460 PUTRGB4DB(dst_1
,py_1
,0,0);
461 PUTRGB4DB(dst_2
,py_2
,0,0+8);
464 PUTRGB4DB(dst_2
,py_2
,1,2+8);
465 PUTRGB4DB(dst_1
,py_1
,1,2);
468 PUTRGB4DB(dst_1
,py_1
,2,4);
469 PUTRGB4DB(dst_2
,py_2
,2,4+8);
472 PUTRGB4DB(dst_2
,py_2
,3,6+8);
473 PUTRGB4DB(dst_1
,py_1
,3,6);
476 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither
, uint8_t, 0)
477 const uint8_t *d128
= dither_8x8_220
[y
&7];
478 char out_1
= 0, out_2
= 0;
479 g
= c
->table_gU
[128] + c
->table_gV
[128];
481 #define PUTRGB1(out,src,i,o) \
483 out+= out + g[Y+d128[0+o]]; \
485 out+= out + g[Y+d128[1+o]];
487 PUTRGB1(out_1
,py_1
,0,0);
488 PUTRGB1(out_2
,py_2
,0,0+8);
490 PUTRGB1(out_2
,py_2
,1,2+8);
491 PUTRGB1(out_1
,py_1
,1,2);
493 PUTRGB1(out_1
,py_1
,2,4);
494 PUTRGB1(out_2
,py_2
,2,4+8);
496 PUTRGB1(out_2
,py_2
,3,6+8);
497 PUTRGB1(out_1
,py_1
,3,6);
503 SwsFunc
ff_yuv2rgb_get_func_ptr(SwsContext
*c
)
506 #if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL
507 t
= ff_yuv2rgb_init_mmx(c
);
510 t
= ff_yuv2rgb_init_vis(c
);
513 t
= ff_yuv2rgb_init_mlib(c
);
516 if (c
->flags
& SWS_CPU_CAPS_ALTIVEC
)
517 t
= ff_yuv2rgb_init_altivec(c
);
521 if (c
->flags
& SWS_CPU_CAPS_BFIN
)
522 t
= ff_yuv2rgb_get_func_ptr_bfin(c
);
528 av_log(c
, AV_LOG_WARNING
, "No accelerated colorspace conversion found.\n");
530 switch (c
->dstFormat
) {
531 case PIX_FMT_RGB48BE
:
532 case PIX_FMT_RGB48LE
: return yuv2rgb_c_48
;
534 case PIX_FMT_ABGR
: if (CONFIG_SWSCALE_ALPHA
&& c
->srcFormat
== PIX_FMT_YUVA420P
) return yuva2argb_c
;
536 case PIX_FMT_BGRA
: return (CONFIG_SWSCALE_ALPHA
&& c
->srcFormat
== PIX_FMT_YUVA420P
) ? yuva2rgba_c
: yuv2rgb_c_32
;
537 case PIX_FMT_RGB24
: return yuv2rgb_c_24_rgb
;
538 case PIX_FMT_BGR24
: return yuv2rgb_c_24_bgr
;
542 case PIX_FMT_BGR555
: return yuv2rgb_c_16
;
544 case PIX_FMT_BGR8
: return yuv2rgb_c_8_ordered_dither
;
546 case PIX_FMT_BGR4
: return yuv2rgb_c_4_ordered_dither
;
547 case PIX_FMT_RGB4_BYTE
:
548 case PIX_FMT_BGR4_BYTE
: return yuv2rgb_c_4b_ordered_dither
;
549 case PIX_FMT_MONOBLACK
: return yuv2rgb_c_1_ordered_dither
;
556 static void fill_table(uint8_t* table
[256], const int elemsize
, const int inc
, uint8_t *y_table
)
561 y_table
-= elemsize
* (inc
>> 9);
563 for (i
= 0; i
< 256; i
++) {
564 table
[i
] = y_table
+ elemsize
* (cb
>> 16);
569 static void fill_gv_table(int table
[256], const int elemsize
, const int inc
)
573 int off
= -(inc
>> 9);
575 for (i
= 0; i
< 256; i
++) {
576 table
[i
] = elemsize
* (off
+ (cb
>> 16));
581 av_cold
int ff_yuv2rgb_c_init_tables(SwsContext
*c
, const int inv_table
[4], int fullRange
,
582 int brightness
, int contrast
, int saturation
)
584 const int isRgb
= c
->dstFormat
==PIX_FMT_RGB32
585 || c
->dstFormat
==PIX_FMT_RGB32_1
586 || c
->dstFormat
==PIX_FMT_BGR24
587 || c
->dstFormat
==PIX_FMT_RGB565
588 || c
->dstFormat
==PIX_FMT_RGB555
589 || c
->dstFormat
==PIX_FMT_RGB8
590 || c
->dstFormat
==PIX_FMT_RGB4
591 || c
->dstFormat
==PIX_FMT_RGB4_BYTE
592 || c
->dstFormat
==PIX_FMT_MONOBLACK
;
593 const int bpp
= fmt_depth(c
->dstFormat
);
597 int i
, base
, rbase
, gbase
, bbase
, abase
, needAlpha
;
598 const int yoffs
= fullRange
? 384 : 326;
600 int64_t crv
= inv_table
[0];
601 int64_t cbu
= inv_table
[1];
602 int64_t cgu
= -inv_table
[2];
603 int64_t cgv
= -inv_table
[3];
613 crv
= (crv
*224) / 255;
614 cbu
= (cbu
*224) / 255;
615 cgu
= (cgu
*224) / 255;
616 cgv
= (cgv
*224) / 255;
619 cy
= (cy
*contrast
) >> 16;
620 crv
= (crv
*contrast
* saturation
) >> 32;
621 cbu
= (cbu
*contrast
* saturation
) >> 32;
622 cgu
= (cgu
*contrast
* saturation
) >> 32;
623 cgv
= (cgv
*contrast
* saturation
) >> 32;
624 oy
-= 256*brightness
;
626 //scale coefficients by cy
627 crv
= ((crv
<< 16) + 0x8000) / cy
;
628 cbu
= ((cbu
<< 16) + 0x8000) / cy
;
629 cgu
= ((cgu
<< 16) + 0x8000) / cy
;
630 cgv
= ((cgv
<< 16) + 0x8000) / cy
;
632 av_free(c
->yuvTable
);
636 c
->yuvTable
= av_malloc(1024);
637 y_table
= c
->yuvTable
;
638 yb
= -(384<<16) - oy
;
639 for (i
= 0; i
< 1024-110; i
++) {
640 y_table
[i
+110] = av_clip_uint8((yb
+ 0x8000) >> 16) >> 7;
643 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
);
644 fill_gv_table(c
->table_gV
, 1, cgv
);
648 rbase
= isRgb
? 3 : 0;
650 bbase
= isRgb
? 0 : 3;
651 c
->yuvTable
= av_malloc(1024*3);
652 y_table
= c
->yuvTable
;
653 yb
= -(384<<16) - oy
;
654 for (i
= 0; i
< 1024-110; i
++) {
655 int yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
656 y_table
[i
+110 ] = (yval
>> 7) << rbase
;
657 y_table
[i
+ 37+1024] = ((yval
+ 43) / 85) << gbase
;
658 y_table
[i
+110+2048] = (yval
>> 7) << bbase
;
661 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
662 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
+ 1024);
663 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
+ 2048);
664 fill_gv_table(c
->table_gV
, 1, cgv
);
667 rbase
= isRgb
? 5 : 0;
668 gbase
= isRgb
? 2 : 3;
669 bbase
= isRgb
? 0 : 6;
670 c
->yuvTable
= av_malloc(1024*3);
671 y_table
= c
->yuvTable
;
672 yb
= -(384<<16) - oy
;
673 for (i
= 0; i
< 1024-38; i
++) {
674 int yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
675 y_table
[i
+16 ] = ((yval
+ 18) / 36) << rbase
;
676 y_table
[i
+16+1024] = ((yval
+ 18) / 36) << gbase
;
677 y_table
[i
+37+2048] = ((yval
+ 43) / 85) << bbase
;
680 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
681 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
+ 1024);
682 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
+ 2048);
683 fill_gv_table(c
->table_gV
, 1, cgv
);
687 rbase
= isRgb
? bpp
- 5 : 0;
689 bbase
= isRgb
? 0 : (bpp
- 5);
690 c
->yuvTable
= av_malloc(1024*3*2);
691 y_table16
= c
->yuvTable
;
692 yb
= -(384<<16) - oy
;
693 for (i
= 0; i
< 1024; i
++) {
694 uint8_t yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
695 y_table16
[i
] = (yval
>> 3) << rbase
;
696 y_table16
[i
+1024] = (yval
>> (18 - bpp
)) << gbase
;
697 y_table16
[i
+2048] = (yval
>> 3) << bbase
;
700 fill_table(c
->table_rV
, 2, crv
, y_table16
+ yoffs
);
701 fill_table(c
->table_gU
, 2, cgu
, y_table16
+ yoffs
+ 1024);
702 fill_table(c
->table_bU
, 2, cbu
, y_table16
+ yoffs
+ 2048);
703 fill_gv_table(c
->table_gV
, 2, cgv
);
707 c
->yuvTable
= av_malloc(1024);
708 y_table
= c
->yuvTable
;
709 yb
= -(384<<16) - oy
;
710 for (i
= 0; i
< 1024; i
++) {
711 y_table
[i
] = av_clip_uint8((yb
+ 0x8000) >> 16);
714 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
715 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
);
716 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
);
717 fill_gv_table(c
->table_gV
, 1, cgv
);
720 base
= (c
->dstFormat
== PIX_FMT_RGB32_1
|| c
->dstFormat
== PIX_FMT_BGR32_1
) ? 8 : 0;
721 rbase
= base
+ (isRgb
? 16 : 0);
723 bbase
= base
+ (isRgb
? 0 : 16);
724 needAlpha
= CONFIG_SWSCALE_ALPHA
&& isALPHA(c
->srcFormat
);
726 abase
= (base
+ 24) & 31;
727 c
->yuvTable
= av_malloc(1024*3*4);
728 y_table32
= c
->yuvTable
;
729 yb
= -(384<<16) - oy
;
730 for (i
= 0; i
< 1024; i
++) {
731 uint8_t yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
732 y_table32
[i
] = (yval
<< rbase
) + (needAlpha
? 0 : (255 << abase
));
733 y_table32
[i
+1024] = yval
<< gbase
;
734 y_table32
[i
+2048] = yval
<< bbase
;
737 fill_table(c
->table_rV
, 4, crv
, y_table32
+ yoffs
);
738 fill_table(c
->table_gU
, 4, cgu
, y_table32
+ yoffs
+ 1024);
739 fill_table(c
->table_bU
, 4, cbu
, y_table32
+ yoffs
+ 2048);
740 fill_gv_table(c
->table_gV
, 4, cgv
);
744 av_log(c
, AV_LOG_ERROR
, "%ibpp not supported by yuv2rgb\n", bpp
);