[gimp] file-tga: Handle 16-bit palettes with transparency (#687802)



commit 6d09237ca15bc2b5ccf8100622769e9114bcc7ab
Author: Mukund Sivaraman <muks banu com>
Date:   Tue Dec 4 23:30:26 2012 +0530

    file-tga: Handle 16-bit palettes with transparency (#687802)
    
    Primarily, this fixes a buffer overflow in the colormap buffer.
    
    * We promote such images to GIMP_RGBA_IMAGE now.
    * The alpha handling for the colormap to RGBA conversion has been
      fixed.
    * Inverted transparency in upsampling has been fixed.

 plug-ins/common/file-tga.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/common/file-tga.c b/plug-ins/common/file-tga.c
index 8cc3477..fcfd4fc 100644
--- a/plug-ins/common/file-tga.c
+++ b/plug-ins/common/file-tga.c
@@ -812,7 +812,7 @@ upsample (guchar       *dest,
 
       if (alpha)
         {
-          dest[3] = (src[1] & 0x80) ? 0 : 255;
+          dest[3] = (src[1] & 0x80) ? 255 : 0;
           dest += 4;
         }
       else
@@ -927,8 +927,12 @@ read_line (FILE         *fp,
     }
   else if (convert_cmap)
     {
-      apply_colormap (row, buf, info->width, convert_cmap,
-                      (info->colorMapSize > 24));
+      gboolean has_alpha = (info->colorMapSize > 24) ||
+                            ((info->colorMapSize == 16 ||
+                              info->colorMapSize == 15) &&
+                             (info->alphaBits > 0));
+
+      apply_colormap (row, buffer, info->width, convert_cmap, has_alpha);
     }
   else
     {
@@ -975,6 +979,13 @@ ReadImage (FILE        *fp,
           dtype = GIMP_RGB_IMAGE;
           convert_cmap = g_new (guchar, info->colorMapLength * 3);
         }
+      else if (info->alphaBits > 0)
+        {
+          /* if alpha exists here, promote to RGB */
+          itype = GIMP_RGB;
+          dtype = GIMP_RGBA_IMAGE;
+          convert_cmap = g_new (guchar, info->colorMapLength * 4);
+        }
       else
         {
           itype = GIMP_INDEXED;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]