Page 1 of 1

Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-07-27T12:51:05-07:00
by cyburgee
Not certain if this is bug or not, but after upgrading to imagemagick version 7, attempting to read or resize many animated gifs result in an 'invalid colormap index' error. This is also happening when trying to open animated gifs with Magick::readImages when using Magick++. This happens on both Mac OS X and Ubuntu 14.04. If this is in fact correct and intended behavior, I would appreciate it greatly if somebody could indicate to me what in particular is wrong with the gif below.

Here's a sample file: https://www.dropbox.com/s/wlz7hdkbz430y44/test.gif?dl=0

The following works as expected:

Code: Select all

$ convert --version
Version: ImageMagick 6.9.9-3 Q8 x86_64 2017-07-27 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules 
Delegates (built-in): bzlib fontconfig freetype jng jpeg ltdl lzma png tiff xml zlib

$ convert test.gif -coalesce -resize x100 test_100.gif
The output: https://www.dropbox.com/s/sb3bfqwov09r5 ... 0.gif?dl=0

This part doesn't work:

Code: Select all

$ convert -version
Version: ImageMagick 7.0.6-1 Q8 x86_64 2017-07-18 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules 
Delegates (built-in): bzlib fftw fontconfig freetype jng jpeg ltdl lzma png tiff x xml zlib

$ convert test.gif -coalesce -resize x100 test_100_v7.gif
convert: invalid colormap index `test.gif' @ error/colormap-private.h/ConstrainColormapIndex/34.
Thank you for your time!

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-07-27T14:15:15-07:00
by fmw42
I can confirm on IM 7.0.6.3 Q16 Mac OSX. I get the same error and no output image with or without the -layers optimize.

Code: Select all

magick test.gif -coalesce -resize x100 -layers optimize test_100_v7.gif

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-07-27T15:15:26-07:00
by cyburgee
fmw42 wrote: 2017-07-27T14:15:15-07:00 I can confirm on IM 7.0.6.3 Q16 Mac OSX. I get the same error and no output image with or without the -layers optimize.

Code: Select all

magick test.gif -coalesce -resize x100 -layers optimize test_100_v7.gif
Thanks for confirming. Does anything seem amiss with that particular file? I know that IM is more restrictive than most utilities when handling images for security purposes, but do you know if there's been an update to the specification that GIFs need to adhere to in order to be considered valid?

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-07-27T16:05:57-07:00
by fmw42
No, I do not know. But if it works in IM 6, then it should work in IM 7. So it seems there may be a bug in IM 7. We will have to wait to hear back from the IM developers.

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-07-27T16:38:49-07:00
by magick
Both IMv6 and IMv7 detect an invalid colormap index. The colormap has 32 colors and the colormap index is 32 which suggests a corrupt image file or ImageMagick is not reading it correctly. IMv6 detects the problem but does not report it. We'll add a patch so it does report the problem.

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-09-13T21:51:20-07:00
by cyburgee
According to all of the graphics control extension that I think that I found in the test file, it looks like 32 is the transparent color index.
From my reading of the GIF89a spec, decoders should skip any pixels with the transparent color index value and not modify the displayed output (https://www.w3.org/Graphics/GIF/spec-gif89a.txt, Pg16 23.viii). I think a number of tools take advantage of this to pack in more colors in conjunction with transparency optimization. My attempt at reading the spec and the raw hex could both be flawed, but I'd like to hear the developers' opinion on this.

Re: Reading animated gif -> 'invalid colormap index' error in version 7

Posted: 2017-09-14T01:50:16-07:00
by magick
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.