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,o) \
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,o,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 YUV2RGBFUNC(func_name, dst_type, alpha) \
84 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
85 int srcSliceH, uint8_t* dst[], int dstStride[]){\
88 if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {\
92 for (y=0; y<srcSliceH; y+=2) {\
93 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
94 dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
95 dst_type av_unused *r, *b;\
97 uint8_t *py_1 = src[0] + y*srcStride[0];\
98 uint8_t *py_2 = py_1 + srcStride[0];\
99 uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
100 uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
101 uint8_t av_unused *pa_1, *pa_2;\
102 unsigned int h_size = c->dstW>>3;\
104 pa_1 = src[3] + y*srcStride[3];\
105 pa_2 = pa_1 + srcStride[3];\
111 #define ENDYUV2RGBLINE(dst_delta)\
120 int av_unused Y, U, V;\
122 #define ENDYUV2RGBFUNC()\
128 #define CLOSEYUV2RGBFUNC(dst_delta)\
129 ENDYUV2RGBLINE(dst_delta)\
132 YUV2RGBFUNC(yuv2rgb_c_32
, uint32_t, 0)
134 PUTRGB(dst_1
,py_1
,0,0);
135 PUTRGB(dst_2
,py_2
,0,1);
138 PUTRGB(dst_2
,py_2
,1,1);
139 PUTRGB(dst_1
,py_1
,1,0);
142 PUTRGB(dst_1
,py_1
,2,0);
143 PUTRGB(dst_2
,py_2
,2,1);
146 PUTRGB(dst_2
,py_2
,3,1);
147 PUTRGB(dst_1
,py_1
,3,0);
150 PUTRGB(dst_1
,py_1
,0,0);
151 PUTRGB(dst_2
,py_2
,0,1);
154 PUTRGB(dst_2
,py_2
,1,1);
155 PUTRGB(dst_1
,py_1
,1,0);
158 YUV2RGBFUNC(yuva2rgba_c
, uint32_t, 1)
160 PUTRGBA(dst_1
,py_1
,pa_1
,0,0,24);
161 PUTRGBA(dst_2
,py_2
,pa_2
,0,1,24);
164 PUTRGBA(dst_2
,py_2
,pa_1
,1,1,24);
165 PUTRGBA(dst_1
,py_1
,pa_2
,1,0,24);
168 PUTRGBA(dst_1
,py_1
,pa_1
,2,0,24);
169 PUTRGBA(dst_2
,py_2
,pa_2
,2,1,24);
172 PUTRGBA(dst_2
,py_2
,pa_1
,3,1,24);
173 PUTRGBA(dst_1
,py_1
,pa_2
,3,0,24);
178 PUTRGBA(dst_1
,py_1
,pa_1
,0,0,24);
179 PUTRGBA(dst_2
,py_2
,pa_2
,0,1,24);
182 PUTRGBA(dst_2
,py_2
,pa_1
,1,1,24);
183 PUTRGBA(dst_1
,py_1
,pa_2
,1,0,24);
186 YUV2RGBFUNC(yuva2argb_c
, uint32_t, 1)
188 PUTRGBA(dst_1
,py_1
,pa_1
,0,0,0);
189 PUTRGBA(dst_2
,py_2
,pa_2
,0,1,0);
192 PUTRGBA(dst_2
,py_2
,pa_2
,1,1,0);
193 PUTRGBA(dst_1
,py_1
,pa_1
,1,0,0);
196 PUTRGBA(dst_1
,py_1
,pa_1
,2,0,0);
197 PUTRGBA(dst_2
,py_2
,pa_2
,2,1,0);
200 PUTRGBA(dst_2
,py_2
,pa_2
,3,1,0);
201 PUTRGBA(dst_1
,py_1
,pa_1
,3,0,0);
206 PUTRGBA(dst_1
,py_1
,pa_1
,0,0,0);
207 PUTRGBA(dst_2
,py_2
,pa_2
,0,1,0);
210 PUTRGBA(dst_2
,py_2
,pa_2
,1,1,0);
211 PUTRGBA(dst_1
,py_1
,pa_1
,1,0,0);
214 YUV2RGBFUNC(yuv2rgb_c_24_rgb
, uint8_t, 0)
216 PUTRGB24(dst_1
,py_1
,0);
217 PUTRGB24(dst_2
,py_2
,0);
220 PUTRGB24(dst_2
,py_2
,1);
221 PUTRGB24(dst_1
,py_1
,1);
224 PUTRGB24(dst_1
,py_1
,2);
225 PUTRGB24(dst_2
,py_2
,2);
228 PUTRGB24(dst_2
,py_2
,3);
229 PUTRGB24(dst_1
,py_1
,3);
232 PUTRGB24(dst_1
,py_1
,0);
233 PUTRGB24(dst_2
,py_2
,0);
236 PUTRGB24(dst_2
,py_2
,1);
237 PUTRGB24(dst_1
,py_1
,1);
240 // only trivial mods from yuv2rgb_c_24_rgb
241 YUV2RGBFUNC(yuv2rgb_c_24_bgr
, uint8_t, 0)
243 PUTBGR24(dst_1
,py_1
,0);
244 PUTBGR24(dst_2
,py_2
,0);
247 PUTBGR24(dst_2
,py_2
,1);
248 PUTBGR24(dst_1
,py_1
,1);
251 PUTBGR24(dst_1
,py_1
,2);
252 PUTBGR24(dst_2
,py_2
,2);
255 PUTBGR24(dst_2
,py_2
,3);
256 PUTBGR24(dst_1
,py_1
,3);
259 PUTBGR24(dst_1
,py_1
,0);
260 PUTBGR24(dst_2
,py_2
,0);
263 PUTBGR24(dst_2
,py_2
,1);
264 PUTBGR24(dst_1
,py_1
,1);
267 // This is exactly the same code as yuv2rgb_c_32 except for the types of
268 // r, g, b, dst_1, dst_2
269 YUV2RGBFUNC(yuv2rgb_c_16
, uint16_t, 0)
271 PUTRGB(dst_1
,py_1
,0,0);
272 PUTRGB(dst_2
,py_2
,0,1);
275 PUTRGB(dst_2
,py_2
,1,1);
276 PUTRGB(dst_1
,py_1
,1,0);
279 PUTRGB(dst_1
,py_1
,2,0);
280 PUTRGB(dst_2
,py_2
,2,1);
283 PUTRGB(dst_2
,py_2
,3,1);
284 PUTRGB(dst_1
,py_1
,3,0);
287 // This is exactly the same code as yuv2rgb_c_32 except for the types of
288 // r, g, b, dst_1, dst_2
289 YUV2RGBFUNC(yuv2rgb_c_8
, uint8_t, 0)
291 PUTRGB(dst_1
,py_1
,0,0);
292 PUTRGB(dst_2
,py_2
,0,1);
295 PUTRGB(dst_2
,py_2
,1,1);
296 PUTRGB(dst_1
,py_1
,1,0);
299 PUTRGB(dst_1
,py_1
,2,0);
300 PUTRGB(dst_2
,py_2
,2,1);
303 PUTRGB(dst_2
,py_2
,3,1);
304 PUTRGB(dst_1
,py_1
,3,0);
307 // r, g, b, dst_1, dst_2
308 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither
, uint8_t, 0)
309 const uint8_t *d32
= dither_8x8_32
[y
&7];
310 const uint8_t *d64
= dither_8x8_73
[y
&7];
311 #define PUTRGB8(dst,src,i,o) \
313 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
315 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
318 PUTRGB8(dst_1
,py_1
,0,0);
319 PUTRGB8(dst_2
,py_2
,0,0+8);
322 PUTRGB8(dst_2
,py_2
,1,2+8);
323 PUTRGB8(dst_1
,py_1
,1,2);
326 PUTRGB8(dst_1
,py_1
,2,4);
327 PUTRGB8(dst_2
,py_2
,2,4+8);
330 PUTRGB8(dst_2
,py_2
,3,6+8);
331 PUTRGB8(dst_1
,py_1
,3,6);
335 // This is exactly the same code as yuv2rgb_c_32 except for the types of
336 // r, g, b, dst_1, dst_2
337 YUV2RGBFUNC(yuv2rgb_c_4
, uint8_t, 0)
339 #define PUTRGB4(dst,src,i) \
341 acc = r[Y] + g[Y] + b[Y]; \
343 acc |= (r[Y] + g[Y] + b[Y])<<4; \
347 PUTRGB4(dst_1
,py_1
,0);
348 PUTRGB4(dst_2
,py_2
,0);
351 PUTRGB4(dst_2
,py_2
,1);
352 PUTRGB4(dst_1
,py_1
,1);
355 PUTRGB4(dst_1
,py_1
,2);
356 PUTRGB4(dst_2
,py_2
,2);
359 PUTRGB4(dst_2
,py_2
,3);
360 PUTRGB4(dst_1
,py_1
,3);
363 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither
, uint8_t, 0)
364 const uint8_t *d64
= dither_8x8_73
[y
&7];
365 const uint8_t *d128
= dither_8x8_220
[y
&7];
368 #define PUTRGB4D(dst,src,i,o) \
370 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
372 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
376 PUTRGB4D(dst_1
,py_1
,0,0);
377 PUTRGB4D(dst_2
,py_2
,0,0+8);
380 PUTRGB4D(dst_2
,py_2
,1,2+8);
381 PUTRGB4D(dst_1
,py_1
,1,2);
384 PUTRGB4D(dst_1
,py_1
,2,4);
385 PUTRGB4D(dst_2
,py_2
,2,4+8);
388 PUTRGB4D(dst_2
,py_2
,3,6+8);
389 PUTRGB4D(dst_1
,py_1
,3,6);
392 // This is exactly the same code as yuv2rgb_c_32 except for the types of
393 // r, g, b, dst_1, dst_2
394 YUV2RGBFUNC(yuv2rgb_c_4b
, uint8_t, 0)
396 PUTRGB(dst_1
,py_1
,0,0);
397 PUTRGB(dst_2
,py_2
,0,1);
400 PUTRGB(dst_2
,py_2
,1,1);
401 PUTRGB(dst_1
,py_1
,1,0);
404 PUTRGB(dst_1
,py_1
,2,0);
405 PUTRGB(dst_2
,py_2
,2,1);
408 PUTRGB(dst_2
,py_2
,3,1);
409 PUTRGB(dst_1
,py_1
,3,0);
412 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither
, uint8_t, 0)
413 const uint8_t *d64
= dither_8x8_73
[y
&7];
414 const uint8_t *d128
= dither_8x8_220
[y
&7];
416 #define PUTRGB4DB(dst,src,i,o) \
418 dst[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
420 dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
423 PUTRGB4DB(dst_1
,py_1
,0,0);
424 PUTRGB4DB(dst_2
,py_2
,0,0+8);
427 PUTRGB4DB(dst_2
,py_2
,1,2+8);
428 PUTRGB4DB(dst_1
,py_1
,1,2);
431 PUTRGB4DB(dst_1
,py_1
,2,4);
432 PUTRGB4DB(dst_2
,py_2
,2,4+8);
435 PUTRGB4DB(dst_2
,py_2
,3,6+8);
436 PUTRGB4DB(dst_1
,py_1
,3,6);
439 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither
, uint8_t, 0)
440 const uint8_t *d128
= dither_8x8_220
[y
&7];
441 char out_1
= 0, out_2
= 0;
442 g
= c
->table_gU
[128] + c
->table_gV
[128];
444 #define PUTRGB1(out,src,i,o) \
446 out+= out + g[Y+d128[0+o]]; \
448 out+= out + g[Y+d128[1+o]];
450 PUTRGB1(out_1
,py_1
,0,0);
451 PUTRGB1(out_2
,py_2
,0,0+8);
453 PUTRGB1(out_2
,py_2
,1,2+8);
454 PUTRGB1(out_1
,py_1
,1,2);
456 PUTRGB1(out_1
,py_1
,2,4);
457 PUTRGB1(out_2
,py_2
,2,4+8);
459 PUTRGB1(out_2
,py_2
,3,6+8);
460 PUTRGB1(out_1
,py_1
,3,6);
466 SwsFunc
ff_yuv2rgb_get_func_ptr(SwsContext
*c
)
469 #if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL
470 t
= ff_yuv2rgb_init_mmx(c
);
473 t
= ff_yuv2rgb_init_vis(c
);
476 t
= ff_yuv2rgb_init_mlib(c
);
478 #if HAVE_ALTIVEC && CONFIG_GPL
479 if (c
->flags
& SWS_CPU_CAPS_ALTIVEC
)
480 t
= ff_yuv2rgb_init_altivec(c
);
484 if (c
->flags
& SWS_CPU_CAPS_BFIN
)
485 t
= ff_yuv2rgb_get_func_ptr_bfin(c
);
491 av_log(c
, AV_LOG_WARNING
, "No accelerated colorspace conversion found.\n");
493 switch (c
->dstFormat
) {
495 case PIX_FMT_ABGR
: if (CONFIG_SWSCALE_ALPHA
&& c
->srcFormat
== PIX_FMT_YUVA420P
) return yuva2argb_c
;
497 case PIX_FMT_BGRA
: return (CONFIG_SWSCALE_ALPHA
&& c
->srcFormat
== PIX_FMT_YUVA420P
) ? yuva2rgba_c
: yuv2rgb_c_32
;
498 case PIX_FMT_RGB24
: return yuv2rgb_c_24_rgb
;
499 case PIX_FMT_BGR24
: return yuv2rgb_c_24_bgr
;
503 case PIX_FMT_BGR555
: return yuv2rgb_c_16
;
505 case PIX_FMT_BGR8
: return yuv2rgb_c_8_ordered_dither
;
507 case PIX_FMT_BGR4
: return yuv2rgb_c_4_ordered_dither
;
508 case PIX_FMT_RGB4_BYTE
:
509 case PIX_FMT_BGR4_BYTE
: return yuv2rgb_c_4b_ordered_dither
;
510 case PIX_FMT_MONOBLACK
: return yuv2rgb_c_1_ordered_dither
;
517 static void fill_table(uint8_t* table
[256], const int elemsize
, const int inc
, uint8_t *y_table
)
522 y_table
-= elemsize
* (inc
>> 9);
524 for (i
= 0; i
< 256; i
++) {
525 table
[i
] = y_table
+ elemsize
* (cb
>> 16);
530 static void fill_gv_table(int table
[256], const int elemsize
, const int inc
)
534 int off
= -(inc
>> 9);
536 for (i
= 0; i
< 256; i
++) {
537 table
[i
] = elemsize
* (off
+ (cb
>> 16));
542 av_cold
int ff_yuv2rgb_c_init_tables(SwsContext
*c
, const int inv_table
[4], int fullRange
,
543 int brightness
, int contrast
, int saturation
)
545 const int isRgb
= c
->dstFormat
==PIX_FMT_RGB32
546 || c
->dstFormat
==PIX_FMT_RGB32_1
547 || c
->dstFormat
==PIX_FMT_BGR24
548 || c
->dstFormat
==PIX_FMT_RGB565
549 || c
->dstFormat
==PIX_FMT_RGB555
550 || c
->dstFormat
==PIX_FMT_RGB8
551 || c
->dstFormat
==PIX_FMT_RGB4
552 || c
->dstFormat
==PIX_FMT_RGB4_BYTE
553 || c
->dstFormat
==PIX_FMT_MONOBLACK
;
554 const int bpp
= fmt_depth(c
->dstFormat
);
558 int i
, base
, rbase
, gbase
, bbase
, abase
, needAlpha
;
559 const int yoffs
= fullRange
? 384 : 326;
561 int64_t crv
= inv_table
[0];
562 int64_t cbu
= inv_table
[1];
563 int64_t cgu
= -inv_table
[2];
564 int64_t cgv
= -inv_table
[3];
574 crv
= (crv
*224) / 255;
575 cbu
= (cbu
*224) / 255;
576 cgu
= (cgu
*224) / 255;
577 cgv
= (cgv
*224) / 255;
580 cy
= (cy
*contrast
) >> 16;
581 crv
= (crv
*contrast
* saturation
) >> 32;
582 cbu
= (cbu
*contrast
* saturation
) >> 32;
583 cgu
= (cgu
*contrast
* saturation
) >> 32;
584 cgv
= (cgv
*contrast
* saturation
) >> 32;
585 oy
-= 256*brightness
;
587 //scale coefficients by cy
588 crv
= ((crv
<< 16) + 0x8000) / cy
;
589 cbu
= ((cbu
<< 16) + 0x8000) / cy
;
590 cgu
= ((cgu
<< 16) + 0x8000) / cy
;
591 cgv
= ((cgv
<< 16) + 0x8000) / cy
;
593 av_free(c
->yuvTable
);
597 c
->yuvTable
= av_malloc(1024);
598 y_table
= c
->yuvTable
;
599 yb
= -(384<<16) - oy
;
600 for (i
= 0; i
< 1024-110; i
++) {
601 y_table
[i
+110] = av_clip_uint8((yb
+ 0x8000) >> 16) >> 7;
604 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
);
605 fill_gv_table(c
->table_gV
, 1, cgv
);
609 rbase
= isRgb
? 3 : 0;
611 bbase
= isRgb
? 0 : 3;
612 c
->yuvTable
= av_malloc(1024*3);
613 y_table
= c
->yuvTable
;
614 yb
= -(384<<16) - oy
;
615 for (i
= 0; i
< 1024-110; i
++) {
616 int yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
617 y_table
[i
+110 ] = (yval
>> 7) << rbase
;
618 y_table
[i
+ 37+1024] = ((yval
+ 43) / 85) << gbase
;
619 y_table
[i
+110+2048] = (yval
>> 7) << bbase
;
622 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
623 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
+ 1024);
624 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
+ 2048);
625 fill_gv_table(c
->table_gV
, 1, cgv
);
628 rbase
= isRgb
? 5 : 0;
629 gbase
= isRgb
? 2 : 3;
630 bbase
= isRgb
? 0 : 6;
631 c
->yuvTable
= av_malloc(1024*3);
632 y_table
= c
->yuvTable
;
633 yb
= -(384<<16) - oy
;
634 for (i
= 0; i
< 1024-38; i
++) {
635 int yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
636 y_table
[i
+16 ] = ((yval
+ 18) / 36) << rbase
;
637 y_table
[i
+16+1024] = ((yval
+ 18) / 36) << gbase
;
638 y_table
[i
+37+2048] = ((yval
+ 43) / 85) << bbase
;
641 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
642 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
+ 1024);
643 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
+ 2048);
644 fill_gv_table(c
->table_gV
, 1, cgv
);
648 rbase
= isRgb
? bpp
- 5 : 0;
650 bbase
= isRgb
? 0 : (bpp
- 5);
651 c
->yuvTable
= av_malloc(1024*3*2);
652 y_table16
= c
->yuvTable
;
653 yb
= -(384<<16) - oy
;
654 for (i
= 0; i
< 1024; i
++) {
655 uint8_t yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
656 y_table16
[i
] = (yval
>> 3) << rbase
;
657 y_table16
[i
+1024] = (yval
>> (18 - bpp
)) << gbase
;
658 y_table16
[i
+2048] = (yval
>> 3) << bbase
;
661 fill_table(c
->table_rV
, 2, crv
, y_table16
+ yoffs
);
662 fill_table(c
->table_gU
, 2, cgu
, y_table16
+ yoffs
+ 1024);
663 fill_table(c
->table_bU
, 2, cbu
, y_table16
+ yoffs
+ 2048);
664 fill_gv_table(c
->table_gV
, 2, cgv
);
667 c
->yuvTable
= av_malloc(1024);
668 y_table
= c
->yuvTable
;
669 yb
= -(384<<16) - oy
;
670 for (i
= 0; i
< 1024; i
++) {
671 y_table
[i
] = av_clip_uint8((yb
+ 0x8000) >> 16);
674 fill_table(c
->table_rV
, 1, crv
, y_table
+ yoffs
);
675 fill_table(c
->table_gU
, 1, cgu
, y_table
+ yoffs
);
676 fill_table(c
->table_bU
, 1, cbu
, y_table
+ yoffs
);
677 fill_gv_table(c
->table_gV
, 1, cgv
);
680 base
= (c
->dstFormat
== PIX_FMT_RGB32_1
|| c
->dstFormat
== PIX_FMT_BGR32_1
) ? 8 : 0;
681 rbase
= base
+ (isRgb
? 16 : 0);
683 bbase
= base
+ (isRgb
? 0 : 16);
684 needAlpha
= CONFIG_SWSCALE_ALPHA
&& isALPHA(c
->srcFormat
);
686 abase
= (base
+ 24) & 31;
687 c
->yuvTable
= av_malloc(1024*3*4);
688 y_table32
= c
->yuvTable
;
689 yb
= -(384<<16) - oy
;
690 for (i
= 0; i
< 1024; i
++) {
691 uint8_t yval
= av_clip_uint8((yb
+ 0x8000) >> 16);
692 y_table32
[i
] = (yval
<< rbase
) + (needAlpha
? 0 : (255 << abase
));
693 y_table32
[i
+1024] = yval
<< gbase
;
694 y_table32
[i
+2048] = yval
<< bbase
;
697 fill_table(c
->table_rV
, 4, crv
, y_table32
+ yoffs
);
698 fill_table(c
->table_gU
, 4, cgu
, y_table32
+ yoffs
+ 1024);
699 fill_table(c
->table_bU
, 4, cbu
, y_table32
+ yoffs
+ 2048);
700 fill_gv_table(c
->table_gV
, 4, cgv
);
704 av_log(c
, AV_LOG_ERROR
, "%ibpp not supported by yuv2rgb\n", bpp
);