]> granicus.if.org Git - imagemagick/blobdiff - coders/pcx.c
(no commit message)
[imagemagick] / coders / pcx.c
index 20a27a2c14396261df85e7160c491bbfbbdca4a8..f8f8356bb5a8b7f22de6240b3637e457e5f6181f 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  %
@@ -267,6 +267,7 @@ static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
     *scanline;
 
   size_t
+    one,
     pcx_packets;
 
   /*
@@ -358,10 +359,11 @@ static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
     count=ReadBlob(image,3*image->colors,pcx_colormap);
     pcx_info.reserved=(unsigned char) ReadBlobByte(image);
     pcx_info.planes=(unsigned char) ReadBlobByte(image);
+    one=1;
     if ((pcx_info.bits_per_pixel != 8) || (pcx_info.planes == 1))
       if ((pcx_info.version == 3) || (pcx_info.version == 5) ||
           ((pcx_info.bits_per_pixel*pcx_info.planes) == 1))
-        image->colors=(size_t) MagickMin(1UL << (1UL*
+        image->colors=(size_t) MagickMin(one << (1UL*
           (pcx_info.bits_per_pixel*pcx_info.planes)),256UL);
     if (AcquireImageColormap(image,image->colors) == MagickFalse)
       ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
@@ -792,31 +794,39 @@ static MagickBooleanType PCXWritePixels(PCXInfo *pcx_info,
   q=pixels;
   for (i=0; i < (ssize_t) pcx_info->planes; i++)
   {
-    previous=(*q++);
-    count=1;
-    for (x=0; x < (ssize_t) (pcx_info->bytes_per_line-1); x++)
-    {
-      packet=(*q++);
-      if ((packet == previous) && (count < 63))
-        {
-          count++;
-          continue;
-        }
-      if ((count > 1) || ((previous & 0xc0) == 0xc0))
+    if (pcx_info->encoding == 0)
+      {
+        for (x=0; x < (ssize_t) pcx_info->bytes_per_line; x++)
+          (void) WriteBlobByte(image,(unsigned char) (*q++));
+      }
+    else
+      {
+        previous=(*q++);
+        count=1;
+        for (x=0; x < (ssize_t) (pcx_info->bytes_per_line-1); x++)
         {
-          count|=0xc0;
-          (void) WriteBlobByte(image,(unsigned char) count);
+          packet=(*q++);
+          if ((packet == previous) && (count < 63))
+            {
+              count++;
+              continue;
+            }
+          if ((count > 1) || ((previous & 0xc0) == 0xc0))
+            {
+              count|=0xc0;
+              (void) WriteBlobByte(image,(unsigned char) count);
+            }
+          (void) WriteBlobByte(image,previous);
+          previous=packet;
+          count=1;
         }
-      (void) WriteBlobByte(image,previous);
-      previous=packet;
-      count=1;
-    }
-    if ((count > 1) || ((previous & 0xc0) == 0xc0))
-      {
-        count|=0xc0;
-        (void) WriteBlobByte(image,(unsigned char) count);
+        if ((count > 1) || ((previous & 0xc0) == 0xc0))
+          {
+            count|=0xc0;
+            (void) WriteBlobByte(image,(unsigned char) count);
+          }
+        (void) WriteBlobByte(image,previous);
       }
-    (void) WriteBlobByte(image,previous);
   }
   return (MagickTrue);
 }
@@ -897,7 +907,7 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
     */
     pcx_info.identifier=0x0a;
     pcx_info.version=5;
-    pcx_info.encoding=1;
+    pcx_info.encoding=image_info->compression == NoCompression ? 0 : 1;
     pcx_info.bits_per_pixel=8;
     if ((image->storage_class == PseudoClass) &&
         (IsMonochromeImage(image,&image->exception) != MagickFalse))
@@ -974,8 +984,8 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
     for (i=0; i < 58; i++)
       (void) WriteBlobByte(image,'\0');
     length=(size_t) pcx_info.bytes_per_line;
-    pcx_pixels=(unsigned char *) AcquireQuantumMemory(length,
-      pcx_info.planes*sizeof(*pcx_pixels));
+    pcx_pixels=(unsigned char *) AcquireQuantumMemory(length,pcx_info.planes*
+      sizeof(*pcx_pixels));
     if (pcx_pixels == (unsigned char *) NULL)
       ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
     q=pcx_pixels;
@@ -1031,7 +1041,8 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
               {
                 for (x=(ssize_t) pcx_info.bytes_per_line; x != 0; x--)
                 {
-                  *q++=ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p)));
+                  *q++=ScaleQuantumToChar((Quantum)
+                    (GetAlphaPixelComponent(p)));
                   p++;
                 }
                 break;
@@ -1119,8 +1130,8 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
                 break;
               if (image->previous == (Image *) NULL)
                 {
-                  status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
-                image->rows);
+                  status=SetImageProgress(image,SaveImageTag,(MagickOffsetType)
+                    y,image->rows);
                   if (status == MagickFalse)
                     break;
                 }
@@ -1154,7 +1165,7 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
         ThrowWriterException(CorruptImageError,"ImproperImageHeader");
       (void) WriteBlobLSBLong(image,0x3ADE68B1L);
       for (i=0; i <= (ssize_t) scene; i++)
-        (void) WriteBlobLSBLong(image,(size_t) page_table[i]);
+        (void) WriteBlobLSBLong(image,(unsigned int) page_table[i]);
       page_table=(MagickOffsetType *) RelinquishMagickMemory(page_table);
     }
   if (status == MagickFalse)