gimp r28105 - in branches/gimp-2-6: . plug-ins/common



Author: neo
Date: Thu Mar  5 14:11:49 2009
New Revision: 28105
URL: http://svn.gnome.org/viewvc/gimp?rev=28105&view=rev

Log:
2009-03-05  Sven Neumann  <sven gimp org>

	Merged from trunk:

	Bug 573695 â 1-bit white background saved as PBM becomes all 
black

	* plug-ins/common/file-pnm.c: need to handle the special case 
that
	the image colormap has only one entry.



Modified:
   branches/gimp-2-6/ChangeLog
   branches/gimp-2-6/plug-ins/common/file-pnm.c

Modified: branches/gimp-2-6/plug-ins/common/file-pnm.c
==============================================================================
--- branches/gimp-2-6/plug-ins/common/file-pnm.c	(original)
+++ branches/gimp-2-6/plug-ins/common/file-pnm.c	Thu Mar  5 14:11:49 2009
@@ -85,7 +85,7 @@
   gint       maxval;            /* For ascii image files, the max value
                                  * which we need to normalize to */
   gint       np;                /* Number of image planes (0 for pbm) */
-  gint       asciibody;         /* 1 if ascii body, 0 if raw body */
+  gboolean   asciibody;         /* 1 if ascii body, 0 if raw body */
   jmp_buf    jmpbuf;            /* Where to jump to on an error loading */
   /* Routine to use to load the pnm body */
   void    (* loader) (PNMScanner *, struct _PNMInfo *, GimpPixelRgn *);
@@ -94,13 +94,14 @@
 /* Contains the information needed to write out PNM rows */
 typedef struct _PNMRowInfo
 {
-  gint    fd;           /* File descriptor */
-  gchar  *rowbuf;       /* Buffer for writing out rows */
-  gint    xres;         /* X resolution */
-  gint    np;           /* Number of planes */
-  guchar *red;          /* Colormap red */
-  guchar *grn;          /* Colormap green */
-  guchar *blu;          /* Colormap blue */
+  gint      fd;           /* File descriptor */
+  gchar    *rowbuf;       /* Buffer for writing out rows */
+  gint      xres;         /* X resolution */
+  gint      np;           /* Number of planes */
+  guchar   *red;          /* Colormap red */
+  guchar   *grn;          /* Colormap green */
+  guchar   *blu;          /* Colormap blue */
+  gboolean  solid_white;  /* image is all white (pbm only) */
 } PNMRowInfo;
 
 /* Save info  */
@@ -808,20 +809,26 @@
 pnmsaverow_raw_pbm (PNMRowInfo   *ri,
                     const guchar *data)
 {
-  gint    b, i, p = 0;
-  gchar  *rbcur   = ri->rowbuf;
-  gint32  len     = (gint) ceil ((gdouble) (ri->xres) / 8.0);
+  gint    b, p  = 0;
+  gchar  *rbcur = ri->rowbuf;
+  gint32  len   = (gint) ceil ((gdouble) (ri->xres) / 8.0);
 
   for (b = 0; b < len; b++) /* each output byte */
     {
-      *(rbcur+b) = 0;
+      gint i;
+
+      rbcur[b] = 0;
+
+      if (ri->solid_white)
+        continue;
+
       for (i = 0; i < 8; i++) /* each bit in this byte */
         {
           if (p >= ri->xres)
-              break;
+            break;
 
-          if (*(data+p) == 0)
-              *(rbcur+b) |= (char) (1 << (7 - i));
+          if (data[p] == 0)
+            rbcur[b] |= (char) (1 << (7 - i));
 
           p++;
         }
@@ -844,16 +851,16 @@
     {
       if (line_len > 69)
         {
-          *(rbcur+i) = '\n';
+          rbcur[i] = '\n';
           line_len = 0;
           len++;
           rbcur++;
         }
 
-      if (*(data+i) == 0)
-        *(rbcur+i) = '1';
+      if (ri->solid_white || data[i] != 0)
+        rbcur[i] = '0';
       else
-        *(rbcur+i) = '0';
+        rbcur[i] = '1';
 
       line_len++;
       len++;
@@ -917,11 +924,11 @@
 
   for (i = 0; i < ri->xres; i++)
     {
-      sprintf ((char *) rbcur,"%d\n", 0xff & ri->red[*(data)]);
+      sprintf (rbcur, "%d\n", 0xff & ri->red[*(data)]);
       rbcur += strlen (rbcur);
-      sprintf ((char *) rbcur,"%d\n", 0xff & ri->grn[*(data)]);
+      sprintf (rbcur, "%d\n", 0xff & ri->grn[*(data)]);
       rbcur += strlen (rbcur);
-      sprintf ((char *) rbcur,"%d\n", 0xff & ri->blu[*(data++)]);
+      sprintf (rbcur, "%d\n", 0xff & ri->blu[*(data++)]);
       rbcur += strlen (rbcur);
     }
 
@@ -1063,24 +1070,43 @@
         }
     }
 
-  if (drawable_type == GIMP_INDEXED_IMAGE && !pbm)
+  rowinfo.solid_white = FALSE;
+
+  if (drawable_type == GIMP_INDEXED_IMAGE)
     {
       guchar *cmap;
       gint    colors;
-      gint    i;
 
       cmap = gimp_image_get_colormap (image_ID, &colors);
 
-      for (i = 0; i < colors; i++)
+      if (pbm)
         {
-          red[i] = *cmap++;
-          grn[i] = *cmap++;
-          blu[i] = *cmap++;
+          /*  If we are dealing with an all-white image, then the colormap
+           *  has one entry only and we can't assume that the first entry
+           *  is black and the second is white.
+           */
+          if (colors == 1 && cmap[0])
+            {
+              rowinfo.solid_white = TRUE;
+            }
+        }
+      else
+        {
+          gint i;
+
+          for (i = 0; i < colors; i++)
+            {
+              red[i] = *cmap++;
+              grn[i] = *cmap++;
+              blu[i] = *cmap++;
+            }
+
+          rowinfo.red = red;
+          rowinfo.grn = grn;
+          rowinfo.blu = blu;
         }
 
-      rowinfo.red = red;
-      rowinfo.grn = grn;
-      rowinfo.blu = blu;
+      g_free (cmap);
     }
 
   /* allocate a buffer for retrieving information from the pixel region  */



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