-complex with alpha

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

-complex with alpha

Post by snibgo »

Version: v6.9.5-3, Q32 HDRI built with Cygwin, on Windows 8.1.

Complex arithmetic on the alpha channel is wrong.

For example, create four images:

Code: Select all

%IMDEV%convert xc:rgba(10%%,11%%,12%%,0.5) r1.png
%IMDEV%convert xc:rgba(10%%,11%%,12%%) i1.png

%IMDEV%convert xc:rgba(20%%,21%%,22%%,0.1) r2.png
%IMDEV%convert xc:rgba(20%%,21%%,22%%) i2.png
Images r1 and r2 have transparency.

If we add them with ordinary (non-complex) arithmetic ...

Code: Select all

%IMDEV%convert ^
  r1.png r2.png ^
  -channel RGBA ^
  -compose Plus -composite ^
  +channel ^
  txt:

Code: Select all

# ImageMagick pixel enumeration: 1,1,4294967295,srgba
0,0: (1.28852e+09,1.37438e+09,1.4603e+09,2.57705e+09)  #4CCD51EB570A999A  srgba(30.0008%,31.9997%,34.0002%,0.600015)
... the resulting alpha is 0.5 + 0.1 = 0.600015. This is correct (or near enough).

But if we add them with complex arithmetic ...

Code: Select all

%IMDEV%convert ^
  r1.png i1.png r2.png i2.png ^
  -complex Add ^
  txt:

Code: Select all

# ImageMagick pixel enumeration: 1,1,4294967295,srgba
0,0: (1.28852e+09,1.37438e+09,1.4603e+09,-1.71792e+09)  #4CCD4CCD51EB51EB570A570A00000000  srgba(30.0008%,31.9997%,34.0002%,-0.399985)
# ImageMagick pixel enumeration: 1,1,4294967295,srgba
0,0: (1.28852e+09,1.37438e+09,1.4603e+09,4.29497e+09)  #4CCD51EB570AFFFF  srgba(30.0008%,31.9997%,34.0002%,1)
... the resulting alpha is 0.5 + 0.1 = -0.399985. This is clearly wrong.

Similar problems occur with the other complex operators.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -complex with alpha

Post by magick »

We're using ImageMagick 7.0.3-6 Q16 HDRI. We get

Code: Select all

$ convert xc:'rgba(10%,11%,12%,0.5)' r1.png
$ convert xc:'rgba(10%,11%,12%,0.0)' i1.png
$ convert xc:'rgba(20%,21%,22%,0.1)' r2.png
$ convert xc:'rgba(20%,21%,22%,0.0)' i2.png
$ convert r1.png r2.png -channel RGBA -compose Plus -composite +channel txt:
$ convert r1.png i1.png r2.png i2.png -complex Add txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (4587.85,4980.86,5373.97,39322)  #11EC137514FE999A  srgba(7.00061%,7.60031%,8.20015%,0.600015)
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (19661,20971,22282,39322)  #4CCD51EB570A999A  srgba(30.0008%,31.9997%,34.0002%,0.600015)
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (19661,20971,22282,0)  #4CCD51EB570A0000  srgba(30.0008%,31.9997%,34.0002%,0)
We get similar results with 6.9.6-4, Q16 HDRI.
Post Reply