44 { 117504, 138453, 13954, 34903 },
45 { 117504, 138453, 13954, 34903 },
46 { 104597, 132201, 25675, 53279 },
47 { 104597, 132201, 25675, 53279 },
48 { 104448, 132798, 24759, 53109 },
49 { 104597, 132201, 25675, 53279 },
50 { 104597, 132201, 25675, 53279 },
51 { 117579, 136230, 16907, 35559 }
56 if (colorspace > 7 || colorspace < 0)
61 #define LOADCHROMA(i) \
64 r = (void *)c->table_rV[V]; \
65 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
66 b = (void *)c->table_bU[U];
68 #define PUTRGB(dst, src, i) \
70 dst[2 * i] = r[Y] + g[Y] + b[Y]; \
72 dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
74 #define PUTRGB24(dst, src, i) \
76 dst[6 * i + 0] = r[Y]; \
77 dst[6 * i + 1] = g[Y]; \
78 dst[6 * i + 2] = b[Y]; \
80 dst[6 * i + 3] = r[Y]; \
81 dst[6 * i + 4] = g[Y]; \
82 dst[6 * i + 5] = b[Y];
84 #define PUTBGR24(dst, src, i) \
86 dst[6 * i + 0] = b[Y]; \
87 dst[6 * i + 1] = g[Y]; \
88 dst[6 * i + 2] = r[Y]; \
90 dst[6 * i + 3] = b[Y]; \
91 dst[6 * i + 4] = g[Y]; \
92 dst[6 * i + 5] = r[Y];
94 #define PUTRGBA(dst, ysrc, asrc, i, s) \
96 dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
97 Y = ysrc[2 * i + 1]; \
98 dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
100 #define PUTRGB48(dst, src, i) \
102 dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
103 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
104 dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
105 Y = src[ 2 * i + 1]; \
106 dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
107 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
108 dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
110 #define PUTBGR48(dst, src, i) \
112 dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
113 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
114 dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
115 Y = src[2 * i + 1]; \
116 dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
117 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
118 dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
120 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
121 static int func_name(SwsContext *c, const uint8_t *src[], \
122 int srcStride[], int srcSliceY, int srcSliceH, \
123 uint8_t *dst[], int dstStride[]) \
127 if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
131 for (y = 0; y < srcSliceH; y += 2) { \
133 (dst_type *)(dst[0] + (y + srcSliceY) * dstStride[0]); \
135 (dst_type *)(dst[0] + (y + srcSliceY + 1) * dstStride[0]); \
136 dst_type av_unused *r, *g, *b; \
137 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
138 const uint8_t *py_2 = py_1 + srcStride[0]; \
139 const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
140 const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
141 const uint8_t av_unused *pa_1, *pa_2; \
142 unsigned int h_size = c->dstW >> 3; \
144 pa_1 = src[3] + y * srcStride[3]; \
145 pa_2 = pa_1 + srcStride[3]; \
148 int av_unused U, V, Y; \
150 #define ENDYUV2RGBLINE(dst_delta, ss) \
155 dst_1 += dst_delta >> ss; \
156 dst_2 += dst_delta >> ss; \
158 if (c->dstW & (4 >> ss)) { \
159 int av_unused Y, U, V; \
161 #define ENDYUV2RGBFUNC() \
167 #define CLOSEYUV2RGBFUNC(dst_delta) \
168 ENDYUV2RGBLINE(dst_delta, 0) \
267 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
268 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
271 PUTRGBA(dst_1, py_1, pa_1, 2, 24);
272 PUTRGBA(dst_2, py_2, pa_2, 2, 24);
275 PUTRGBA(dst_2, py_2, pa_2, 3, 24);
276 PUTRGBA(dst_1, py_1, pa_1, 3, 24);
281 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
282 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
285 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
286 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
291 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
292 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
297 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
298 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
301 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
302 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
305 PUTRGBA(dst_1, py_1, pa_1, 2, 0);
306 PUTRGBA(dst_2, py_2, pa_2, 2, 0);
309 PUTRGBA(dst_2, py_2, pa_2, 3, 0);
310 PUTRGBA(dst_1, py_1, pa_1, 3, 0);
315 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
316 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
319 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
320 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
325 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
326 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
411 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
414 #define PUTRGB12(dst, src, i, o) \
416 dst[2 * i] = r[Y + d16[0 + o]] + \
417 g[Y + d16[0 + o]] + \
419 Y = src[2 * i + 1]; \
420 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
421 g[Y + d16[1 + o]] + \
442 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
446 #define PUTRGB8(dst, src, i, o) \
448 dst[2 * i] = r[Y + d32[0 + o]] + \
449 g[Y + d32[0 + o]] + \
451 Y = src[2 * i + 1]; \
452 dst[2 * i + 1] = r[Y + d32[1 + o]] + \
453 g[Y + d32[1 + o]] + \
458 PUTRGB8(dst_2, py_2, 0, 0 + 8);
461 PUTRGB8(dst_2, py_2, 1, 2 + 8);
466 PUTRGB8(dst_2, py_2, 2, 4 + 8);
469 PUTRGB8(dst_2, py_2, 3, 6 + 8);
473 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
478 #define PUTRGB4D(dst, src, i, o) \
480 acc = r[Y + d128[0 + o]] + \
481 g[Y + d64[0 + o]] + \
482 b[Y + d128[0 + o]]; \
483 Y = src[2 * i + 1]; \
484 acc |= (r[Y + d128[1 + o]] + \
485 g[Y + d64[1 + o]] + \
486 b[Y + d128[1 + o]]) << 4; \
506 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
510 #define PUTRGB4DB(dst, src, i, o) \
512 dst[2 * i] = r[Y + d128[0 + o]] + \
513 g[Y + d64[0 + o]] + \
514 b[Y + d128[0 + o]]; \
515 Y = src[2 * i + 1]; \
516 dst[2 * i + 1] = r[Y + d128[1 + o]] + \
517 g[Y + d64[1 + o]] + \
537 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
542 #define PUTRGB1(out, src, i, o) \
544 out += out + g[Y + d128[0 + o]]; \
545 Y = src[2 * i + 1]; \
546 out += out + g[Y + d128[1 + o]];
549 PUTRGB1(out_2, py_2, 0, 0 + 8);
551 PUTRGB1(out_2, py_2, 1, 2 + 8);
555 PUTRGB1(out_2, py_2, 2, 4 + 8);
557 PUTRGB1(out_2, py_2, 3, 6 + 8);
581 "No accelerated colorspace conversion found from %s to %s.\n",
584 switch (c->dstFormat) {
587 return yuv2rgb_c_bgr48;
602 return yuv2rgb_c_24_rgb;
604 return yuv2rgb_c_24_bgr;
612 return yuv2rgb_c_12_ordered_dither;
615 return yuv2rgb_c_8_ordered_dither;
618 return yuv2rgb_c_4_ordered_dither;
621 return yuv2rgb_c_4b_ordered_dither;
623 return yuv2rgb_c_1_ordered_dither;
630 static void fill_table(uint8_t *table[256],
const int elemsize,
631 const int inc,
void *y_tab)
635 uint8_t *y_table = y_tab;
637 y_table -= elemsize * (inc >> 9);
639 for (i = 0; i < 256; i++) {
640 table[i] = y_table + elemsize * (cb >> 16);
645 static void fill_gv_table(
int table[256],
const int elemsize,
const int inc)
649 int off = -(inc >> 9);
651 for (i = 0; i < 256; i++) {
652 table[i] = elemsize * (off + (cb >> 16));
659 int r = (f + (1 << 15)) >> 16;
696 int i, base, rbase, gbase, bbase, abase, needAlpha;
697 const int yoffs = fullRange ? 384 : 326;
699 int64_t crv = inv_table[0];
700 int64_t cbu = inv_table[1];
701 int64_t cgu = -inv_table[2];
702 int64_t cgv = -inv_table[3];
703 int64_t cy = 1 << 16;
708 cy = (cy * 255) / 219;
711 crv = (crv * 224) / 255;
712 cbu = (cbu * 224) / 255;
713 cgu = (cgu * 224) / 255;
714 cgv = (cgv * 224) / 255;
724 c->
uOffset = 0x0400040004000400LL;
725 c->
vOffset = 0x0400040004000400LL;
741 crv = ((crv << 16) + 0x8000) / cy;
742 cbu = ((cbu << 16) + 0x8000) / cy;
743 cgu = ((cgu << 16) + 0x8000) / cy;
744 cgv = ((cgv << 16) + 0x8000) / cy;
752 yb = -(384 << 16) - oy;
753 for (i = 0; i < 1024 - 110; i++) {
754 y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
762 rbase = isRgb ? 3 : 0;
764 bbase = isRgb ? 0 : 3;
767 yb = -(384 << 16) - oy;
768 for (i = 0; i < 1024 - 110; i++) {
769 int yval = av_clip_uint8((yb + 0x8000) >> 16);
770 y_table[i + 110] = (yval >> 7) << rbase;
771 y_table[i + 37 + 1024] = ((yval + 43) / 85) << gbase;
772 y_table[i + 110 + 2048] = (yval >> 7) << bbase;
781 rbase = isRgb ? 5 : 0;
782 gbase = isRgb ? 2 : 3;
783 bbase = isRgb ? 0 : 6;
786 yb = -(384 << 16) - oy;
787 for (i = 0; i < 1024 - 38; i++) {
788 int yval = av_clip_uint8((yb + 0x8000) >> 16);
789 y_table[i + 16] = ((yval + 18) / 36) << rbase;
790 y_table[i + 16 + 1024] = ((yval + 18) / 36) << gbase;
791 y_table[i + 37 + 2048] = ((yval + 43) / 85) << bbase;
800 rbase = isRgb ? 8 : 0;
802 bbase = isRgb ? 0 : 8;
805 yb = -(384 << 16) - oy;
806 for (i = 0; i < 1024; i++) {
807 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
808 y_table16[i] = (yval >> 4) << rbase;
809 y_table16[i + 1024] = (yval >> 4) << gbase;
810 y_table16[i + 2048] = (yval >> 4) << bbase;
814 for (i = 0; i < 1024 * 3; i++)
823 rbase = isRgb ? bpp - 5 : 0;
825 bbase = isRgb ? 0 : (bpp - 5);
828 yb = -(384 << 16) - oy;
829 for (i = 0; i < 1024; i++) {
830 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
831 y_table16[i] = (yval >> 3) << rbase;
832 y_table16[i + 1024] = (yval >> (18 - bpp)) << gbase;
833 y_table16[i + 2048] = (yval >> 3) << bbase;
837 for (i = 0; i < 1024 * 3; i++)
848 yb = -(384 << 16) - oy;
849 for (i = 0; i < 1024; i++) {
850 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
861 rbase = base + (isRgb ? 16 : 0);
863 bbase = base + (isRgb ? 0 : 16);
866 abase = (base + 24) & 31;
869 yb = -(384 << 16) - oy;
870 for (i = 0; i < 1024; i++) {
871 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
872 y_table32[i] = (yval << rbase) +
873 (needAlpha ? 0 : (255u << abase));
874 y_table32[i + 1024] = yval << gbase;
875 y_table32[i + 2048] = yval << bbase;