46 { 117504, 138453, 13954, 34903 },
47 { 117504, 138453, 13954, 34903 },
48 { 104597, 132201, 25675, 53279 },
49 { 104597, 132201, 25675, 53279 },
50 { 104448, 132798, 24759, 53109 },
51 { 104597, 132201, 25675, 53279 },
52 { 104597, 132201, 25675, 53279 },
53 { 117579, 136230, 16907, 35559 }
58 if (colorspace > 7 || colorspace < 0)
63 #define LOADCHROMA(i) \
66 r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
67 g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
68 b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
70 #define PUTRGB(dst, src, i) \
72 dst[2 * i] = r[Y] + g[Y] + b[Y]; \
74 dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
76 #define PUTRGB24(dst, src, i) \
78 dst[6 * i + 0] = r[Y]; \
79 dst[6 * i + 1] = g[Y]; \
80 dst[6 * i + 2] = b[Y]; \
82 dst[6 * i + 3] = r[Y]; \
83 dst[6 * i + 4] = g[Y]; \
84 dst[6 * i + 5] = b[Y];
86 #define PUTBGR24(dst, src, i) \
88 dst[6 * i + 0] = b[Y]; \
89 dst[6 * i + 1] = g[Y]; \
90 dst[6 * i + 2] = r[Y]; \
92 dst[6 * i + 3] = b[Y]; \
93 dst[6 * i + 4] = g[Y]; \
94 dst[6 * i + 5] = r[Y];
96 #define PUTRGBA(dst, ysrc, asrc, i, s) \
98 dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
99 Y = ysrc[2 * i + 1]; \
100 dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
102 #define PUTRGB48(dst, src, i) \
104 dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
105 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
106 dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
107 Y = src[ 2 * i + 1]; \
108 dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
109 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
110 dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
112 #define PUTBGR48(dst, src, i) \
114 dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
115 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
116 dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
117 Y = src[2 * i + 1]; \
118 dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
119 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
120 dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
122 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
123 static int func_name(SwsContext *c, const uint8_t *src[], \
124 int srcStride[], int srcSliceY, int srcSliceH, \
125 uint8_t *dst[], int dstStride[]) \
129 if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
133 for (y = 0; y < srcSliceH; y += 2) { \
135 (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]); \
137 (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]); \
138 dst_type av_unused *r, *g, *b; \
139 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
140 const uint8_t *py_2 = py_1 + srcStride[0]; \
141 const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
142 const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
143 const uint8_t av_unused *pa_1, *pa_2; \
144 unsigned int h_size = c->dstW >> 3; \
146 pa_1 = src[3] + y * srcStride[3]; \
147 pa_2 = pa_1 + srcStride[3]; \
150 int av_unused U, V, Y; \
152 #define ENDYUV2RGBLINE(dst_delta, ss) \
157 dst_1 += dst_delta >> ss; \
158 dst_2 += dst_delta >> ss; \
160 if (c->dstW & (4 >> ss)) { \
161 int av_unused Y, U, V; \
163 #define ENDYUV2RGBFUNC() \
169 #define CLOSEYUV2RGBFUNC(dst_delta) \
170 ENDYUV2RGBLINE(dst_delta, 0) \
269 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
270 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
273 PUTRGBA(dst_1, py_1, pa_1, 2, 24);
274 PUTRGBA(dst_2, py_2, pa_2, 2, 24);
277 PUTRGBA(dst_2, py_2, pa_2, 3, 24);
278 PUTRGBA(dst_1, py_1, pa_1, 3, 24);
283 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
284 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
287 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
288 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
293 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
294 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
299 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
300 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
303 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
304 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
307 PUTRGBA(dst_1, py_1, pa_1, 2, 0);
308 PUTRGBA(dst_2, py_2, pa_2, 2, 0);
311 PUTRGBA(dst_2, py_2, pa_2, 3, 0);
312 PUTRGBA(dst_1, py_1, pa_1, 3, 0);
317 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
318 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
321 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
322 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
327 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
328 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
392 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
397 #define PUTRGB16(dst, src, i, o) \
399 dst[2 * i] = r[Y + d16[0 + o]] + \
400 g[Y + e16[0 + o]] + \
402 Y = src[2 * i + 1]; \
403 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
404 g[Y + e16[1 + o]] + \
423 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
427 #define PUTRGB15(dst, src, i, o) \
429 dst[2 * i] = r[Y + d16[0 + o]] + \
430 g[Y + d16[1 + o]] + \
432 Y = src[2 * i + 1]; \
433 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
434 g[Y + d16[0 + o]] + \
454 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
457 #define PUTRGB12(dst, src, i, o) \
459 dst[2 * i] = r[Y + d16[0 + o]] + \
460 g[Y + d16[0 + o]] + \
462 Y = src[2 * i + 1]; \
463 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
464 g[Y + d16[1 + o]] + \
485 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
489 #define PUTRGB8(dst, src, i, o) \
491 dst[2 * i] = r[Y + d32[0 + o]] + \
492 g[Y + d32[0 + o]] + \
494 Y = src[2 * i + 1]; \
495 dst[2 * i + 1] = r[Y + d32[1 + o]] + \
496 g[Y + d32[1 + o]] + \
501 PUTRGB8(dst_2, py_2, 0, 0 + 8);
504 PUTRGB8(dst_2, py_2, 1, 2 + 8);
509 PUTRGB8(dst_2, py_2, 2, 4 + 8);
512 PUTRGB8(dst_2, py_2, 3, 6 + 8);
516 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
521 #define PUTRGB4D(dst, src, i, o) \
523 acc = r[Y + d128[0 + o]] + \
524 g[Y + d64[0 + o]] + \
525 b[Y + d128[0 + o]]; \
526 Y = src[2 * i + 1]; \
527 acc |= (r[Y + d128[1 + o]] + \
528 g[Y + d64[1 + o]] + \
529 b[Y + d128[1 + o]]) << 4; \
549 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
553 #define PUTRGB4DB(dst, src, i, o) \
555 dst[2 * i] = r[Y + d128[0 + o]] + \
556 g[Y + d64[0 + o]] + \
557 b[Y + d128[0 + o]]; \
558 Y = src[2 * i + 1]; \
559 dst[2 * i + 1] = r[Y + d128[1 + o]] + \
560 g[Y + d64[1 + o]] + \
580 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
585 #define PUTRGB1(out, src, i, o) \
587 out += out + g[Y + d128[0 + o]]; \
588 Y = src[2 * i + 1]; \
589 out += out + g[Y + d128[1 + o]];
592 PUTRGB1(out_2, py_2, 0, 0 + 8);
594 PUTRGB1(out_2, py_2, 1, 2 + 8);
598 PUTRGB1(out_2, py_2, 2, 4 + 8);
600 PUTRGB1(out_2, py_2, 3, 6 + 8);
615 else if (HAVE_ALTIVEC)
624 "No accelerated colorspace conversion found from %s to %s.\n",
627 switch (c->dstFormat) {
630 return yuv2rgb_c_bgr48;
636 if (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat))
640 return (CONFIG_SWSCALE_ALPHA &&
isALPHA(c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
642 return yuv2rgb_c_24_rgb;
644 return yuv2rgb_c_24_bgr;
647 return yuv2rgb_c_16_ordered_dither;
650 return yuv2rgb_c_15_ordered_dither;
653 return yuv2rgb_c_12_ordered_dither;
656 return yuv2rgb_c_8_ordered_dither;
659 return yuv2rgb_c_4_ordered_dither;
662 return yuv2rgb_c_4b_ordered_dither;
664 return yuv2rgb_c_1_ordered_dither;
669 static void fill_table(uint8_t*
table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
670 const int64_t inc,
void *y_tab)
673 uint8_t *y_table = y_tab;
675 y_table -= elemsize * (inc >> 9);
678 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
679 table[i] = y_table + elemsize * (cb >> 16);
683 static void fill_gv_table(
int table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
const int64_t inc)
686 int off = -(inc >> 9);
689 int64_t
cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc;
690 table[i] = elemsize * (off + (cb >> 16));
696 int r = (f + (1 << 15)) >> 16;
733 int i, base, rbase, gbase, bbase,
av_uninit(abase), needAlpha;
734 const int yoffs = fullRange ? 384 : 326;
736 int64_t crv = inv_table[0];
737 int64_t cbu = inv_table[1];
738 int64_t cgu = -inv_table[2];
739 int64_t cgv = -inv_table[3];
740 int64_t cy = 1 << 16;
745 cy = (cy * 255) / 219;
748 crv = (crv * 224) / 255;
749 cbu = (cbu * 224) / 255;
750 cgu = (cgu * 224) / 255;
751 cgv = (cgv * 224) / 255;
761 c->
uOffset = 0x0400040004000400LL;
762 c->
vOffset = 0x0400040004000400LL;
778 crv = ((crv << 16) + 0x8000) / cy;
779 cbu = ((cbu << 16) + 0x8000) / cy;
780 cgu = ((cgu << 16) + 0x8000) / cy;
781 cgv = ((cgv << 16) + 0x8000) / cy;
789 yb = -(384 << 16) - oy;
790 for (i = 0; i < 1024 - 110; i++) {
791 y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
799 rbase = isRgb ? 3 : 0;
801 bbase = isRgb ? 0 : 3;
804 yb = -(384 << 16) - oy;
805 for (i = 0; i < 1024 - 110; i++) {
806 int yval = av_clip_uint8((yb + 0x8000) >> 16);
807 y_table[i + 110] = (yval >> 7) << rbase;
808 y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
809 y_table[i + 110 + 2048] = (yval >> 7) << bbase;
818 rbase = isRgb ? 5 : 0;
819 gbase = isRgb ? 2 : 3;
820 bbase = isRgb ? 0 : 6;
823 yb = -(384 << 16) - oy;
824 for (i = 0; i < 1024 - 38; i++) {
825 int yval = av_clip_uint8((yb + 0x8000) >> 16);
826 y_table[i + 16] = ((yval + 18) / 36) << rbase;
827 y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
828 y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
837 rbase = isRgb ? 8 : 0;
839 bbase = isRgb ? 0 : 8;
842 yb = -(384 << 16) - oy;
843 for (i = 0; i < 1024; i++) {
844 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
845 y_table16[i] = (yval >> 4) << rbase;
846 y_table16[i + 1024] = (yval >> 4) << gbase;
847 y_table16[i + 2048] = (yval >> 4) << bbase;
851 for (i = 0; i < 1024 * 3; i++)
860 rbase = isRgb ? bpp - 5 : 0;
862 bbase = isRgb ? 0 : (bpp - 5);
865 yb = -(384 << 16) - oy;
866 for (i = 0; i < 1024; i++) {
867 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
868 y_table16[i] = (yval >> 3) << rbase;
869 y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
870 y_table16[i + 2048] = (yval >> 3) << bbase;
874 for (i = 0; i < 1024 * 3; i++)
885 yb = -(384 << 16) - oy;
886 for (i = 0; i < 1024; i++) {
887 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
898 rbase = base + (isRgb ? 16 : 0);
900 bbase = base + (isRgb ? 0 : 16);
903 abase = (base + 24) & 31;
906 yb = -(384 << 16) - oy;
907 for (i = 0; i < 1024; i++) {
908 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
909 y_table32[i] = (yval << rbase) +
910 (needAlpha ? 0 : (255u << abase));
911 y_table32[i + 1024] = yval << gbase;
912 y_table32[i + 2048] = yval << bbase;