Possible bug in FX hypot() function

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Matjaz.Kljun
Posts: 1
Joined: 2019-07-03T00:27:59-07:00
Authentication code: 1152

Possible bug in FX hypot() function

Post by Matjaz.Kljun »

If I try to reproduce Anthony Thyssen example from page:

https://imagemagick.org/Usage/canvas/#gradient_complex

Code: Select all

magick -size 100x100 xc: +size xc:red xc:yellow -colorspace RGB ^
          -fx "ar=hypot( i/w-.8, j/h-.3 )*4; br=hypot( i/w-.3, j/h-.7 )*4; u[1]*br/(ar+br) + u[2]*ar/(ar+br)" ^
          -colorspace sRGB gradient_dist_ratio.gif
I get image with two extra vertical lines:

Image

Command is run on Windows 7. IM version used is from release ImageMagick-7.0.8-51-portable-Q16-x64.zip.

On the other hand if the same command is run with the older version of IM ImageMagick-7.0.7-9-portable-Q16-x64.zip image produced is without extra lines:

Image

The same command modified only with slightly bigger canvas size of “-size 101x101” also produce the image without extra lines. Something must be wrong in -fx expression calculation!

If the hypot() function is properly replaced with sqrt() function in -fx expresion, the produced image is without extra lines in old and also in new IM version.

After some debugging of hypot() function it looks like result is wrong when first argument is zero (0):

Code: Select all

$ magick -size 3x3 xc: -channel red -fx "aa=i; bb=j; Fhypot=hypot(aa,bb); Fsqrt=sqrt(aa*aa+bb*bb); debug(aa); debug(bb); debug(Fhypot); debug(Fsqrt)" null:
[0,0].red: aa=0
[0,0].red: bb=0
[0,0].red: Fhypot=0
[0,0].red: Fsqrt=0
[1,0].red: aa=1
[1,0].red: bb=0
[1,0].red: Fhypot=1
[1,0].red: Fsqrt=1
[2,0].red: aa=2
[2,0].red: bb=0
[2,0].red: Fhypot=2
[2,0].red: Fsqrt=2
[0,1].red: aa=0
[0,1].red: bb=1
[0,1].red: [color=#FF0000]Fhypot=0[/color]
[0,1].red: [color=#00BF00]Fsqrt=1[/color]
[1,1].red: aa=1
[1,1].red: bb=1
[1,1].red: Fhypot=1.41421
[1,1].red: Fsqrt=1.41421
[2,1].red: aa=2
[2,1].red: bb=1
[2,1].red: Fhypot=2.23607
[2,1].red: Fsqrt=2.23607
[0,2].red: aa=0
[0,2].red: bb=2
[0,2].red: [color=#FF0000]Fhypot=0[/color]
[0,2].red: [color=#00BF00]Fsqrt=2[/color]
[1,2].red: aa=1
[1,2].red: bb=2
[1,2].red: Fhypot=2.23607
[1,2].red: Fsqrt=2.23607
[2,2].red: aa=2
This is possible bug or I miss something obvious.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug in FX hypot() function

Post by snibgo »

Here is a simple test:

Code: Select all

magick xc: -fx "hypot(0.3,0.4)" txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (32767.5,32767.5,32767.5)  #800080008000  srgb(50%,50%,50%)

magick xc: -fx "hypot(0,0.4)" txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (26214,26214,26214)  #666666666666  grey40

magick xc: -fx "hypot(0.4,0)" txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (26214,26214,26214)  #666666666666  grey40
In v7.0.7-28, the results are correct. There may be a more recent bug.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug in FX hypot() function

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
Post Reply