49 { 104597, 132201, 25675, 53279 },
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]];
686 #elif ARCH_LOONGARCH64
694 "No accelerated colorspace conversion found from %s to %s.\n",
697 switch (
c->dstFormat) {
700 return yuv2rgb_c_bgr48;
706 if (CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat))
710 return (CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat)) ? yuva2rgba_c : yuv2rgb_c_32;
712 return yuv2rgb_c_24_rgb;
714 return yuv2rgb_c_24_bgr;
717 return yuv2rgb_c_16_ordered_dither;
720 return yuv2rgb_c_15_ordered_dither;
723 return yuv2rgb_c_12_ordered_dither;
726 return yuv2rgb_c_8_ordered_dither;
729 return yuv2rgb_c_4_ordered_dither;
732 return yuv2rgb_c_4b_ordered_dither;
734 return yuv2rgb_c_1_ordered_dither;
740 const int64_t inc,
void *y_tab)
743 uint8_t *y_table = y_tab;
745 y_table -= elemsize * (inc >> 9);
749 table[
i] = y_table + elemsize * (
cb >> 16);
756 int off = -(inc >> 9);
760 table[
i] = elemsize * (off + (
cb >> 16));
766 int r = (
f + (1 << 15)) >> 16;
777 int fullRange,
int brightness,
778 int contrast,
int saturation)
795 const int isNotNe =
c->dstFormat ==
AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
803 const int bpp =
c->dstFormatBpp;
820 cy = (cy * 255) / 219;
823 crv = (crv * 224) / 255;
824 cbu = (cbu * 224) / 255;
825 cgu = (cgu * 224) / 255;
826 cgv = (cgv * 224) / 255;
829 cy = (cy * contrast) >> 16;
830 crv = (crv * contrast * saturation) >> 32;
831 cbu = (cbu * contrast * saturation) >> 32;
832 cgu = (cgu * contrast * saturation) >> 32;
833 cgv = (cgv * contrast * saturation) >> 32;
834 oy -= 256LL * brightness;
836 c->uOffset = 0x0400040004000400LL;
837 c->vOffset = 0x0400040004000400LL;
838 c->yCoeff =
roundToInt16(cy * (1 << 13)) * 0x0001000100010001ULL;
839 c->vrCoeff =
roundToInt16(crv * (1 << 13)) * 0x0001000100010001ULL;
840 c->ubCoeff =
roundToInt16(cbu * (1 << 13)) * 0x0001000100010001ULL;
841 c->vgCoeff =
roundToInt16(cgv * (1 << 13)) * 0x0001000100010001ULL;
842 c->ugCoeff =
roundToInt16(cgu * (1 << 13)) * 0x0001000100010001ULL;
843 c->yOffset =
roundToInt16(oy * (1 << 3)) * 0x0001000100010001ULL;
847 c->yuv2rgb_v2r_coeff = (int16_t)
roundToInt16(crv * (1 << 13));
848 c->yuv2rgb_v2g_coeff = (int16_t)
roundToInt16(cgv * (1 << 13));
849 c->yuv2rgb_u2g_coeff = (int16_t)
roundToInt16(cgu * (1 << 13));
850 c->yuv2rgb_u2b_coeff = (int16_t)
roundToInt16(cbu * (1 << 13));
853 crv = ((crv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
854 cbu = ((cbu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
855 cgu = ((cgu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
856 cgv = ((cgv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
860 #define ALLOC_YUV_TABLE(x) \
861 c->yuvTable = av_malloc(x); \
863 return AVERROR(ENOMEM);
867 y_table =
c->yuvTable;
869 for (
i = 0;
i < table_plane_size - 110;
i++) {
878 rbase = isRgb ? 3 : 0;
880 bbase = isRgb ? 0 : 3;
882 y_table =
c->yuvTable;
884 for (
i = 0;
i < table_plane_size - 110;
i++) {
886 y_table[
i + 110] = (yval >> 7) << rbase;
887 y_table[
i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
888 y_table[
i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
892 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
893 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
897 rbase = isRgb ? 5 : 0;
898 gbase = isRgb ? 2 : 3;
899 bbase = isRgb ? 0 : 6;
901 y_table =
c->yuvTable;
903 for (
i = 0;
i < table_plane_size - 38;
i++) {
905 y_table[
i + 16] = ((yval + 18) / 36) << rbase;
906 y_table[
i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
907 y_table[
i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
911 fill_table(
c->table_gU, 1, cgu, y_table + yoffs + table_plane_size);
912 fill_table(
c->table_bU, 1, cbu, y_table + yoffs + 2*table_plane_size);
916 rbase = isRgb ? 8 : 0;
918 bbase = isRgb ? 0 : 8;
920 y_table16 =
c->yuvTable;
922 for (
i = 0;
i < table_plane_size;
i++) {
924 y_table16[
i] = (yval >> 4) << rbase;
925 y_table16[
i + table_plane_size] = (yval >> 4) << gbase;
926 y_table16[
i + 2*table_plane_size] = (yval >> 4) << bbase;
930 for (
i = 0;
i < table_plane_size * 3;
i++)
932 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
933 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
934 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
939 rbase = isRgb ? bpp - 5 : 0;
941 bbase = isRgb ? 0 : (bpp - 5);
943 y_table16 =
c->yuvTable;
945 for (
i = 0;
i < table_plane_size;
i++) {
947 y_table16[
i] = (yval >> 3) << rbase;
948 y_table16[
i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
949 y_table16[
i + 2*table_plane_size] = (yval >> 3) << bbase;
953 for (
i = 0;
i < table_plane_size * 3;
i++)
955 fill_table(
c->table_rV, 2, crv, y_table16 + yoffs);
956 fill_table(
c->table_gU, 2, cgu, y_table16 + yoffs + table_plane_size);
957 fill_table(
c->table_bU, 2, cbu, y_table16 + yoffs + 2*table_plane_size);
963 y_table =
c->yuvTable;
965 for (
i = 0;
i < table_plane_size;
i++) {
975 rbase = isRgb ? 20 : 0;
977 bbase = isRgb ? 0 : 20;
978 needAlpha = CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat);
982 y_table32 =
c->yuvTable;
984 for (
i = 0;
i < table_plane_size;
i++) {
986 y_table32[
i]= (yval << rbase) + (needAlpha ? 0 : (255
u << abase));
987 y_table32[
i + table_plane_size] = yval << gbase;
988 y_table32[
i + 2 * table_plane_size] = yval << bbase;
992 for (
i = 0;
i < table_plane_size * 3;
i++)
995 fill_table(
c->table_rV, 4, crv, y_table32 + yoffs);
996 fill_table(
c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
997 fill_table(
c->table_bU, 4, cbu, y_table32 + yoffs + 2 * table_plane_size);
1004 rbase =
base + (isRgb ? 16 : 0);
1006 bbase =
base + (isRgb ? 0 : 16);
1007 needAlpha = CONFIG_SWSCALE_ALPHA &&
isALPHA(
c->srcFormat);
1009 abase = (
base + 24) & 31;
1011 y_table32 =
c->yuvTable;
1013 for (
i = 0;
i < table_plane_size;
i++) {
1015 y_table32[
i] = (yval << rbase) +
1016 (needAlpha ? 0 : (255
u << abase));
1017 y_table32[
i + table_plane_size] = yval << gbase;
1018 y_table32[
i + 2*table_plane_size] = yval << bbase;
1021 fill_table(
c->table_rV, 4, crv, y_table32 + yoffs);
1022 fill_table(
c->table_gU, 4, cgu, y_table32 + yoffs + table_plane_size);
1023 fill_table(
c->table_bU, 4, cbu, y_table32 + yoffs + 2*table_plane_size);
1027 if(!
isPlanar(
c->dstFormat) || bpp <= 24)