]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Mon, 26 Aug 2013 12:23:46 +0000 (12:23 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Mon, 26 Aug 2013 12:23:46 +0000 (12:23 +0000)
MagickCore/identify.c
coders/pnm.c

index 26329c61d22ace50bf51bf8fae067ba47a6049dc..0f51e1c63e2d8a478f1c1cccb3fa1f478e11e6ec 100644 (file)
@@ -771,7 +771,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
   (void) FormatLocaleFile(file,"  Compression: %s\n",CommandOptionToMnemonic(
     MagickCompressOptions,(ssize_t) image->compression));
   if (image->quality != UndefinedCompressionQuality)
-    (void) FormatLocaleFile(file,"  Quality: %.20g\n",(double) image->quality)
+    (void) FormatLocaleFile(file,"  Quality: %.20g\n",(double) image->quality);
   (void) FormatLocaleFile(file,"  Orientation: %s\n",CommandOptionToMnemonic(
     MagickOrientationOptions,(ssize_t) image->orientation));
   if (image->montage != (char *) NULL)
index 2e5a3d7ee7fb0dd96afa2330529103eed4c28ece..0d1c0b9b724ca9dbb8f8c1f564bdef66bd5436ef 100644 (file)
@@ -246,6 +246,9 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   Quantum
     *scale;
 
+  QuantumAny
+    max_value;
+
   QuantumInfo
     *quantum_info;
 
@@ -258,7 +261,6 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   size_t
     depth,
     extent,
-    max_value,
     packet_size;
 
   ssize_t
@@ -513,10 +515,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
           for (x=0; x < (ssize_t) image->columns; x++)
           {
             intensity=PNMInteger(image,10,exception);
-            SetPixelGray(image,intensity,q);
+            SetPixelGray(image,(Quantum) intensity,q);
             if (scale != (Quantum *) NULL)
               SetPixelGray(image,scale[ConstrainPixel(image,(ssize_t) intensity,
-                max_value,exception)],q);
+                (size_t) max_value,exception)],q);
             q+=GetPixelChannels(image);
           }
           if (SyncAuthenticPixels(image,exception) == MagickFalse)
@@ -574,11 +576,11 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
             if (scale != (Quantum *) NULL)
               {
                 pixel.red=(double) scale[ConstrainPixel(image,(ssize_t)
-                  pixel.red,max_value,exception)];
+                  pixel.red,(size_t) max_value,exception)];
                 pixel.green=(double) scale[ConstrainPixel(image,
-                  (ssize_t) pixel.green,max_value,exception)];
+                  (ssize_t) pixel.green,(size_t) max_value,exception)];
                 pixel.blue=(double) scale[ConstrainPixel(image,(ssize_t)
-                  pixel.blue,max_value,exception)];
+                  pixel.blue,(size_t) max_value,exception)];
               }
             SetPixelRed(image,ClampToQuantum(pixel.red),q);
             SetPixelGreen(image,ClampToQuantum(pixel.green),q);
@@ -673,14 +675,10 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       }
       case '5':
       {
-        QuantumAny
-          range;
-
         /*
           Convert PGM raw image to pixel packets.
         */
         (void) SetImageColorspace(image,GRAYColorspace,exception);
-        range=GetQuantumRange(image->depth);
         quantum_type=GrayQuantum;
         extent=(image->depth <= 8 ? 1 : 2)*image->columns;
         quantum_info=AcquireQuantumInfo(image_info,image);
@@ -746,7 +744,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                 for (x=0; x < (ssize_t) image->columns; x++)
                 {
                   p=PushCharPixel(p,&pixel);
-                  SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
+                  SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q);
                   q+=GetPixelChannels(image);
                 }
               }
@@ -758,7 +756,7 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                 for (x=0; x < (ssize_t) image->columns; x++)
                 {
                   p=PushShortPixel(MSBEndian,p,&pixel);
-                  SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
+                  SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q);
                   q+=GetPixelChannels(image);
                 }
               }
@@ -774,15 +772,11 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       }
       case '6':
       {
-        QuantumAny
-          range;
-
         /*
           Convert PNM raster image to pixel packets.
         */
         quantum_type=RGBQuantum;
         extent=3*(image->depth <= 8 ? 1 : 2)*image->columns;
-        range=GetQuantumRange(image->depth);
         quantum_info=AcquireQuantumInfo(image_info,image);
         if (quantum_info == (QuantumInfo *) NULL)
           ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
@@ -871,11 +865,11 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                   for (x=0; x < (ssize_t) image->columns; x++)
                   {
                     p=PushCharPixel(p,&pixel);
-                    SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                     p=PushCharPixel(p,&pixel);
-                    SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                     p=PushCharPixel(p,&pixel);
-                    SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                     SetPixelAlpha(image,OpaqueAlpha,q);
                     q+=GetPixelChannels(image);
                   }
@@ -888,11 +882,11 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                   for (x=0; x < (ssize_t) image->columns; x++)
                   {
                     p=PushShortPixel(MSBEndian,p,&pixel);
-                    SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                     p=PushShortPixel(MSBEndian,p,&pixel);
-                    SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                     p=PushShortPixel(MSBEndian,p,&pixel);
-                    SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                    SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                     SetPixelAlpha(image,OpaqueAlpha,q);
                     q+=GetPixelChannels(image);
                   }
@@ -908,16 +902,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       }
       case '7':
       {
-        QuantumAny
-          range;
-
         size_t
           channels;
 
         /*
           Convert PAM raster image to pixel packets.
         */
-        range=GetQuantumRange(image->depth);
         switch (quantum_type)
         {
           case GrayQuantum:
@@ -1009,12 +999,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushCharPixel(p,&pixel);
-                      SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushCharPixel(p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1027,12 +1017,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushShortPixel(MSBEndian,p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1050,18 +1040,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushCharPixel(p,&pixel);
-                      SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushCharPixel(p,&pixel);
-                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushCharPixel(p,&pixel);
-                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushCharPixel(p,&pixel);
-                      SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushCharPixel(p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1074,18 +1064,18 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushShortPixel(MSBEndian,p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1102,16 +1092,16 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushCharPixel(p,&pixel);
-                      SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushCharPixel(p,&pixel);
-                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushCharPixel(p,&pixel);
-                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushCharPixel(p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1124,16 +1114,16 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q);
                       p=PushShortPixel(MSBEndian,p,&pixel);
-                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
+                      SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q);
                       SetPixelAlpha(image,OpaqueAlpha,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           p=PushShortPixel(MSBEndian,p,&pixel);
-                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
+                          SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q);
                         }
                       q+=GetPixelChannels(image);
                     }
@@ -1469,12 +1459,16 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
   scene=0;
   do
   {
+    QuantumAny
+      max_value;
+
     /*
       Write PNM file header.
     */
     packet_size=3;
     quantum_type=RGBQuantum;
     (void) CopyMagickString(magick,image_info->magick,MaxTextExtent);
+    max_value=GetQuantumRange(image->depth);
     switch (magick[1])
     {
       case 'A':
@@ -1827,9 +1821,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
       }
       case '5':
       {
-        QuantumAny
-          range;
-
         /*
           Convert image to a PGM image.
         */
@@ -1844,7 +1835,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
         quantum_info->min_is_white=MagickTrue;
         pixels=GetQuantumPixels(quantum_info);
         extent=GetQuantumExtent(image,quantum_info,GrayQuantum);
-        range=GetQuantumRange(image->depth);
         for (y=0; y < (ssize_t) image->rows; y++)
         {
           register const Quantum
@@ -1867,13 +1857,13 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                 {
                   if (IsPixelGray(image,p) == MagickFalse)
                     pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(
-                      image,p)),range);
+                      image,p)),max_value);
                   else
                     {
                       if (image->depth == 8)
                         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
                       else
-                        pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                        pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                     }
                   q=PopCharPixel((unsigned char) pixel,q);
                   p+=GetPixelChannels(image);
@@ -1883,13 +1873,13 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                 {
                   if (IsPixelGray(image,p) == MagickFalse)
                     pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(
-                      image,p)),range);
+                      image,p)),max_value);
                   else
                     {
                       if (image->depth == 16)
                         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
                       else
-                        pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                        pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                     }
                   q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                   p+=GetPixelChannels(image);
@@ -1912,9 +1902,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
       }
       case '6':
       {
-        QuantumAny
-          range;
-
         /*
           Convert image to a PNM image.
         */
@@ -1931,7 +1918,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
         (void) SetQuantumEndian(image,quantum_info,MSBEndian);
         pixels=GetQuantumPixels(quantum_info);
         extent=GetQuantumExtent(image,quantum_info,quantum_type);
-        range=GetQuantumRange(image->depth);
         for (y=0; y < (ssize_t) image->rows; y++)
         {
           register const Quantum
@@ -1952,22 +1938,22 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
               if (image->depth <= 8)
                 for (x=0; x < (ssize_t) image->columns; x++)
                 {
-                  pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                   q=PopCharPixel((unsigned char) pixel,q);
-                  pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                   q=PopCharPixel((unsigned char) pixel,q);
-                  pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                   q=PopCharPixel((unsigned char) pixel,q);
                   p+=GetPixelChannels(image);
                 }
               else
                 for (x=0; x < (ssize_t) image->columns; x++)
                 {
-                  pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                   q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                  pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                   q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                  pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                  pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                   q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                   p+=GetPixelChannels(image);
                 }
@@ -1989,9 +1975,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
       }
       case '7':
       {
-        QuantumAny
-          range;
-
         /*
           Convert image to a PAM.
         */
@@ -1999,7 +1982,6 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
           image->depth=16;
         quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
         pixels=GetQuantumPixels(quantum_info);
-        range=GetQuantumRange(image->depth);
         for (y=0; y < (ssize_t) image->rows; y++)
         {
           register const Quantum
@@ -2026,12 +2008,12 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(
-                        image,p)),range);
+                        image,p)),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           pixel=(unsigned char) ScaleQuantumToAny(
-                            ClampToQuantum(GetPixelAlpha(image,p)),range);
+                            GetPixelAlpha(image,p),max_value);
                           q=PopCharPixel((unsigned char) pixel,q);
                         }
                       p+=GetPixelChannels(image);
@@ -2040,12 +2022,12 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
                       pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(
-                        image,p)),range);
+                        image,p)),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
                           pixel=(unsigned char) ScaleQuantumToAny(
-                            GetPixelAlpha(image,p),range);
+                            GetPixelAlpha(image,p),max_value);
                           q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                         }
                       p+=GetPixelChannels(image);
@@ -2058,17 +2040,18 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                   if (image->depth <= 8)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
-                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlack(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlack(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
-                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),range);
+                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),
+                            max_value);
                           q=PopCharPixel((unsigned char) pixel,q);
                         }
                       p+=GetPixelChannels(image);
@@ -2076,17 +2059,18 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                   else
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
-                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlack(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlack(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
-                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),range);
+                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),
+                            max_value);
                           q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                         }
                       p+=GetPixelChannels(image);
@@ -2098,15 +2082,16 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                   if (image->depth <= 8)
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
-                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                       q=PopCharPixel((unsigned char) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
-                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),range);
+                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),
+                            max_value);
                           q=PopCharPixel((unsigned char) pixel,q);
                         }
                       p+=GetPixelChannels(image);
@@ -2114,15 +2099,16 @@ static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image,
                   else
                     for (x=0; x < (ssize_t) image->columns; x++)
                     {
-                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
-                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),range);
+                      pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value);
                       q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                       if (image->alpha_trait == BlendPixelTrait)
                         {
-                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),range);
+                          pixel=ScaleQuantumToAny(GetPixelAlpha(image,p),
+                            max_value);
                           q=PopShortPixel(MSBEndian,(unsigned short) pixel,q);
                         }
                       p+=GetPixelChannels(image);