]> granicus.if.org Git - imagemagick/blobdiff - coders/pdb.c
(no commit message)
[imagemagick] / coders / pdb.c
index 82801fb815bad7f622d3ea947fdd2e6a92844263..c716557b39b04de156ce4645193023bb0b274782 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2012 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  %
 /*
   Include declarations.
 */
-#include "magick/studio.h"
-#include "magick/attribute.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/colormap-private.h"
-#include "magick/color-private.h"
-#include "magick/colormap.h"
-#include "magick/colorspace.h"
-#include "magick/constitute.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-private.h"
-#include "magick/list.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/monitor.h"
-#include "magick/monitor-private.h"
-#include "magick/property.h"
-#include "magick/quantum-private.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/colormap-private.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colormap.h"
+#include "MagickCore/colorspace.h"
+#include "MagickCore/colorspace-private.h"
+#include "MagickCore/constitute.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/monitor.h"
+#include "MagickCore/monitor-private.h"
+#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/property.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
 \f
 /*
   Typedef declarations.
@@ -132,7 +134,7 @@ typedef struct _PDBImage
   Forward declarations.
 */
 static MagickBooleanType
-  WritePDBImage(const ImageInfo *,Image *);
+  WritePDBImage(const ImageInfo *,Image *,ExceptionInfo *);
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -268,14 +270,6 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   Image
     *image;
 
-  IndexPacket
-    index;
-
-  ssize_t
-    img_offset, /* TS */
-    comment_offset = 0,
-    y;
-
   MagickBooleanType
     status;
 
@@ -285,29 +279,33 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   PDBInfo
     pdb_info;
 
-  register IndexPacket
-    *indexes;
+  Quantum
+    index;
 
   register ssize_t
     x;
 
-  register PixelPacket
+  register Quantum
     *q;
 
   register unsigned char
     *p;
 
+  size_t
+    bits_per_pixel,
+    num_pad_bytes, /* TS */
+    one,
+    packets;
+
   ssize_t
-    count;
+    count,
+    img_offset, /* TS */
+    comment_offset = 0,
+    y;
 
   unsigned char
     *pixels;
 
-  size_t
-    num_pad_bytes, /* TS */
-    bits_per_pixel,
-    packets;
-
   /*
     Open image file.
   */
@@ -318,7 +316,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
-  image=AcquireImage(image_info);
+  image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
     {
@@ -350,21 +348,20 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   /*
     Read record header.
   */
-  img_offset=(ssize_t) ReadBlobMSBLong(image); /* TS */
+  img_offset=(int) ReadBlobMSBLong(image); /* TS */
   attributes=(unsigned char) ReadBlobByte(image);
+  (void) attributes;
   count=ReadBlob(image,3,(unsigned char *) tag);
   if (count != 3  ||  memcmp(tag,"\x6f\x80\x00",3) != 0)
     ThrowReaderException(CorruptImageError,"CorruptImage");
-
   if (pdb_info.number_records > 1)
     {
-      comment_offset=(ssize_t) ReadBlobMSBLong(image);
+      comment_offset=(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)
         ThrowReaderException(CorruptImageError,"CorruptImage");
     }
-
   num_pad_bytes = (size_t) (img_offset - TellBlob( image ));
   while (num_pad_bytes--) ReadBlobByte( image );
   /*
@@ -390,7 +387,8 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
   image->depth=8;
   image->storage_class=PseudoClass;
   bits_per_pixel=pdb_image.type == 0 ? 2UL : pdb_image.type == 2 ? 4UL : 1UL;
-  if (AcquireImageColormap(image,1 << bits_per_pixel) == MagickFalse)
+  one=1;
+  if (AcquireImageColormap(image,one << bits_per_pixel,exception) == MagickFalse)
     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
   if (image_info->ping != MagickFalse)
     {
@@ -436,26 +434,26 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
       for (y=0; y < (ssize_t) image->rows; y++)
       {
         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (PixelPacket *) NULL)
+        if (q == (Quantum *) NULL)
           break;
-        indexes=GetAuthenticIndexQueue(image);
         for (x=0; x < ((ssize_t) image->columns-7); x+=8)
         {
           for (bit=0; bit < 8; bit++)
           {
-            index=(IndexPacket) (*p & (0x80 >> bit) ? 0x00 : 0x01);
-            indexes[x+bit]=index;
-            *q++=image->colormap[(ssize_t) index];
+            index=(Quantum) (*p & (0x80 >> bit) ? 0x00 : 0x01);
+            SetPixelIndex(image,index,q);
+            q+=GetPixelChannels(image);
           }
           p++;
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
         status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
-                image->rows);
+          image->rows);
         if (status == MagickFalse)
           break;
       }
+      (void) SyncImage(image,exception);
       break;
     }
     case 2:
@@ -466,32 +464,32 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
       for (y=0; y < (ssize_t) image->rows; y++)
       {
         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (PixelPacket *) NULL)
+        if (q == (Quantum *) NULL)
           break;
-        indexes=GetAuthenticIndexQueue(image);
         for (x=0; x < (ssize_t) image->columns; x+=4)
         {
-          index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03));
-          indexes[x]=index;
-          *q++=image->colormap[(ssize_t) index];
-          index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03));
-          indexes[x+1]=index;
-          *q++=image->colormap[(ssize_t) index];
-          index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03));
-          indexes[x+2]=index;
-          *q++=image->colormap[(ssize_t) index];
-          index=ConstrainColormapIndex(image,3UL-((*p) & 0x03));
-          indexes[x+3]=index;
-          *q++=image->colormap[(ssize_t) index];
+          index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03),exception);
+          SetPixelIndex(image,index,q);
+          q+=GetPixelChannels(image);
+          index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03),exception);
+          SetPixelIndex(image,index,q);
+          q+=GetPixelChannels(image);
+          index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03),exception);
+          SetPixelIndex(image,index,q);
+          q+=GetPixelChannels(image);
+          index=ConstrainColormapIndex(image,3UL-((*p) & 0x03),exception);
+          SetPixelIndex(image,index,q);
           p++;
+          q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
         status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
-                image->rows);
+          image->rows);
         if (status == MagickFalse)
           break;
       }
+      (void) SyncImage(image,exception);
       break;
     }
     case 4:
@@ -502,26 +500,26 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
       for (y=0; y < (ssize_t) image->rows; y++)
       {
         q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (PixelPacket *) NULL)
+        if (q == (Quantum *) NULL)
           break;
-        indexes=GetAuthenticIndexQueue(image);
         for (x=0; x < (ssize_t) image->columns; x+=2)
         {
-          index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f));
-          indexes[x]=index;
-          *q++=image->colormap[(ssize_t) index];
-          index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f));
-          indexes[x+1]=index;
-          *q++=image->colormap[(ssize_t) index];
+          index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f),exception);
+          SetPixelIndex(image,index,q);
+          q+=GetPixelChannels(image);
+          index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f),exception);
+          SetPixelIndex(image,index,q);
           p++;
+          q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
         status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
-                image->rows);
+          image->rows);
         if (status == MagickFalse)
           break;
       }
+      (void) SyncImage(image,exception);
       break;
     }
     default:
@@ -574,7 +572,7 @@ static Image *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
       *p='\0';
       if (comment == (char *) NULL)
         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
-      (void) SetImageProperty(image,"comment",comment);
+      (void) SetImageProperty(image,"comment",comment,exception);
       comment=DestroyString(comment);
     }
   (void) CloseBlob(image);
@@ -658,7 +656,8 @@ ModuleExport void UnregisterPDBImage(void)
 %
 %  The format of the WritePDBImage method is:
 %
-%      MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
+%      MagickBooleanType WritePDBImage(const ImageInfo *image_info,
+%        Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
@@ -666,6 +665,7 @@ ModuleExport void UnregisterPDBImage(void)
 %
 %    o image:  The image.
 %
+%    o exception: return any errors or warnings in this structure.
 %
 */
 
@@ -684,7 +684,8 @@ static unsigned char *EncodeRLE(unsigned char *destination,
   return(destination);
 }
 
-static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
+static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
+  ExceptionInfo *exception)
 {
   const char
     *comment;
@@ -692,9 +693,6 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   int
     bits;
 
-  ssize_t
-    y;
-
   MagickBooleanType
     status;
 
@@ -707,7 +705,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   QuantumInfo
     *quantum_info;
 
-  register const PixelPacket
+  register const Quantum
     *p;
 
   register ssize_t
@@ -717,19 +715,20 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
     *q;
 
   size_t
-    packet_size;
+    bits_per_pixel,
+    literal,
+    packets,
+    packet_size,
+    repeat;
+
+  ssize_t
+    y;
 
   unsigned char
     *buffer,
     *runlength,
     *scanline;
 
-  size_t
-    bits_per_pixel,
-    literal,
-    packets,
-    repeat;
-
   /*
     Open output image file.
   */
@@ -739,13 +738,14 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
+  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
-  if (image->colorspace != RGBColorspace)
-    (void) TransformImageColorspace(image,RGBColorspace);
-
-  if (image -> colors <= 2  ||  GetImageType( image, &image -> exception ) == BilevelType) { /* TS */
+  if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+    (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;
@@ -769,21 +769,21 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   (void) CopyMagickMemory(pdb_info.id,"View",4);
   pdb_info.seed=0;
   pdb_info.next_record=0;
-  comment=GetImageProperty(image,"comment");
+  comment=GetImageProperty(image,"comment",exception);
   pdb_info.number_records=(comment == (const char *) NULL ? 1 : 2);
   (void) WriteBlob(image,32,(unsigned char *) pdb_info.name);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.attributes);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.version);
-  (void) WriteBlobMSBLong(image,pdb_info.create_time);
-  (void) WriteBlobMSBLong(image,pdb_info.modify_time);
-  (void) WriteBlobMSBLong(image,pdb_info.archive_time);
-  (void) WriteBlobMSBLong(image,pdb_info.modify_number);
-  (void) WriteBlobMSBLong(image,pdb_info.application_info);
-  (void) WriteBlobMSBLong(image,pdb_info.sort_info);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.create_time);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_time);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.archive_time);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_number);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.application_info);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.sort_info);
   (void) WriteBlob(image,4,(unsigned char *) pdb_info.type);
   (void) WriteBlob(image,4,(unsigned char *) pdb_info.id);
-  (void) WriteBlobMSBLong(image,(size_t) pdb_info.seed);
-  (void) WriteBlobMSBLong(image,(size_t) pdb_info.next_record);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.seed);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_info.next_record);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_info.number_records);
   (void) CopyMagickString(pdb_image.name,pdb_info.name,32);
   pdb_image.version=1;  /* RLE Compressed */
@@ -817,26 +817,26 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
     sizeof(*scanline));
   if (scanline == (unsigned char *) NULL)
     ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
-  if (image->colorspace != RGBColorspace)
-    (void) TransformImageColorspace(image,RGBColorspace);
+  if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+    (void) TransformImageColorspace(image,sRGBColorspace,exception);
   /*
     Convert to GRAY raster scanline.
   */
   quantum_info=AcquireQuantumInfo(image_info,image);
   if (quantum_info == (QuantumInfo *) NULL)
     ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
-  bits=8/(ssize_t) bits_per_pixel-1;  /* start at most significant bits */
+  bits=8/(int) bits_per_pixel-1;  /* start at most significant bits */
   literal=0;
   repeat=0;
   q=runlength;
   buffer[0]=0x00;
   for (y=0; y < (ssize_t) image->rows; y++)
   {
-    p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
-    if (p == (const PixelPacket *) NULL)
+    p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+    if (p == (const Quantum *) NULL)
       break;
-    (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
-      GrayQuantum,scanline,&image->exception);
+    (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
+      GrayQuantum,scanline,exception);
     for (x=0; x < pdb_image.width; x++)
     {
       if (x < (ssize_t) image->columns)
@@ -880,7 +880,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
                   literal-=0x80;
                 }
             }
-        bits=8/(ssize_t) bits_per_pixel-1;
+        bits=8/(int) bits_per_pixel-1;
         buffer[literal+repeat]=0x00;
       }
     }
@@ -896,7 +896,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   /*
     Write the Image record header.
   */
-  (void) WriteBlobMSBLong(image,(size_t)
+  (void) WriteBlobMSBLong(image,(unsigned int)
     (TellBlob(image)+8*pdb_info.number_records));
   (void) WriteBlobByte(image,0x40);
   (void) WriteBlobByte(image,0x6f);
@@ -907,7 +907,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
       /*
         Write the comment record header.
       */
-      (void) WriteBlobMSBLong(image,(size_t) (TellBlob(image)+8+58+q-
+      (void) WriteBlobMSBLong(image,(unsigned int) (TellBlob(image)+8+58+q-
         runlength));
       (void) WriteBlobByte(image,0x40);
       (void) WriteBlobByte(image,0x6f);
@@ -920,11 +920,11 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
   (void) WriteBlob(image,32,(unsigned char *) pdb_image.name);
   (void) WriteBlobByte(image,(unsigned char) pdb_image.version);
   (void) WriteBlobByte(image,(unsigned char) pdb_image.type);
-  (void) WriteBlobMSBLong(image,pdb_image.reserved_1);
-  (void) WriteBlobMSBLong(image,pdb_image.note);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_1);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.note);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_last);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_last);
-  (void) WriteBlobMSBLong(image,pdb_image.reserved_2);
+  (void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_2);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_anchor);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_anchor);
   (void) WriteBlobMSBShort(image,(unsigned short) pdb_image.width);