-compose Modulus
Posted: 2015-08-11T14:02:58-07:00
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:
I suggest that both "if" tests are changed to "while" tests, or equivalent code.
Composite.c, function ModulusAdd currently has:
Composite.c, function ModulusSubtract currently has:
I suggest these are both changed to:
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
Composite.c, function ModulusAdd currently has:
Code: Select all
if (pixel > QuantumRange)
pixel-=QuantumRange;
Code: Select all
if (pixel < 0.0)
pixel+=QuantumRange;
Code: Select all
while (pixel > QuantumRange)
pixel-=QuantumRange;
while (pixel < 0.0)
pixel+=QuantumRange;