]> granicus.if.org Git - imagemagick/blobdiff - coders/miff.c
(no commit message)
[imagemagick] / coders / miff.c
index f3b28773c7de81db160dad1b34696f0138f59ecc..eeabb5da8f03603f9793c7816fc923f263412076 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 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  %
@@ -49,6 +49,7 @@
 #include "MagickCore/colormap.h"
 #include "MagickCore/colormap-private.h"
 #include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
 #include "MagickCore/constitute.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
@@ -241,7 +242,7 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
           unsigned char
             quantum;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               p=PushCharPixel(p,&quantum);
               pixel->alpha=ScaleCharToQuantum(quantum);
@@ -253,7 +254,7 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
           unsigned short
             quantum;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               p=PushShortPixel(MSBEndian,p,&quantum);
               pixel->alpha=(Quantum) (quantum >> (image->depth-
@@ -266,7 +267,7 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
           unsigned int
             quantum;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               p=PushLongPixel(MSBEndian,p,&quantum);
               pixel->alpha=(Quantum) (quantum >> (image->depth-
@@ -290,16 +291,21 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
 
       p=PushCharPixel(p,&quantum);
       pixel->red=ScaleCharToQuantum(quantum);
-      p=PushCharPixel(p,&quantum);
-      pixel->green=ScaleCharToQuantum(quantum);
-      p=PushCharPixel(p,&quantum);
-      pixel->blue=ScaleCharToQuantum(quantum);
+      pixel->green=pixel->red;
+      pixel->blue=pixel->red;
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          p=PushCharPixel(p,&quantum);
+          pixel->green=ScaleCharToQuantum(quantum);
+          p=PushCharPixel(p,&quantum);
+          pixel->blue=ScaleCharToQuantum(quantum);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           p=PushCharPixel(p,&quantum);
           pixel->black=ScaleCharToQuantum(quantum);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           p=PushCharPixel(p,&quantum);
           pixel->alpha=ScaleCharToQuantum(quantum);
@@ -313,16 +319,21 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
 
       p=PushShortPixel(MSBEndian,p,&quantum);
       pixel->red=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
-      p=PushShortPixel(MSBEndian,p,&quantum);
-      pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
-      p=PushShortPixel(MSBEndian,p,&quantum);
-      pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+      pixel->green=pixel->red;
+      pixel->blue=pixel->red;
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          p=PushShortPixel(MSBEndian,p,&quantum);
+          pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+          p=PushShortPixel(MSBEndian,p,&quantum);
+          pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           p=PushShortPixel(MSBEndian,p,&quantum);
           pixel->black=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           p=PushShortPixel(MSBEndian,p,&quantum);
           pixel->alpha=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
@@ -336,16 +347,21 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
 
       p=PushLongPixel(MSBEndian,p,&quantum);
       pixel->red=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
-      p=PushLongPixel(MSBEndian,p,&quantum);
-      pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
-      p=PushLongPixel(MSBEndian,p,&quantum);
-      pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+      pixel->green=pixel->red;
+      pixel->blue=pixel->red;
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          p=PushLongPixel(MSBEndian,p,&quantum);
+          pixel->green=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+          p=PushLongPixel(MSBEndian,p,&quantum);
+          pixel->blue=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           p=PushLongPixel(MSBEndian,p,&quantum);
           pixel->black=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           p=PushLongPixel(MSBEndian,p,&quantum);
           pixel->alpha=quantum >> (image->depth-MAGICKCORE_QUANTUM_DEPTH);
@@ -413,8 +429,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
     *image;
 
   int
-    c,
-    code;
+    c;
+
+  LinkedListInfo
+    *profiles;
 
 #if defined(MAGICKCORE_LZMA_DELEGATE)
   lzma_stream
@@ -425,9 +443,6 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
     allocator;
 #endif
 
-  LinkedListInfo
-    *profiles;
-
   MagickBooleanType
     status;
 
@@ -494,10 +509,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
   c=ReadBlobByte(image);
   if (c == EOF)
     ThrowReaderException(CorruptImageError,"ImproperImageHeader");
-  code=0;
   *id='\0';
   (void) ResetMagickMemory(keyword,0,sizeof(keyword));
   version=0.0;
+  (void) version;
   do
   {
     /*
@@ -528,8 +543,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
           for (p=comment; comment != (char *) NULL; p++)
           {
             c=ReadBlobByte(image);
-            if ((c == EOF) || (c == (int) '}'))
-              break;
+            if (c == (int) '\\')
+              c=ReadBlobByte(image);
+            else
+              if ((c == EOF) || (c == (int) '}'))
+                break;
             if ((size_t) (p-comment+1) >= length)
               {
                 *p='\0';
@@ -591,19 +609,45 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                       "MemoryAllocationFailed");
                   *p++=(char) c;
                   c=ReadBlobByte(image);
+                  if (c == '\\')
+                    {
+                      c=ReadBlobByte(image);
+                      if (c == (int) '}')
+                        {
+                          *p++=(char) c;
+                          c=ReadBlobByte(image);
+                        }
+                    }
                   if (*options != '{')
                     if (isspace((int) ((unsigned char) c)) != 0)
                       break;
-                }
-              }
+                } }
             *p='\0';
             if (*options == '{')
-              (void) CopyMagickString(options,options+1,MaxTextExtent);
+              (void) CopyMagickString(options,options+1,strlen(options));
             /*
               Assign a value to the specified keyword.
             */
             switch (*keyword)
             {
+              case 'a':
+              case 'A':
+              {
+                if (LocaleCompare(keyword,"alpha-trait") == 0)
+                  {
+                    ssize_t
+                      alpha_trait;
+
+                    alpha_trait=ParseCommandOption(MagickPixelTraitOptions,
+                      MagickFalse,options);
+                    if (alpha_trait < 0)
+                      break;
+                    image->alpha_trait=(PixelTrait) alpha_trait;
+                    break;
+                  }
+                (void) SetImageProperty(image,keyword,options,exception);
+                break;
+              }
               case 'b':
               case 'B':
               {
@@ -661,7 +705,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                       MagickFalse,options);
                     if (colorspace < 0)
                       break;
-                    image->colorspace=(ColorspaceType) colorspace;
+                    (void) SetImageColorspace(image,(ColorspaceType) colorspace,                      exception);
                     break;
                   }
                 if (LocaleCompare(keyword,"compression") == 0)
@@ -791,7 +835,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                       options);
                     if (matte < 0)
                       break;
-                    image->matte=(MagickBooleanType) matte;
+                    image->alpha_trait=matte == 0 ? UndefinedPixelTrait :
+                      BlendPixelTrait;
                     break;
                   }
                 if (LocaleCompare(keyword,"matte-color") == 0)
@@ -811,18 +856,6 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
               case 'o':
               case 'O':
               {
-                if (LocaleCompare(keyword,"opaque") == 0)
-                  {
-                    ssize_t
-                      matte;
-
-                    matte=ParseCommandOption(MagickBooleanOptions,MagickFalse,
-                      options);
-                    if (matte < 0)
-                      break;
-                    image->matte=(MagickBooleanType) matte;
-                    break;
-                  }
                 if (LocaleCompare(keyword,"orientation") == 0)
                   {
                     ssize_t
@@ -1019,8 +1052,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                   {
                     flags=ParseGeometry(options,&geometry_info);
                     image->chromaticity.white_point.x=geometry_info.rho;
-                    image->chromaticity.white_point.y=geometry_info.rho;
-                    if ((flags & SigmaValue) != 0)
+                    image->chromaticity.white_point.y=geometry_info.sigma;
+                    if ((flags & SigmaValue) == 0)
                       image->chromaticity.white_point.y=
                         image->chromaticity.white_point.x;
                     break;
@@ -1210,10 +1243,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
     packet_size=(size_t) (quantum_info->depth/8);
     if (image->storage_class == DirectClass)
       packet_size=(size_t) (3*quantum_info->depth/8);
-    if ((image->type == BilevelType) || (image->type == GrayscaleType) ||
-        (image->type == GrayscaleMatteType))
+    if (IsGrayColorspace(image->colorspace) != MagickFalse)
       packet_size=quantum_info->depth/8;
-    if (image->matte != MagickFalse)
+    if (image->alpha_trait == BlendPixelTrait)
       packet_size+=quantum_info->depth/8;
     if (image->colorspace == CMYKColorspace)
       packet_size+=quantum_info->depth/8;
@@ -1231,33 +1263,35 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
       Read image pixels.
     */
     quantum_type=RGBQuantum;
-    if (image->matte != MagickFalse)
+    if (image->alpha_trait == BlendPixelTrait)
       quantum_type=RGBAQuantum;
     if (image->colorspace == CMYKColorspace)
       {
         quantum_type=CMYKQuantum;
-        if (image->matte != MagickFalse)
+        if (image->alpha_trait == BlendPixelTrait)
           quantum_type=CMYKAQuantum;
       }
+    if (IsGrayColorspace(image->colorspace) != MagickFalse)
+      {
+        quantum_type=GrayQuantum;
+        if (image->alpha_trait == BlendPixelTrait)
+          quantum_type=GrayAlphaQuantum;
+      }
     if (image->storage_class == PseudoClass)
       {
         quantum_type=IndexQuantum;
-        if (image->matte != MagickFalse)
+        if (image->alpha_trait == BlendPixelTrait)
           quantum_type=IndexAlphaQuantum;
       }
-    if ((image->type == BilevelType) || (image->type == GrayscaleType) ||
-        (image->type == GrayscaleMatteType))
-      {
-        quantum_type=GrayQuantum;
-        if (image->matte != MagickFalse)
-          quantum_type=GrayAlphaQuantum;
-      }
     status=MagickTrue;
     switch (image->compression)
     {
 #if defined(MAGICKCORE_BZLIB_DELEGATE)
       case BZipCompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&bzip_info,0,sizeof(bzip_info));
         bzip_info.bzalloc=AcquireBZIPMemory;
         bzip_info.bzfree=RelinquishBZIPMemory;
@@ -1272,6 +1306,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_LZMA_DELEGATE)
       case LZMACompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&allocator,0,sizeof(allocator));
         allocator.alloc=AcquireLZMAMemory;
         allocator.free=RelinquishLZMAMemory;
@@ -1287,6 +1324,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
       case LZWCompression:
       case ZipCompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&zip_info,0,sizeof(zip_info));
         zip_info.zalloc=AcquireZIPMemory;
         zip_info.zfree=RelinquishZIPMemory;
@@ -1333,7 +1373,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
               {
                 bzip_info.next_in=(char *) compress_pixels;
                 length=(size_t) BZipMaxExtent(packet_size*image->columns);
-                if (version != 0)
+                if (version != 0.0)
                   length=(size_t) ReadBlobMSBLong(image);
                 bzip_info.avail_in=(unsigned int) ReadBlob(image,length,
                   (unsigned char *) bzip_info.next_in);
@@ -1353,6 +1393,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
           lzma_info.avail_out=packet_size*image->columns;
           do
           {
+            int
+              code;
+
             if (lzma_info.avail_in == 0)
               {
                 lzma_info.next_in=compress_pixels;
@@ -1386,7 +1429,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
               {
                 zip_info.next_in=compress_pixels;
                 length=(size_t) ZipMaxExtent(packet_size*image->columns);
-                if (version != 0)
+                if (version != 0.0)
                   length=(size_t) ReadBlobMSBLong(image);
                 zip_info.avail_in=(unsigned int) ReadBlob(image,length,
                   zip_info.next_in);
@@ -1419,7 +1462,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                 if (image->colorspace == CMYKColorspace)
                   SetPixelBlack(image,ClampToQuantum(pixel.black),q);
               }
-            if (image->matte != MagickFalse)
+            if (image->alpha_trait == BlendPixelTrait)
               SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
             q+=GetPixelChannels(image);
           }
@@ -1442,7 +1485,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_BZLIB_DELEGATE)
       case BZipCompression:
       {
-        if (version == 0)
+        int
+          code;
+
+        if (version == 0.0)
           {
             MagickOffsetType
               offset;
@@ -1462,6 +1508,9 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_LZMA_DELEGATE)
       case LZMACompression:
       {
+        int
+          code;
+
         code=lzma_code(&lzma_info,LZMA_FINISH);
         if ((code != LZMA_STREAM_END) && (code != LZMA_OK))
           status=MagickFalse;
@@ -1473,7 +1522,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
       case LZWCompression:
       case ZipCompression:
       {
-        if (version == 0)
+        int
+          code;
+
+        if (version == 0.0)
           {
             MagickOffsetType
               offset;
@@ -1676,7 +1728,7 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
           unsigned int
             value;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
               pixels=PopLongPixel(MSBEndian,value,pixels);
@@ -1688,7 +1740,7 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
           unsigned short
             value;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
               pixels=PopShortPixel(MSBEndian,value,pixels);
@@ -1700,7 +1752,7 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
           unsigned char
             value;
 
-          if (image->matte != MagickFalse)
+          if (image->alpha_trait == BlendPixelTrait)
             {
               value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
                 pixel->alpha));
@@ -1724,16 +1776,19 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
 
       value=ScaleQuantumToLong(ClampToQuantum(pixel->red));
       pixels=PopLongPixel(MSBEndian,value,pixels);
-      value=ScaleQuantumToLong(ClampToQuantum(pixel->green));
-      pixels=PopLongPixel(MSBEndian,value,pixels);
-      value=ScaleQuantumToLong(ClampToQuantum(pixel->blue));
-      pixels=PopLongPixel(MSBEndian,value,pixels);
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          value=ScaleQuantumToLong(ClampToQuantum(pixel->green));
+          pixels=PopLongPixel(MSBEndian,value,pixels);
+          value=ScaleQuantumToLong(ClampToQuantum(pixel->blue));
+          pixels=PopLongPixel(MSBEndian,value,pixels);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           value=ScaleQuantumToLong(ClampToQuantum(pixel->black));
           pixels=PopLongPixel(MSBEndian,value,pixels);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           value=ScaleQuantumToLong(ClampToQuantum(pixel->alpha));
           pixels=PopLongPixel(MSBEndian,value,pixels);
@@ -1747,16 +1802,19 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
 
       value=ScaleQuantumToShort(ClampToQuantum(pixel->red));
       pixels=PopShortPixel(MSBEndian,value,pixels);
-      value=ScaleQuantumToShort(ClampToQuantum(pixel->green));
-      pixels=PopShortPixel(MSBEndian,value,pixels);
-      value=ScaleQuantumToShort(ClampToQuantum(pixel->blue));
-      pixels=PopShortPixel(MSBEndian,value,pixels);
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          value=ScaleQuantumToShort(ClampToQuantum(pixel->green));
+          pixels=PopShortPixel(MSBEndian,value,pixels);
+          value=ScaleQuantumToShort(ClampToQuantum(pixel->blue));
+          pixels=PopShortPixel(MSBEndian,value,pixels);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           value=ScaleQuantumToShort(ClampToQuantum(pixel->black));
           pixels=PopShortPixel(MSBEndian,value,pixels);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           value=ScaleQuantumToShort(ClampToQuantum(pixel->alpha));
           pixels=PopShortPixel(MSBEndian,value,pixels);
@@ -1770,17 +1828,21 @@ static unsigned char *PopRunlengthPacket(Image *image,unsigned char *pixels,
 
       value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->red));
       pixels=PopCharPixel(value,pixels);
-      value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->green));
-      pixels=PopCharPixel(value,pixels);
-      value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->blue));
-      pixels=PopCharPixel(value,pixels);
+      if (IsGrayColorspace(image->colorspace) == MagickFalse)
+        {
+          value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
+            pixel->green));
+          pixels=PopCharPixel(value,pixels);
+          value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(pixel->blue));
+          pixels=PopCharPixel(value,pixels);
+        }
       if (image->colorspace == CMYKColorspace)
         {
           value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
             pixel->black));
           pixels=PopCharPixel(value,pixels);
         }
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         {
           value=(unsigned char) ScaleQuantumToChar(ClampToQuantum(
             pixel->alpha));
@@ -1814,9 +1876,6 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
     *property,
     *value;
 
-  int
-    code;
-
 #if defined(MAGICKCORE_LZMA_DELEGATE)
   lzma_allocator
     allocator;
@@ -1876,7 +1935,6 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
   status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
-  code=0;
   scene=0;
   do
   {
@@ -1900,10 +1958,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
         (image->colors > (size_t) (GetQuantumRange(image->depth)+1)))
       (void) SetImageStorageClass(image,DirectClass,exception);
     if (IsImageGray(image,exception) != MagickFalse)
-      {
-        (void) SetImageStorageClass(image,DirectClass,exception);
-        (void) SetImageColorspace(image,GRAYColorspace,exception);
-      }
+      (void) SetImageColorspace(image,GRAYColorspace,exception);
     compression=image->compression;
     if (image_info->compression != UndefinedCompression)
       compression=image_info->compression;
@@ -1932,9 +1987,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
     packet_size=(size_t) (quantum_info->depth/8);
     if (image->storage_class == DirectClass)
       packet_size=(size_t) (3*quantum_info->depth/8);
-    if (IsImageGray(image,exception) != MagickFalse)
+    if (IsGrayColorspace(image->colorspace) != MagickFalse)
       packet_size=(size_t) (quantum_info->depth/8);
-    if (image->matte != MagickFalse)
+    if (image->alpha_trait == BlendPixelTrait)
       packet_size+=quantum_info->depth/8;
     if (image->colorspace == CMYKColorspace)
       packet_size+=quantum_info->depth/8;
@@ -1955,9 +2010,10 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
     */
     (void) WriteBlobString(image,"id=ImageMagick  version=1.0\n");
     (void) FormatLocaleString(buffer,MaxTextExtent,
-      "class=%s  colors=%.20g  matte=%s\n",CommandOptionToMnemonic(
+      "class=%s  colors=%.20g  alpha-trait=%s\n",CommandOptionToMnemonic(
       MagickClassOptions,image->storage_class),(double) image->colors,
-      CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
+      CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
+      image->alpha_trait));
     (void) WriteBlobString(image,buffer);
     (void) FormatLocaleString(buffer,MaxTextExtent,"columns=%.20g  rows=%.20g  "
       "depth=%.20g\n",(double) image->columns,(double) image->rows,(double)
@@ -2147,14 +2203,29 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
       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) WriteBlobByte(image,'{');
-          (void) WriteBlob(image,strlen(value),(const unsigned char *) value);
-          if (i <= (ssize_t) strlen(value))
-            (void) WriteBlobByte(image,'}');
+          if (i == (ssize_t) length)
+            (void) WriteBlob(image,length,(const unsigned char *) value);
+          else
+            {
+              (void) WriteBlobByte(image,'{');
+              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,'}');
+            }
         }
       (void) WriteBlobByte(image,'\n');
       property=GetNextImageProperty(image);
@@ -2272,6 +2343,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_BZLIB_DELEGATE)
       case BZipCompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&bzip_info,0,sizeof(bzip_info));
         bzip_info.bzalloc=AcquireBZIPMemory;
         bzip_info.bzfree=RelinquishBZIPMemory;
@@ -2286,6 +2360,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_LZMA_DELEGATE)
       case LZMACompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&allocator,0,sizeof(allocator));
         allocator.alloc=AcquireLZMAMemory;
         allocator.free=RelinquishLZMAMemory;
@@ -2301,6 +2378,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
       case LZWCompression:
       case ZipCompression:
       {
+        int
+          code;
+
         (void) ResetMagickMemory(&zip_info,0,sizeof(zip_info));
         zip_info.zalloc=AcquireZIPMemory;
         zip_info.zfree=RelinquishZIPMemory;
@@ -2341,6 +2421,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
             quantum_type,pixels,exception);
           do
           {
+            int
+              code;
+
             bzip_info.next_out=(char *) compress_pixels;
             bzip_info.avail_out=(unsigned int) BZipMaxExtent(packet_size*
               image->columns);
@@ -2366,6 +2449,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
             quantum_type,pixels,exception);
           do
           {
+            int
+              code;
+
             lzma_info.next_out=compress_pixels;
             lzma_info.avail_out=packet_size*image->columns;
             code=lzma_code(&lzma_info,LZMA_RUN);
@@ -2391,6 +2477,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
             quantum_type,pixels,exception);
           do
           {
+            int
+              code;
+
             zip_info.next_out=compress_pixels;
             zip_info.avail_out=(uInt) ZipMaxExtent(packet_size*image->columns);
             code=deflate(&zip_info,Z_SYNC_FLUSH);
@@ -2409,11 +2498,11 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
         case RLECompression:
         {
           length=0;
-          SetPixelInfo(image,p,&pixel);
+          GetPixelInfoPixel(image,p,&pixel);
           p+=GetPixelChannels(image);
           for (x=1; x < (ssize_t) image->columns; x++)
           {
-            SetPixelInfo(image,p,&target);
+            GetPixelInfoPixel(image,p,&target);
             if ((length < 255) &&
                 (IsPixelInfoEquivalent(&pixel,&target) != MagickFalse))
               length++;
@@ -2422,7 +2511,7 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
                 q=PopRunlengthPacket(image,q,length,&pixel,exception);
                 length=0;
               }
-            SetPixelInfo(image,p,&pixel);
+            GetPixelInfoPixel(image,p,&pixel);
             p+=GetPixelChannels(image);
           }
           q=PopRunlengthPacket(image,q,length,&pixel,exception);
@@ -2450,6 +2539,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_BZLIB_DELEGATE)
       case BZipCompression:
       {
+        int
+          code;
+
         for ( ; ; )
         {
           if (status == MagickFalse)
@@ -2476,6 +2568,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
 #if defined(MAGICKCORE_LZMA_DELEGATE)
       case LZMACompression:
       {
+        int
+          code;
+
         for ( ; ; )
         {
           if (status == MagickFalse)
@@ -2500,6 +2595,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
       case LZWCompression:
       case ZipCompression:
       {
+        int
+          code;
+
         for ( ; ; )
         {
           if (status == MagickFalse)