Page 1 of 1

ColorMapIndex field in TGA file header ignored

Posted: 2014-12-20T10:55:45-07:00
by visitor x
TGA headers have a ColorMapIndex field allowing to store only a part of the actual color map if the image does not make use of all entries. This field is currently ignored by ImageMagick, images that have a non-zero value for ColorMapIndex fail to load as the image data is assumed to be corrupted. I propose the following changes to tga.c fixing this:

Code: Select all

@@ -264,7 +264,7 @@ static Image *ReadTGAImage(const ImageIn
   if (image->storage_class == PseudoClass)
     {
       if (tga_info.colormap_type != 0)
-        image->colors=tga_info.colormap_length;
+        image->colors=tga_info.colormap_index+tga_info.colormap_length;
       else
         {
           size_t
@@ -316,7 +316,9 @@ static Image *ReadTGAImage(const ImageIn
       */
       if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-      for (i=0; i < (ssize_t) image->colors; i++)
+      for (i=0; i < (ssize_t) image->tga_info.colormap_index; i++)
+        image->colormap[i]=pixel;
+      for (i=(ssize_t) tga_info.colormap_index; i < (ssize_t) image->colors; i++)
       {
         switch (tga_info.colormap_size)
         {
Unfortenuately, I am unable to test this patch myself but if anyone wants to give it a try, there's a sample file at http://www.datafilehost.com/d/0d9dc491.

Re: ColorMapIndex field in TGA file header ignored

Posted: 2014-12-20T13:35:14-07:00
by magick
Thanks for the alert and patch. Look for it in ImageMagick 6.9.0-1 Beta by sometime tomorrow.

Re: ColorMapIndex field in TGA file header ignored

Posted: 2014-12-21T10:14:00-07:00
by visitor x
Thank you!