Possible bug in FX hypot() function
Posted: 2019-07-03T00:58:10-07:00
If I try to reproduce Anthony Thyssen example from page:
https://imagemagick.org/Usage/canvas/#gradient_complex
I get image with two extra vertical lines:
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:
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):
This is possible bug or I miss something obvious.
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
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:
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