]> granicus.if.org Git - imagemagick/blobdiff - coders/xpm.c
(no commit message)
[imagemagick] / coders / xpm.c
index 51654fb491b34c02439f201d3632c269cf92d8af..ba657c214efc7013e12e42cc7b152b1ac046c556 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -139,11 +139,11 @@ static MagickBooleanType IsXPM(const unsigned char *magick,const size_t length)
 */
 
 static int CompareXPMColor(const void *target,const void *source)
-{ 
+{
   const char
     *p,
     *q;
-  
   p=(const char *) target;
   q=(const char *) source;
   return(strcmp(p,q));
@@ -242,7 +242,6 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     *indexes;
 
   register ssize_t
-    i,
     x;
 
   register PixelPacket
@@ -314,11 +313,11 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (*p != '"')
       continue;
     count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&columns,&rows,&colors,&width);
-    if (count == 4)
-      break;
     image->columns=columns;
     image->rows=rows;
     image->colors=colors;
+    if (count == 4)
+      break;
   }
   if ((count != 4) || (width > 10) || (image->columns == 0) ||
       (image->rows == 0) || (image->colors == 0))
@@ -327,7 +326,6 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Remove unquoted characters.
   */
-  i=0;
   active=MagickFalse;
   q=xpm_buffer;
   while (*p != '\0')
@@ -352,7 +350,6 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Read image colormap.
   */
-  i=1;
   next=NextXPMLine(xpm_buffer);
   for (j=0; (j < (ssize_t) image->colors) && (next != (char*) NULL); j++)
   {
@@ -384,7 +381,9 @@ static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
         image->storage_class=DirectClass;
         image->matte=MagickTrue;
       }
-    if (QueryColorDatabase(target,&image->colormap[j],exception) == MagickFalse)
+    status=QueryColorCompliance(target,AllCompliance,&image->colormap[j],
+      exception);
+    if (status == MagickFalse)
       break;
   }
   if (j < (ssize_t) image->colors)
@@ -519,8 +518,7 @@ ModuleExport void UnregisterXPMImage(void)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  Procedure WritePICONImage() writes an image to a file in the Personal Icon
-%  format.
+%  WritePICONImage() writes an image to a file in the Personal Icon format.
 %
 %  The format of the WritePICONImage method is:
 %
@@ -667,7 +665,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
   exception=(&image->exception);
   if (picon->storage_class == PseudoClass)
     {
-      CompressImageColormap(picon);
+      (void) CompressImageColormap(picon);
       if (picon->matte != MagickFalse)
         transparent=MagickTrue;
     }
@@ -742,9 +740,9 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
     "static char *%s[] = {\n",basename);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"/* columns rows colors chars-per-pixel */\n");
-  (void) FormatMagickString(buffer,MaxTextExtent,"\"%lu %lu %lu %ld\",\n",
-    (unsigned long) picon->columns,(unsigned long) picon->rows,(unsigned long)
-    colors,(long) characters_per_pixel);
+  (void) FormatMagickString(buffer,MaxTextExtent,
+    "\"%.20g %.20g %.20g %.20g\",\n",(double) picon->columns,(double)
+    picon->rows,(double) colors,(double) characters_per_pixel);
   (void) WriteBlobString(image,buffer);
   GetMagickPixelPacket(image,&pixel);
   for (i=0; i < (ssize_t) colors; i++)
@@ -774,8 +772,8 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
       symbol[j]=Cixel[k];
     }
     symbol[j]='\0';
-    (void) FormatMagickString(buffer,MaxTextExtent,"\"%s c %s\",\n",symbol,
-      name);
+    (void) FormatMagickString(buffer,MaxTextExtent,"\"%s c %s\",\n",
+       symbol,name);
     (void) WriteBlobString(image,buffer);
   }
   /*
@@ -805,7 +803,8 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
     (void) FormatMagickString(buffer,MaxTextExtent,"\"%s\n",
       y == (ssize_t) (picon->rows-1) ? "" : ",");
     (void) WriteBlobString(image,buffer);
-    status=SetImageProgress(image,SaveImageTag,y,picon->rows);
+    status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+      picon->rows);
     if (status == MagickFalse)
       break;
   }
@@ -826,7 +825,7 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  Procedure WriteXPMImage() writes an image to a file in the X pixmap format.
+%  WriteXPMImage() writes an image to a file in the X pixmap format.
 %
 %  The format of the WriteXPMImage method is:
 %
@@ -838,7 +837,6 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
 %
 %    o image:  The image.
 %
-%
 */
 static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image)
 {
@@ -967,16 +965,18 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image)
       (void) FormatMagickString(buffer,MaxTextExtent,"xpm_%s",basename);
       (void) CopyMagickString(basename,buffer,MaxTextExtent);
     }
-  for (i=0; basename[i] != '\0'; i++)
-    if (isalpha((int) ((unsigned char) basename[i])) == 0)
+  if (isalpha((int) ((unsigned char) basename[0])) == 0)
+    basename[0]='_';
+  for (i=1; basename[i] != '\0'; i++)
+    if (isalnum((int) ((unsigned char) basename[i])) == 0)
       basename[i]='_';
   (void) FormatMagickString(buffer,MaxTextExtent,
     "static char *%s[] = {\n",basename);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"/* columns rows colors chars-per-pixel */\n");
-  (void) FormatMagickString(buffer,MaxTextExtent,"\"%lu %lu %lu %ld\",\n",
-    (unsigned long) image->columns,(unsigned long) image->rows,
-    (unsigned long) image->colors,(long) characters_per_pixel);
+  (void) FormatMagickString(buffer,MaxTextExtent,
+    "\"%.20g %.20g %.20g %.20g \",\n",(double) image->columns,(double)
+    image->rows,(double) image->colors,(double) characters_per_pixel);
   (void) WriteBlobString(image,buffer);
   GetMagickPixelPacket(image,&pixel);
   for (i=0; i < (ssize_t) image->colors; i++)
@@ -1037,7 +1037,7 @@ static MagickBooleanType WriteXPMImage(const ImageInfo *image_info,Image *image)
     if (image->previous == (Image *) NULL)
       {
         status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
-                image->rows);
+          image->rows);
         if (status == MagickFalse)
           break;
       }