]> granicus.if.org Git - imagemagick/blobdiff - coders/pict.c
(no commit message)
[imagemagick] / coders / pict.c
index 2f7352230358eccc42be25a0c8450701fc7ee502..22d8b6e5cba24a9c89541ae6094b6eb2541a23ee 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2010 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  %
@@ -44,6 +44,7 @@
 #include "magick/blob-private.h"
 #include "magick/cache.h"
 #include "magick/color-private.h"
+#include "magick/colormap.h"
 #include "magick/colormap-private.h"
 #include "magick/colorspace.h"
 #include "magick/composite.h"
@@ -108,7 +109,7 @@ typedef struct _PICTCode
   const char
     *name;
 
-  long
+  ssize_t
     length;
 
   const char
@@ -121,7 +122,7 @@ typedef struct _PICTPixmap
     version,
     pack_type;
 
-  unsigned long
+  size_t
     pack_size,
     horizontal_resolution,
     vertical_resolution;
@@ -132,7 +133,7 @@ typedef struct _PICTPixmap
     component_count,
     component_size;
 
-  unsigned long
+  size_t
     plane_bytes,
     table,
     reserved;
@@ -164,8 +165,8 @@ static const PICTCode
     /* 0x0b */ { "OvSize", 4, "oval size (point)" },
     /* 0x0c */ { "Origin", 4, "dh, dv (word)" },
     /* 0x0d */ { "TxSize", 2, "text size (word)" },
-    /* 0x0e */ { "FgColor", 4, "foreground color (longword)" },
-    /* 0x0f */ { "BkColor", 4, "background color (longword)" },
+    /* 0x0e */ { "FgColor", 4, "foreground color (ssize_tword)" },
+    /* 0x0f */ { "BkColor", 4, "background color (ssize_tword)" },
     /* 0x10 */ { "TxRatio", 8, "numerator (point), denominator (point)" },
     /* 0x11 */ { "Version", 1, "version (byte)" },
     /* 0x12 */ { "BkPixPat", 0, "color background pattern" },
@@ -337,7 +338,7 @@ static MagickBooleanType
 %  The format of the DecodeImage method is:
 %
 %      unsigned char *DecodeImage(Image *blob,Image *image,
-%        unsigned long bytes_per_line,const int bits_per_pixel,
+%        size_t bytes_per_line,const int bits_per_pixel,
 %        unsigned size_t extent)
 %
 %  A description of each parameter follows:
@@ -358,7 +359,7 @@ static MagickBooleanType
 static unsigned char *ExpandBuffer(unsigned char *pixels,
   MagickSizeType *bytes_per_line,const unsigned int bits_per_pixel)
 {
-  register long
+  register ssize_t
     i;
 
   register unsigned char
@@ -378,7 +379,7 @@ static unsigned char *ExpandBuffer(unsigned char *pixels,
       return(pixels);
     case 4:
     {
-      for (i=0; i < (long) *bytes_per_line; i++)
+      for (i=0; i < (ssize_t) *bytes_per_line; i++)
       {
         *q++=(*p >> 4) & 0xff;
         *q++=(*p & 15);
@@ -389,7 +390,7 @@ static unsigned char *ExpandBuffer(unsigned char *pixels,
     }
     case 2:
     {
-      for (i=0; i < (long) *bytes_per_line; i++)
+      for (i=0; i < (ssize_t) *bytes_per_line; i++)
       {
         *q++=(*p >> 6) & 0x03;
         *q++=(*p >> 4) & 0x03;
@@ -402,7 +403,7 @@ static unsigned char *ExpandBuffer(unsigned char *pixels,
     }
     case 1:
     {
-      for (i=0; i < (long) *bytes_per_line; i++)
+      for (i=0; i < (ssize_t) *bytes_per_line; i++)
       {
         *q++=(*p >> 7) & 0x01;
         *q++=(*p >> 6) & 0x01;
@@ -424,16 +425,16 @@ static unsigned char *ExpandBuffer(unsigned char *pixels,
 }
 
 static unsigned char *DecodeImage(Image *blob,Image *image,
-  unsigned long bytes_per_line,const unsigned int bits_per_pixel,size_t *extent)
+  size_t bytes_per_line,const unsigned int bits_per_pixel,size_t *extent)
 {
-  long
+  ssize_t
     j,
     y;
 
   MagickSizeType
     number_pixels;
 
-  register long
+  register ssize_t
     i;
 
   register unsigned char
@@ -451,7 +452,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
     *pixels,
     *scanline;
 
-  unsigned long
+  size_t
     bytes_per_pixel,
     scanline_length,
     width;
@@ -493,7 +494,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
       /*
         Pixels are already uncompressed.
       */
-      for (y=0; y < (long) image->rows; y++)
+      for (y=0; y < (ssize_t) image->rows; y++)
       {
         q=pixels+y*width;
         number_pixels=bytes_per_line;
@@ -514,7 +515,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
   /*
     Uncompress RLE pixels into uncompressed pixel buffer.
   */
-  for (y=0; y < (long) image->rows; y++)
+  for (y=0; y < (ssize_t) image->rows; y++)
   {
     q=pixels+y*width;
     if (bytes_per_line > 200)
@@ -528,7 +529,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
         break;
       }
     count=ReadBlob(blob,scanline_length,scanline);
-    for (j=0; j < (long) scanline_length; )
+    for (j=0; j < (ssize_t) scanline_length; )
       if ((scanline[j] & 0x80) == 0)
         {
           length=(size_t) ((scanline[j] & 0xff)+1);
@@ -537,20 +538,20 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
           if ((q-pixels+number_pixels) <= *extent)
             (void) CopyMagickMemory(q,p,(size_t) number_pixels);
           q+=number_pixels;
-          j+=(long) (length*bytes_per_pixel+1);
+          j+=(ssize_t) (length*bytes_per_pixel+1);
         }
       else
         {
           length=(size_t) (((scanline[j] ^ 0xff) & 0xff)+2);
           number_pixels=bytes_per_pixel;
           p=ExpandBuffer(scanline+j+1,&number_pixels,bits_per_pixel);
-          for (i=0; i < (long) length; i++)
+          for (i=0; i < (ssize_t) length; i++)
           {
             if ((q-pixels+number_pixels) <= *extent)
               (void) CopyMagickMemory(q,p,(size_t) number_pixels);
             q+=number_pixels;
           }
-          j+=bytes_per_pixel+1;
+          j+=(ssize_t) bytes_per_pixel+1;
         }
   }
   scanline=(unsigned char *) RelinquishMagickMemory(scanline);
@@ -574,7 +575,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
 %  The format of the EncodeImage method is:
 %
 %      size_t EncodeImage(Image *image,const unsigned char *scanline,
-%        const unsigned long bytes_per_line,unsigned char *pixels)
+%        const size_t bytes_per_line,unsigned char *pixels)
 %
 %  A description of each parameter follows:
 %
@@ -587,15 +588,14 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
 %    o pixels: A pointer to an array of characters where the packed
 %      characters are stored.
 %
-%
 */
 static size_t EncodeImage(Image *image,const unsigned char *scanline,
-  const unsigned long bytes_per_line,unsigned char *pixels)
+  const size_t bytes_per_line,unsigned char *pixels)
 {
 #define MaxCount  128
 #define MaxPackbitsRunlength  128
 
-  long
+  ssize_t
     count,
     repeat_count,
     runlength;
@@ -603,7 +603,7 @@ static size_t EncodeImage(Image *image,const unsigned char *scanline,
   register const unsigned char
     *p;
 
-  register long
+  register ssize_t
     i;
 
   register unsigned char
@@ -629,7 +629,7 @@ static size_t EncodeImage(Image *image,const unsigned char *scanline,
   p=scanline+(bytes_per_line-1);
   q=pixels;
   index=(*p);
-  for (i=(long) bytes_per_line-1; i >= 0; i--)
+  for (i=(ssize_t) bytes_per_line-1; i >= 0; i--)
   {
     if (index == *p)
       runlength++;
@@ -742,7 +742,6 @@ static size_t EncodeImage(Image *image,const unsigned char *scanline,
 %
 %    o length: Specifies the length of the magick string.
 %
-%
 */
 static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length)
 {
@@ -782,8 +781,8 @@ static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length)
 %
 */
 
-static inline unsigned long MagickMax(const unsigned long x,
-  const unsigned long y)
+static inline size_t MagickMax(const size_t x,
+  const size_t y)
 {
   if (x > y)
     return(x);
@@ -806,7 +805,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
     c,
     code;
 
-  long
+  ssize_t
     flags,
     j,
     version,
@@ -825,13 +824,13 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
   register IndexPacket
     *indexes;
 
-  register long
+  register ssize_t
     x;
 
   register PixelPacket
     *q;
 
-  register long
+  register ssize_t
     i;
 
   size_t
@@ -930,7 +929,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
             length=ReadBlobMSBShort(image);
             if (length != 0x000a)
               {
-                for (i=0; i < (long) (length-2); i++)
+                for (i=0; i < (ssize_t) (length-2); i++)
                   (void) ReadBlobByte(image);
                 break;
               }
@@ -946,10 +945,10 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
           case 0x13:
           case 0x14:
           {
-            long
+            ssize_t
               pattern;
 
-            unsigned long
+            size_t
               height,
               width;
 
@@ -977,7 +976,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
             (void) ReadBlobMSBLong(image);
             flags=1L*ReadBlobMSBShort(image);
             length=ReadBlobMSBShort(image);
-            for (i=0; i <= (long) length; i++)
+            for (i=0; i <= (ssize_t) length; i++)
               (void) ReadBlobMSBLong(image);
             width=1UL*(frame.bottom-frame.top);
             height=1UL*(frame.right-frame.left);
@@ -989,16 +988,16 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
               length=width;
             if (length < 8)
               {
-                for (i=0; i < (long) (length*height); i++)
+                for (i=0; i < (ssize_t) (length*height); i++)
                   (void) ReadBlobByte(image);
               }
             else
               for (j=0; j < (int) height; j++)
                 if (length > 200)
-                  for (j=0; j < (long) ReadBlobMSBShort(image); j++)
+                  for (j=0; j < (ssize_t) ReadBlobMSBShort(image); j++)
                     (void) ReadBlobByte(image);
                 else
-                  for (j=0; j < (long) ReadBlobByte(image); j++)
+                  for (j=0; j < (ssize_t) ReadBlobByte(image); j++)
                     (void) ReadBlobByte(image);
             break;
           }
@@ -1028,7 +1027,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
               Skip polygon or region.
             */
             length=ReadBlobMSBShort(image);
-            for (i=0; i < (long) (length-2); i++)
+            for (i=0; i < (ssize_t) (length-2); i++)
               (void) ReadBlobByte(image);
             break;
           }
@@ -1039,7 +1038,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
           case 0x9a:
           case 0x9b:
           {
-            long
+            ssize_t
               bytes_per_line;
 
             PICTRectangle
@@ -1112,7 +1111,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
                   }
                 if ((bytes_per_line & 0x8000) != 0)
                   {
-                    for (i=0; i < (long) tile_image->colors; i++)
+                    for (i=0; i < (ssize_t) tile_image->colors; i++)
                     {
                       j=ReadBlobMSBShort(image) % tile_image->colors;
                       if ((flags & 0x8000) != 0)
@@ -1127,7 +1126,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
                   }
                 else
                   {
-                    for (i=0; i < (long) tile_image->colors; i++)
+                    for (i=0; i < (ssize_t) tile_image->colors; i++)
                     {
                       tile_image->colormap[i].red=(Quantum) (QuantumRange-
                         tile_image->colormap[i].red);
@@ -1147,7 +1146,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
                   Skip region.
                 */
                 length=ReadBlobMSBShort(image);
-                for (i=0; i < (long) (length-2); i++)
+                for (i=0; i < (ssize_t) (length-2); i++)
                   (void) ReadBlobByte(image);
               }
             if ((code != 0x9a) && (code != 0x9b) &&
@@ -1166,23 +1165,24 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
               Convert PICT tile image to pixel packets.
             */
             p=pixels;
-            for (y=0; y < (long) tile_image->rows; y++)
+            for (y=0; y < (ssize_t) tile_image->rows; y++)
             {
               if (p > (pixels+extent+image->columns))
                 ThrowReaderException(CorruptImageError,"NotEnoughPixelData");
-              q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1,exception);
+              q=QueueAuthenticPixels(tile_image,0,y,tile_image->columns,1,
+                exception);
               if (q == (PixelPacket *) NULL)
                 break;
               indexes=GetAuthenticIndexQueue(tile_image);
-              for (x=0; x < (long) tile_image->columns; x++)
+              for (x=0; x < (ssize_t) tile_image->columns; x++)
               {
                 if (tile_image->storage_class == PseudoClass)
                   {
                     index=ConstrainColormapIndex(tile_image,*p);
                     indexes[x]=index;
-                    q->red=tile_image->colormap[(long) index].red;
-                    q->green=tile_image->colormap[(long) index].green;
-                    q->blue=tile_image->colormap[(long) index].blue;
+                    q->red=tile_image->colormap[(ssize_t) index].red;
+                    q->green=tile_image->colormap[(ssize_t) index].green;
+                    q->blue=tile_image->colormap[(ssize_t) index].blue;
                   }
                 else
                   {
@@ -1253,7 +1253,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
             unsigned char
               *info;
 
-            unsigned long
+            size_t
               type;
 
             /*
@@ -1313,7 +1313,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
             if (codes[code].length == -1)
               (void) ReadBlobMSBShort(image);
             else
-              for (i=0; i < (long) codes[code].length; i++)
+              for (i=0; i < (ssize_t) codes[code].length; i++)
                 (void) ReadBlobByte(image);
           }
         }
@@ -1353,7 +1353,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
         file=(FILE *) NULL;
         unique_file=AcquireUniqueFileResource(read_info->filename);
         if (unique_file != -1)
-          file=OpenMagickStream(read_info->filename,"wb");
+          file=fdopen(unique_file,"wb");
         if ((unique_file == -1) || (file == (FILE *) NULL))
           {
             (void) CopyMagickString(image->filename,read_info->filename,
@@ -1369,7 +1369,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
         ReadRectangle(image,frame);
         for (i=0; i < 122; i++)
           (void) ReadBlobByte(image);
-        for (i=0; i < (long) (length-154); i++)
+        for (i=0; i < (ssize_t) (length-154); i++)
         {
           c=ReadBlobByte(image);
           (void) fputc(c,file);
@@ -1380,10 +1380,12 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
         read_info=DestroyImageInfo(read_info);
         if (tile_image == (Image *) NULL)
           continue;
-        (void) FormatMagickString(geometry,MaxTextExtent,"%lux%lu",
+        (void) FormatMagickString(geometry,MaxTextExtent,"%.20gx%.20g",
+          (double) MagickMax(image->columns,tile_image->columns),
+          (double) MagickMax(image->rows,tile_image->rows));
+        (void) SetImageExtent(image,
           MagickMax(image->columns,tile_image->columns),
           MagickMax(image->rows,tile_image->rows));
-        (void) TransformImage(&image,(char *) NULL,geometry);
         if (image->colorspace != RGBColorspace)
           (void) TransformImageColorspace(image,tile_image->colorspace);
         (void) CompositeImage(image,CopyCompositeOp,tile_image,frame.left,
@@ -1401,7 +1403,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
           Skip reserved.
         */
         length=ReadBlobMSBShort(image);
-        for (i=0; i < (long) length; i++)
+        for (i=0; i < (ssize_t) length; i++)
           (void) ReadBlobByte(image);
         continue;
       }
@@ -1411,7 +1413,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
           Skip reserved.
         */
         length=(size_t) ((code >> 7) & 0xff);
-        for (i=0; i < (long) length; i++)
+        for (i=0; i < (ssize_t) length; i++)
           (void) ReadBlobByte(image);
         continue;
       }
@@ -1441,10 +1443,10 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
 %
 %  The format of the RegisterPICTImage method is:
 %
-%      unsigned long RegisterPICTImage(void)
+%      size_t RegisterPICTImage(void)
 %
 */
-ModuleExport unsigned long RegisterPICTImage(void)
+ModuleExport size_t RegisterPICTImage(void)
 {
   MagickInfo
     *entry;
@@ -1509,7 +1511,8 @@ ModuleExport void UnregisterPICTImage(void)
 %
 %  The format of the WritePICTImage method is:
 %
-%      MagickBooleanType WritePICTImage(const ImageInfo *image_info,Image *image)
+%      MagickBooleanType WritePICTImage(const ImageInfo *image_info,
+%        Image *image)
 %
 %  A description of each parameter follows.
 %
@@ -1517,7 +1520,6 @@ ModuleExport void UnregisterPICTImage(void)
 %
 %    o image:  The image.
 %
-%
 */
 static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   Image *image)
@@ -1539,7 +1541,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
     x_resolution,
     y_resolution;
 
-  long
+  ssize_t
     y;
 
   MagickBooleanType
@@ -1565,7 +1567,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   register const PixelPacket
     *p;
 
-  register long
+  register ssize_t
     i,
     x;
 
@@ -1577,7 +1579,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
     *packed_scanline,
     *scanline;
 
-  unsigned long
+  size_t
     bytes_per_line,
     storage_class;
 
@@ -1693,18 +1695,22 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
     {
       (void) WriteBlobMSBShort(image,0xa1);
       (void) WriteBlobMSBShort(image,0x1f2);
-      (void) WriteBlobMSBShort(image,(unsigned short) (GetStringInfoLength(profile)+4));
+      (void) WriteBlobMSBShort(image,(unsigned short)
+        (GetStringInfoLength(profile)+4));
       (void) WriteBlobString(image,"8BIM");
-      (void) WriteBlob(image,GetStringInfoLength(profile),GetStringInfoDatum(profile));
+      (void) WriteBlob(image,GetStringInfoLength(profile),
+        GetStringInfoDatum(profile));
     }
   profile=GetImageProfile(image,"icc");
   if (profile != (StringInfo *) NULL)
     {
       (void) WriteBlobMSBShort(image,0xa1);
       (void) WriteBlobMSBShort(image,0xe0);
-      (void) WriteBlobMSBShort(image,(unsigned short) (GetStringInfoLength(profile)+4));
+      (void) WriteBlobMSBShort(image,(unsigned short)
+        (GetStringInfoLength(profile)+4));
       (void) WriteBlobMSBLong(image,0x00000000UL);
-      (void) WriteBlob(image,GetStringInfoLength(profile),GetStringInfoDatum(profile));
+      (void) WriteBlob(image,GetStringInfoLength(profile),
+        GetStringInfoDatum(profile));
       (void) WriteBlobMSBShort(image,0xa1);
       (void) WriteBlobMSBShort(image,0xe0);
       (void) WriteBlobMSBShort(image,4);
@@ -1749,7 +1755,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
         return(MagickFalse);
       jpeg_image=DestroyImage(jpeg_image);
       (void) WriteBlobMSBShort(image,PictJPEGOp);
-      (void) WriteBlobMSBLong(image,(unsigned long) length+154);
+      (void) WriteBlobMSBLong(image,(unsigned int) length+154);
       (void) WriteBlobMSBShort(image,0x0000);
       (void) WriteBlobMSBLong(image,0x00010000UL);
       (void) WriteBlobMSBLong(image,0x00000000UL);
@@ -1808,7 +1814,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   else
     {
       (void) WriteBlobMSBShort(image,PictPixmapOp);
-      (void) WriteBlobMSBLong(image,(unsigned long) base_address);
+      (void) WriteBlobMSBLong(image,(size_t) base_address);
     }
   (void) WriteBlobMSBShort(image,(unsigned short) (row_bytes | 0x8000));
   (void) WriteBlobMSBShort(image,(unsigned short) bounds.top);
@@ -1820,7 +1826,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   */
   (void) WriteBlobMSBShort(image,(unsigned short) pixmap.version);
   (void) WriteBlobMSBShort(image,(unsigned short) pixmap.pack_type);
-  (void) WriteBlobMSBLong(image,pixmap.pack_size);
+  (void) WriteBlobMSBLong(image,(unsigned int) pixmap.pack_size);
   (void) WriteBlobMSBShort(image,(unsigned short) (x_resolution+0.5));
   (void) WriteBlobMSBShort(image,0x0000);
   (void) WriteBlobMSBShort(image,(unsigned short) (y_resolution+0.5));
@@ -1832,9 +1838,9 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   */
   (void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_count);
   (void) WriteBlobMSBShort(image,(unsigned short) pixmap.component_size);
-  (void) WriteBlobMSBLong(image,(unsigned long) pixmap.plane_bytes);
-  (void) WriteBlobMSBLong(image,(unsigned long) pixmap.table);
-  (void) WriteBlobMSBLong(image,(unsigned long) pixmap.reserved);
+  (void) WriteBlobMSBLong(image,(unsigned int) pixmap.plane_bytes);
+  (void) WriteBlobMSBLong(image,(unsigned int) pixmap.table);
+  (void) WriteBlobMSBLong(image,(unsigned int) pixmap.reserved);
   if (storage_class == PseudoClass)
     {
       /*
@@ -1843,7 +1849,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
       (void) WriteBlobMSBLong(image,0x00000000L);  /* color seed */
       (void) WriteBlobMSBShort(image,0L);  /* color flags */
       (void) WriteBlobMSBShort(image,(unsigned short) (image->colors-1));
-      for (i=0; i < (long) image->colors; i++)
+      for (i=0; i < (ssize_t) image->colors; i++)
       {
         (void) WriteBlobMSBShort(image,(unsigned short) i);
         (void) WriteBlobMSBShort(image,ScaleQuantumToShort(
@@ -1871,21 +1877,20 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
   */
   count=0;
   if ((storage_class == PseudoClass) && (image->matte == MagickFalse))
-    for (y=0; y < (long) image->rows; y++)
+    for (y=0; y < (ssize_t) image->rows; y++)
     {
       p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetVirtualIndexQueue(image);
-      for (x=0; x < (long) image->columns; x++)
+      for (x=0; x < (ssize_t) image->columns; x++)
         scanline[x]=(unsigned char) indexes[x];
-      count+=EncodeImage(image,scanline,(unsigned long) (row_bytes & 0x7FFF),
+      count+=EncodeImage(image,scanline,(size_t) (row_bytes & 0x7FFF),
         packed_scanline);
-      if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
-          (QuantumTick(y,image->rows) != MagickFalse))
+      if (image->previous == (Image *) NULL)
         {
-          status=image->progress_monitor(SaveImageTag,y,image->rows,
-            image->client_data);
+          status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+                image->rows);
           if (status == MagickFalse)
             break;
         }
@@ -1894,8 +1899,8 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
     if (image_info->compression == JPEGCompression)
       {
         (void) ResetMagickMemory(scanline,0,row_bytes);
-        for (y=0; y < (long) image->rows; y++)
-          count+=EncodeImage(image,scanline,(unsigned long)
+        for (y=0; y < (ssize_t) image->rows; y++)
+          count+=EncodeImage(image,scanline,(size_t)
             (row_bytes & 0x7FFF),packed_scanline);
       }
     else
@@ -1910,7 +1915,7 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
         green=scanline+image->columns;
         blue=scanline+2*image->columns;
         opacity=scanline+3*image->columns;
-        for (y=0; y < (long) image->rows; y++)
+        for (y=0; y < (ssize_t) image->rows; y++)
         {
           p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
           if (p == (const PixelPacket *) NULL)
@@ -1925,23 +1930,22 @@ static MagickBooleanType WritePICTImage(const ImageInfo *image_info,
               green=scanline+2*image->columns;
               blue=scanline+3*image->columns;
             }
-          for (x=0; x < (long) image->columns; x++)
+          for (x=0; x < (ssize_t) image->columns; x++)
           {
-            *red++=ScaleQuantumToChar(p->red);
-            *green++=ScaleQuantumToChar(p->green);
-            *blue++=ScaleQuantumToChar(p->blue);
+            *red++=ScaleQuantumToChar(GetRedPixelComponent(p));
+            *green++=ScaleQuantumToChar(GetGreenPixelComponent(p));
+            *blue++=ScaleQuantumToChar(GetBluePixelComponent(p));
             if (image->matte != MagickFalse)
               *opacity++=ScaleQuantumToChar((Quantum)
-                (QuantumRange-p->opacity));
+                (GetAlphaPixelComponent(p)));
             p++;
           }
           count+=EncodeImage(image,scanline,bytes_per_line & 0x7FFF,
             packed_scanline);
-          if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
-              (QuantumTick(y,image->rows) != MagickFalse))
+          if (image->previous == (Image *) NULL)
             {
-              status=image->progress_monitor(SaveImageTag,y,image->rows,
-                image->client_data);
+              status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
+                image->rows);
               if (status == MagickFalse)
                 break;
             }