39 { 117504, 138453, 13954, 34903 },
40 { 117504, 138453, 13954, 34903 },
41 { 104597, 132201, 25675, 53279 },
42 { 104597, 132201, 25675, 53279 },
43 { 104448, 132798, 24759, 53109 },
44 { 104597, 132201, 25675, 53279 },
45 { 104597, 132201, 25675, 53279 },
46 { 117579, 136230, 16907, 35559 }
51 if (colorspace > 7 || colorspace < 0)
56 #define LOADCHROMA(i) \
59 r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
60 g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
61 b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
63 #define PUTRGB(dst, src, i) \
65 dst[2 * i] = r[Y] + g[Y] + b[Y]; \
67 dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
69 #define PUTRGB24(dst, src, i) \
71 dst[6 * i + 0] = r[Y]; \
72 dst[6 * i + 1] = g[Y]; \
73 dst[6 * i + 2] = b[Y]; \
75 dst[6 * i + 3] = r[Y]; \
76 dst[6 * i + 4] = g[Y]; \
77 dst[6 * i + 5] = b[Y];
79 #define PUTBGR24(dst, src, i) \
81 dst[6 * i + 0] = b[Y]; \
82 dst[6 * i + 1] = g[Y]; \
83 dst[6 * i + 2] = r[Y]; \
85 dst[6 * i + 3] = b[Y]; \
86 dst[6 * i + 4] = g[Y]; \
87 dst[6 * i + 5] = r[Y];
89 #define PUTRGBA(dst, ysrc, asrc, i, s) \
91 dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
92 Y = ysrc[2 * i + 1]; \
93 dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
95 #define PUTRGB48(dst, src, i) \
97 dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
98 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
99 dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
100 Y = src[ 2 * i + 1]; \
101 dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
102 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
103 dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
105 #define PUTBGR48(dst, src, i) \
107 dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
108 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
109 dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
110 Y = src[2 * i + 1]; \
111 dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
112 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
113 dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
115 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
116 static int func_name(SwsContext *c, const uint8_t *src[], \
117 int srcStride[], int srcSliceY, int srcSliceH, \
118 uint8_t *dst[], int dstStride[]) \
122 if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
126 for (y = 0; y < srcSliceH; y += 2) { \
128 (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]); \
130 (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]); \
131 dst_type av_unused *r, *g, *b; \
132 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
133 const uint8_t *py_2 = py_1 + srcStride[0]; \
134 const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
135 const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
136 const uint8_t av_unused *pa_1, *pa_2; \
137 unsigned int h_size = c->dstW >> 3; \
139 pa_1 = src[3] + y * srcStride[3]; \
140 pa_2 = pa_1 + srcStride[3]; \
143 int av_unused U, V, Y; \
145 #define ENDYUV2RGBLINE(dst_delta, ss) \
150 dst_1 += dst_delta >> ss; \
151 dst_2 += dst_delta >> ss; \
153 if (c->dstW & (4 >> ss)) { \
154 int av_unused Y, U, V; \
156 #define ENDYUV2RGBFUNC() \
162 #define CLOSEYUV2RGBFUNC(dst_delta) \
163 ENDYUV2RGBLINE(dst_delta, 0) \
262 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
263 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
266 PUTRGBA(dst_1, py_1, pa_1, 2, 24);
267 PUTRGBA(dst_2, py_2, pa_2, 2, 24);
270 PUTRGBA(dst_2, py_2, pa_2, 3, 24);
271 PUTRGBA(dst_1, py_1, pa_1, 3, 24);
276 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
277 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
280 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
281 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
286 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
287 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
292 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
293 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
296 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
297 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
300 PUTRGBA(dst_1, py_1, pa_1, 2, 0);
301 PUTRGBA(dst_2, py_2, pa_2, 2, 0);
304 PUTRGBA(dst_2, py_2, pa_2, 3, 0);
305 PUTRGBA(dst_1, py_1, pa_1, 3, 0);
310 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
311 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
314 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
315 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
320 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
321 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
385 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
390 #define PUTRGB16(dst, src, i, o) \
392 dst[2 * i] = r[Y + d16[0 + o]] + \
393 g[Y + e16[0 + o]] + \
395 Y = src[2 * i + 1]; \
396 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
397 g[Y + e16[1 + o]] + \
416 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
420 #define PUTRGB15(dst, src, i, o) \
422 dst[2 * i] = r[Y + d16[0 + o]] + \
423 g[Y + d16[1 + o]] + \
425 Y = src[2 * i + 1]; \
426 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
427 g[Y + d16[0 + o]] + \
447 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
450 #define PUTRGB12(dst, src, i, o) \
452 dst[2 * i] = r[Y + d16[0 + o]] + \
453 g[Y + d16[0 + o]] + \
455 Y = src[2 * i + 1]; \
456 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
457 g[Y + d16[1 + o]] + \
478 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
482 #define PUTRGB8(dst, src, i, o) \
484 dst[2 * i] = r[Y + d32[0 + o]] + \
485 g[Y + d32[0 + o]] + \
487 Y = src[2 * i + 1]; \
488 dst[2 * i + 1] = r[Y + d32[1 + o]] + \
489 g[Y + d32[1 + o]] + \
494 PUTRGB8(dst_2, py_2, 0, 0 + 8);
497 PUTRGB8(dst_2, py_2, 1, 2 + 8);
502 PUTRGB8(dst_2, py_2, 2, 4 + 8);
505 PUTRGB8(dst_2, py_2, 3, 6 + 8);
509 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
514 #define PUTRGB4D(dst, src, i, o) \
516 acc = r[Y + d128[0 + o]] + \
517 g[Y + d64[0 + o]] + \
518 b[Y + d128[0 + o]]; \
519 Y = src[2 * i + 1]; \
520 acc |= (r[Y + d128[1 + o]] + \
521 g[Y + d64[1 + o]] + \
522 b[Y + d128[1 + o]]) << 4; \
542 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
546 #define PUTRGB4DB(dst, src, i, o) \
548 dst[2 * i] = r[Y + d128[0 + o]] + \
549 g[Y + d64[0 + o]] + \
550 b[Y + d128[0 + o]]; \
551 Y = src[2 * i + 1]; \
552 dst[2 * i + 1] = r[Y + d128[1 + o]] + \
553 g[Y + d64[1 + o]] + \
573 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
578 #define PUTRGB1(out, src, i, o) \
580 out += out + g[Y + d128[0 + o]]; \
581 Y = src[2 * i + 1]; \
582 out += out + g[Y + d128[1 + o]];
585 PUTRGB1(out_2, py_2, 0, 0 + 8);
587 PUTRGB1(out_2, py_2, 1, 2 + 8);
591 PUTRGB1(out_2, py_2, 2, 4 + 8);
593 PUTRGB1(out_2, py_2, 3, 6 + 8);
617 "No accelerated colorspace conversion found from %s to %s.\n",
620 switch (c->dstFormat) {
623 return yuv2rgb_c_bgr48;
629 if (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat))
633 return (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
635 return yuv2rgb_c_24_rgb;
637 return yuv2rgb_c_24_bgr;
640 return yuv2rgb_c_16_ordered_dither;
643 return yuv2rgb_c_15_ordered_dither;
646 return yuv2rgb_c_12_ordered_dither;
649 return yuv2rgb_c_8_ordered_dither;
652 return yuv2rgb_c_4_ordered_dither;
655 return yuv2rgb_c_4b_ordered_dither;
657 return yuv2rgb_c_1_ordered_dither;
662 static void fill_table(uint8_t*
table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
663 const int64_t inc,
void *y_tab)
666 uint8_t *y_table = y_tab;
668 y_table -= elemsize * (inc >> 9);
671 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
672 table[i] = y_table + elemsize * (cb >> 16);
676 static void fill_gv_table(
int table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
const int64_t inc)
679 int off = -(inc >> 9);
682 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
683 table[i] = elemsize * (off + (cb >> 16));
689 int r = (f + (1 << 15)) >> 16;
726 int i, base, rbase, gbase, bbase,
av_uninit(abase), needAlpha;
727 const int yoffs = fullRange ? 384 : 326;
729 int64_t crv = inv_table[0];
730 int64_t cbu = inv_table[1];
731 int64_t cgu = -inv_table[2];
732 int64_t cgv = -inv_table[3];
733 int64_t cy = 1 << 16;
738 cy = (cy * 255) / 219;
741 crv = (crv * 224) / 255;
742 cbu = (cbu * 224) / 255;
743 cgu = (cgu * 224) / 255;
744 cgv = (cgv * 224) / 255;
754 c->
uOffset = 0x0400040004000400LL;
755 c->
vOffset = 0x0400040004000400LL;
771 crv = ((crv << 16) + 0x8000) /
FFMAX(cy, 1);
772 cbu = ((cbu << 16) + 0x8000) /
FFMAX(cy, 1);
773 cgu = ((cgu << 16) + 0x8000) /
FFMAX(cy, 1);
774 cgv = ((cgv << 16) + 0x8000) /
FFMAX(cy, 1);
782 yb = -(384 << 16) - oy;
783 for (i = 0; i < 1024 - 110; i++) {
784 y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
792 rbase = isRgb ? 3 : 0;
794 bbase = isRgb ? 0 : 3;
797 yb = -(384 << 16) - oy;
798 for (i = 0; i < 1024 - 110; i++) {
799 int yval = av_clip_uint8((yb + 0x8000) >> 16);
800 y_table[i + 110] = (yval >> 7) << rbase;
801 y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
802 y_table[i + 110 + 2048] = (yval >> 7) << bbase;
811 rbase = isRgb ? 5 : 0;
812 gbase = isRgb ? 2 : 3;
813 bbase = isRgb ? 0 : 6;
816 yb = -(384 << 16) - oy;
817 for (i = 0; i < 1024 - 38; i++) {
818 int yval = av_clip_uint8((yb + 0x8000) >> 16);
819 y_table[i + 16] = ((yval + 18) / 36) << rbase;
820 y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
821 y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
830 rbase = isRgb ? 8 : 0;
832 bbase = isRgb ? 0 : 8;
835 yb = -(384 << 16) - oy;
836 for (i = 0; i < 1024; i++) {
837 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
838 y_table16[i] = (yval >> 4) << rbase;
839 y_table16[i + 1024] = (yval >> 4) << gbase;
840 y_table16[i + 2048] = (yval >> 4) << bbase;
844 for (i = 0; i < 1024 * 3; i++)
853 rbase = isRgb ? bpp - 5 : 0;
855 bbase = isRgb ? 0 : (bpp - 5);
858 yb = -(384 << 16) - oy;
859 for (i = 0; i < 1024; i++) {
860 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
861 y_table16[i] = (yval >> 3) << rbase;
862 y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
863 y_table16[i + 2048] = (yval >> 3) << bbase;
867 for (i = 0; i < 1024 * 3; i++)
878 yb = -(384 << 16) - oy;
879 for (i = 0; i < 1024; i++) {
880 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
892 rbase = base + (isRgb ? 16 : 0);
894 bbase = base + (isRgb ? 0 : 16);
897 abase = (base + 24) & 31;
900 yb = -(384 << 16) - oy;
901 for (i = 0; i < 1024; i++) {
902 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
903 y_table32[i] = (yval << rbase) +
904 (needAlpha ? 0 : (255
u << abase));
905 y_table32[i + 1024] = yval << gbase;
906 y_table32[i + 2048] = yval << bbase;