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);
613 "No accelerated colorspace conversion found from %s to %s.\n",
616 switch (c->dstFormat) {
619 return yuv2rgb_c_bgr48;
625 if (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat))
629 return (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
631 return yuv2rgb_c_24_rgb;
633 return yuv2rgb_c_24_bgr;
636 return yuv2rgb_c_16_ordered_dither;
639 return yuv2rgb_c_15_ordered_dither;
642 return yuv2rgb_c_12_ordered_dither;
645 return yuv2rgb_c_8_ordered_dither;
648 return yuv2rgb_c_4_ordered_dither;
651 return yuv2rgb_c_4b_ordered_dither;
653 return yuv2rgb_c_1_ordered_dither;
658 static void fill_table(uint8_t*
table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
659 const int64_t inc,
void *y_tab)
662 uint8_t *y_table = y_tab;
664 y_table -= elemsize * (inc >> 9);
667 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
668 table[i] = y_table + elemsize * (cb >> 16);
672 static void fill_gv_table(
int table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
const int64_t inc)
675 int off = -(inc >> 9);
678 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
679 table[i] = elemsize * (off + (cb >> 16));
685 int r = (f + (1 << 15)) >> 16;
722 int i, base, rbase, gbase, bbase,
av_uninit(abase), needAlpha;
723 const int yoffs = fullRange ? 384 : 326;
725 int64_t crv = inv_table[0];
726 int64_t cbu = inv_table[1];
727 int64_t cgu = -inv_table[2];
728 int64_t cgv = -inv_table[3];
729 int64_t cy = 1 << 16;
734 cy = (cy * 255) / 219;
737 crv = (crv * 224) / 255;
738 cbu = (cbu * 224) / 255;
739 cgu = (cgu * 224) / 255;
740 cgv = (cgv * 224) / 255;
750 c->
uOffset = 0x0400040004000400LL;
751 c->
vOffset = 0x0400040004000400LL;
767 crv = ((crv << 16) + 0x8000) /
FFMAX(cy, 1);
768 cbu = ((cbu << 16) + 0x8000) /
FFMAX(cy, 1);
769 cgu = ((cgu << 16) + 0x8000) /
FFMAX(cy, 1);
770 cgv = ((cgv << 16) + 0x8000) /
FFMAX(cy, 1);
778 yb = -(384 << 16) - oy;
779 for (i = 0; i < 1024 - 110; i++) {
780 y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
788 rbase = isRgb ? 3 : 0;
790 bbase = isRgb ? 0 : 3;
793 yb = -(384 << 16) - oy;
794 for (i = 0; i < 1024 - 110; i++) {
795 int yval = av_clip_uint8((yb + 0x8000) >> 16);
796 y_table[i + 110] = (yval >> 7) << rbase;
797 y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
798 y_table[i + 110 + 2048] = (yval >> 7) << bbase;
807 rbase = isRgb ? 5 : 0;
808 gbase = isRgb ? 2 : 3;
809 bbase = isRgb ? 0 : 6;
812 yb = -(384 << 16) - oy;
813 for (i = 0; i < 1024 - 38; i++) {
814 int yval = av_clip_uint8((yb + 0x8000) >> 16);
815 y_table[i + 16] = ((yval + 18) / 36) << rbase;
816 y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
817 y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
826 rbase = isRgb ? 8 : 0;
828 bbase = isRgb ? 0 : 8;
831 yb = -(384 << 16) - oy;
832 for (i = 0; i < 1024; i++) {
833 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
834 y_table16[i] = (yval >> 4) << rbase;
835 y_table16[i + 1024] = (yval >> 4) << gbase;
836 y_table16[i + 2048] = (yval >> 4) << bbase;
840 for (i = 0; i < 1024 * 3; i++)
849 rbase = isRgb ? bpp - 5 : 0;
851 bbase = isRgb ? 0 : (bpp - 5);
854 yb = -(384 << 16) - oy;
855 for (i = 0; i < 1024; i++) {
856 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
857 y_table16[i] = (yval >> 3) << rbase;
858 y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
859 y_table16[i + 2048] = (yval >> 3) << bbase;
863 for (i = 0; i < 1024 * 3; i++)
874 yb = -(384 << 16) - oy;
875 for (i = 0; i < 1024; i++) {
876 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
888 rbase = base + (isRgb ? 16 : 0);
890 bbase = base + (isRgb ? 0 : 16);
893 abase = (base + 24) & 31;
896 yb = -(384 << 16) - oy;
897 for (i = 0; i < 1024; i++) {
898 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
899 y_table32[i] = (yval << rbase) +
900 (needAlpha ? 0 : (255
u << abase));
901 y_table32[i + 1024] = yval << gbase;
902 y_table32[i + 2048] = yval << bbase;