diff mbox

[FFmpeg-devel] delogo will fail if interp is zero.

Message ID 1517369100-13756-1-git-send-email-bonderwu@gmail.com
State New
Headers show

Commit Message

wuxiaoyong Jan. 31, 2018, 3:25 a.m. UTC
With ROUNDED_DIV operation, if the first parameter is 0, it will
overflow and return a very large number, delogo will fail.
So, if it's zero, just set it to 1, it will not affect the result so
much.

Signed-off-by: wuxiaoyong <bonderwu@gmail.com>
---
 libavfilter/vf_delogo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Niedermayer Feb. 1, 2018, 9:25 p.m. UTC | #1
On Wed, Jan 31, 2018 at 11:25:00AM +0800, wuxiaoyong wrote:
> With ROUNDED_DIV operation, if the first parameter is 0, it will
> overflow and return a very large number, delogo will fail.
> So, if it's zero, just set it to 1, it will not affect the result so
> much.
> 
> Signed-off-by: wuxiaoyong <bonderwu@gmail.com>
> ---
>  libavfilter/vf_delogo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
> index 065d093..73ad6b9 100644
> --- a/libavfilter/vf_delogo.c
> +++ b/libavfilter/vf_delogo.c
> @@ -126,7 +126,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize,
>                   botleft[x-logo_x1-1]  +
>                   botleft[x-logo_x1+1]) * weightb;
>              weight = (weightl + weightr + weightt + weightb) * 3U;
> -            interp = ROUNDED_DIV(interp, weight);
> +            interp = ROUNDED_DIV(interp <= 0 ? 1 : interp, weight);
>  
>              if (y >= logo_y+band && y < logo_y+logo_h-band &&
>                  x >= logo_x+band && x < logo_x+logo_w-band) {

this is definitly not correct
ROUNDED_DIV expects signed values interp and weight are uint64_t 

you can fix ROUNDED_DIV so it works with unsigned values for example

[...]
diff mbox

Patch

diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c
index 065d093..73ad6b9 100644
--- a/libavfilter/vf_delogo.c
+++ b/libavfilter/vf_delogo.c
@@ -126,7 +126,7 @@  static void apply_delogo(uint8_t *dst, int dst_linesize,
                  botleft[x-logo_x1-1]  +
                  botleft[x-logo_x1+1]) * weightb;
             weight = (weightl + weightr + weightt + weightb) * 3U;
-            interp = ROUNDED_DIV(interp, weight);
+            interp = ROUNDED_DIV(interp <= 0 ? 1 : interp, weight);
 
             if (y >= logo_y+band && y < logo_y+logo_h-band &&
                 x >= logo_x+band && x < logo_x+logo_w-band) {