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) \ 299 PUTRGBA(dst_2, py_2, pa_2, 1, 24);
300 PUTRGBA(dst_1, py_1, pa_1, 1, 24);
305 PUTRGBA(dst_1, py_1, pa_1, 0, 24);
306 PUTRGBA(dst_2, py_2, pa_2, 0, 24);
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);
323 PUTRGBA(dst_1, py_1, pa_1, 2, 0);
324 PUTRGBA(dst_2, py_2, pa_2, 2, 0);
327 PUTRGBA(dst_2, py_2, pa_2, 3, 0);
328 PUTRGBA(dst_1, py_1, pa_1, 3, 0);
333 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
334 PUTRGBA(dst_2, py_2, pa_2, 0, 0);
337 PUTRGBA(dst_2, py_2, pa_2, 1, 0);
338 PUTRGBA(dst_1, py_1, pa_1, 1, 0);
343 PUTRGBA(dst_1, py_1, pa_1, 0, 0);
344 PUTRGBA(dst_2, py_2, pa_2, 0, 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]] + \ 501 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
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]] + \ 517 PUTRGB8(dst_2, py_2, 0, 0 + 8);
520 PUTRGB8(dst_2, py_2, 1, 2 + 8);
525 PUTRGB8(dst_2, py_2, 2, 4 + 8);
528 PUTRGB8(dst_2, py_2, 3, 6 + 8);
536 PUTRGB8(dst_2, py_2, 0, 0 + 8);
539 PUTRGB8(dst_2, py_2, 1, 2 + 8);
547 PUTRGB8(dst_2, py_2, 0, 0 + 8);
552 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
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; \ 605 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
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]] + \ 652 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
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]]; 664 PUTRGB1(out_2, py_2, 0, 0 + 8);
666 PUTRGB1(out_2, py_2, 1, 2 + 8);
670 PUTRGB1(out_2, py_2, 2, 4 + 8);
672 PUTRGB1(out_2, py_2, 3, 6 + 8);
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;
737 static void fill_table(uint8_t*
table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
738 const int64_t inc,
void *y_tab)
741 uint8_t *y_table = y_tab;
743 y_table -= elemsize * (inc >> 9);
746 int64_t
cb = av_clip_uint8(i-YUVRGB_TABLE_HEADROOM)*inc;
747 table[
i] = y_table + elemsize * (cb >> 16);
751 static void fill_gv_table(
int table[256 + 2*YUVRGB_TABLE_HEADROOM],
const int elemsize,
const int64_t inc)
754 int off = -(inc >> 9);
757 int64_t
cb = av_clip_uint8(i-YUVRGB_TABLE_HEADROOM)*inc;
758 table[
i] = elemsize * (off + (cb >> 16));
764 int r = (f + (1 << 15)) >> 16;
775 int fullRange,
int brightness,
776 int contrast,
int saturation)
806 int64_t crv = inv_table[0];
807 int64_t cbu = inv_table[1];
808 int64_t cgu = -inv_table[2];
809 int64_t cgv = -inv_table[3];
810 int64_t cy = 1 << 16;
815 cy = (cy * 255) / 219;
818 crv = (crv * 224) / 255;
819 cbu = (cbu * 224) / 255;
820 cgu = (cgu * 224) / 255;
821 cgv = (cgv * 224) / 255;
824 cy = (cy * contrast) >> 16;
825 crv = (crv * contrast * saturation) >> 32;
826 cbu = (cbu * contrast * saturation) >> 32;
827 cgu = (cgu * contrast * saturation) >> 32;
828 cgv = (cgv * contrast * saturation) >> 32;
829 oy -= 256 * brightness;
831 c->
uOffset = 0x0400040004000400LL;
832 c->
vOffset = 0x0400040004000400LL;
848 crv = ((crv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
849 cbu = ((cbu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
850 cgu = ((cgu * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
851 cgv = ((cgv * (1 << 16)) + 0x8000) /
FFMAX(cy, 1);
855 #define ALLOC_YUV_TABLE(x) \ 856 c->yuvTable = av_malloc(x); \ 858 return AVERROR(ENOMEM); 864 for (i = 0; i < table_plane_size - 110; i++) {
865 y_table[i + 110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
873 rbase = isRgb ? 3 : 0;
875 bbase = isRgb ? 0 : 3;
879 for (i = 0; i < table_plane_size - 110; i++) {
880 int yval = av_clip_uint8((yb + 0x8000) >> 16);
881 y_table[i + 110] = (yval >> 7) << rbase;
882 y_table[i + 37 + table_plane_size] = ((yval + 43) / 85) << gbase;
883 y_table[i + 110 + 2*table_plane_size] = (yval >> 7) << bbase;
892 rbase = isRgb ? 5 : 0;
893 gbase = isRgb ? 2 : 3;
894 bbase = isRgb ? 0 : 6;
898 for (i = 0; i < table_plane_size - 38; i++) {
899 int yval = av_clip_uint8((yb + 0x8000) >> 16);
900 y_table[i + 16] = ((yval + 18) / 36) << rbase;
901 y_table[i + 16 + table_plane_size] = ((yval + 18) / 36) << gbase;
902 y_table[i + 37 + 2*table_plane_size] = ((yval + 43) / 85) << bbase;
911 rbase = isRgb ? 8 : 0;
913 bbase = isRgb ? 0 : 8;
917 for (i = 0; i < table_plane_size; i++) {
918 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
919 y_table16[
i] = (yval >> 4) << rbase;
920 y_table16[i + table_plane_size] = (yval >> 4) << gbase;
921 y_table16[i + 2*table_plane_size] = (yval >> 4) << bbase;
925 for (i = 0; i < table_plane_size * 3; i++)
934 rbase = isRgb ? bpp - 5 : 0;
936 bbase = isRgb ? 0 : (bpp - 5);
940 for (i = 0; i < table_plane_size; i++) {
941 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
942 y_table16[
i] = (yval >> 3) << rbase;
943 y_table16[i + table_plane_size] = (yval >> (18 - bpp)) << gbase;
944 y_table16[i + 2*table_plane_size] = (yval >> 3) << bbase;
948 for (i = 0; i < table_plane_size * 3; i++)
960 for (i = 0; i < table_plane_size; i++) {
961 y_table[
i] = av_clip_uint8((yb + 0x8000) >> 16);
979 for (i = 0; i < table_plane_size; i++) {
980 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
981 y_table32[
i]= (yval << rbase) + (needAlpha ? 0 : (255
u << abase));
982 y_table32[i + table_plane_size] = yval << gbase;
983 y_table32[i + 2 * table_plane_size] = yval << bbase;
987 for (i = 0; i < table_plane_size * 3; i++)
999 rbase = base + (isRgb ? 16 : 0);
1001 bbase = base + (isRgb ? 0 : 16);
1004 abase = (base + 24) & 31;
1008 for (i = 0; i < table_plane_size; i++) {
1009 unsigned yval = av_clip_uint8((yb + 0x8000) >> 16);
1010 y_table32[
i] = (yval << rbase) +
1011 (needAlpha ? 0 : (255
u << abase));
1012 y_table32[i + table_plane_size] = yval << gbase;
1013 y_table32[i + 2*table_plane_size] = yval << bbase;
#define YUVRGB_TABLE_HEADROOM
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
const uint8_t ff_dither_2x2_8[][8]
av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
uint8_t * table_bU[256+2 *YUVRGB_TABLE_HEADROOM]
int dstFormatBpp
Number of bits per pixel of the destination pixel format.
#define ALLOC_YUV_TABLE(x)
#define PUTRGB15(dst, src, i, o)
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), big-endian, X=unused/undefined
#define PUTBGR24(dst, src, i)
#define AV_PIX_FMT_RGB444
const uint8_t ff_dither_8x8_220[][8]
packed RGB 1:2:1 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in ...
static void fill_table(uint8_t *table[256+2 *YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc, void *y_tab)
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
const uint8_t ff_dither_8x8_32[][8]
#define PUTRGB(dst, src, i)
static double cb(void *priv, double x, double y)
const uint8_t ff_dither_2x2_4[][8]
const uint8_t ff_dither_4x4_16[][8]
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static void fill_gv_table(int table[256+2 *YUVRGB_TABLE_HEADROOM], const int elemsize, const int64_t inc)
packed RGB 4:4:4, 16bpp, (msb)4X 4R 4G 4B(lsb), little-endian, X=unused/undefined ...
#define u(width, name, range_min, range_max)
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
#define PUTRGB16(dst, src, i, o)
enum AVPixelFormat dstFormat
Destination pixel format.
uint8_t * table_gU[256+2 *YUVRGB_TABLE_HEADROOM]
#define PUTRGBA(dst, ysrc, asrc, i, s)
static const uint16_t table[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_NE(be, le)
const int32_t ff_yuv2rgb_coeffs[11][4]
#define PUTBGR48(dst, src, i)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
#define YUVRGB_TABLE_LUMA_HEADROOM
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define YUV2RGBFUNC(func_name, dst_type, alpha)
static uint16_t roundToInt16(int64_t f)
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
int table_gV[256+2 *YUVRGB_TABLE_HEADROOM]
const int * sws_getCoefficients(int colorspace)
Return a pointer to yuv<->rgb coefficients for the given colorspace suitable for sws_setColorspaceDet...
packed RGB 8:8:8, 24bpp, BGRBGR...
uint8_t * table_rV[256+2 *YUVRGB_TABLE_HEADROOM]
#define PUTRGB4D(dst, src, i, o)
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_BGR555
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
#define CLOSEYUV2RGBFUNC(dst_delta)
SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
#define PUTRGB12(dst, src, i, o)
const uint8_t ff_dither_8x8_73[][8]
#define ENDYUV2RGBLINE(dst_delta, ss)
#define AV_PIX_FMT_BGR565
av_cold SwsFunc ff_yuv2rgb_init_ppc(SwsContext *c)
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
#define PUTRGB48(dst, src, i)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
#define PUTRGB4DB(dst, src, i, o)
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
#define PUTRGB8(dst, src, i, o)
#define AV_PIX_FMT_BGR444
enum AVPixelFormat srcFormat
Source pixel format.
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
#define AV_PIX_FMT_RGB555
#define PUTRGB1(out, src, i, o)
#define AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB565
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
#define PUTRGB24(dst, src, i)