]> granicus.if.org Git - imagemagick/blobdiff - coders/palm.c
(no commit message)
[imagemagick] / coders / palm.c
index 66fa9b6bf7cf9b7cdb61f4232cee76a20f04adff..84bea22db69b22ff12638f144ee41749bddeb909 100644 (file)
@@ -42,6 +42,7 @@
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
 #include "MagickCore/cache.h"
@@ -161,7 +162,7 @@ static unsigned char
   Forward declarations.
 */
 static MagickBooleanType
-  WritePALMImage(const ImageInfo *,Image *);
+  WritePALMImage(const ImageInfo *,Image *,ExceptionInfo *);
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -175,20 +176,20 @@ static MagickBooleanType
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  FindColor() returns the index of the matching entry from PalmPalette for a
-%  given PixelPacket.
+%  given PixelInfo.
 %
 %  The format of the FindColor method is:
 %
-%      int FindColor(const Image *image,PixelPacket *pixel)
+%      int FindColor(const Image *image,PixelInfo *pixel)
 %
 %  A description of each parameter follows:
 %
 %    o int: the index of the matching color or -1 if not found/
 %
-%    o pixel: a pointer to the PixelPacket to be matched.
+%    o pixel: a pointer to the PixelInfo to be matched.
 %
 */
-static int FindColor(const Image *image,PixelPacket *packet)
+static int FindColor(const Image *image,PixelInfo *packet)
 {
   register ssize_t
     i;
@@ -309,7 +310,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
       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)
     {
@@ -342,7 +343,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
     */
     one=1;
     if ((bits_per_pixel < 16) &&
-        (AcquireImageColormap(image,one << bits_per_pixel) == MagickFalse))
+        (AcquireImageColormap(image,one << bits_per_pixel,exception) == MagickFalse))
       ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
     GetPixelInfo(image,&transpix);
     if (bits_per_pixel == 16)  /* Direct Color */
@@ -370,7 +371,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
             for (i=0; i < (ssize_t) count; i++)
             {
               ReadBlobByte(image);
-              index=ConstrainColormapIndex(image,255-i);
+              index=ConstrainColormapIndex(image,255-i,exception);
               image->colormap[(int) index].red=
                 ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
               image->colormap[(int) index].green=
@@ -383,7 +384,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
         {
           for (i=0; i < (ssize_t) (1L << bits_per_pixel); i++)
           {
-            index=ConstrainColormapIndex(image,255-i);
+            index=ConstrainColormapIndex(image,255-i,exception);
             image->colormap[(int) index].red=
               ScaleCharToQuantum(PalmPalette[i][0]);
             image->colormap[(int) index].green=
@@ -463,7 +464,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
         }
       ptr=one_row;
       q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-      if (q == (const Quantum *) NULL)
+      if (q == (Quantum *) NULL)
         break;
       if (bits_per_pixel == 16)
         {
@@ -477,7 +478,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
             SetPixelGreen(image,(QuantumRange*((color16 >> 5) & 0x3f))/0x3f,q);
             SetPixelBlue(image,(QuantumRange*((color16 >> 0) & 0x1f))/0x1f,q);
             SetPixelAlpha(image,OpaqueAlpha,q);
-            q+=GetPixelComponents(image);
+            q+=GetPixelChannels(image);
           }
         }
       else
@@ -489,7 +490,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
               ThrowReaderException(CorruptImageError,"CorruptImage");
             index=(Quantum) (mask-(((*ptr) & (mask << bit)) >> bit));
             SetPixelIndex(image,index,q);
-            SetPixelPacket(image,image->colormap+(ssize_t) index,q);
+            SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
             if (bit)
               bit-=bits_per_pixel;
             else
@@ -497,7 +498,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
                 ptr++;
                 bit=8-bits_per_pixel;
               }
-            q+=GetPixelComponents(image);
+            q+=GetPixelChannels(image);
           }
           if (SyncAuthenticPixels(image,exception) == MagickFalse)
             break;
@@ -513,14 +514,13 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
     if (flags & PALM_HAS_TRANSPARENCY_FLAG)
       {
         if (bits_per_pixel != 16)
-          SetPixelInfoPacket(image,image->colormap+(mask-transparentIndex),
-            &transpix);
-        (void) TransparentPaintImage(image,&transpix,(Quantum)
-          TransparentAlpha,MagickFalse);
+          transpix=image->colormap[mask-transparentIndex];
+        (void) TransparentPaintImage(image,&transpix,(Quantum) TransparentAlpha,
+          MagickFalse,exception);
       }
     one_row=(unsigned char *) RelinquishMagickMemory(one_row);
     if (compressionType == PALM_COMPRESSION_SCANLINE)
-    lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
+      lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
     /*
       Proceed to next image. Copied from coders/pnm.c
     */
@@ -546,7 +546,7 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
         /*
           Allocate next image structure. Copied from coders/pnm.c
         */
-        AcquireNextImage(image_info,image);
+        AcquireNextImage(image_info,image,exception);
         if (GetNextImageInList(image) == (Image *) NULL)
           {
             (void) DestroyImageList(image);
@@ -640,7 +640,7 @@ ModuleExport void UnregisterPALMImage(void)
 %  The format of the WritePALMImage method is:
 %
 %      MagickBooleanType WritePALMImage(const ImageInfo *image_info,
-%        Image *image)
+%        Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
@@ -648,16 +648,15 @@ ModuleExport void UnregisterPALMImage(void)
 %
 %    o image:  A pointer to a Image structure.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
-  Image *image)
+  Image *image,ExceptionInfo *exception)
 {
   int
     y;
 
-  ExceptionInfo
-    exception;
-
   MagickBooleanType
     status;
 
@@ -669,7 +668,7 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
   MagickSizeType
     cc;
 
-  PixelPacket
+  PixelInfo
     transpix;
 
   QuantizeInfo
@@ -716,10 +715,11 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  status=OpenBlob(image_info,image,WriteBinaryBlobMode,&exception);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
+  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
   if (status == MagickFalse)
     return(status);
-  GetExceptionInfo(&exception);
   quantize_info=AcquireQuantizeInfo(image_info);
   flags=0;
   currentOffset=0;
@@ -733,22 +733,22 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
   scene=0;
   do
   {
-    if (IsRGBColorspace(image->colorspace) == MagickFalse)
-      (void) TransformImageColorspace(image,RGBColorspace);
-    count=GetNumberColors(image,NULL,&exception);
+    if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+      (void) TransformImageColorspace(image,sRGBColorspace,exception);
+    count=GetNumberColors(image,NULL,exception);
     for (bits_per_pixel=1;  (one << bits_per_pixel) < count; bits_per_pixel*=2) ;
     if (image_info->depth > 100)
       bits_per_pixel=image_info->depth-100;
     if (bits_per_pixel < 16)
-      (void) TransformImageColorspace(image,image->colorspace);
+      (void) TransformImageColorspace(image,image->colorspace,exception);
     if (bits_per_pixel < 8)
       {
-        (void) TransformImageColorspace(image,GRAYColorspace);
-        (void) SetImageType(image,PaletteType);
-        (void) SortColormapByIntensity(image);
+        (void) TransformImageColorspace(image,GRAYColorspace,exception);
+        (void) SetImageType(image,PaletteType,exception);
+        (void) SortColormapByIntensity(image,exception);
       }
     if ((image->storage_class == PseudoClass) && (image->colors > 256))
-      (void) SetImageStorageClass(image,DirectClass);
+      (void) SetImageStorageClass(image,DirectClass,exception);
     if (image->storage_class == PseudoClass)
       flags|=PALM_HAS_COLORMAP_FLAG;
     else
@@ -793,9 +793,10 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
       {
         if (flags & PALM_HAS_COLORMAP_FLAG)  /* Write out colormap */
           {
-            quantize_info->dither=IsPaletteImage(image,&image->exception);
+            quantize_info->dither_method=IsPaletteImage(image,exception)
+              == MagickFalse ? RiemersmaDitherMethod : NoDitherMethod;
             quantize_info->number_colors=image->colors;
-            (void) QuantizeImage(quantize_info,image);
+            (void) QuantizeImage(quantize_info,image,exception);
             (void) WriteBlobMSBShort(image,(unsigned short) image->colors);
             for (count = 0; count < image->colors; count++)
             {
@@ -815,18 +816,18 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
             *affinity_image;
 
           affinity_image=ConstituteImage(256,1,"RGB",CharPixel,&PalmPalette,
-            &exception);
+            exception);
           (void) TransformImageColorspace(affinity_image,
-            affinity_image->colorspace);
-          (void) RemapImage(quantize_info,image,affinity_image);
+            affinity_image->colorspace,exception);
+          (void) RemapImage(quantize_info,image,affinity_image,exception);
           for (y=0; y < (ssize_t) image->rows; y++)
           {
-            q=GetAuthenticPixels(image,0,y,image->columns,1,&exception);
+            q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
             for (x=0; x < (ssize_t) image->columns; x++)
             {
               SetPixelIndex(image,FindColor(image,&image->colormap[(ssize_t)
                 GetPixelIndex(image,q)]),q);
-              q+=GetPixelComponents(image);
+              q+=GetPixelChannels(image);
             }
           }
           affinity_image=DestroyImage(affinity_image);
@@ -847,7 +848,7 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
     {
       ptr=one_row;
       (void) ResetMagickMemory(ptr,0,bytes_per_row);
-      p=GetVirtualPixels(image,0,y,image->columns,1,&exception);
+      p=GetVirtualPixels(image,0,y,image->columns,1,exception);
       if (p == (const Quantum *) NULL)
         break;
       if (bits_per_pixel == 16)
@@ -868,7 +869,7 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
               }
             *ptr++=(unsigned char) ((color16 >> 8) & 0xff);
             *ptr++=(unsigned char) (color16 & 0xff);
-            p+=GetPixelComponents(image);
+            p+=GetPixelChannels(image);
           }
         }
       else
@@ -891,7 +892,7 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
                 byte=0x00;
                 bit=(unsigned char) (8-bits_per_pixel);
               }
-            p+=GetPixelComponents(image);
+            p+=GetPixelChannels(image);
           }
           if ((image->columns % (8/bits_per_pixel)) != 0)
             *ptr++=byte;
@@ -982,6 +983,5 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
   } while (image_info->adjoin != MagickFalse);
   quantize_info=DestroyQuantizeInfo(quantize_info);
   (void) CloseBlob(image);
-  (void) DestroyExceptionInfo(&exception);
   return(MagickTrue);
 }