diff options
author | Ronald S. Bultje <rsbultje@gmail.com> | 2012-03-07 02:35:24 +0400 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2012-03-07 21:35:46 +0400 |
commit | 9487fb4dea3498eb4711eb023f43199f68701b1e (patch) | |
tree | a18b1e4f9ad30b3bbd172fccf91de27fab5e11c8 /libswscale | |
parent | a93b572ae4f517ce0c35cf085167c318e9215908 (diff) |
swscale: clip unscaled output intermediates.
Fixes bug 240, as well as several integer overflows (visible as glitches)
in other scaling output routines, e.g. YUV422.
Diffstat (limited to 'libswscale')
-rw-r--r-- | libswscale/output.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libswscale/output.c b/libswscale/output.c index 8263da1f5e..533fcd945d 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -511,6 +511,11 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + output_pixels(i * 4, Y1, U, Y2, V); } } @@ -531,6 +536,11 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, int U = ubuf0[i] >> 7; int V = vbuf0[i] >> 7; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + output_pixels(i * 4, Y1, U, Y2, V); } } else { @@ -541,6 +551,11 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, int U = (ubuf0[i] + ubuf1[i]) >> 8; int V = (vbuf0[i] + vbuf1[i]) >> 8; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + output_pixels(i * 4, Y1, U, Y2, V); } } @@ -990,9 +1005,16 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], *g = (c->table_gU[U] + c->table_gV[V]), *b = c->table_bU[U]; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + if (hasAlpha) { A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19; A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19; + A1 = av_clip_uint8(A1); + A2 = av_clip_uint8(A2); } yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, @@ -1021,9 +1043,16 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, *g = (c->table_gU[U] + c->table_gV[V]), *b = c->table_bU[U]; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + if (hasAlpha) { A1 = abuf0[i * 2 ] >> 7; A2 = abuf0[i * 2 + 1] >> 7; + A1 = av_clip_uint8(A1); + A2 = av_clip_uint8(A2); } yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, @@ -1041,9 +1070,16 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, *g = (c->table_gU[U] + c->table_gV[V]), *b = c->table_bU[U]; + Y1 = av_clip_uint8(Y1); + Y2 = av_clip_uint8(Y2); + U = av_clip_uint8(U); + V = av_clip_uint8(V); + if (hasAlpha) { A1 = abuf0[i * 2 ] >> 7; A2 = abuf0[i * 2 + 1] >> 7; + A1 = av_clip_uint8(A1); + A2 = av_clip_uint8(A2); } yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, |