-clut in Q32

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

-clut in Q32

Post by snibgo » 2014-08-23T08:48:54-07:00

"-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.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 10823
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -clut in Q32

Post by snibgo » 2014-08-29T09:25:26-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 10849
Joined: 2003-05-31T11:32:55-07:00

Re: -clut in Q32

Post by magick » 2014-08-29T10:06:57-07:00

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.9-8 Beta, available by sometime tomorrow. Thanks.

Post Reply