[AD] minor patch to make GIMP recognize the alpha channel in saved TGAs

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Someone on allegro.cc complained about it, and wotsit.org says the
number of bits in the alpha channel is set by the lower 4 bits of the
modified field - so I guess it has to be 8.

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: src/tga.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/tga.c,v
retrieving revision 1.13
diff -u -r1.13 tga.c
--- src/tga.c	29 May 2003 11:02:12 -0000	1.13
+++ src/tga.c	7 Feb 2004 13:01:20 -0000
@@ -451,6 +451,29 @@
 
 
 
+/* _bitmap_has_alpha:
+ *  Checks whether this bitmap has an alpha channel.
+ */
+static int _bitmap_has_alpha(BITMAP *bmp)
+{
+   int x, y, c;
+
+   if (bitmap_color_depth(bmp) != 32)
+      return FALSE;
+
+   for (y = 0; y < bmp->h; y++) {
+      for (x = 0; x < bmp->w; x++) {
+	 c = getpixel(bmp, x, y);
+	 if (geta32(c))
+	    return TRUE;
+      }
+   }
+
+   return FALSE;
+}
+
+
+
 /* save_tga:
  *  Writes a bitmap into a TGA file, using the specified palette (this
  *  should be an array of at least 256 RGB structures).
@@ -492,7 +515,7 @@
    pack_iputw(bmp->w, f);                    /* width */
    pack_iputw(bmp->h, f);                    /* height */
    pack_putc(depth, f);                      /* bits per pixel */
-   pack_putc(0, f);                          /* descriptor (bottom to top) */
+   pack_putc(_bitmap_has_alpha (bmp) ? 8 : 0, f); /* descriptor (bottom to top, 8-bit alpha) */
 
    if (depth == 8) {
       for (y=0; y<256; y++) {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/