50 { 117489, 138438, 13975, 34925 },
51 { 117489, 138438, 13975, 34925 },
52 { 104597, 132201, 25675, 53279 },
53 { 104597, 132201, 25675, 53279 },
54 { 104448, 132798, 24759, 53109 },
55 { 104597, 132201, 25675, 53279 },
56 { 104597, 132201, 25675, 53279 },
57 { 117579, 136230, 16907, 35559 },
59 { 110013, 140363, 12277, 42626 },
60 { 110013, 140363, 12277, 42626 },
65 if (colorspace > 10 || colorspace < 0 || colorspace == 8)
70 #define LOADCHROMA(i) \
73 r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \
74 g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \
75 b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM];
77 #define PUTRGB(dst, src, i) \
79 dst[2 * i] = r[Y] + g[Y] + b[Y]; \
81 dst[2 * i + 1] = r[Y] + g[Y] + b[Y];
83 #define PUTRGB24(dst, src, i) \
85 dst[6 * i + 0] = r[Y]; \
86 dst[6 * i + 1] = g[Y]; \
87 dst[6 * i + 2] = b[Y]; \
89 dst[6 * i + 3] = r[Y]; \
90 dst[6 * i + 4] = g[Y]; \
91 dst[6 * i + 5] = b[Y];
93 #define PUTBGR24(dst, src, i) \
95 dst[6 * i + 0] = b[Y]; \
96 dst[6 * i + 1] = g[Y]; \
97 dst[6 * i + 2] = r[Y]; \
99 dst[6 * i + 3] = b[Y]; \
100 dst[6 * i + 4] = g[Y]; \
101 dst[6 * i + 5] = r[Y];
103 #define PUTRGBA(dst, ysrc, asrc, i, s) \
105 dst[2 * i] = r[Y] + g[Y] + b[Y] + (asrc[2 * i] << s); \
106 Y = ysrc[2 * i + 1]; \
107 dst[2 * i + 1] = r[Y] + g[Y] + b[Y] + (asrc[2 * i + 1] << s);
109 #define PUTRGB48(dst, src, i) \
111 dst[12 * i + 0] = dst[12 * i + 1] = r[Y]; \
112 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
113 dst[12 * i + 4] = dst[12 * i + 5] = b[Y]; \
114 Y = src[ 2 * i + 1]; \
115 dst[12 * i + 6] = dst[12 * i + 7] = r[Y]; \
116 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
117 dst[12 * i + 10] = dst[12 * i + 11] = b[Y];
119 #define PUTBGR48(dst, src, i) \
121 dst[12 * i + 0] = dst[12 * i + 1] = b[Y]; \
122 dst[12 * i + 2] = dst[12 * i + 3] = g[Y]; \
123 dst[12 * i + 4] = dst[12 * i + 5] = r[Y]; \
124 Y = src[2 * i + 1]; \
125 dst[12 * i + 6] = dst[12 * i + 7] = b[Y]; \
126 dst[12 * i + 8] = dst[12 * i + 9] = g[Y]; \
127 dst[12 * i + 10] = dst[12 * i + 11] = r[Y];
129 #define YUV2RGBFUNC(func_name, dst_type, alpha) \
130 static int func_name(SwsContext *c, const uint8_t *src[], \
131 int srcStride[], int srcSliceY, int srcSliceH, \
132 uint8_t *dst[], int dstStride[]) \
136 if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) { \
140 for (y = 0; y < srcSliceH; y += 2) { \
141 int yd = y + srcSliceY; \
143 (dst_type *)(dst[0] + (yd) * dstStride[0]); \
145 (dst_type *)(dst[0] + (yd + 1) * dstStride[0]); \
146 dst_type av_unused *r, *g, *b; \
147 const uint8_t *py_1 = src[0] + y * srcStride[0]; \
148 const uint8_t *py_2 = py_1 + srcStride[0]; \
149 const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \
150 const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \
151 const uint8_t av_unused *pa_1, *pa_2; \
152 unsigned int h_size = c->dstW >> 3; \
154 pa_1 = src[3] + y * srcStride[3]; \
155 pa_2 = pa_1 + srcStride[3]; \
158 int av_unused U, V, Y; \
160 #define ENDYUV2RGBLINE(dst_delta, ss) \
165 dst_1 += dst_delta >> ss; \
166 dst_2 += dst_delta >> ss; \
168 if (c->dstW & (4 >> ss)) { \
169 int av_unused Y, U, V; \
171 #define ENDYUV2RGBFUNC() \
177 #define CLOSEYUV2RGBFUNC(dst_delta) \
178 ENDYUV2RGBLINE(dst_delta, 0) \
408 YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0)
413 #define PUTRGB16(dst, src, i, o) \
415 dst[2 * i] = r[Y + d16[0 + o]] + \
416 g[Y + e16[0 + o]] + \
418 Y = src[2 * i + 1]; \
419 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
420 g[Y + e16[1 + o]] + \
439 YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0)
443 #define PUTRGB15(dst, src, i, o) \
445 dst[2 * i] = r[Y + d16[0 + o]] + \
446 g[Y + d16[1 + o]] + \
448 Y = src[2 * i + 1]; \
449 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
450 g[Y + d16[0 + o]] + \
470 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
473 #define PUTRGB12(dst, src, i, o) \
475 dst[2 * i] = r[Y + d16[0 + o]] + \
476 g[Y + d16[0 + o]] + \
478 Y = src[2 * i + 1]; \
479 dst[2 * i + 1] = r[Y + d16[1 + o]] + \
480 g[Y + d16[1 + o]] + \
505 #define PUTRGB8(dst, src, i, o) \
507 dst[2 * i] = r[Y + d32[0 + o]] + \
508 g[Y + d32[0 + o]] + \
510 Y = src[2 * i + 1]; \
511 dst[2 * i + 1] = r[Y + d32[1 + o]] + \
512 g[Y + d32[1 + o]] + \
557 #define PUTRGB4D(dst, src, i, o) \
559 acc = r[Y + d128[0 + o]] + \
560 g[Y + d64[0 + o]] + \
561 b[Y + d128[0 + o]]; \
562 Y = src[2 * i + 1]; \
563 acc |= (r[Y + d128[1 + o]] + \
564 g[Y + d64[1 + o]] + \
565 b[Y + d128[1 + o]]) << 4; \
609 #define PUTRGB4DB(dst, src, i, o) \
611 dst[2 * i] = r[Y + d128[0 + o]] + \
612 g[Y + d64[0 + o]] + \
613 b[Y + d128[0 + o]]; \
614 Y = src[2 * i + 1]; \
615 dst[2 * i + 1] = r[Y + d128[1 + o]] + \
616 g[Y + d64[1 + o]] + \
657 #define PUTRGB1(out, src, i, o) \
659 out += out + g[Y + d128[0 + o]]; \
660 Y = src[2 * i + 1]; \
661 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)
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)
791 const int isNotNe =
c->dstFormat ==
AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
797 const int bpp =
c->dstFormatBpp;
805 int64_t crv = inv_table[0];
806 int64_t cbu = inv_table[1];
807 int64_t cgu = -inv_table[2];
808 int64_t cgv = -inv_table[3];
809 int64_t cy = 1 << 16;
814 cy = (cy * 255) / 219;
817 crv = (crv * 224) / 255;
818 cbu = (cbu * 224) / 255;
819 cgu = (cgu * 224) / 255;
820 cgv = (cgv * 224) / 255;
823 cy = (cy * contrast) >> 16;
824 crv = (crv * contrast * saturation) >> 32;
825 cbu = (cbu * contrast * saturation) >> 32;
826 cgu = (cgu * contrast * saturation) >> 32;
827 cgv = (cgv * contrast * saturation) >> 32;
828 oy -= 256 * brightness;
830 c->uOffset = 0x0400040004000400LL;
831 c->vOffset = 0x0400040004000400LL;
832 c->yCoeff =
roundToInt16(cy * (1 << 13)) * 0x0001000100010001ULL;
833 c->vrCoeff =
roundToInt16(crv * (1 << 13)) * 0x0001000100010001ULL;
834 c->ubCoeff =
roundToInt16(cbu * (1 << 13)) * 0x0001000100010001ULL;
835 c->vgCoeff =
roundToInt16(cgv * (1 << 13)) * 0x0001000100010001ULL;
836 c->ugCoeff =
roundToInt16(cgu * (1 << 13)) * 0x0001000100010001ULL;
837 c->yOffset =
roundToInt16(oy * (1 << 3)) * 0x0001000100010001ULL;
841 c->yuv2rgb_v2r_coeff = (int16_t)
roundToInt16(crv * (1 << 13));
842 c->yuv2rgb_v2g_coeff = (int16_t)
roundToInt16(cgv * (1 << 13));
843 c->yuv2rgb_u2g_coeff = (int16_t)
roundToInt16(cgu * (1 << 13));
844 c->yuv2rgb_u2b_coeff = (int16_t)
roundToInt16(cbu * (1 << 13));
847 crv = ((crv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
848 cbu = ((cbu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
849 cgu = ((cgu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
850 cgv = ((cgv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
854 #define ALLOC_YUV_TABLE(x) \
855 c->yuvTable = av_malloc(x); \
857 return AVERROR(ENOMEM);
861 y_table =
c->yuvTable;
863 for (
i = 0;
i < table_plane_size - 110;
i++) {
864 y_table[
i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
872 rbase = isRgb ? 3 : 0;
874 bbase = isRgb ? 0 : 3;
876 y_table =
c->yuvTable;
878 for (
i = 0;
i < table_plane_size - 110;
i++) {
879 int yval = av_clip_uint8((yb + 0x8000) >> 16);
880 y_table[
i + 110] = (yval >> 7) << rbase;
881 y_table[
i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
882 y_table[
i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
886 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
887 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
891 rbase = isRgb ? 5 : 0;
892 gbase = isRgb ? 2 : 3;
893 bbase = isRgb ? 0 : 6;
895 y_table =
c->yuvTable;
897 for (
i = 0;
i < table_plane_size - 38;
i++) {
898 int yval = av_clip_uint8((yb + 0x8000) >> 16);
899 y_table[
i + 16] = ((yval + 18) / 36) << rbase;
900 y_table[
i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
901 y_table[
i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
905 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
906 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
910 rbase = isRgb ? 8 : 0;
912 bbase = isRgb ? 0 : 8;
914 y_table16 =
c->yuvTable;
916 for (
i = 0;
i < table_plane_size;
i++) {
917 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
918 y_table16[
i] = (yval >> 4) << rbase;
919 y_table16[
i + table_plane_size] = (yval >> 4) << gbase;
920 y_table16[
i + 2*table_plane_size] = (yval >> 4) << bbase;
924 for (
i = 0;
i < table_plane_size * 3;
i++)
926 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
927 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
928 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
933 rbase = isRgb ? bpp - 5 : 0;
935 bbase = isRgb ? 0 : (bpp - 5);
937 y_table16 =
c->yuvTable;
939 for (
i = 0;
i < table_plane_size;
i++) {
940 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
941 y_table16[
i] = (yval >> 3) << rbase;
942 y_table16[
i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
943 y_table16[
i + 2*table_plane_size] = (yval >> 3) << bbase;
947 for (
i = 0;
i < table_plane_size * 3;
i++)
949 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
950 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
951 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
957 y_table =
c->yuvTable;
959 for (
i = 0;
i < table_plane_size;
i++) {
960 y_table[
i] = av_clip_uint8((yb + 0x8000) >> 16);
972 rbase =
base + (isRgb ? 16 : 0);
974 bbase =
base + (isRgb ? 0 : 16);
975 needAlpha = CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat);
977 abase = (
base + 24) & 31;
979 y_table32 =
c->yuvTable;
981 for (
i = 0;
i < table_plane_size;
i++) {
982 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
983 y_table32[
i] = (yval << rbase) +
984 (needAlpha ? 0 : (255
u << abase));
985 y_table32[
i + table_plane_size] = yval << gbase;
986 y_table32[
i + 2*table_plane_size] = yval << bbase;
989 fill_table(
c->table_rV, 4, crv, y_table32 + yoffs);
990 fill_table(
c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
991 fill_table(
c->table_bU, 4, cbu, y_table32 + yoffs + 2*table_plane_size);