From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 375FD44ABB for ; Wed, 2 Nov 2022 22:53:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BCDDE68BEDA; Thu, 3 Nov 2022 00:52:57 +0200 (EET) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9FF8068BD19 for ; Thu, 3 Nov 2022 00:52:51 +0200 (EET) Received: by mail-lj1-f176.google.com with SMTP id a15so160850ljb.7 for ; Wed, 02 Nov 2022 15:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=eED1tMjNDbt1h2to32IZGIG+eErfYeEL154eKBxt0P4=; b=dVpIiEGGWAr+v0FnMEVqWMJYmBr9Zw0barU9ZTyWG83R9PfLxtmso2t1rufg+JhPoV ptJYyenfTU9JGLBMu70girANbNjtSugK9jGxUqtynvz/ES4RAYOr97ISOtktknyub9Zm VFAOgRldJTYg+xUFD0qxoBllrESJbvQhhvL1Tnloa7AUXz5tcbyvsbU3sITRJ/+Nwe/w GBl6x/tW/Cd9ZIhlcWHlOg22NnnlLbSqSWzNzMRDF4DFYG19ya/o1r6kbpbxn82++cHL zIfJxTEdnOTFCEYXQzV/iqEgua27fPzrBdWe/0nKTMnmdXcVYWAmmYfTCYvHUoQmpOiJ TiQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eED1tMjNDbt1h2to32IZGIG+eErfYeEL154eKBxt0P4=; b=k3lBUjwxzzKNGJVpH7rVr/ws1y9T8fRZiSDLpfNpHsRgGz0VuWMojosZgSA84EumLM ReKmskQKcM2eX96vg8wCyAT/qFowzV12CMNW0tQ0VmK+lA8dPzQnMQ6adqCCL8ULOyLY kVrw531LTB2h/ZVawJLbkYRNgje4HEVB/Oww5nhiqnAtguKnqE+gRJnLcUZdz2MWC2Ez vVk5kjOQlSdg7CLrgIcmv+jCubwBUeu0S3eEbvuZ8u8Aa/9+0P3FbZDrL1nbK61vImGr 1p6BPsfUxyfiFe63oiEi2bD8PAUI6bvUKrjzxLoze6BORzxleiUQHeWNm2fv0IsCx6zu y2zQ== X-Gm-Message-State: ACrzQf0kY67sjL/Y7mzJU6LKZKam43eejZNfQHKo3XyTszXN5Kd3Ijnx cQm5ngIzICev7kXb+CbtThGqwiHe5sFRKwnI5XOiTIbFnvw= X-Google-Smtp-Source: AMsMyM79u1NdIz7sOsIPZJcukGAaE/d6I14pU/lnwsYEFzORrmLiRmHF/ubrp/JkUr1S4DRSLG1RayZ95kU0R+1+me8= X-Received: by 2002:a05:651c:1784:b0:26f:ed03:a1f7 with SMTP id bn4-20020a05651c178400b0026fed03a1f7mr10628959ljb.30.1667429569925; Wed, 02 Nov 2022 15:52:49 -0700 (PDT) MIME-Version: 1.0 References: <20221102210239.1689-1-michael@niedermayer.cc> <20221102210239.1689-2-michael@niedermayer.cc> In-Reply-To: <20221102210239.1689-2-michael@niedermayer.cc> From: Mark Reid Date: Wed, 2 Nov 2022 15:52:37 -0700 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH 2/2] swscale/output: Bias 16bps output calculations to improve non overflowing range for GBRP16/GBRPF32 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Wed, Nov 2, 2022 at 2:03 PM Michael Niedermayer wrote: > Fixes: integer overflow > Signed-off-by: Michael Niedermayer > --- > libswscale/output.c | 25 +++++++++++-------------- > libswscale/x86/output.asm | 16 +++++++++++++++- > 2 files changed, 26 insertions(+), 15 deletions(-) > > diff --git a/libswscale/output.c b/libswscale/output.c > index df4647adde..5c85bff971 100644 > --- a/libswscale/output.c > +++ b/libswscale/output.c > @@ -2372,18 +2372,15 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t > *lumFilter, > > Y -= c->yuv2rgb_y_offset; > Y *= c->yuv2rgb_y_coeff; > - Y += 1 << 13; > + Y += (1 << 13) - (1 << 29); > R = V * c->yuv2rgb_v2r_coeff; > G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; > B = U * c->yuv2rgb_u2b_coeff; > > - R = av_clip_uintp2(Y + R, 30); > - G = av_clip_uintp2(Y + G, 30); > - B = av_clip_uintp2(Y + B, 30); > + dest16[2][i] = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16); > + dest16[0][i] = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16); > + dest16[1][i] = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16); > > - dest16[0][i] = G >> 14; > - dest16[1][i] = B >> 14; > - dest16[2][i] = R >> 14; > if (hasAlpha) > dest16[3][i] = av_clip_uintp2(A, 30) >> 14; > } > @@ -2448,18 +2445,18 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t > *lumFilter, > > Y -= c->yuv2rgb_y_offset; > Y *= c->yuv2rgb_y_coeff; > - Y += 1 << 13; > + Y += (1 << 13) - (1 << 29); > R = V * c->yuv2rgb_v2r_coeff; > G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; > B = U * c->yuv2rgb_u2b_coeff; > > - R = av_clip_uintp2(Y + R, 30); > - G = av_clip_uintp2(Y + G, 30); > - B = av_clip_uintp2(Y + B, 30); > + R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16); > + G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16); > + B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16); > > - dest32[0][i] = av_float2int(float_mult * (float)(G >> 14)); > - dest32[1][i] = av_float2int(float_mult * (float)(B >> 14)); > - dest32[2][i] = av_float2int(float_mult * (float)(R >> 14)); > + dest32[0][i] = av_float2int(float_mult * (float)G); > + dest32[1][i] = av_float2int(float_mult * (float)B); > + dest32[2][i] = av_float2int(float_mult * (float)R); > if (hasAlpha) > dest32[3][i] = av_float2int(float_mult * > (float)(av_clip_uintp2(A, 30) >> 14)); > } > diff --git a/libswscale/x86/output.asm b/libswscale/x86/output.asm > index 84e94baaf6..f943a27534 100644 > --- a/libswscale/x86/output.asm > +++ b/libswscale/x86/output.asm > @@ -44,11 +44,13 @@ pd_yuv2gbrp_y_start: times 8 dd (1 << 9) > pd_yuv2gbrp_uv_start: times 8 dd ((1 << 9) - (128 << 19)) > pd_yuv2gbrp_a_start: times 8 dd (1 << 18) > pd_yuv2gbrp16_offset: times 8 dd 0x10000 ;(1 << 16) > -pd_yuv2gbrp16_round13: times 8 dd 0x02000 ;(1 << 13) > +pd_yuv2gbrp16_round13: times 8 dd 0xE0002000 ;(1 << 13) - (1 << 29) > pd_yuv2gbrp16_a_offset: times 8 dd 0x20002000 > pd_yuv2gbrp16_upper30: times 8 dd 0x3FFFFFFF ;(1<<30) - 1 > pd_yuv2gbrp16_upper27: times 8 dd 0x07FFFFFF ;(1<<27) - 1 > +pd_yuv2gbrp16_upper16: times 8 dd 0x0000FFFF ;(1<<16) - 1 > pd_yuv2gbrp16_upper16 doesn't appear to be used anywhere > pd_yuv2gbrp16_upperC: times 8 dd 0xC0000000 > +pd_yuv2gbrp_debias: times 8 dd 0x00008000 ;(1 << 29 - 14) > pb_pack_shuffle8: db 0, 4, 8, 12, \ > -1, -1, -1, -1, \ > -1, -1, -1, -1, \ > @@ -883,14 +885,26 @@ cglobal yuv2%1_full_X, 12, 14, 16, ptr, lumFilter, > lumSrcx, lumFilterSize, chrFi > paddd G, Y > paddd B, Y > > +%if DEPTH < 16 > CLIPP2 R, 30 > CLIPP2 G, 30 > CLIPP2 B, 30 > +%endif > > psrad R, RGB_SHIFT > psrad G, RGB_SHIFT > psrad B, RGB_SHIFT > > +%if DEPTH >= 16 > + paddd R, [pd_yuv2gbrp_debias] > + paddd G, [pd_yuv2gbrp_debias] > + paddd B, [pd_yuv2gbrp_debias] > + > + CLIPP2 R, 16 > + CLIPP2 G, 16 > + CLIPP2 B, 16 > +%endif > + > %if FLOAT > cvtdq2ps R, R > cvtdq2ps G, G > -- > 2.17.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".