From 329dd528ab79531d884c0ba131e97d43f872ab5d Mon Sep 17 00:00:00 2001 From: ruc_zhangxiaohui <553441439@qq.com> Date: Thu, 4 Feb 2021 04:19:08 +0800 Subject: [PATCH] uses the PerceptibleReciprocal() to prevent the divide-by-zero from occurring (#3194) Co-authored-by: Zhang Xiaohui --- MagickCore/visual-effects.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MagickCore/visual-effects.c b/MagickCore/visual-effects.c index af8ce735e06..0b75e686540 100644 --- a/MagickCore/visual-effects.c +++ b/MagickCore/visual-effects.c @@ -1005,11 +1005,11 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount, center.y=0.5*canvas_image->rows; radius=center.x; if (canvas_image->columns > canvas_image->rows) - scale.y=(double) canvas_image->columns/(double) canvas_image->rows; + scale.y=(double) canvas_image->columns*PerceptibleReciprocal((double) canvas_image->rows); else if (canvas_image->columns < canvas_image->rows) { - scale.x=(double) canvas_image->rows/(double) canvas_image->columns; + scale.x=(double) canvas_image->rows*PerceptibleReciprocal((double) canvas_image->columns); radius=center.y; } /* @@ -1085,10 +1085,10 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount, */ factor=1.0; if (distance > 0.0) - factor=pow(sin(MagickPI*sqrt((double) distance)/radius/2),-amount); + factor=pow(sin(MagickPI*sqrt((double) distance)*PerceptibleReciprocal(radius)/2),-amount); status=InterpolatePixelChannels(canvas_image,interpolate_view, - implode_image,method,(double) (factor*delta.x/scale.x+center.x), - (double) (factor*delta.y/scale.y+center.y),q,exception); + implode_image,method,(double) (factor*delta.x*PerceptibleReciprocal(scale.x)+center.x), + (double) (factor*delta.y*PerceptibleReciprocal(scale.y)+center.y),q,exception); if (status == MagickFalse) break; }