Re: 8bit tiff -- Change in Behavior / Bug : 8bit, 256color, PHOTOMETRIC_PALETTE == converted to 16-bit tiff

Scott Callaway <[email protected]> Fri, 28 Aug 2009 17:22:32 -0400
Newsgroups gmane.comp.video.image-magick.bugs
Message-ID <[email protected]>
I have combined the description of the problem and the link to the example image into one post.

######### 

I am upgrading an application that was using ImageMagick 6.3.6 use the most recent source ( ImageMagick 6.5.4-10  // ~ 8/6/2009 ).
The tests below are using Visual Studio 2008 on WinXP (32bit).

Using ImageMagick 6.3.6, the 8bit tiff image loads as a 8-bit image.
Using Imagemagick 6.5.4-10, the same 8bit tiff loads as a 16-bit image.

The translation is not a perfect scaling ( ie. The 8bit image is not multiplied by 256 ).  In one example image, the source 8bit image has a max pixel of 255 (2^8).  When ImageMagick 6.5.4-10 converts this image to 16bit, the max pixel is NOT 2^16 - the value is 65280 and not 65536.  I believe this is happening due to round-off errors in the LUT translations.

The following programs load this image as 8bit:  ImageJ, GIMP, MsPaint, etc.

The following url is a tiff image that can be used to reproduce the bug.
This tiff image will display in internet explorer or firefox.
http://www.huntermikic.com/imagemagick/imagemagick_AS_09047_050428030001_O01f00d0.TIF

The current version (6.5.4-10) of ImageMagick will convert this image to a 16bit tiff.  This was not the behavior of ImageMagick 6.3.6.

Best regards,
Scott Callaway

#########################################  Possible fix listed below

On around line 1000 of  coders/tiff.c, the following changes do resolve the problem.  Since I am not familiar with the internals of the imageMagick source code, I am hoping someone with more expertise can give advice or supply a fix for this issue.


/*
  Convert TIFF image to PseudoClass MIFF image.
*/
if ((image->storage_class == PseudoClass) &&
    (   (photometric == PHOTOMETRIC_PALETTE)
                  && (image->depth != 8)   <<<<---  Added this line
                  && (image->colors != 256) )  )   <<<<---  Added this line
  {
        /* Skip this step for 8bit, 256 color, PHOTOMETRIC_PALETTE (3), tiff images. */
        /* Some 8-bit monochrome tiff images are created this way. */
        /* If you don't skip this code, then the 8-bit mono image will be */
        /*  converted to a 16-bit image with mono colormap.  However, this  */
        /*  16-bit image will not be a strait translation from 8 to 16 bit. */
        /* This approach seems reasonable since other programs */
        /*  like ImageJ and gimp treat these images as 8bit mono images */
        /* ALSO, previous versions of ImageMagick ( ~ ver. 6.3.6 ) treated these */
        /*  tiff images as 8-bit tiffs as well. Seems like a bug fix is needed here. */
        /* NOTE: I am not sure this is the best place to put this work-around. */
        /*  If this type of image had a different 'storage_class' setting */
        /*    like (image->storage_class != PseudoClass) [ or  == DirectClass ] */
        /*    then this would have skipped this section as well.  */
        /*   I am not familiar with enough with the underlying code ... */

###############