]> granicus.if.org Git - imagemagick/blobdiff - coders/mpc.c
Accommodate background color index in PLTE chunk
[imagemagick] / coders / mpc.c
index 4046d3e4a750064cef04a57e83dbac762b6b8bfe..429ce79b9d4b1efa714b241a823ec1c199bdae87 100644 (file)
@@ -325,7 +325,7 @@ static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
               }
             *p='\0';
             if (*options == '{')
-              (void) CopyMagickString(options,options+1,MaxTextExtent);
+              (void) strcpy(options,options+1);
             /*
               Assign a value to the specified keyword.
             */
@@ -388,7 +388,7 @@ static Image *ReadMPCImage(const ImageInfo *image_info,ExceptionInfo *exception)
                       MagickFalse,options);
                     if (colorspace < 0)
                       break;
-                    image->colorspace=(ColorspaceType) colorspace;
+                    (void) SetImageColorspace(image,(ColorspaceType) colorspace,                      exception);
                     break;
                   }
                 if (LocaleCompare(keyword,"compression") == 0)
@@ -1298,20 +1298,27 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
       value=GetImageProperty(image,property,exception);
       if (value != (const char *) NULL)
         {
-          for (i=0; i < (ssize_t) strlen(value); i++)
+          size_t
+            length;
+
+          length=strlen(value);
+          for (i=0; i < (ssize_t) length; i++)
             if (isspace((int) ((unsigned char) value[i])) != 0)
               break;
-          if (i == (ssize_t) strlen(value))
-            (void) WriteBlob(image,strlen(value),(const unsigned char *) value);
+          if (i == (ssize_t) length)
+            (void) WriteBlob(image,length,(const unsigned char *) value);
           else
             {
               (void) WriteBlobByte(image,'{');
-              for (i=0; i < (ssize_t) strlen(value); i++)
-              {
-                if (value[i] == (int) '}')
-                  (void) WriteBlobByte(image,'\\');
-                (void) WriteBlobByte(image,value[i]);
-              }
+              if (strchr(value,'}') == (char *) NULL)
+                (void) WriteBlob(image,length,(const unsigned char *) value);
+              else
+                for (i=0; i < (ssize_t) length; i++)
+                {
+                  if (value[i] == (int) '}')
+                    (void) WriteBlobByte(image,'\\');
+                  (void) WriteBlobByte(image,value[i]);
+                }
               (void) WriteBlobByte(image,'}');
             }
         }