[FFmpeg-devel] [PATCH 1/2] sws/yuv2rgb: avoid a few ub on signed left shifts

2016-02-26 Thread Clément Bœsch
---
 libswscale/yuv2rgb.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c
index 3671fe3..9d79d79 100644
--- a/libswscale/yuv2rgb.c
+++ b/libswscale/yuv2rgb.c
@@ -824,18 +824,18 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const 
int inv_table[4],
 c->ugCoeff = roundToInt16(cgu * 8192) * 0x0001000100010001ULL;
 c->yOffset = roundToInt16(oy  *8) * 0x0001000100010001ULL;
 
-c->yuv2rgb_y_coeff   = (int16_t)roundToInt16(cy  << 13);
-c->yuv2rgb_y_offset  = (int16_t)roundToInt16(oy  <<  9);
-c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv << 13);
-c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv << 13);
-c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu << 13);
-c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu << 13);
+c->yuv2rgb_y_coeff   = (int16_t)roundToInt16(cy  * (1 << 13));
+c->yuv2rgb_y_offset  = (int16_t)roundToInt16(oy  * (1 <<  9));
+c->yuv2rgb_v2r_coeff = (int16_t)roundToInt16(crv * (1 << 13));
+c->yuv2rgb_v2g_coeff = (int16_t)roundToInt16(cgv * (1 << 13));
+c->yuv2rgb_u2g_coeff = (int16_t)roundToInt16(cgu * (1 << 13));
+c->yuv2rgb_u2b_coeff = (int16_t)roundToInt16(cbu * (1 << 13));
 
 //scale coefficients by cy
-crv = ((crv << 16) + 0x8000) / FFMAX(cy, 1);
-cbu = ((cbu << 16) + 0x8000) / FFMAX(cy, 1);
-cgu = ((cgu << 16) + 0x8000) / FFMAX(cy, 1);
-cgv = ((cgv << 16) + 0x8000) / FFMAX(cy, 1);
+crv = ((crv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
+cbu = ((cbu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
+cgu = ((cgu * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
+cgv = ((cgv * (1 << 16)) + 0x8000) / FFMAX(cy, 1);
 
 av_freep(&c->yuvTable);
 
-- 
2.7.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] sws/yuv2rgb: avoid a few ub on signed left shifts

2016-02-26 Thread Michael Niedermayer
On Fri, Feb 26, 2016 at 10:34:45PM +0100, Clément Bœsch wrote:
> ---
>  libswscale/yuv2rgb.c | 20 ++--
>  1 file changed, 10 insertions(+), 10 deletions(-)

LGTM

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] sws/yuv2rgb: avoid a few ub on signed left shifts

2016-02-27 Thread Clément Bœsch
On Sat, Feb 27, 2016 at 01:05:35AM +0100, Michael Niedermayer wrote:
> On Fri, Feb 26, 2016 at 10:34:45PM +0100, Clément Bœsch wrote:
> > ---
> >  libswscale/yuv2rgb.c | 20 ++--
> >  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> LGTM
> 
> thanks
> 

applied

-- 
Clément B.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel