49 { 117489, 138438, 13975, 34925 },
50 { 117489, 138438, 13975, 34925 },
51 { 104597, 132201, 25675, 53279 },
52 { 104597, 132201, 25675, 53279 },
53 { 104448, 132798, 24759, 53109 },
54 { 104597, 132201, 25675, 53279 },
55 { 104597, 132201, 25675, 53279 },
56 { 117579, 136230, 16907, 35559 },
58 { 110013, 140363, 12277, 42626 },
59 { 110013, 140363, 12277, 42626 },
64 if (colorspace > 10 || colorspace < 0 || colorspace == 8)
69 #define LOADCHROMA(i) \
72 r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
73 g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
74 b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
76 #define PUTRGB(dst, src, i) \
78 dst[2 * i] = r[Y] + g[Y] + b[Y]; \
80 dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
82 #define PUTRGB24(dst, src, i) \
84 dst[6 * i + 0] = r[Y]; \
85 dst[6 * i + 1] = g[Y]; \
86 dst[6 * i + 2] = b[Y]; \
88 dst[6 * i + 3] = r[Y]; \
89 dst[6 * i + 4] = g[Y]; \
90 dst[6 * i + 5] = b[Y];
92 #define PUTBGR24(dst, src, i) \
94 dst[6 * i + 0] = b[Y]; \
95 dst[6 * i + 1] = g[Y]; \
96 dst[6 * i + 2] = r[Y]; \
98 dst[6 * i + 3] = b[Y]; \
99 dst[6 * i + 4] = g[Y]; \
100 dst[6 * i + 5] = r[Y];
102 #define PUTRGBA(dst, ysrc, asrc, i, s) \
104 dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
105 Y = ysrc[2 * i + 1]; \
106 dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
108 #define PUTRGB48(dst, src, i) \
110 dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
111 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
112 dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
113 Y = src[ 2 * i + 1]; \
114 dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
115 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
116 dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
118 #define PUTBGR48(dst, src, i) \
120 dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
121 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
122 dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
123 Y = src[2 * i + 1]; \
124 dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
125 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
126 dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
128 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
129 static int func_name(SwsContext *c, const uint8_t *src[], \
130 int srcStride[], int srcSliceY, int srcSliceH, \
131 uint8_t *dst[], int dstStride[]) \
135 if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
139 for (y = 0; y < srcSliceH; y += 2) { \
140 int yd = y + srcSliceY; \
142 (dst_type *)(dst[0] + (yd) * dstStride[0]); \
144 (dst_type *)(dst[0] + (yd + 1) * dstStride[0]); \
145 dst_type av_unused *r, *g, *b; \
146 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
147 const uint8_t *py_2 = py_1 + srcStride[0]; \
148 const uint8_t av_unused *pu = src[1] + (y >> 1) * srcStride[1]; \
149 const uint8_t av_unused *pv = src[2] + (y >> 1) * srcStride[2]; \
150 const uint8_t av_unused *pa_1, *pa_2; \
151 unsigned int h_size = c->dstW >> 3; \
153 pa_1 = src[3] + y * srcStride[3]; \
154 pa_2 = pa_1 + srcStride[3]; \
157 int av_unused U, V, Y; \
159 #define ENDYUV2RGBLINE(dst_delta, ss) \
164 dst_1 += dst_delta >> ss; \
165 dst_2 += dst_delta >> ss; \
167 if (c->dstW & (4 >> ss)) { \
168 int av_unused Y, U, V; \
170 #define ENDYUV2RGBFUNC() \
176 #define CLOSEYUV2RGBFUNC(dst_delta) \
177 ENDYUV2RGBLINE(dst_delta, 0) \
407 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
412 #define PUTRGB16(dst, src, i, o) \
414 dst[2 * i] = r[Y + d16[0 + o]] + \
415 g[Y + e16[0 + o]] + \
417 Y = src[2 * i + 1]; \
418 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
419 g[Y + e16[1 + o]] + \
438 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
442 #define PUTRGB15(dst, src, i, o) \
444 dst[2 * i] = r[Y + d16[0 + o]] + \
445 g[Y + d16[1 + o]] + \
447 Y = src[2 * i + 1]; \
448 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
449 g[Y + d16[0 + o]] + \
469 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
472 #define PUTRGB12(dst, src, i, o) \
474 dst[2 * i] = r[Y + d16[0 + o]] + \
475 g[Y + d16[0 + o]] + \
477 Y = src[2 * i + 1]; \
478 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
479 g[Y + d16[1 + o]] + \
500 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
504 #define PUTRGB8(dst, src, i, o) \
506 dst[2 * i] = r[Y + d32[0 + o]] + \
507 g[Y + d32[0 + o]] + \
509 Y = src[2 * i + 1]; \
510 dst[2 * i + 1] = r[Y + d32[1 + o]] + \
511 g[Y + d32[1 + o]] + \
551 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
556 #define PUTRGB4D(dst, src, i, o) \
558 acc = r[Y + d128[0 + o]] + \
559 g[Y + d64[0 + o]] + \
560 b[Y + d128[0 + o]]; \
561 Y = src[2 * i + 1]; \
562 acc |= (r[Y + d128[1 + o]] + \
563 g[Y + d64[1 + o]] + \
564 b[Y + d128[1 + o]]) << 4; \
604 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
608 #define PUTRGB4DB(dst, src, i, o) \
610 dst[2 * i] = r[Y + d128[0 + o]] + \
611 g[Y + d64[0 + o]] + \
612 b[Y + d128[0 + o]]; \
613 Y = src[2 * i + 1]; \
614 dst[2 * i + 1] = r[Y + d128[1 + o]] + \
615 g[Y + d64[1 + o]] + \
651 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
656 #define PUTRGB1(out, src, i, o) \
658 out += out + g[Y + d128[0 + o]]; \
659 Y = src[2 * i + 1]; \
660 out += out + g[Y + d128[1 + o]];
692 "No accelerated colorspace conversion found from %s to %s.\n",
695 switch (
c->dstFormat) {
698 return yuv2rgb_c_bgr48;
704 if (CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat))
708 return (CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
710 return yuv2rgb_c_24_rgb;
712 return yuv2rgb_c_24_bgr;
715 return yuv2rgb_c_16_ordered_dither;
718 return yuv2rgb_c_15_ordered_dither;
721 return yuv2rgb_c_12_ordered_dither;
724 return yuv2rgb_c_8_ordered_dither;
727 return yuv2rgb_c_4_ordered_dither;
730 return yuv2rgb_c_4b_ordered_dither;
732 return yuv2rgb_c_1_ordered_dither;
738 const int64_t inc,
void *y_tab)
741 uint8_t *y_table = y_tab;
743 y_table -= elemsize * (inc >> 9);
747 table[
i] = y_table + elemsize * (
cb >> 16);
754 int off = -(inc >> 9);
758 table[
i] = elemsize * (off + (
cb >> 16));
764 int r = (
f + (1 << 15)) >> 16;
775 int fullRange,
int brightness,
776 int contrast,
int saturation)
793 const int isNotNe =
c->dstFormat ==
AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
801 const int bpp =
c->dstFormatBpp;
809 int64_t crv = inv_table[0];
810 int64_t cbu = inv_table[1];
811 int64_t cgu = -inv_table[2];
812 int64_t cgv = -inv_table[3];
813 int64_t cy = 1 << 16;
818 cy = (cy * 255) / 219;
821 crv = (crv * 224) / 255;
822 cbu = (cbu * 224) / 255;
823 cgu = (cgu * 224) / 255;
824 cgv = (cgv * 224) / 255;
827 cy = (cy * contrast) >> 16;
828 crv = (crv * contrast * saturation) >> 32;
829 cbu = (cbu * contrast * saturation) >> 32;
830 cgu = (cgu * contrast * saturation) >> 32;
831 cgv = (cgv * contrast * saturation) >> 32;
832 oy -= 256 * brightness;
834 c->uOffset = 0x0400040004000400LL;
835 c->vOffset = 0x0400040004000400LL;
836 c->yCoeff =
roundToInt16(cy * (1 << 13)) * 0x0001000100010001ULL;
837 c->vrCoeff =
roundToInt16(crv * (1 << 13)) * 0x0001000100010001ULL;
838 c->ubCoeff =
roundToInt16(cbu * (1 << 13)) * 0x0001000100010001ULL;
839 c->vgCoeff =
roundToInt16(cgv * (1 << 13)) * 0x0001000100010001ULL;
840 c->ugCoeff =
roundToInt16(cgu * (1 << 13)) * 0x0001000100010001ULL;
841 c->yOffset =
roundToInt16(oy * (1 << 3)) * 0x0001000100010001ULL;
845 c->yuv2rgb_v2r_coeff = (int16_t)
roundToInt16(crv * (1 << 13));
846 c->yuv2rgb_v2g_coeff = (int16_t)
roundToInt16(cgv * (1 << 13));
847 c->yuv2rgb_u2g_coeff = (int16_t)
roundToInt16(cgu * (1 << 13));
848 c->yuv2rgb_u2b_coeff = (int16_t)
roundToInt16(cbu * (1 << 13));
851 crv = ((crv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
852 cbu = ((cbu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
853 cgu = ((cgu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
854 cgv = ((cgv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
858 #define ALLOC_YUV_TABLE(x) \
859 c->yuvTable = av_malloc(x); \
861 return AVERROR(ENOMEM);
865 y_table =
c->yuvTable;
867 for (
i = 0;
i < table_plane_size - 110;
i++) {
876 rbase = isRgb ? 3 : 0;
878 bbase = isRgb ? 0 : 3;
880 y_table =
c->yuvTable;
882 for (
i = 0;
i < table_plane_size - 110;
i++) {
884 y_table[
i + 110] = (yval >> 7) << rbase;
885 y_table[
i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
886 y_table[
i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
890 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
891 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
895 rbase = isRgb ? 5 : 0;
896 gbase = isRgb ? 2 : 3;
897 bbase = isRgb ? 0 : 6;
899 y_table =
c->yuvTable;
901 for (
i = 0;
i < table_plane_size - 38;
i++) {
903 y_table[
i + 16] = ((yval + 18) / 36) << rbase;
904 y_table[
i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
905 y_table[
i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
909 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
910 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
914 rbase = isRgb ? 8 : 0;
916 bbase = isRgb ? 0 : 8;
918 y_table16 =
c->yuvTable;
920 for (
i = 0;
i < table_plane_size;
i++) {
922 y_table16[
i] = (yval >> 4) << rbase;
923 y_table16[
i + table_plane_size] = (yval >> 4) << gbase;
924 y_table16[
i + 2*table_plane_size] = (yval >> 4) << bbase;
928 for (
i = 0;
i < table_plane_size * 3;
i++)
930 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
931 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
932 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
937 rbase = isRgb ? bpp - 5 : 0;
939 bbase = isRgb ? 0 : (bpp - 5);
941 y_table16 =
c->yuvTable;
943 for (
i = 0;
i < table_plane_size;
i++) {
945 y_table16[
i] = (yval >> 3) << rbase;
946 y_table16[
i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
947 y_table16[
i + 2*table_plane_size] = (yval >> 3) << bbase;
951 for (
i = 0;
i < table_plane_size * 3;
i++)
953 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
954 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
955 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
961 y_table =
c->yuvTable;
963 for (
i = 0;
i < table_plane_size;
i++) {
973 rbase = isRgb ? 20 : 0;
975 bbase = isRgb ? 0 : 20;
976 needAlpha = CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat);
980 y_table32 =
c->yuvTable;
982 for (
i = 0;
i < table_plane_size;
i++) {
984 y_table32[
i]= (yval << rbase) + (needAlpha ? 0 : (255
u << abase));
985 y_table32[
i + table_plane_size] = yval << gbase;
986 y_table32[
i + 2 * table_plane_size] = yval << bbase;
990 for (
i = 0;
i < table_plane_size * 3;
i++)
993 fill_table(
c->table_rV, 4, crv, y_table32 + yoffs);
994 fill_table(
c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
995 fill_table(
c->table_bU, 4, cbu, y_table32 + yoffs + 2 * table_plane_size);
1002 rbase =
base + (isRgb ? 16 : 0);
1004 bbase =
base + (isRgb ? 0 : 16);
1005 needAlpha = CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat);
1007 abase = (
base + 24) & 31;
1009 y_table32 =
c->yuvTable;
1011 for (
i = 0;
i < table_plane_size;
i++) {
1013 y_table32[
i] = (yval << rbase) +
1014 (needAlpha ? 0 : (255
u << abase));
1015 y_table32[
i + table_plane_size] = yval << gbase;
1016 y_table32[
i + 2*table_plane_size] = yval << bbase;
1019 fill_table(
c->table_rV, 4, crv, y_table32 + yoffs);
1020 fill_table(
c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
1021 fill_table(
c->table_bU, 4, cbu, y_table32 + yoffs + 2*table_plane_size);
1025 if(!
isPlanar(
c->dstFormat) || bpp <= 24)