Page 1 of 1

-clut in Q32

Posted: 2014-08-23T08:48:54-07:00
by snibgo
"-clut" doesn't seem to work properly in Q32 (whether or not HDRI).

Test case: if we clut a gradient with a gradient, we should get a gradient. Windows BAT script.

Code: Select all

rem Official Windows binary release v6.8.9-5:

%IM%convert ^
  -size 100x100 gradient: ^
  ( -size 1x10 gradient: -rotate 90 ) ^
  -clut ^
  clut_c1.png
Image

Code: Select all

rem Self-compiled on Cygwin Q32 v6.8.9-6, bad result:

%IM32i%convert ^
  -size 100x100 gradient: ^
  ( -size 1x10 gradient: -rotate 90 ) ^
  -clut ^
  clut_c2.png
Image
clut_c2.png is very nearly black. It should be a gradient.

I've looked at ClutImageChannel(...) in enhance.c, and the 4 versions of ScaleQuantumToMap, and I can't figure out the bug.

Contrast Stretch and Equalize seem to work fine in Q32.

Re: -clut in Q32

Posted: 2014-08-29T09:25:26-07:00
by snibgo
I think I've cracked it.

enhance.c contains function ClutImageChannel(...)

Code: Select all

  for (i=0; i <= (ssize_t) MaxMap; i++)
  {
    GetMagickPixelPacket(clut_image,clut_map+i);
    (void) InterpolateMagickPixelPacket(clut_image,clut_view,
      UndefinedInterpolatePixel,QuantumScale*i*(clut_image->columns-adjust),
      QuantumScale*i*(clut_image->rows-adjust),clut_map+i,exception);
  }
Replace both occurrences of "QuantumScale" with "1.0/(MaxMap-1)". These values are equal in Q8 and Q16, but not in Q32 because MaxMap has a maximum value of 65536.

So those lines should be:

Code: Select all

  for (i=0; i <= (ssize_t) MaxMap; i++)
  {
    GetMagickPixelPacket(clut_image,clut_map+i);
    (void) InterpolateMagickPixelPacket(clut_image,clut_view,
      UndefinedInterpolatePixel,1.0/(MaxMap-1)*i*(clut_image->columns-adjust),
      1.0/(MaxMap-1)*i*(clut_image->rows-adjust),clut_map+i,exception);
  }
With this change, cluts seem to work correctly in Q32 HDRI.

Re: -clut in Q32

Posted: 2014-08-29T10:06:57-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.8.9-8 Beta, available by sometime tomorrow. Thanks.