Index: gimp/plug-ins/common/tga.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/tga.c,v
retrieving revision 1.46
diff -p -u -r1.46 tga.c
--- gimp/plug-ins/common/tga.c	18 Apr 2004 17:29:43 -0000	1.46
+++ gimp/plug-ins/common/tga.c	22 Apr 2004 19:48:30 -0000
@@ -404,6 +404,8 @@ load_image (const gchar *filename)
   guchar    footer[26];
   guchar    extension[495];
   long      offset;
+  guchar   *id = NULL;
+  GimpParasite *parasite;
 
   gint32 image_ID = -1;
 
@@ -506,6 +508,9 @@ load_image (const gchar *filename)
   info.flipHoriz = (header[17] & 0x10) ? 1 : 0;
   info.flipVert  = (header[17] & 0x20) ? 0 : 1;
 
+  if (info.bpp == 32 && info.alphaBits == 0)  /* prob alphaBits is bogus */
+    info.alphaBits = 8;
+
   switch (info.imageType)
     {
       case TGA_TYPE_MAPPED:
@@ -561,15 +566,35 @@ load_image (const gchar *filename)
       return -1;
     }
 
-  /* Skip the image ID field. */
-  if (info.idLength && fseek (fp, info.idLength, SEEK_CUR))
+  /* Read the image ID field if there is one. */
+  if (info.idLength)
     {
-      g_message ("File '%s' is truncated or corrupted",
-                 gimp_filename_to_utf8 (filename));
-      return -1;
+      id = g_malloc (info.idLength);
+      if(1 != fread (id, info.idLength, 1, fp))
+	{
+	  g_message ("File '%s' is truncated or corrupted",
+		     gimp_filename_to_utf8 (filename));
+	  return -1;
+	}
     }
 
   image_ID = ReadImage (fp, &info, filename);
+
+  /* Attach a parasite containing the ID, if there is one.  Pretend to
+   * be a gimp comment so other plugins will use this description as
+   * an image comment where appropriate. */
+  if (info.idLength)
+    {
+      if (g_utf8_validate (id, -1, NULL))
+	{
+	  parasite = gimp_parasite_new ("gimp-comment",
+					GIMP_PARASITE_PERSISTENT,
+					info.idLength + 1, id);
+	  gimp_image_parasite_attach (image_ID, parasite);
+	  gimp_parasite_free (parasite);
+	}
+    }
+  
   fclose (fp);
   return image_ID;
 }
@@ -1001,14 +1026,15 @@ save_image (const gchar *filename,
   GimpImageType  dtype;
   gint           width;
   gint           height;
-
+  GimpParasite  *parasite;
+  guchar        *id = NULL;
   FILE     *fp;
   gchar    *name_buf;
   gint      tileheight;
   gint      out_bpp = 0;
   gboolean  status  = TRUE;
   gint      i, row;
-
+  gint      idLength;
   guchar  header[18];
   guchar  footer[26];
   guchar *pixels;
@@ -1017,6 +1043,7 @@ save_image (const gchar *filename,
   gint    num_colors;
   guchar *gimp_cmap = NULL;
 
+
   drawable = gimp_drawable_get (drawable_ID);
   dtype    = gimp_drawable_type (drawable_ID);
 
@@ -1035,7 +1062,21 @@ save_image (const gchar *filename,
   gimp_progress_init (name_buf);
   g_free (name_buf);
 
-  header[0] = 0; /* No image identifier / description */
+  /* if there is an image comment, save it as the identifier.
+   * Or, the first 255 bytes of it if it is longer than that */
+  parasite = gimp_image_parasite_find (image_ID, "gimp-comment");
+  if (parasite)
+    {
+      id = g_strdup (parasite->data);
+      idLength = MIN (255, strlen (id));
+      if (idLength == 255)
+	id[255] = '\0';
+    }
+  else
+    idLength = 0;
+  gimp_parasite_free (parasite);
+
+  header[0] = idLength;
 
   if (dtype == GIMP_INDEXED_IMAGE || dtype == GIMP_INDEXEDA_IMAGE)
     {
@@ -1105,6 +1146,9 @@ save_image (const gchar *filename,
   /* write header to front of file */
   fwrite (header, sizeof (header), 1, fp);
 
+  if(idLength)
+    fwrite (id, idLength, 1, fp);
+
   if (dtype == GIMP_INDEXED_IMAGE || dtype == GIMP_INDEXEDA_IMAGE)
     {
       /* write out palette */
