From 1ca7dc60d2f2cac8fce1bdb53d3d5bae195161b0 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 12 Feb 2012 15:47:14 -0800 Subject: swscale: fix invalid memory accesses in yuvpacked1() functions. --- libswscale/output.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index 93a6a03061..5b2ba37993 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -629,20 +629,20 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, const int16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int y, enum PixelFormat target) { - const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], - *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; + const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0]; int i; if (uvalpha < 2048) { for (i = 0; i < (dstW >> 1); i++) { int Y1 = buf0[i * 2] >> 7; int Y2 = buf0[i * 2 + 1] >> 7; - int U = ubuf1[i] >> 7; - int V = vbuf1[i] >> 7; + int U = ubuf0[i] >> 7; + int V = vbuf0[i] >> 7; output_pixels(i * 4, Y1, U, Y2, V); } } else { + const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; for (i = 0; i < (dstW >> 1); i++) { int Y1 = buf0[i * 2] >> 7; int Y2 = buf0[i * 2 + 1] >> 7; @@ -775,8 +775,7 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, const int32_t *abuf0, uint16_t *dest, int dstW, int uvalpha, int y, enum PixelFormat target) { - const int32_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], - *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; + const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0]; int i; if (uvalpha < 2048) { @@ -807,6 +806,7 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, dest += 6; } } else { + const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; for (i = 0; i < (dstW >> 1); i++) { int Y1 = (buf0[i * 2] ) >> 2; int Y2 = (buf0[i * 2 + 1]) >> 2; @@ -1070,16 +1070,15 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, int uvalpha, int y, enum PixelFormat target, int hasAlpha) { - const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], - *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; + const int16_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0]; int i; if (uvalpha < 2048) { for (i = 0; i < (dstW >> 1); i++) { int Y1 = buf0[i * 2] >> 7; int Y2 = buf0[i * 2 + 1] >> 7; - int U = ubuf1[i] >> 7; - int V = vbuf1[i] >> 7; + int U = ubuf0[i] >> 7; + int V = vbuf0[i] >> 7; int A1, A2; const void *r = c->table_rV[V], *g = (c->table_gU[U] + c->table_gV[V]), @@ -1094,6 +1093,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, r, g, b, y, target, hasAlpha); } } else { + const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; for (i = 0; i < (dstW >> 1); i++) { int Y1 = buf0[i * 2] >> 7; int Y2 = buf0[i * 2 + 1] >> 7; -- cgit v1.2.3 From d63b7d8c37e6d18c36d6e95f76efd934beb704c0 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 12 Feb 2012 15:55:44 -0800 Subject: swscale: fix incorrect chroma bias in yuv2rgb48_1_c(). --- libswscale/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index 5b2ba37993..a70cf1fc7c 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -810,8 +810,8 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, for (i = 0; i < (dstW >> 1); i++) { int Y1 = (buf0[i * 2] ) >> 2; int Y2 = (buf0[i * 2 + 1]) >> 2; - int U = (ubuf0[i] + ubuf1[i] + (-128 << 11)) >> 3; - int V = (vbuf0[i] + vbuf1[i] + (-128 << 11)) >> 3; + int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3; + int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3; int R, G, B; Y1 -= c->yuv2rgb_y_offset; -- cgit v1.2.3 From c0b87359b29ae1267902c41f2576a1c0ca32849f Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 12 Feb 2012 17:07:09 -0800 Subject: swscale: handle gray16 as a "planar" YUV format (Y-only, of course). This allows removing any gray16-specific code, which is essentially identical to the per-plane code in yuv2plane*(). --- libswscale/output.c | 87 ----------------------------------------------------- 1 file changed, 87 deletions(-) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index a70cf1fc7c..d24bb9e9c7 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -295,80 +295,6 @@ static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterS } } -#define output_pixel(pos, val) \ - if (target == PIX_FMT_GRAY16BE) { \ - AV_WB16(pos, val); \ - } else { \ - AV_WL16(pos, val); \ - } - -static av_always_inline void -yuv2gray16_X_c_template(SwsContext *c, const int16_t *lumFilter, - const int32_t **lumSrc, int lumFilterSize, - const int16_t *chrFilter, const int32_t **chrUSrc, - const int32_t **chrVSrc, int chrFilterSize, - const int32_t **alpSrc, uint16_t *dest, int dstW, - int y, enum PixelFormat target) -{ - int i; - - for (i = 0; i < (dstW >> 1); i++) { - int j; - int Y1 = (1 << 14) - 0x40000000; - int Y2 = (1 << 14) - 0x40000000; - - for (j = 0; j < lumFilterSize; j++) { - Y1 += lumSrc[j][i * 2] * lumFilter[j]; - Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; - } - Y1 >>= 15; - Y2 >>= 15; - Y1 = av_clip_int16(Y1); - Y2 = av_clip_int16(Y2); - output_pixel(&dest[i * 2 + 0], 0x8000 + Y1); - output_pixel(&dest[i * 2 + 1], 0x8000 + Y2); - } -} - -static av_always_inline void -yuv2gray16_2_c_template(SwsContext *c, const int32_t *buf[2], - const int32_t *ubuf[2], const int32_t *vbuf[2], - const int32_t *abuf[2], uint16_t *dest, int dstW, - int yalpha, int uvalpha, int y, - enum PixelFormat target) -{ - int yalpha1 = 4095 - yalpha; - int i; - const int32_t *buf0 = buf[0], *buf1 = buf[1]; - - for (i = 0; i < (dstW >> 1); i++) { - int Y1 = (buf0[i * 2 ] * yalpha1 + buf1[i * 2 ] * yalpha) >> 15; - int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 15; - - output_pixel(&dest[i * 2 + 0], Y1); - output_pixel(&dest[i * 2 + 1], Y2); - } -} - -static av_always_inline void -yuv2gray16_1_c_template(SwsContext *c, const int32_t *buf0, - const int32_t *ubuf[2], const int32_t *vbuf[2], - const int32_t *abuf0, uint16_t *dest, int dstW, - int uvalpha, int y, enum PixelFormat target) -{ - int i; - - for (i = 0; i < (dstW >> 1); i++) { - int Y1 = buf0[i * 2 ] << 1; - int Y2 = buf0[i * 2 + 1] << 1; - - output_pixel(&dest[i * 2 + 0], Y1); - output_pixel(&dest[i * 2 + 1], Y2); - } -} - -#undef output_pixel - #define YUV2PACKED16WRAPPER(name, base, ext, fmt) \ static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ const int16_t **_lumSrc, int lumFilterSize, \ @@ -415,9 +341,6 @@ static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \ dstW, uvalpha, y, fmt); \ } -YUV2PACKED16WRAPPER(yuv2gray16,, LE, PIX_FMT_GRAY16LE) -YUV2PACKED16WRAPPER(yuv2gray16,, BE, PIX_FMT_GRAY16BE) - #define output_pixel(pos, acc) \ if (target == PIX_FMT_MONOBLACK) { \ pos = acc; \ @@ -1490,16 +1413,6 @@ void ff_sws_init_output_funcs(SwsContext *c, } } switch (dstFormat) { - case PIX_FMT_GRAY16BE: - *yuv2packed1 = yuv2gray16BE_1_c; - *yuv2packed2 = yuv2gray16BE_2_c; - *yuv2packedX = yuv2gray16BE_X_c; - break; - case PIX_FMT_GRAY16LE: - *yuv2packed1 = yuv2gray16LE_1_c; - *yuv2packed2 = yuv2gray16LE_2_c; - *yuv2packedX = yuv2gray16LE_X_c; - break; case PIX_FMT_MONOWHITE: *yuv2packed1 = yuv2monowhite_1_c; *yuv2packed2 = yuv2monowhite_2_c; -- cgit v1.2.3 From 3cac47565507dba4eb5c21ab70e4950521fa6e71 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 12 Feb 2012 17:10:32 -0800 Subject: swscale: move YUV2PACKED16WRAPPER() macro down to where it is used. --- libswscale/output.c | 92 ++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index d24bb9e9c7..39d39c79cc 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -295,52 +295,6 @@ static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterS } } -#define YUV2PACKED16WRAPPER(name, base, ext, fmt) \ -static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ - const int16_t **_lumSrc, int lumFilterSize, \ - const int16_t *chrFilter, const int16_t **_chrUSrc, \ - const int16_t **_chrVSrc, int chrFilterSize, \ - const int16_t **_alpSrc, uint8_t *_dest, int dstW, \ - int y) \ -{ \ - const int32_t **lumSrc = (const int32_t **) _lumSrc, \ - **chrUSrc = (const int32_t **) _chrUSrc, \ - **chrVSrc = (const int32_t **) _chrVSrc, \ - **alpSrc = (const int32_t **) _alpSrc; \ - uint16_t *dest = (uint16_t *) _dest; \ - name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \ - chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ - alpSrc, dest, dstW, y, fmt); \ -} \ - \ -static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \ - const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ - const int16_t *_abuf[2], uint8_t *_dest, int dstW, \ - int yalpha, int uvalpha, int y) \ -{ \ - const int32_t **buf = (const int32_t **) _buf, \ - **ubuf = (const int32_t **) _ubuf, \ - **vbuf = (const int32_t **) _vbuf, \ - **abuf = (const int32_t **) _abuf; \ - uint16_t *dest = (uint16_t *) _dest; \ - name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \ - dest, dstW, yalpha, uvalpha, y, fmt); \ -} \ - \ -static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \ - const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ - const int16_t *_abuf0, uint8_t *_dest, int dstW, \ - int uvalpha, int y) \ -{ \ - const int32_t *buf0 = (const int32_t *) _buf0, \ - **ubuf = (const int32_t **) _ubuf, \ - **vbuf = (const int32_t **) _vbuf, \ - *abuf0 = (const int32_t *) _abuf0; \ - uint16_t *dest = (uint16_t *) _dest; \ - name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \ - dstW, uvalpha, y, fmt); \ -} - #define output_pixel(pos, acc) \ if (target == PIX_FMT_MONOBLACK) { \ pos = acc; \ @@ -763,6 +717,52 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, #undef r_b #undef b_r +#define YUV2PACKED16WRAPPER(name, base, ext, fmt) \ +static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ + const int16_t **_lumSrc, int lumFilterSize, \ + const int16_t *chrFilter, const int16_t **_chrUSrc, \ + const int16_t **_chrVSrc, int chrFilterSize, \ + const int16_t **_alpSrc, uint8_t *_dest, int dstW, \ + int y) \ +{ \ + const int32_t **lumSrc = (const int32_t **) _lumSrc, \ + **chrUSrc = (const int32_t **) _chrUSrc, \ + **chrVSrc = (const int32_t **) _chrVSrc, \ + **alpSrc = (const int32_t **) _alpSrc; \ + uint16_t *dest = (uint16_t *) _dest; \ + name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \ + chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ + alpSrc, dest, dstW, y, fmt); \ +} \ + \ +static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \ + const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ + const int16_t *_abuf[2], uint8_t *_dest, int dstW, \ + int yalpha, int uvalpha, int y) \ +{ \ + const int32_t **buf = (const int32_t **) _buf, \ + **ubuf = (const int32_t **) _ubuf, \ + **vbuf = (const int32_t **) _vbuf, \ + **abuf = (const int32_t **) _abuf; \ + uint16_t *dest = (uint16_t *) _dest; \ + name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \ + dest, dstW, yalpha, uvalpha, y, fmt); \ +} \ + \ +static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \ + const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ + const int16_t *_abuf0, uint8_t *_dest, int dstW, \ + int uvalpha, int y) \ +{ \ + const int32_t *buf0 = (const int32_t *) _buf0, \ + **ubuf = (const int32_t **) _ubuf, \ + **vbuf = (const int32_t **) _vbuf, \ + *abuf0 = (const int32_t *) _abuf0; \ + uint16_t *dest = (uint16_t *) _dest; \ + name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \ + dstW, uvalpha, y, fmt); \ +} + YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE) YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE) YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE) -- cgit v1.2.3 From 7331b6e718243c276d391898199e08ba3cdb9545 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 10 Feb 2012 15:13:32 +0100 Subject: Drop some completely unnecessary av_unused attributes. --- libswscale/output.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libswscale/output.c') diff --git a/libswscale/output.c b/libswscale/output.c index 39d39c79cc..b29018f2bb 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -899,12 +899,11 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter, int i; for (i = 0; i < (dstW >> 1); i++) { - int j; + int j, A1, A2; int Y1 = 1 << 18; int Y2 = 1 << 18; int U = 1 << 18; int V = 1 << 18; - int av_unused A1, A2; const void *r, *g, *b; for (j = 0; j < lumFilterSize; j++) { @@ -1106,8 +1105,7 @@ yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter, int Y = 0; int U = -128 << 19; int V = -128 << 19; - int av_unused A; - int R, G, B; + int R, G, B, A; for (j = 0; j < lumFilterSize; j++) { Y += lumSrc[j][i] * lumFilter[j]; -- cgit v1.2.3