Page 1 of 1

-compose Modulus

Posted: 2015-08-11T14:02:58-07:00
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;

Re: -compose Modulus

Posted: 2015-08-11T14:23:40-07:00
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.

Re: -compose Modulus

Posted: 2015-08-12T04:35:53-07:00
by magick
Look for your patch in ImageMagick 6.9.2-0 Beta by sometime tomorrow. Thanks.