Index: psd.c
===================================================================
RCS file: /cvs/gnome/gimp/plug-ins/common/psd.c,v
retrieving revision 1.51
diff -u -r1.51 psd.c
--- psd.c	12 Dec 2003 15:49:49 -0000	1.51
+++ psd.c	6 Jan 2004 21:56:40 -0000
@@ -1,5 +1,5 @@
 /*
- * PSD Plugin version 3.0.10
+ * PSD Plugin version 3.0.13
  * This GIMP plug-in is designed to load Adobe Photoshop(tm) files (.PSD)
  *
  * Adam D. Moss <adam@gimp.org> <adam@foxbox.org>
@@ -9,7 +9,7 @@
  *     about the image you tried to load.  Please don't send big PSD
  *     files to me without asking first.
  *
- *          Copyright (C) 1997-2003 Adam D. Moss
+ *          Copyright (C) 1997-2004 Adam D. Moss
  *          Copyright (C) 1996      Torsten Martinsen
  *
  * This program is free software; you can redistribute it and/or modify
@@ -35,6 +35,17 @@
 /*
  * Revision history:
  *
+ *  2004-01-06 / v3.0.13 / Adam D. Moss
+ *       Disable one of the PanoTools fixes by default, since it causes
+ *       regressions in some ordinary PSD file loading.
+ *
+ *  2004-01-06 / v3.0.12 / Adam D. Moss
+ *       Try to avoid 0-sized drawables (including channels) in all
+ *       circumstances under GIMP 2.
+ *
+ *  2004-01-01 / v3.0.11 / Daniel Rogers <dsrogers@phaseveloctiy.org>
+ *       GIMP crashes on 0x0 layers, so we skip them.
+ *       
  *  2003-11-27 / v3.0.10 / Adam D. Moss
  *       GIMP 1.3/2.0 needs its layer/channel names to be UTF8 or it
  *       fails wackily, so convert the strings from the PSD file to
@@ -149,11 +160,16 @@
 /* *** USER DEFINES *** */
 
 /* set to TRUE if you want debugging, FALSE otherwise */
-#define PSD_DEBUG FALSE
+#define PSD_DEBUG TRUE
 
 /* the max number of channels that this plugin should let a layer have */
 #define MAX_CHANNELS 30
 
+/* set to TRUE to allow a fix for transparency in PSD files
+   generated by PanoTools that unfortunately causes regressions
+   in some other ordinary files saved by Photoshop. */
+#define PANOTOOLS_FIX FALSE
+
 /* *** END OF USER DEFINES *** */
 
 
@@ -1415,6 +1431,7 @@
 }
 
 
+#if PANOTOOLS_FIX
 /* Convert RGB data to RGBA data */
 static guchar*
 RGB_to_RGBA (const guchar* rgb_data, gint numpix)
@@ -1441,6 +1458,7 @@
 
   return rtn;
 }
+#endif /* PANOTOOLS_FIX */
 
 
 static guchar*
@@ -1565,6 +1583,13 @@
   IFDBG printf("Extracting primary channel data (%d channels)\n"
 	 "\tand %d auxiliary channels.\n", gimpstep, psstep-gimpstep);
 
+  /* gimp doesn't like 0 width/height drawables. */
+  if ((width == 0) || (height == 0))
+    {
+      IFDBG printf("(bad channel dimensions -- skipping)");
+      return;
+    }
+
   primary_data = g_malloc(width * height * gimpstep);
   {
     int pix,chan;
@@ -1602,7 +1627,6 @@
 	  {
 	    aux_data [pix] = src [pix * psstep + chan];
 	  }
-
 	channel_ID = gimp_channel_new (image_ID,
                                        psd_image.aux_channel[chan-gimpstep].name,
                                        width, height,
@@ -1637,6 +1661,13 @@
 
   IFDBG printf("Extracting %d/%d auxiliary channels.\n", num_wanted, psstep);
 
+  /* gimp doesn't like 0 width/height drawables. */
+  if ((width == 0) || (height == 0))
+    {
+      IFDBG printf("(bad channel dimensions -- skipping)");
+      return;
+    }
+
   aux_data = g_malloc(width * height);
   {
     int pix, chan;
@@ -1774,9 +1805,20 @@
 	  gint numc;
 	  guchar* merged_data = NULL;
 	  PSDlayer *layer = psd_image.layer + lnum;
-
+	  
+	  /*
+	   * since ps supports sloppy bounding boxes it is possible to
+	   * have a 0x0 or Xx0 or 0xY layer.  Gimp doesn't support a
+	   * 0x0 layer so we will just skip these.  We might be able
+	   * to do something better here.
+	   */
+	  if ((layer->width == 0) || (layer->height == 0))
+	    {
+	      IFDBG printf("(bad layer dimensions -- skipping)");
+	      continue;
+	    }
 	  numc = layer->num_channels;
-
+	  
 	  IFDBG printf("Hey, it's a LAYER with %d channels!\n", numc);
 
 	  switch (gimagetype)
@@ -1951,6 +1993,7 @@
 		    /* give it to GIMP */
 		    mask_id = gimp_layer_create_mask(layer_ID, 0);
 
+#if PANOTOOLS_FIX
  		    /* Convert the layer RGB data (not the mask) to RGBA */
                     tmp = merged_data;
  		    merged_data = RGB_to_RGBA (tmp,
@@ -1963,7 +2006,7 @@
 
  		    /* Add layer mask */
 		    gimp_layer_add_mask (layer_ID, mask_id);
-
+#endif /* PANOTOOLS_FIX */
 		    drawable = gimp_drawable_get (mask_id);
 
 		    gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
@@ -2105,6 +2148,14 @@
 
       if (!want_aux)
 	{
+	  /* gimp doesn't like 0 width/height drawables. */
+	  if ((PSDheader.columns == 0) || (PSDheader.rows == 0))
+	    {
+	      IFDBG printf("(bad psd2-style image dimensions -- skipping)");
+	      image_ID = -1;
+	      goto finish_up;
+	    }
+
 	  image_ID = gimp_image_new (PSDheader.columns, PSDheader.rows,
 				     psd_type_to_gimp_base_type(imagetype));
 	  gimp_image_set_filename (image_ID, name);
