]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Thu, 20 Nov 2014 23:46:19 +0000 (23:46 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Thu, 20 Nov 2014 23:46:19 +0000 (23:46 +0000)
coders/pdb.c

index 9ac686851f873e5d09be31ad2606f5ea783d0440..9fcf811ff58822f04186bc9c1734cf292d2d82c1 100644 (file)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %
-    20071202 TS * rewrote RLE decoder - old version could cause buffer overflows
-                * failure of RLE decoding now thows error RLEDecoderError
-                * fixed bug in RLE decoding - now all rows are decoded, not just
-      the first one
-    * fixed bug in reader - record offsets now handled correctly
-    * fixed bug in reader - only bits 0..2 indicate compression type
-                * in writer: now using image color count instead of depth
+%   20071202 TS * rewrote RLE decoder - old version could cause buffer overflows
+%               * failure of RLE decoding now thows error RLEDecoderError
+%               * fixed bug in RLE decoding - now all rows are decoded, not just
+%     the first one
+%   * fixed bug in reader - record offsets now handled correctly
+%   * fixed bug in reader - only bits 0..2 indicate compression type
+%               * in writer: now using image color count instead of depth
 */
 \f
 /*
@@ -268,7 +268,7 @@ static MagickBooleanType IsPDB(const unsigned char *magick,const size_t length)
 static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
   unsigned char
-    attributes, /* TS */
+    attributes,
     tag[3];
 
   Image
@@ -297,13 +297,13 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
 
   size_t
     bits_per_pixel,
-    num_pad_bytes, /* TS */
+    num_pad_bytes,
     one,
     packets;
 
   ssize_t
     count,
-    img_offset, /* TS */
+    img_offset,
     comment_offset = 0,
     y;
 
@@ -352,7 +352,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Read record header.
   */
-  img_offset=(int) ReadBlobMSBLong(image); /* TS */
+  img_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
   attributes=(unsigned char) ReadBlobByte(image);
   (void) attributes;
   count=ReadBlob(image,3,(unsigned char *) tag);
@@ -360,7 +360,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
     ThrowReaderException(CorruptImageError,"CorruptImage");
   if (pdb_info.number_records > 1)
     {
-      comment_offset=(int) ReadBlobMSBLong(image);
+      comment_offset=(ssize_t) ((int) ReadBlobMSBLong(image));
       attributes=(unsigned char) ReadBlobByte(image);
       count=ReadBlob(image,3,(unsigned char *) tag);
       if (count != 3  ||  memcmp(tag,"\x6f\x80\x01",3) != 0)
@@ -373,7 +373,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   */
   count=ReadBlob(image,32,(unsigned char *) pdb_image.name);
   pdb_image.version=ReadBlobByte(image);
-  pdb_image.type=ReadBlobByte(image);
+  pdb_image.type=(unsigned char) ((int) ReadBlobByte(image));
   pdb_image.reserved_1=ReadBlobMSBLong(image);
   pdb_image.note=ReadBlobMSBLong(image);
   pdb_image.x_last=(short) ReadBlobMSBShort(image);
@@ -405,7 +405,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   if (pixels == (unsigned char *) NULL)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
-  switch (pdb_image.version & 7) /* TS */
+  switch (pdb_image.version & 0x07) 
   {
     case 0:
     {
@@ -417,7 +417,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
     {
       image->compression=RLECompression;
       if (!DecodeImage(image, pixels, packets * image -> rows))
-        ThrowReaderException( CorruptImageError, "RLEDecoderError" ); /* TS */
+        ThrowReaderException( CorruptImageError, "RLEDecoderError" );
       break;
     }
     default:
@@ -534,7 +534,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   if (EOFBlob(image) != MagickFalse)
     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
       image->filename);
-  if (pdb_info.number_records > 1) /* TS */
+  if (pdb_info.number_records > 1)
     {
       char
         *comment;
@@ -748,16 +748,16 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
   if (status == MagickFalse)
     return(status);
   (void) TransformImageColorspace(image,sRGBColorspace,exception);
-  if (image -> colors <= 2  ||  GetImageType( image, exception ) == BilevelType) { /* TS */
-    bits_per_pixel = 1;
-  } else if (image -> colors <= 4) {
-    bits_per_pixel = 2;
-  } else if (image -> colors <= 8) {
-    bits_per_pixel = 3;
+  if ((image->colors <= 2) ||
+      (GetImageType(image,exception ) == BilevelType)) {
+    bits_per_pixel=1;
+  } else if (image->colors <= 4) {
+    bits_per_pixel=2;
+  } else if (image->colors <= 8) {
+    bits_per_pixel=3;
   } else {
-    bits_per_pixel = 4;
+    bits_per_pixel=4;
   }
-
   (void) ResetMagickMemory(pdb_info.name,0,32);
   (void) CopyMagickString(pdb_info.name,image_info->filename,32);
   pdb_info.attributes=0;
@@ -807,7 +807,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
   if (image->columns % 16)
     pdb_image.width=(short) (16*(image->columns/16+1));
   pdb_image.height=(short) image->rows;
-  packets=(bits_per_pixel*image->columns/8)*image->rows;
+  packets=(bits_per_pixel*image->columns/8+4)*image->rows;
   runlength=(unsigned char *) AcquireQuantumMemory(2UL*packets,
     sizeof(*runlength));
   if (runlength == (unsigned char *) NULL)
@@ -840,7 +840,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
       break;
     (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
       GrayQuantum,scanline,exception);
-    for (x=0; x < pdb_image.width; x++)
+    for (x=0; x < (ssize_t) pdb_image.width; x++)
     {
       if (x < (ssize_t) image->columns)
         buffer[literal+repeat]|=(0xff-scanline[x*packet_size]) >>
@@ -888,7 +888,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
       }
     }
     status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
-                image->rows);
+      image->rows);
     if (status == MagickFalse)
       break;
   }