ColorMapIndex field in TGA file header ignored

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
visitor x
Posts: 16
Joined: 2013-07-27T13:26:38-07:00
Authentication code: 6789

ColorMapIndex field in TGA file header ignored

Post by visitor x » 2014-12-20T10:55:45-07:00

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.

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

Re: ColorMapIndex field in TGA file header ignored

Post by magick » 2014-12-20T13:35:14-07:00

Thanks for the alert and patch. Look for it in ImageMagick 6.9.0-1 Beta by sometime tomorrow.

visitor x
Posts: 16
Joined: 2013-07-27T13:26:38-07:00
Authentication code: 6789

Re: ColorMapIndex field in TGA file header ignored

Post by visitor x » 2014-12-21T10:14:00-07:00

Thank you!

Post Reply