-compose Modulus

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

-compose Modulus

Post by snibgo »

Documentation at http://www.imagemagick.org/script/compose.php doesn't describe "-compose ModulusAdd" or "-compose ModulusSubtract" so I don't know exactly what these are supposed to do, but I think they are wrong for HDRI..

They do exactly the same as the "Add" and "Subtract" compose methods. If the "Add" result is > 100%, it subtracts 100%. If the "Subtract" result is < 0, it adds 100%.

So for integer IM, where the inputs must already be in the range 0 to 100%, the outputs will also be in that range. But this isn't true for HDRI. For floating-point, to ensure the output is in the range 0 to 100%, the subtraction or addition must be repeated until the test is true. And both tests (for > 100% or < 0) must be applied to both operations.

Examples:

Code: Select all

f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:gray(75%) xc:gray(65%) -compose ModulusAdd -composite txt:

# ImageMagick pixel enumeration: 1,1,4294967295,srgb
0,0: (40%,40%,40%)  #666666666666666666666666  grey40 <=== GOOD

f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:gray(175%) xc:gray(65%) -compose ModulusAdd -composite txt:

# ImageMagick pixel enumeration: 1,1,4294967295,srgb
0,0: (140%,140%,140%)  #FFFFFFFFFFFFFFFFFFFFFFFF  srgb(140%,140%,140%) <=== BAD

f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:gray(75%) xc:gray(65%) -compose ModulusSubtract -composite txt:

# ImageMagick pixel enumeration: 1,1,4294967295,srgb
0,0: (90%,90%,90%)  #E6666666E6666666E6666666  srgb(90%,90%,90%) <=== GOOD

f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:gray(175%) xc:gray(65%) -compose ModulusSubtract -composite txt:

# ImageMagick pixel enumeration: 1,1,4294967295,srgb
0,0: (-10%,-10%,-10%)  #000000000000000000000000  srgb(-10%,-10%,-10%) <=== BAD

f:\web\im>c:\cygwin64\home\Alan\iminst32f\bin\convert xc:gray(-10%) xc:gray(-20%) -compose ModulusAdd -composite txt:

# ImageMagick pixel enumeration: 1,1,4294967295,srgb
0,0: (-30%,-30%,-30%)  #000000000000000000000000  srgb(-30%,-30%,-30%) <=== BAD
I suggest that both "if" tests are changed to "while" tests, or equivalent code.


Composite.c, function ModulusAdd currently has:

Code: Select all

  if (pixel > QuantumRange)
    pixel-=QuantumRange;
Composite.c, function ModulusSubtract currently has:

Code: Select all

  if (pixel < 0.0)
    pixel+=QuantumRange;
I suggest these are both changed to:

Code: Select all

  while (pixel > QuantumRange)
    pixel-=QuantumRange;

  while (pixel < 0.0)
    pixel+=QuantumRange;
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -compose Modulus

Post by fmw42 »

The old add and subtract were rename to modulusAdd and modulusSubtract by Anthony some time ago, though the old name still work, I think they are now deprecated. The old names were to distinguish from plus and minus, the latter of which do not wrap around in value.

I am not sure how they should behave whether the new or old names in HDRI mode.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -compose Modulus

Post by magick »

Look for your patch in ImageMagick 6.9.2-0 Beta by sometime tomorrow. Thanks.
Post Reply