]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel.c
(no commit message)
[imagemagick] / MagickCore / pixel.c
index 9f9cf08f5852cc5a006d12d68718adf88d8e04c0..a30d4facea50a1282fe801c7edeab1c33574c5bb 100644 (file)
@@ -16,7 +16,7 @@
 %                               October 1998                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 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  %
@@ -42,6 +42,7 @@
 #include "MagickCore/property.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
+#include "MagickCore/cache-private.h"
 #include "MagickCore/color-private.h"
 #include "MagickCore/draw.h"
 #include "MagickCore/exception.h"
@@ -58,6 +59,7 @@
 #include "MagickCore/option.h"
 #include "MagickCore/pixel.h"
 #include "MagickCore/pixel-accessor.h"
+#include "MagickCore/pixel-private.h"
 #include "MagickCore/quantum.h"
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/transform.h"
 #include "MagickCore/utility.h"
 \f
+#define LogPixelChannels(image) \
+{ \
+  register ssize_t \
+    i; \
+ \
+  (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \
+    image->filename,(double) image->number_channels); \
+  for (i=0; i < (ssize_t) image->number_channels; i++) \
+  { \
+    char \
+      traits[MaxTextExtent]; \
+ \
+    const char \
+      *name; \
+ \
+    PixelChannel \
+      channel; \
+ \
+    switch (GetPixelChannelChannel(image,i)) \
+    { \
+      case RedPixelChannel: \
+      { \
+        name="red"; \
+        if (image->colorspace == CMYKColorspace) \
+          name="cyan"; \
+        if (image->colorspace == GRAYColorspace) \
+          name="gray"; \
+        break; \
+      } \
+      case GreenPixelChannel: \
+      { \
+        name="green"; \
+        if (image->colorspace == CMYKColorspace) \
+          name="magenta"; \
+        break; \
+      } \
+      case BluePixelChannel: \
+      { \
+        name="blue"; \
+        if (image->colorspace == CMYKColorspace) \
+          name="yellow"; \
+        break; \
+      } \
+      case BlackPixelChannel: \
+      { \
+        name="black"; \
+        if (image->storage_class == PseudoClass) \
+          name="index"; \
+        break; \
+      } \
+      case IndexPixelChannel: \
+      { \
+        name="index"; \
+        break; \
+      } \
+      case AlphaPixelChannel: \
+      { \
+        name="alpha"; \
+        break; \
+      } \
+      case MaskPixelChannel: \
+      { \
+        name="mask"; \
+        break; \
+      } \
+      case MetaPixelChannel: \
+      { \
+        name="meta"; \
+        break; \
+      } \
+      default: \
+        name="undefined"; \
+    } \
+    channel=GetPixelChannelChannel(image,i); \
+    *traits='\0'; \
+    if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0) \
+      (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \
+    if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0) \
+      (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \
+    if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0) \
+      (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \
+    if (*traits == '\0') \
+      (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \
+    traits[strlen(traits)-1]='\0'; \
+    (void) LogMagickEvent(PixelEvent,GetMagickModule(),"  %.20g: %s (%s)", \
+      (double) i,name,traits); \
+  } \
+}
+\f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -168,7 +259,7 @@ MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel)
   PixelInfo
     *pixel_info;
 
-  pixel_info=(PixelInfo *) AcquireAlignedMemory(1,sizeof(*pixel_info));
+  pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info));
   if (pixel_info == (PixelInfo *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   *pixel_info=(*pixel);
@@ -219,8 +310,8 @@ MagickExport PixelChannelMap *DestroyPixelChannelMap(
 %
 %  ExportImagePixels() extracts pixel data from an image and returns it to you.
 %  The method returns MagickTrue on success otherwise MagickFalse if an error is
-%  encountered.  The data is returned as char, short int, int, ssize_t, float,
-%  or double in the order specified by map.
+%  encountered.  The data is returned as char, short int, Quantum, unsigned int,
+%  unsigned long long, float, or double in the order specified by map.
 %
 %  Suppose you want to extract the first scanline of a 640x480 image as
 %  character data in red-green-blue order:
@@ -229,16 +320,16 @@ MagickExport PixelChannelMap *DestroyPixelChannelMap(
 %
 %  The format of the ExportImagePixels method is:
 %
-%      MagickBooleanType ExportImagePixels(const Image *image,
-%        const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
-%        const size_t rows,const char *map,const StorageType type,
-%        void *pixels,ExceptionInfo *exception)
+%      MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x,
+%        const ssize_t y,const size_t width,const size_t height,
+%        const char *map,const StorageType type,void *pixels,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o x_offset,y_offset,columns,rows:  These values define the perimeter
+%    o x,y,width,height:  These values define the perimeter
 %      of a region of pixels you want to extract.
 %
 %    o map:  This string reflects the expected ordering of the pixel array.
@@ -249,8 +340,9 @@ MagickExport PixelChannelMap *DestroyPixelChannelMap(
 %
 %    o type: Define the data type of the pixels.  Float and double types are
 %      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
-%      types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, LongPixel,
-%      QuantumPixel, or ShortPixel.
+%      types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
+%      LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
+%      QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
 %
 %    o pixels: This array of values contain the pixel components as defined by
 %      map and type.  You must preallocate this array where the expected
@@ -259,20 +351,19 @@ MagickExport PixelChannelMap *DestroyPixelChannelMap(
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport MagickBooleanType ExportImagePixels(const Image *image,
-  const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
-  const size_t rows,const char *map,const StorageType type,void *pixels,
+
+static void ExportCharPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
   ExceptionInfo *exception)
 {
-  QuantumType
-    *quantum_map;
+  register const Quantum
+    *restrict p;
 
   register ssize_t
-    i,
     x;
 
-  register const Quantum
-    *p;
+  register unsigned char
+    *restrict q;
 
   size_t
     length;
@@ -280,1563 +371,2226 @@ MagickExport MagickBooleanType ExportImagePixels(const Image *image,
   ssize_t
     y;
 
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  length=strlen(map);
-  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
-  if (quantum_map == (QuantumType *) NULL)
+  q=(unsigned char *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
     {
-      (void) ThrowMagickException(exception,GetMagickModule(),
-        ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
-      return(MagickFalse);
-    }
-  for (i=0; i < (ssize_t) length; i++)
-  {
-    switch (map[i])
-    {
-      case 'A':
-      case 'a':
-      {
-        quantum_map[i]=AlphaQuantum;
-        break;
-      }
-      case 'B':
-      case 'b':
-      {
-        quantum_map[i]=BlueQuantum;
-        break;
-      }
-      case 'C':
-      case 'c':
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=CyanQuantum;
-        if (image->colorspace == CMYKColorspace)
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",map);
-        return(MagickFalse);
-      }
-      case 'g':
-      case 'G':
-      {
-        quantum_map[i]=GreenQuantum;
-        break;
-      }
-      case 'I':
-      case 'i':
-      {
-        quantum_map[i]=IndexQuantum;
-        break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          p+=GetPixelChannels(image);
+        }
       }
-      case 'K':
-      case 'k':
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=BlackQuantum;
-        if (image->colorspace == CMYKColorspace)
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",map);
-        return(MagickFalse);
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
       }
-      case 'M':
-      case 'm':
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=MagentaQuantum;
-        if (image->colorspace == CMYKColorspace)
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",map);
-        return(MagickFalse);
-      }
-      case 'o':
-      case 'O':
-      {
-        quantum_map[i]=OpacityQuantum;
-        break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          *q++=ScaleQuantumToChar((Quantum) 0);
+          p+=GetPixelChannels(image);
+        }
       }
-      case 'P':
-      case 'p':
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=UndefinedQuantum;
-        break;
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
+        }
       }
-      case 'R':
-      case 'r':
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=RedQuantum;
-        break;
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
       }
-      case 'Y':
-      case 'y':
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=YellowQuantum;
-        if (image->colorspace == CMYKColorspace)
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",map);
-        return(MagickFalse);
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
       }
-      default:
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-          "UnrecognizedPixelMap","`%s'",map);
-        return(MagickFalse);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToChar(GetPixelRed(image,p));
+          *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToChar((Quantum) 0);
+          p+=GetPixelChannels(image);
+        }
       }
+      return;
     }
-  }
-  switch (type)
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
   {
-    case CharPixel:
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register unsigned char
-        *q;
+      register ssize_t
+        i;
 
-      q=(unsigned char *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelRed(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelGreen(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              *q++=ScaleQuantumToChar((Quantum) 0);
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelBlue(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            if (image->colorspace == CMYKColorspace)
+              *q=ScaleQuantumToChar(GetPixelBlack(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToChar(GetPixelRed(image,p));
-              *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToChar((Quantum) 0);
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
+            break;
           }
-          break;
+          default:
+            break;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportDoublePixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register double
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(double *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=ScaleQuantumToChar(GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=ScaleQuantumToChar(GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                break;
-            }
-            q++;
-          }
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case DoublePixel:
+  if (LocaleCompare(map,"BGRA") == 0)
     {
-      register double
-        *q;
-
-      q=(double *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
+          *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              *q++=0.0;
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
+          *q++=0.0;
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(double) (QuantumScale*GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBP") == 0)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(double) (QuantumScale*GetPixelRed(image,p));
-              *q++=(double) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(double) (QuantumScale*GetPixelBlue(image,p));
-              *q++=0.0;
-              p+=GetPixelChannels(image);
-            }
-          }
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(double) (QuantumScale*GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=(double) (QuantumScale*
-                    GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=(double) (QuantumScale*GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                *q=0;
-            }
-            q++;
-          }
+          *q++=(double) (QuantumScale*GetPixelRed(image,p));
+          *q++=(double) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(double) (QuantumScale*GetPixelBlue(image,p));
+          *q++=0.0;
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case FloatPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register float
-        *q;
+      register ssize_t
+        i;
 
-      q=(float *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelRed(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelGreen(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              *q++=0.0;
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelBlue(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            if (image->colorspace == CMYKColorspace)
+              *q=(double) (QuantumScale*
+                GetPixelBlack(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(float) (QuantumScale*GetPixelRed(image,p));
-              *q++=(float) (QuantumScale*GetPixelGreen(image,p));
-              *q++=(float) (QuantumScale*GetPixelBlue(image,p));
-              *q++=0.0;
-              p+=GetPixelChannels(image);
-            }
+            *q=(double) (QuantumScale*GetPixelIntensity(image,p));
+            break;
           }
-          break;
+          default:
+            *q=0;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportFloatPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register float
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(float *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=(float) (QuantumScale*GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=(float) (QuantumScale*GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=(float) (QuantumScale*GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=(float) (QuantumScale*GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=(float) (QuantumScale* GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=(float) (QuantumScale*GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                *q=0;
-            }
-            q++;
-          }
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case IntegerPixel:
+  if (LocaleCompare(map,"BGRA") == 0)
     {
-      register unsigned int
-        *q;
-
-      q=(unsigned int *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
+          *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=0U;
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(
-                GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
+          *q++=0.0;
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=(float) (QuantumScale*GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBP") == 0)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=0U;
-              p+=GetPixelChannels(image);
-            }
-          }
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          *q++=(float) (QuantumScale*GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=(unsigned int) ScaleQuantumToLong(GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=(unsigned int) ScaleQuantumToLong(
-                  GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                *q=0;
-            }
-            q++;
-          }
+          *q++=(float) (QuantumScale*GetPixelRed(image,p));
+          *q++=(float) (QuantumScale*GetPixelGreen(image,p));
+          *q++=(float) (QuantumScale*GetPixelBlue(image,p));
+          *q++=0.0;
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case LongPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register size_t
-        *q;
+      register ssize_t
+        i;
 
-      q=(size_t *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*GetPixelRed(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*GetPixelGreen(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=0;
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*GetPixelBlue(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p))));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            if (image->colorspace == CMYKColorspace)
+              *q=(float) (QuantumScale* GetPixelBlack(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToLong(GetPixelRed(image,p));
-              *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
-              *q++=0;
-              p+=GetPixelChannels(image);
-            }
+            *q=(float) (QuantumScale*GetPixelIntensity(image,p));
+            break;
           }
-          break;
+          default:
+            *q=0;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportLongPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register ssize_t
+    x;
+
+  register unsigned int
+    *restrict q;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(unsigned int *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=ScaleQuantumToLong(GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                break;
-            }
-            q++;
-          }
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case QuantumPixel:
+  if (LocaleCompare(map,"BGRA") == 0)
     {
-      register Quantum
-        *q;
-
-      q=(Quantum *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelBlue(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelRed(image,p);
-              p+=GetPixelChannels(image);
-            }
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelBlue(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelRed(image,p);
-              *q++=(Quantum) (GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelBlue(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelRed(image,p);
-              *q++=(Quantum) 0;
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelIntensity(image,p);
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
+          *q++=0;
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelRed(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelBlue(image,p);
-              p+=GetPixelChannels(image);
-            }
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelRed(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelBlue(image,p);
-              *q++=(Quantum) (GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
-          }
-          break;
+          *q++=ScaleQuantumToLong(GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBP") == 0)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=GetPixelRed(image,p);
-              *q++=GetPixelGreen(image,p);
-              *q++=GetPixelBlue(image,p);
-              *q++=(Quantum) 0;
-              p+=GetPixelChannels(image);
-            }
-          }
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=(Quantum) 0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=GetPixelRed(image,p);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=GetPixelGreen(image,p);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=GetPixelBlue(image,p);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=(Quantum) (GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=GetPixelAlpha(image,p);
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=GetPixelBlack(image,p);
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=(GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                *q=(Quantum) 0;
-            }
-            q++;
-          }
+          *q++=ScaleQuantumToLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
+          *q++=0;
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    case ShortPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register unsigned short
-        *q;
+      register ssize_t
+        i;
 
-      q=(unsigned short *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelRed(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelGreen(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              *q++=0;
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelBlue(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
-              p+=GetPixelChannels(image);
-            }
+            if (image->colorspace == CMYKColorspace)
+              *q=ScaleQuantumToLong(GetPixelBlack(image,p));
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (p == (const Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              *q++=ScaleQuantumToShort(GetPixelRed(image,p));
-              *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
-              *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
-              *q++=0;
-              p+=GetPixelChannels(image);
-            }
+            *q=ScaleQuantumToLong(GetPixelIntensity(image,p));
+            break;
           }
-          break;
+          default:
+            break;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportLongLongPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register ssize_t
+    x;
+
+  register MagickSizeType
+    *restrict q;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(MagickSizeType *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        p=GetVirtualPixels(image,x_offset,y_offset+y,columns,1,exception);
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (p == (const Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            *q=0;
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelRed(image,p));
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelGreen(image,p));
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelBlue(image,p));
-                break;
-              }
-              case AlphaQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
-                break;
-              }
-              case OpacityQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
-                break;
-              }
-              case BlackQuantum:
-              {
-                if (image->colorspace == CMYKColorspace)
-                  *q=ScaleQuantumToShort(GetPixelBlack(image,p));
-                break;
-              }
-              case IndexQuantum:
-              {
-                *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
-                break;
-              }
-              default:
-                break;
-            }
-            q++;
-          }
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
           p+=GetPixelChannels(image);
         }
       }
-      break;
+      return;
     }
-    default:
+  if (LocaleCompare(map,"BGRA") == 0)
     {
-      quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "UnrecognizedPixelMap","`%s'",map);
-      break;
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
     }
-  }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
+          *q++=0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+          *q++=0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
+            break;
+          }
+          case AlphaQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
+            break;
+          }
+          case OpacityQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
+            break;
+          }
+          case BlackQuantum:
+          {
+            if (image->colorspace == CMYKColorspace)
+              *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
+            break;
+          }
+          case IndexQuantum:
+          {
+            *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p));
+            break;
+          }
+          default:
+            break;
+        }
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportQuantumPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(Quantum *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelBlue(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelRed(image,p);
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelBlue(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelRed(image,p);
+          *q++=(Quantum) (GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelBlue(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelRed(image,p);
+          *q++=(Quantum) 0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelIntensity(image,p);
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelRed(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelBlue(image,p);
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelRed(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelBlue(image,p);
+          *q++=(Quantum) (GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=GetPixelRed(image,p);
+          *q++=GetPixelGreen(image,p);
+          *q++=GetPixelBlue(image,p);
+          *q++=(Quantum) 0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=(Quantum) 0;
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            *q=GetPixelRed(image,p);
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            *q=GetPixelGreen(image,p);
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            *q=GetPixelBlue(image,p);
+            break;
+          }
+          case AlphaQuantum:
+          {
+            *q=GetPixelAlpha(image,p);
+            break;
+          }
+          case OpacityQuantum:
+          {
+            *q=GetPixelAlpha(image,p);
+            break;
+          }
+          case BlackQuantum:
+          {
+            if (image->colorspace == CMYKColorspace)
+              *q=GetPixelBlack(image,p);
+            break;
+          }
+          case IndexQuantum:
+          {
+            *q=(GetPixelIntensity(image,p));
+            break;
+          }
+          default:
+          {
+            *q=(Quantum) 0;
+            break;
+          }
+        }
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+static void ExportShortPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register ssize_t
+    x;
+
+  register unsigned short
+    *restrict q;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  q=(unsigned short *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          *q++=0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelIntensity(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (p == (const Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          *q++=ScaleQuantumToShort(GetPixelRed(image,p));
+          *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
+          *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
+          *q++=0;
+          p+=GetPixelChannels(image);
+        }
+      }
+      return;
+    }
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (p == (const Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        *q=0;
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelRed(image,p));
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelGreen(image,p));
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelBlue(image,p));
+            break;
+          }
+          case AlphaQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
+            break;
+          }
+          case OpacityQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
+            break;
+          }
+          case BlackQuantum:
+          {
+            if (image->colorspace == CMYKColorspace)
+              *q=ScaleQuantumToShort(GetPixelBlack(image,p));
+            break;
+          }
+          case IndexQuantum:
+          {
+            *q=ScaleQuantumToShort(GetPixelIntensity(image,p));
+            break;
+          }
+          default:
+            break;
+        }
+        q++;
+      }
+      p+=GetPixelChannels(image);
+    }
+  }
+}
+
+MagickExport MagickBooleanType ExportImagePixels(Image *image,
+  const ssize_t x,const ssize_t y,const size_t width,const size_t height,
+  const char *map,const StorageType type,void *pixels,ExceptionInfo *exception)
+{
+  QuantumType
+    *quantum_map;
+
+  RectangleInfo
+    roi;
+
+  register ssize_t
+    i;
+
+  size_t
+    length;
+
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  length=strlen(map);
+  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
+  if (quantum_map == (QuantumType *) NULL)
+    {
+      (void) ThrowMagickException(exception,GetMagickModule(),
+        ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
+      return(MagickFalse);
+    }
+  for (i=0; i < (ssize_t) length; i++)
+  {
+    switch (map[i])
+    {
+      case 'A':
+      case 'a':
+      {
+        quantum_map[i]=AlphaQuantum;
+        break;
+      }
+      case 'B':
+      case 'b':
+      {
+        quantum_map[i]=BlueQuantum;
+        break;
+      }
+      case 'C':
+      case 'c':
+      {
+        quantum_map[i]=CyanQuantum;
+        if (image->colorspace == CMYKColorspace)
+          break;
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
+          "ColorSeparatedImageRequired","'%s'",map);
+        return(MagickFalse);
+      }
+      case 'g':
+      case 'G':
+      {
+        quantum_map[i]=GreenQuantum;
+        break;
+      }
+      case 'I':
+      case 'i':
+      {
+        quantum_map[i]=IndexQuantum;
+        break;
+      }
+      case 'K':
+      case 'k':
+      {
+        quantum_map[i]=BlackQuantum;
+        if (image->colorspace == CMYKColorspace)
+          break;
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
+          "ColorSeparatedImageRequired","'%s'",map);
+        return(MagickFalse);
+      }
+      case 'M':
+      case 'm':
+      {
+        quantum_map[i]=MagentaQuantum;
+        if (image->colorspace == CMYKColorspace)
+          break;
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
+          "ColorSeparatedImageRequired","'%s'",map);
+        return(MagickFalse);
+      }
+      case 'o':
+      case 'O':
+      {
+        quantum_map[i]=OpacityQuantum;
+        break;
+      }
+      case 'P':
+      case 'p':
+      {
+        quantum_map[i]=UndefinedQuantum;
+        break;
+      }
+      case 'R':
+      case 'r':
+      {
+        quantum_map[i]=RedQuantum;
+        break;
+      }
+      case 'Y':
+      case 'y':
+      {
+        quantum_map[i]=YellowQuantum;
+        if (image->colorspace == CMYKColorspace)
+          break;
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
+          "ColorSeparatedImageRequired","'%s'",map);
+        return(MagickFalse);
+      }
+      default:
+      {
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+          "UnrecognizedPixelMap","'%s'",map);
+        return(MagickFalse);
+      }
+    }
+  }
+  roi.width=width;
+  roi.height=height;
+  roi.x=x;
+  roi.y=y;
+  switch (type)
+  {
+    case CharPixel:
+    {
+      ExportCharPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case DoublePixel:
+    {
+      ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case FloatPixel:
+    {
+      ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case LongPixel:
+    {
+      ExportLongPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case LongLongPixel:
+    {
+      ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case QuantumPixel:
+    {
+      ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case ShortPixel:
+    {
+      ExportShortPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    default:
+    {
+      quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+        "UnrecognizedPixelMap","'%s'",map);
+      break;
+    }
+  }
   quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
   return(MagickTrue);
 }
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%   G e t M a g i c k P i x e l P a c k e t                                   %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  GetPixelInfo() initializes the PixelInfo structure.
-%
-%  The format of the GetPixelInfo method is:
-%
-%      GetPixelInfo(const Image *image,PixelInfo *pixel)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o pixel: Specifies a pointer to a PixelPacket structure.
-%
-*/
-MagickExport void GetPixelInfo(const Image *image,
-  PixelInfo *pixel)
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   G e t P i x e l I n f o                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetPixelInfo() initializes the PixelInfo structure.
+%
+%  The format of the GetPixelInfo method is:
+%
+%      GetPixelInfo(const Image *image,PixelInfo *pixel)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o pixel: Specifies a pointer to a PixelInfo structure.
+%
+*/
+MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel)
+{
+  pixel->storage_class=DirectClass;
+  pixel->colorspace=sRGBColorspace;
+  pixel->alpha_trait=UndefinedPixelTrait;
+  pixel->fuzz=0.0;
+  pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
+  pixel->red=0.0;
+  pixel->green=0.0;
+  pixel->blue=0.0;
+  pixel->black=0.0;
+  pixel->alpha=(double) OpaqueAlpha;
+  pixel->index=0.0;
+  if (image == (const Image *) NULL)
+    return;
+  pixel->storage_class=image->storage_class;
+  pixel->colorspace=image->colorspace;
+  pixel->alpha_trait=image->alpha_trait;
+  pixel->depth=image->depth;
+  pixel->fuzz=image->fuzz;
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   I m p o r t I m a g e P i x e l s                                         %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ImportImagePixels() accepts pixel data and stores in the image at the
+%  location you specify.  The method returns MagickTrue on success otherwise
+%  MagickFalse if an error is encountered.  The pixel data can be either char,
+%  Quantum, short int, unsigned int, unsigned long long, float, or double in
+%  the order specified by map.
+%
+%  Suppose your want to upload the first scanline of a 640x480 image from
+%  character data in red-green-blue order:
+%
+%      ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
+%
+%  The format of the ImportImagePixels method is:
+%
+%      MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
+%        const ssize_t y,const size_t width,const size_t height,
+%        const char *map,const StorageType type,const void *pixels,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o x,y,width,height:  These values define the perimeter
+%      of a region of pixels you want to define.
+%
+%    o map:  This string reflects the expected ordering of the pixel array.
+%      It can be any combination or order of R = red, G = green, B = blue,
+%      A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
+%      Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
+%      P = pad.
+%
+%    o type: Define the data type of the pixels.  Float and double types are
+%      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
+%      types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *),
+%      LongPixel (unsigned int *), LongLongPixel (unsigned long long *),
+%      QuantumPixel (Quantum *), or ShortPixel (unsigned short *).
+%
+%    o pixels: This array of values contain the pixel components as defined by
+%      map and type.  You must preallocate this array where the expected
+%      length varies depending on the values of width, height, map, and type.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+
+static void ImportCharPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
+{
+  register const unsigned char
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const unsigned char *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRO") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelGray(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBO") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleCharToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            SetPixelRed(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            SetPixelGreen(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            SetPixelBlue(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case AlphaQuantum:
+          {
+            SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case OpacityQuantum:
+          {
+            SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case BlackQuantum:
+          {
+            SetPixelBlack(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          case IndexQuantum:
+          {
+            SetPixelGray(image,ScaleCharToQuantum(*p),q);
+            break;
+          }
+          default:
+            break;
+        }
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+static void ImportDoublePixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
 {
-  pixel->storage_class=DirectClass;
-  pixel->colorspace=RGBColorspace;
-  pixel->matte=MagickFalse;
-  pixel->fuzz=0.0;
-  pixel->depth=MAGICKCORE_QUANTUM_DEPTH;
-  pixel->red=0.0;
-  pixel->green=0.0;
-  pixel->blue=0.0;
-  pixel->black=0.0;
-  pixel->alpha=(MagickRealType) OpaqueAlpha;
-  pixel->index=0.0;
-  if (image == (const Image *) NULL)
-    return;
-  pixel->storage_class=image->storage_class;
-  pixel->colorspace=image->colorspace;
-  pixel->matte=image->matte;
-  pixel->depth=image->depth;
-  pixel->fuzz=image->fuzz;
+  register const double
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const double *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+   length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case AlphaQuantum:
+          {
+            SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case OpacityQuantum:
+          {
+            SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case BlackQuantum:
+          {
+            SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case IndexQuantum:
+          {
+            SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          default:
+            break;
+        }
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
 }
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%   I m p o r t I m a g e P i x e l s                                         %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  ImportImagePixels() accepts pixel data and stores in the image at the
-%  location you specify.  The method returns MagickTrue on success otherwise
-%  MagickFalse if an error is encountered.  The pixel data can be either char,
-%  short int, int, ssize_t, float, or double in the order specified by map.
-%
-%  Suppose your want to upload the first scanline of a 640x480 image from
-%  character data in red-green-blue order:
-%
-%      ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels);
-%
-%  The format of the ImportImagePixels method is:
-%
-%      MagickBooleanType ImportImagePixels(Image *image,const ssize_t x_offset,
-%        const ssize_t y_offset,const size_t columns,
-%        const size_t rows,const char *map,const StorageType type,
-%        const void *pixels,ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o x_offset,y_offset,columns,rows:  These values define the perimeter
-%      of a region of pixels you want to define.
-%
-%    o map:  This string reflects the expected ordering of the pixel array.
-%      It can be any combination or order of R = red, G = green, B = blue,
-%      A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
-%      Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
-%      P = pad.
-%
-%    o type: Define the data type of the pixels.  Float and double types are
-%      normalized to [0..1] otherwise [0..QuantumRange].  Choose from these
-%      types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or
-%      DoublePixel.
-%
-%    o pixels: This array of values contain the pixel components as defined by
-%      map and type.  You must preallocate this array where the expected
-%      length varies depending on the values of width, height, map, and type.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-MagickExport MagickBooleanType ImportImagePixels(Image *image,
-  const ssize_t x_offset,const ssize_t y_offset,const size_t columns,
-  const size_t rows,const char *map,const StorageType type,
-  const void *pixels,ExceptionInfo *exception)
+
+static void ImportFloatPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
 {
-  QuantumType
-    *quantum_map;
+  register const float
+    *restrict p;
 
   register Quantum
-    *q;
+    *restrict q;
 
   register ssize_t
-    i,
     x;
 
   size_t
@@ -1845,1693 +2599,1272 @@ MagickExport MagickBooleanType ImportImagePixels(Image *image,
   ssize_t
     y;
 
-  /*
-    Allocate image structure.
-  */
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  length=strlen(map);
-  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
-  if (quantum_map == (QuantumType *) NULL)
-    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
-      image->filename);
-  for (i=0; i < (ssize_t) length; i++)
-  {
-    switch (map[i])
+  p=(const float *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
     {
-      case 'a':
-      case 'A':
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=AlphaQuantum;
-        image->matte=MagickTrue;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'B':
-      case 'b':
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=BlueQuantum;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'C':
-      case 'c':
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=CyanQuantum;
-        (void) SetImageColorspace(image,CMYKColorspace,exception);
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'g':
-      case 'G':
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=GreenQuantum;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'K':
-      case 'k':
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=BlackQuantum;
-        (void) SetImageColorspace(image,CMYKColorspace,exception);
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'I':
-      case 'i':
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=IndexQuantum;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'm':
-      case 'M':
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=MagentaQuantum;
-        (void) SetImageColorspace(image,CMYKColorspace,exception);
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'O':
-      case 'o':
+      return;
+    }
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) length; i++)
       {
-        quantum_map[i]=OpacityQuantum;
-        image->matte=MagickTrue;
-        break;
+        switch (quantum_map[i])
+        {
+          case RedQuantum:
+          case CyanQuantum:
+          {
+            SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case GreenQuantum:
+          case MagentaQuantum:
+          {
+            SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case BlueQuantum:
+          case YellowQuantum:
+          {
+            SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case AlphaQuantum:
+          {
+            SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case OpacityQuantum:
+          {
+            SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case BlackQuantum:
+          {
+            SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          case IndexQuantum:
+          {
+            SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q);
+            break;
+          }
+          default:
+            break;
+        }
+        p++;
       }
-      case 'P':
-      case 'p':
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+static void ImportLongPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
+{
+  register const unsigned int
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const unsigned int *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=UndefinedQuantum;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelGray(image,ScaleLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'R':
-      case 'r':
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=RedQuantum;
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      case 'Y':
-      case 'y':
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map[i]=YellowQuantum;
-        (void) SetImageColorspace(image,CMYKColorspace,exception);
-        break;
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
-      default:
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-          "UnrecognizedPixelMap","`%s'",map);
-        return(MagickFalse);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
+          p++;
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
       }
+      return;
     }
-  }
-  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
-    return(MagickFalse);
-  /*
-    Transfer the pixels from the pixel datarray to the image.
-  */
-  switch (type)
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
   {
-    case CharPixel:
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register const unsigned char
-        *p;
+      register ssize_t
+        i;
 
-      p=(const unsigned char *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelRed(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGreen(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRO") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlue(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlack(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGray(image,ScaleLongToQuantum(*p),q);
+            break;
           }
-          break;
+          default:
+            break;
         }
-      if (LocaleCompare(map,"RGBO") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+static void ImportLongLongPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
+{
+  register const MagickSizeType
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const MagickSizeType *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleCharToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ScaleCharToQuantum(*p),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ScaleCharToQuantum(*p),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case DoublePixel:
+  if (LocaleCompare(map,"BGRP") == 0)
     {
-      register const double
-        *p;
-
-      p=(const double *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          p++;
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelGray(image,ScaleLongLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelRed(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q);
+          p++;
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case FloatPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register const float
-        *p;
+      register ssize_t
+        i;
 
-      p=(const float *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelRed(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGreen(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlue(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType)
-                QuantumRange*(*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlack(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
-                (*p)),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGray(image,ScaleLongLongToQuantum(*p),q);
+            break;
           }
-          break;
+          default:
+            break;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+static void ImportQuantumPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
+{
+  register const Quantum
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const Quantum *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ClampToQuantum((MagickRealType)
-                  QuantumRange*(*p)),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelBlue(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelRed(image,*p++,q);
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case IntegerPixel:
+  if (LocaleCompare(map,"BGRA") == 0)
     {
-      register const unsigned int
-        *p;
-
-      p=(const unsigned int *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelBlue(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelRed(image,*p++,q);
+          SetPixelAlpha(image,*p++,q);
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelBlue(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelRed(image,*p++,q);
+          p++;
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"I") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelGray(image,*p++,q);
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBP") == 0)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+          SetPixelRed(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelBlue(image,*p++,q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelBlue(image,*p++,q);
+          SetPixelAlpha(image,*p++,q);
+          q+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ScaleLongToQuantum(*p),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelRed(image,*p++,q);
+          SetPixelGreen(image,*p++,q);
+          SetPixelBlue(image,*p++,q);
+          p++;
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case LongPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register const unsigned int
-        *p;
+      register ssize_t
+        i;
 
-      p=(const unsigned int *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelRed(image,*p,q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGreen(image,*p,q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlue(image,*p,q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,*p,q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,*p,q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleLongToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlack(image,*p,q);
+            break;
           }
+          case IndexQuantum:
+          {
+            SetPixelGray(image,*p,q);
+            break;
+          }
+          default:
+            break;
+        }
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+static void ImportShortPixel(Image *image,const RectangleInfo *roi,
+  const char *restrict map,const QuantumType *quantum_map,const void *pixels,
+  ExceptionInfo *exception)
+{
+  register const unsigned short
+    *restrict p;
+
+  register Quantum
+    *restrict q;
+
+  register ssize_t
+    x;
+
+  size_t
+    length;
+
+  ssize_t
+    y;
+
+  p=(const unsigned short *) pixels;
+  if (LocaleCompare(map,"BGR") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
+          break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleLongToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleLongToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleLongToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"BGRP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ScaleLongToQuantum(*p),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ScaleLongToQuantum(*p),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          p++;
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case QuantumPixel:
+  if (LocaleCompare(map,"I") == 0)
     {
-      register const Quantum
-        *p;
-
-      p=(const Quantum *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelRed(image,*p++,q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelRed(image,*p++,q);
-              SetPixelAlpha(image,*p++,q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelGray(image,ScaleShortToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelRed(image,*p++,q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,*p++,q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGB") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelBlue(image,*p++,q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
-          break;
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelBlue(image,*p++,q);
-              SetPixelAlpha(image,*p++,q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
-          {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,*p++,q);
-              SetPixelGreen(image,*p++,q);
-              SetPixelBlue(image,*p++,q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
-          }
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBA") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
+      {
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+        if (q == (Quantum *) NULL)
           break;
+        for (x=0; x < (ssize_t) roi->width; x++)
+        {
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
+          q+=GetPixelChannels(image);
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        if (SyncAuthenticPixels(image,exception) == MagickFalse)
+          break;
+      }
+      return;
+    }
+  if (LocaleCompare(map,"RGBP") == 0)
+    {
+      for (y=0; y < (ssize_t) roi->height; y++)
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
+        q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
         if (q == (Quantum *) NULL)
           break;
-        for (x=0; x < (ssize_t) columns; x++)
+        for (x=0; x < (ssize_t) roi->width; x++)
         {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,*p,q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,*p,q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,*p,q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,*p,q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,*p,q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,*p,q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,*p,q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
+          SetPixelRed(image,ScaleShortToQuantum(*p++),q);
+          SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
+          SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
+          p++;
           q+=GetPixelChannels(image);
         }
         if (SyncAuthenticPixels(image,exception) == MagickFalse)
           break;
       }
-      break;
+      return;
     }
-    case ShortPixel:
+  length=strlen(map);
+  for (y=0; y < (ssize_t) roi->height; y++)
+  {
+    q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) roi->width; x++)
     {
-      register const unsigned short
-        *p;
+      register ssize_t
+        i;
 
-      p=(const unsigned short *) pixels;
-      if (LocaleCompare(map,"BGR") == 0)
+      for (i=0; i < (ssize_t) length; i++)
+      {
+        switch (quantum_map[i])
         {
-          for (y=0; y < (ssize_t) rows; y++)
+          case RedQuantum:
+          case CyanQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelRed(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case GreenQuantum:
+          case MagentaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGreen(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"BGRP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlueQuantum:
+          case YellowQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlue(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"I") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case AlphaQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,GetPixelRed(image,q),q);
-              SetPixelBlue(image,GetPixelRed(image,q),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGB") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case OpacityQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBA") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case BlackQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              SetPixelAlpha(image,ScaleShortToQuantum(*p++),q);
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelBlack(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
-        }
-      if (LocaleCompare(map,"RGBP") == 0)
-        {
-          for (y=0; y < (ssize_t) rows; y++)
+          case IndexQuantum:
           {
-            q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-            if (q == (Quantum *) NULL)
-              break;
-            for (x=0; x < (ssize_t) columns; x++)
-            {
-              SetPixelRed(image,ScaleShortToQuantum(*p++),q);
-              SetPixelGreen(image,ScaleShortToQuantum(*p++),q);
-              SetPixelBlue(image,ScaleShortToQuantum(*p++),q);
-              p++;
-              q+=GetPixelChannels(image);
-            }
-            if (SyncAuthenticPixels(image,exception) == MagickFalse)
-              break;
+            SetPixelGray(image,ScaleShortToQuantum(*p),q);
+            break;
           }
-          break;
+          default:
+            break;
         }
-      for (y=0; y < (ssize_t) rows; y++)
+        p++;
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
+}
+
+MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x,
+  const ssize_t y,const size_t width,const size_t height,const char *map,
+  const StorageType type,const void *pixels,ExceptionInfo *exception)
+{
+  QuantumType
+    *quantum_map;
+
+  RectangleInfo
+    roi;
+
+  register ssize_t
+    i;
+
+  size_t
+    length;
+
+  /*
+    Allocate image structure.
+  */
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  length=strlen(map);
+  quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map));
+  if (quantum_map == (QuantumType *) NULL)
+    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
+      image->filename);
+  for (i=0; i < (ssize_t) length; i++)
+  {
+    switch (map[i])
+    {
+      case 'a':
+      case 'A':
+      {
+        quantum_map[i]=AlphaQuantum;
+        image->alpha_trait=BlendPixelTrait;
+        break;
+      }
+      case 'B':
+      case 'b':
+      {
+        quantum_map[i]=BlueQuantum;
+        break;
+      }
+      case 'C':
+      case 'c':
+      {
+        quantum_map[i]=CyanQuantum;
+        (void) SetImageColorspace(image,CMYKColorspace,exception);
+        break;
+      }
+      case 'g':
+      case 'G':
+      {
+        quantum_map[i]=GreenQuantum;
+        break;
+      }
+      case 'K':
+      case 'k':
+      {
+        quantum_map[i]=BlackQuantum;
+        (void) SetImageColorspace(image,CMYKColorspace,exception);
+        break;
+      }
+      case 'I':
+      case 'i':
+      {
+        quantum_map[i]=IndexQuantum;
+        (void) SetImageColorspace(image,GRAYColorspace,exception);
+        break;
+      }
+      case 'm':
+      case 'M':
+      {
+        quantum_map[i]=MagentaQuantum;
+        (void) SetImageColorspace(image,CMYKColorspace,exception);
+        break;
+      }
+      case 'O':
+      case 'o':
+      {
+        quantum_map[i]=OpacityQuantum;
+        image->alpha_trait=BlendPixelTrait;
+        break;
+      }
+      case 'P':
+      case 'p':
+      {
+        quantum_map[i]=UndefinedQuantum;
+        break;
+      }
+      case 'R':
+      case 'r':
+      {
+        quantum_map[i]=RedQuantum;
+        break;
+      }
+      case 'Y':
+      case 'y':
       {
-        q=GetAuthenticPixels(image,x_offset,y_offset+y,columns,1,exception);
-        if (q == (Quantum *) NULL)
-          break;
-        for (x=0; x < (ssize_t) columns; x++)
-        {
-          for (i=0; i < (ssize_t) length; i++)
-          {
-            switch (quantum_map[i])
-            {
-              case RedQuantum:
-              case CyanQuantum:
-              {
-                SetPixelRed(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case GreenQuantum:
-              case MagentaQuantum:
-              {
-                SetPixelGreen(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case BlueQuantum:
-              case YellowQuantum:
-              {
-                SetPixelBlue(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case AlphaQuantum:
-              {
-                SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case OpacityQuantum:
-              {
-                SetPixelAlpha(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case BlackQuantum:
-              {
-                SetPixelBlack(image,ScaleShortToQuantum(*p),q);
-                break;
-              }
-              case IndexQuantum:
-              {
-                SetPixelRed(image,ScaleShortToQuantum(*p),q);
-                SetPixelGreen(image,GetPixelRed(image,q),q);
-                SetPixelBlue(image,GetPixelRed(image,q),q);
-                break;
-              }
-              default:
-                break;
-            }
-            p++;
-          }
-          q+=GetPixelChannels(image);
-        }
-        if (SyncAuthenticPixels(image,exception) == MagickFalse)
-          break;
+        quantum_map[i]=YellowQuantum;
+        (void) SetImageColorspace(image,CMYKColorspace,exception);
+        break;
+      }
+      default:
+      {
+        quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
+        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+          "UnrecognizedPixelMap","'%s'",map);
+        return(MagickFalse);
       }
+    }
+  }
+  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+    return(MagickFalse);
+  /*
+    Transfer the pixels from the pixel data to the image.
+  */
+  roi.width=width;
+  roi.height=height;
+  roi.x=x;
+  roi.y=y;
+  switch (type)
+  {
+    case CharPixel:
+    {
+      ImportCharPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case DoublePixel:
+    {
+      ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case FloatPixel:
+    {
+      ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case LongPixel:
+    {
+      ImportLongPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case LongLongPixel:
+    {
+      ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case QuantumPixel:
+    {
+      ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception);
+      break;
+    }
+    case ShortPixel:
+    {
+      ImportShortPixel(image,&roi,map,quantum_map,pixels,exception);
       break;
     }
     default:
     {
       quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
-      (void) ThrowMagickException(&image->exception,GetMagickModule(),
-        OptionError,"UnrecognizedPixelMap","`%s'",map);
+      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+        "UnrecognizedPixelMap","'%s'",map);
       break;
     }
   }
@@ -3563,51 +3896,51 @@ MagickExport MagickBooleanType ImportImagePixels(Image *image,
 */
 MagickExport void InitializePixelChannelMap(Image *image)
 {
-  PixelChannel
-    alpha_channel;
+  PixelTrait
+    trait;
 
   register ssize_t
     i;
 
-  for (i=0; i < (ssize_t) MaxPixelChannels; i++)
-  {
-    SetPixelChannelMapChannel(image,(PixelChannel) i,(PixelChannel) i);
-    SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait);
-  }
-  image->sync=MagickTrue;
-  image->number_channels=4;
-  if (0 && image->colorspace == GRAYColorspace)
-    image->number_channels=2;
-  if (image->colorspace == CMYKColorspace)
-    image->number_channels++;
-  if (image->storage_class == PseudoClass)
-    image->number_channels++;
-  for (i=0; i < (ssize_t) image->number_channels; i++)
-    SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait)
-      UpdatePixelTrait);
-  alpha_channel=GetPixelChannelMapChannel(image,AlphaPixelChannel);
-  if (image->matte == MagickFalse)
-    SetPixelChannelMapTraits(image,AlphaPixelChannel,CopyPixelTrait);
-  else
-    for (i=0; i < (ssize_t) image->number_channels; i++)
-      if ((PixelChannel) i != alpha_channel)
-        SetPixelChannelMapTraits(image,(PixelChannel) i,(PixelTrait)
-          (UpdatePixelTrait | BlendPixelTrait));
-  if (0 && image->colorspace == GRAYColorspace)
+  ssize_t
+    n;
+
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickSignature);
+  (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels*
+    sizeof(*image->channel_map));
+  trait=UpdatePixelTrait;
+  if (image->alpha_trait == BlendPixelTrait)
+    trait=(PixelTrait) (trait | BlendPixelTrait);
+  n=0;
+  if (image->colorspace == GRAYColorspace)
     {
-      image->number_channels=2;
-      SetPixelChannelMapChannel(image,GreenPixelChannel,RedPixelChannel);
-      SetPixelChannelMapChannel(image,BluePixelChannel,RedPixelChannel);
+      SetPixelChannelAttributes(image,BluePixelChannel,trait,n);
+      SetPixelChannelAttributes(image,GreenPixelChannel,trait,n);
+      SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
     }
-  if (image->storage_class == PseudoClass)
+  else
     {
-      SetPixelChannelMapChannel(image,IndexPixelChannel,IndexPixelChannel);
-      SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
+      SetPixelChannelAttributes(image,RedPixelChannel,trait,n++);
+      SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++);
+      SetPixelChannelAttributes(image,BluePixelChannel,trait,n++);
     }
-  image->number_channels+=image->number_meta_channels;
-  for ( ; i < (ssize_t) image->number_channels; i++)
-    SetPixelChannelMapTraits(image,(PixelChannel) i,CopyPixelTrait);
-  (void) SetPixelChannelMask(image,image->channel_mask);
+  if (image->colorspace == CMYKColorspace)
+    SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++);
+  if (image->alpha_trait != UndefinedPixelTrait)
+    SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++);
+  if (image->storage_class == PseudoClass)
+    SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++);
+  if (image->mask != MagickFalse)
+    SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++);
+  assert((n+image->number_meta_channels) < MaxPixelChannels);
+  for (i=0; i < (ssize_t) image->number_meta_channels; i++)
+    SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i),
+      CopyPixelTrait,n++);
+  image->number_channels=(size_t) n;
+  if (image->debug != MagickFalse)
+    LogPixelChannels(image);
+  (void) SetImageChannelMask(image,image->channel_mask);
 }
 \f
 /*
@@ -3625,6 +3958,8 @@ MagickExport void InitializePixelChannelMap(Image *image)
 %  floating point coordinate and the pixels surrounding that coordinate.  No
 %  pixel area resampling, or scaling of the result is performed.
 %
+%  Interpolation is restricted to just the specified channel.
+%
 %  The format of the InterpolatePixelChannel method is:
 %
 %      MagickBooleanType InterpolatePixelChannel(const Image *image,
@@ -3650,28 +3985,59 @@ MagickExport void InitializePixelChannelMap(Image *image)
 %
 */
 
-static inline double MagickMax(const MagickRealType x,const MagickRealType y)
+static inline double MagickMax(const double x,const double y)
 {
   if (x > y)
     return(x);
   return(y);
 }
 
-static inline MagickRealType CubicWeightingFunction(const MagickRealType x)
+static inline void CatromWeights(const double x,double (*weights)[4])
 {
-  MagickRealType
+  double
     alpha,
+    beta,
     gamma;
 
-  alpha=MagickMax(x+2.0,0.0);
-  gamma=1.0*alpha*alpha*alpha;
-  alpha=MagickMax(x+1.0,0.0);
-  gamma-=4.0*alpha*alpha*alpha;
-  alpha=MagickMax(x+0.0,0.0);
-  gamma+=6.0*alpha*alpha*alpha;
-  alpha=MagickMax(x-1.0,0.0);
-  gamma-=4.0*alpha*alpha*alpha;
-  return(gamma/6.0);
+  /*
+    Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation
+    of the standard four 1D Catmull-Rom weights. The sampling location is
+    assumed between the second and third input pixel locations, and x is the
+    position relative to the second input pixel location. Formulas originally
+    derived for the VIPS (Virtual Image Processing System) library.
+  */
+  alpha=(double) 1.0-x;
+  beta=(double) (-0.5)*x*alpha;
+  (*weights)[0]=alpha*beta;
+  (*weights)[3]=x*beta;
+  /*
+    The following computation of the inner weights from the outer ones work
+    for all Keys cubics.
+  */
+  gamma=(*weights)[3]-(*weights)[0];
+  (*weights)[1]=alpha-(*weights)[0]+gamma;
+  (*weights)[2]=x-(*weights)[3]-gamma;
+}
+
+static inline void SplineWeights(const double x,double (*weights)[4])
+{
+  double
+    alpha,
+    beta;
+
+  /*
+    Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the
+    computation of the standard four 1D cubic B-spline smoothing
+    weights. The sampling location is assumed between the second and
+    third input pixel locations, and x is the position relative to the
+    second input pixel location.
+  */
+  alpha=(double) 1.0-x;
+  (*weights)[3]=(double) (1.0/6.0)*x*x*x;
+  (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha;
+  beta=(*weights)[3]-(*weights)[0];
+  (*weights)[1]=alpha-(*weights)[0]+beta;
+  (*weights)[2]=x-(*weights)[3]-beta;
 }
 
 static inline double MeshInterpolate(const PointInfo *delta,const double p,
@@ -3680,12 +4046,14 @@ static inline double MeshInterpolate(const PointInfo *delta,const double p,
   return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p);
 }
 
-static inline ssize_t NearestNeighbor(const MagickRealType x)
+/*
+static inline ssize_t NearestNeighbor(const double x)
 {
   if (x >= 0.0)
     return((ssize_t) (x+0.5));
   return((ssize_t) (x-0.5));
 }
+*/
 
 MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
   const CacheView *image_view,const PixelChannel channel,
@@ -3695,7 +4063,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
   MagickBooleanType
     status;
 
-  MagickRealType
+  double
     alpha[16],
     gamma,
     pixels[16];
@@ -3713,70 +4081,92 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
     x_offset,
     y_offset;
 
+  PixelInterpolateMethod
+    interpolate;
+
   assert(image != (Image *) NULL);
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   assert(image_view != (CacheView *) NULL);
   status=MagickTrue;
   *pixel=0.0;
-  traits=GetPixelChannelMapTraits(image,channel);
+  traits=GetPixelChannelTraits(image,channel);
   x_offset=(ssize_t) floor(x);
   y_offset=(ssize_t) floor(y);
-  switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
+  interpolate = method;
+  if ( interpolate == UndefinedInterpolatePixel )
+    interpolate = image->interpolate;
+  switch (interpolate)
   {
-    case AverageInterpolatePixel:
+    case AverageInterpolatePixel:        /* nearest 4 neighbours */
+    case Average9InterpolatePixel:       /* nearest 9 neighbours */
+    case Average16InterpolatePixel:      /* nearest 16 neighbours */
     {
-      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
+      size_t
+        count=2; /* size of the area to average - default nearest 4 */
+
+      if (interpolate == Average9InterpolatePixel)
+        {
+          count=3;
+          x_offset=(ssize_t) (floor(x+0.5)-1);
+          y_offset=(ssize_t) (floor(y+0.5)-1);
+        }
+      else if (interpolate == Average16InterpolatePixel)
+        {
+          count=4;
+          x_offset--;
+          y_offset--;
+        }
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
         exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
+
+      count*=count;   /* Number of pixels to Average */
       if ((traits & BlendPixelTrait) == 0)
-        for (i=0; i < 16; i++)
+        for (i=0; i < (ssize_t) count; i++)
         {
           alpha[i]=1.0;
-          pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
+          pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
         }
       else
-        for (i=0; i < 16; i++)
+        for (i=0; i < (ssize_t) count; i++)
         {
           alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
             GetPixelChannels(image));
           pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
         }
-      for (i=0; i < 16; i++)
+      for (i=0; i < (ssize_t) count; i++)
       {
-        gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
-        *pixel+=gamma*0.0625*pixels[i];
+        gamma=MagickEpsilonReciprocal(alpha[i])/count;
+        *pixel+=gamma*pixels[i];
       }
       break;
     }
-    case BicubicInterpolatePixel:
+    case BilinearInterpolatePixel:
+    default:
     {
-      MagickRealType
-        u[4],
-        v[4];
-
       PointInfo
-        delta;
+        delta,
+        epsilon;
 
-      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
-        exception);
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
       if ((traits & BlendPixelTrait) == 0)
-        for (i=0; i < 16; i++)
+        for (i=0; i < 4; i++)
         {
           alpha[i]=1.0;
-          pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
+          pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
         }
       else
-        for (i=0; i < 16; i++)
+        for (i=0; i < 4; i++)
         {
           alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
             GetPixelChannels(image));
@@ -3784,30 +4174,17 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
         }
       delta.x=x-x_offset;
       delta.y=y-y_offset;
-      for (i=0; i < 4; i++)
-      {
-        u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]);
-        u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0];
-        u[2]=pixels[4*i+2]-pixels[4*i+0];
-        u[3]=pixels[4*i+1];
-        v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
-          u[2])+u[3];
-      }
-      u[0]=(v[3]-v[2])-(v[0]-v[1]);
-      u[1]=(v[0]-v[1])-u[0];
-      u[2]=v[2]-v[0];
-      u[3]=v[1];
-      *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*
-        u[2])+u[3];
+      epsilon.x=1.0-delta.x;
+      epsilon.y=1.0-delta.y;
+      gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
+        (epsilon.x*alpha[2]+delta.x*alpha[3])));
+      gamma=MagickEpsilonReciprocal(gamma);
+      *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
+        (epsilon.x*pixels[2]+delta.x*pixels[3]));
       break;
     }
-    case BilinearInterpolatePixel:
-    default:
+    case BlendInterpolatePixel:
     {
-      PointInfo
-        delta,
-        epsilon;
-
       p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
       if (p == (const Quantum *) NULL)
         {
@@ -3827,17 +4204,77 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
             GetPixelChannels(image));
           pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
         }
-      delta.x=x-x_offset;
-      delta.y=y-y_offset;
-      epsilon.x=1.0-delta.x;
-      epsilon.y=1.0-delta.y;
-      gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
-        (epsilon.x*alpha[2]+delta.x*alpha[3])));
-      gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-      *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*
-        (epsilon.x*pixels[2]+delta.x*pixels[3]));
+      gamma=1.0;    /* number of pixels blended together (its variable) */
+      for (i=0; i <= 1L; i++) {
+        if ( y-y_offset >= 0.75 ) { /* take right pixels */
+          alpha[i]  = alpha[i+2];
+          pixels[i] = pixels[i+2];
+        }
+        else if ( y-y_offset > 0.25 ) {
+          gamma = 2.0;              /* blend both pixels in row */
+          alpha[i]  += alpha[i+2];  /* add up alpha weights */
+          pixels[i] += pixels[i+2];
+        }
+      }
+      if ( x-x_offset >= 0.75 ) {   /* take bottom row blend */
+        alpha[0]  = alpha[1];
+        pixels[0] = pixels[1];
+      }
+      else if ( x-x_offset > 0.25 ) {
+        gamma *= 2.0;               /* blend both rows */
+        alpha[0]  += alpha[1];      /* add up alpha weights */
+        pixels[0] += pixels[1];
+      }
+      if (channel != AlphaPixelChannel)
+        gamma=MagickEpsilonReciprocal(alpha[0]); /* (color) 1/alpha_weights */
+      else
+        gamma=MagickEpsilonReciprocal(gamma); /* (alpha) 1/number_of_pixels */
+      *pixel=gamma*pixels[0];
+      break;
+    }
+    case CatromInterpolatePixel:
+    {
+      double
+        cx[4],
+        cy[4];
+
+      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
+        exception);
+      if (p == (const Quantum *) NULL)
+        {
+          status=MagickFalse;
+          break;
+        }
+      if ((traits & BlendPixelTrait) == 0)
+        for (i=0; i < 16; i++)
+        {
+          alpha[i]=1.0;
+          pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
+        }
+      else
+        for (i=0; i < 16; i++)
+        {
+          alpha[i]=QuantumScale*GetPixelAlpha(image,p+i*
+            GetPixelChannels(image));
+          pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
+        }
+      CatromWeights((double) (x-x_offset),&cx);
+      CatromWeights((double) (y-y_offset),&cy);
+      gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
+        MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
+        alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
+        alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
+        alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
+        cx[2]*alpha[14]+cx[3]*alpha[15])));
+      *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
+        cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
+        pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
+        cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
+        pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
       break;
     }
+#if 0
+    /* deprecated useless and very slow interpolator */
     case FilterInterpolatePixel:
     {
       CacheView
@@ -3860,21 +4297,21 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
           status=MagickFalse;
           break;
         }
-      filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
-        exception);
+      filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
       excerpt_image=DestroyImage(excerpt_image);
       if (filter_image == (Image *) NULL)
         break;
-      filter_view=AcquireCacheView(filter_image);
+      filter_view=AcquireVirtualCacheView(filter_image,exception);
       p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
       if (p == (const Quantum *) NULL)
         status=MagickFalse;
       else
-        *pixel=(double) p[channel];
+        *pixel=(double) GetPixelChannel(image,channel,p);
       filter_view=DestroyCacheView(filter_view);
       filter_image=DestroyImage(filter_image);
       break;
     }
+#endif
     case IntegerInterpolatePixel:
     {
       p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
@@ -3883,19 +4320,20 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
           status=MagickFalse;
           break;
         }
-      *pixel=(double) p[channel];
+      *pixel=(double) GetPixelChannel(image,channel,p);
       break;
     }
-    case NearestNeighborInterpolatePixel:
+    case NearestInterpolatePixel:
     {
-      p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
-        NearestNeighbor(y),1,1,exception);
+      x_offset=(ssize_t) floor(x+0.5);
+      y_offset=(ssize_t) floor(y+0.5);
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
-      *pixel=(double) p[channel];
+      *pixel=(double) GetPixelChannel(image,channel,p);
       break;
     }
     case MeshInterpolatePixel:
@@ -3914,7 +4352,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
         for (i=0; i < 4; i++)
         {
           alpha[i]=1.0;
-          pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
+          pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
         }
       else
         for (i=0; i < 4; i++)
@@ -3927,7 +4365,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
       delta.y=y-y_offset;
       luminance.x=GetPixelLuminance(image,p)-(double)
         GetPixelLuminance(image,p+3*GetPixelChannels(image));
-      luminance.y=GetPixelLuminance(image,p+1*GetPixelChannels(image))-(double)
+      luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
         GetPixelLuminance(image,p+2*GetPixelChannels(image));
       if (fabs(luminance.x) < fabs(luminance.y))
         {
@@ -3941,7 +4379,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
               */
               delta.y=1.0-delta.y;
               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3],
                 pixels[0]);
             }
@@ -3952,7 +4390,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
               */
               delta.x=1.0-delta.x;
               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0],
                 pixels[3]);
             }
@@ -3968,7 +4406,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
                 Top-left triangle (pixel: 0, diagonal: 1-2).
               */
               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1],
                 pixels[2]);
             }
@@ -3980,7 +4418,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
               delta.x=1.0-delta.x;
               delta.y=1.0-delta.y;
               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2],
                 pixels[1]);
             }
@@ -3989,16 +4427,9 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
     }
     case SplineInterpolatePixel:
     {
-      MagickRealType
-        dx,
-        dy;
-
-      PointInfo
-        delta;
-
-      ssize_t
-        j,
-        n;
+      double
+        cx[4],
+        cy[4];
 
       p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
         exception);
@@ -4011,7 +4442,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
         for (i=0; i < 16; i++)
         {
           alpha[i]=1.0;
-          pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel];
+          pixels[i]=(double) p[i*GetPixelChannels(image)+channel];
         }
       else
         for (i=0; i < 16; i++)
@@ -4020,20 +4451,19 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
             GetPixelChannels(image));
           pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel];
         }
-      delta.x=x-x_offset;
-      delta.y=y-y_offset;
-      n=0;
-      for (i=(-1); i < 3L; i++)
-      {
-        dy=CubicWeightingFunction((MagickRealType) i-delta.y);
-        for (j=(-1); j < 3L; j++)
-        {
-          dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
-          gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
-          *pixel+=gamma*dx*dy*pixels[n];
-          n++;
-        }
-      }
+      SplineWeights((double) (x-x_offset),&cx);
+      SplineWeights((double) (y-y_offset),&cy);
+      gamma=(channel == AlphaPixelChannel ? (double) 1.0 :
+        MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
+        alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
+        alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
+        alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
+        cx[2]*alpha[14]+cx[3]*alpha[15])));
+      *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+
+        cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*
+        pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+
+        cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*
+        pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15]));
       break;
     }
   }
@@ -4055,6 +4485,9 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
 %  floating point coordinate and the pixels surrounding that coordinate.  No
 %  pixel area resampling, or scaling of the result is performed.
 %
+%  Interpolation is restricted to just the current channel setting of the
+%  destination image into which the color is to be stored
+%
 %  The format of the InterpolatePixelChannels method is:
 %
 %      MagickBooleanType InterpolatePixelChannels(const Image *source,
@@ -4068,7 +4501,7 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image,
 %
 %    o source_view: the source view.
 %
-%    o destination: the destination image.
+%    o destination: the destination image, for the interpolated color
 %
 %    o method: the pixel color interpolation method.
 %
@@ -4087,7 +4520,7 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
   MagickBooleanType
     status;
 
-  MagickRealType
+  double
     alpha[16],
     gamma,
     pixels[16];
@@ -4109,6 +4542,9 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
     x_offset,
     y_offset;
 
+  PixelInterpolateMethod
+    interpolate;
+
   assert(source != (Image *) NULL);
   assert(source != (Image *) NULL);
   assert(source->signature == MagickSignature);
@@ -4116,17 +4552,38 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
   status=MagickTrue;
   x_offset=(ssize_t) floor(x);
   y_offset=(ssize_t) floor(y);
-  switch (method == UndefinedInterpolatePixel ? source->interpolate : method)
+  interpolate = method;
+  if ( interpolate == UndefinedInterpolatePixel )
+    interpolate = source->interpolate;
+  switch (interpolate)
   {
-    case AverageInterpolatePixel:
+    case AverageInterpolatePixel:        /* nearest 4 neighbours */
+    case Average9InterpolatePixel:       /* nearest 9 neighbours */
+    case Average16InterpolatePixel:      /* nearest 16 neighbours */
     {
-      p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
+      size_t
+        count=2; /* size of the area to average - default nearest 4 */
+
+      if (interpolate == Average9InterpolatePixel)
+        {
+          count=3;
+          x_offset=(ssize_t) (floor(x+0.5)-1);
+          y_offset=(ssize_t) (floor(y+0.5)-1);
+        }
+      else if (interpolate == Average16InterpolatePixel)
+        {
+          count=4;
+          x_offset--;
+          y_offset--;
+        }
+      p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,count,count,
         exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
+      count*=count;   /* Number of pixels to Average */
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
         double
@@ -4135,44 +4592,96 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         register ssize_t
           j;
 
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
-        for (j=0; j < 16; j++)
-          pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
+        for (j=0; j < (ssize_t) count; j++)
+          pixels[j]=(double) p[j*GetPixelChannels(source)+i];
+        sum=0.0;
         if ((traits & BlendPixelTrait) == 0)
           {
-            for (j=0; j < 16; j++)
-              pixel[channel]+=0.0625*pixels[j];
+            for (j=0; j < (ssize_t) count; j++)
+              sum+=pixels[j];
+            sum/=count;
+            SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
             continue;
           }
-        sum=0.0;
-        for (j=0; j < 16; j++)
+        for (j=0; j < (ssize_t) count; j++)
         {
           alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
             GetPixelChannels(source));
           pixels[j]*=alpha[j];
-          gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]);
-          sum+=gamma*0.0625*pixels[j];
+          gamma=MagickEpsilonReciprocal(alpha[j]);
+          sum+=gamma*pixels[j];
         }
-        pixel[channel]=ClampToQuantum(sum);
+        sum/=count;
+        SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel);
       }
       break;
     }
-    case BicubicInterpolatePixel:
+    case BilinearInterpolatePixel:
+    default:
     {
-      MagickRealType
-        u[4],
-        v[4];
-
-      PointInfo
-        delta;
+      p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
+      if (p == (const Quantum *) NULL)
+        {
+          status=MagickFalse;
+          break;
+        }
+      for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
+      {
+        PointInfo
+          delta,
+          epsilon;
 
-      p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
-        exception);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
+        if ((traits == UndefinedPixelTrait) ||
+            (destination_traits == UndefinedPixelTrait))
+          continue;
+        delta.x=x-x_offset;
+        delta.y=y-y_offset;
+        epsilon.x=1.0-delta.x;
+        epsilon.y=1.0-delta.y;
+        pixels[0]=(double) p[i];
+        pixels[1]=(double) p[GetPixelChannels(source)+i];
+        pixels[2]=(double) p[2*GetPixelChannels(source)+i];
+        pixels[3]=(double) p[3*GetPixelChannels(source)+i];
+        if ((traits & BlendPixelTrait) == 0)
+          {
+            gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
+            gamma=MagickEpsilonReciprocal(gamma);
+            SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
+              (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*
+              pixels[2]+delta.x*pixels[3]))),pixel);
+            continue;
+          }
+        alpha[0]=QuantumScale*GetPixelAlpha(source,p);
+        alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source));
+        alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
+          GetPixelChannels(source));
+        alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
+          GetPixelChannels(source));
+        pixels[0]*=alpha[0];
+        pixels[1]*=alpha[1];
+        pixels[2]*=alpha[2];
+        pixels[3]*=alpha[3];
+        gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
+          (epsilon.x*alpha[2]+delta.x*alpha[3])));
+        gamma=MagickEpsilonReciprocal(gamma);
+        SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y*
+          (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+
+          delta.x*pixels[3]))),pixel);
+      }
+      break;
+    }
+    case BlendInterpolatePixel:
+    {
+      p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
@@ -4183,49 +4692,63 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         register ssize_t
           j;
 
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
         if ((traits & BlendPixelTrait) == 0)
-          for (j=0; j < 16; j++)
+          for (j=0; j < 4; j++)
           {
             alpha[j]=1.0;
-            pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
+            pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel];
           }
         else
-          for (j=0; j < 16; j++)
+          for (j=0; j < 4; j++)
           {
             alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
               GetPixelChannels(source));
-            pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
+            pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel];
           }
-        delta.x=x-x_offset;
-        delta.y=y-y_offset;
-        for (j=0; j < 4; j++)
-        {
-          u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]);
-          u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0];
-          u[2]=pixels[4*j+2]-pixels[4*j+0];
-          u[3]=pixels[4*j+1];
-          v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x*
-            u[2])+u[3];
-        }
-        u[0]=(v[3]-v[2])-(v[0]-v[1]);
-        u[1]=(v[0]-v[1])-u[0];
-        u[2]=v[2]-v[0];
-        u[3]=v[1];
-        pixel[channel]=ClampToQuantum((delta.y*delta.y*delta.y*u[0])+(delta.y*
-          delta.y*u[1])+(delta.y*u[2])+u[3]);
+        gamma=1.0;    /* number of pixels blended together (its variable) */
+        for (j=0; j <= 1L; j++) {
+          if ( y-y_offset >= 0.75 ) { /* take right pixels */
+            alpha[j]  = alpha[j+2];
+            pixels[j] = pixels[j+2];
+          }
+          else if ( y-y_offset > 0.25 ) {
+            gamma = 2.0;              /* blend both pixels in row */
+            alpha[j]  += alpha[j+2];  /* add up alpha weights */
+            pixels[j] += pixels[j+2];
+          }
+        }
+        if ( x-x_offset >= 0.75 ) {   /* take bottom row blend */
+          alpha[0]  = alpha[1];
+          pixels[0] = pixels[1];
+        }
+        else if ( x-x_offset > 0.25 ) {
+          gamma *= 2.0;               /* blend both rows */
+          alpha[0]  += alpha[1];      /* add up alpha weights */
+          pixels[0] += pixels[1];
+        }
+        if ((traits & BlendPixelTrait) == 0)
+          gamma=MagickEpsilonReciprocal(alpha[0]); /* (color) 1/alpha_weights */
+        else
+          gamma=MagickEpsilonReciprocal(gamma); /* (alpha) 1/number_of_pixels */
+        SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]),
+             pixel);
       }
       break;
     }
-    case BilinearInterpolatePixel:
-    default:
+    case CatromInterpolatePixel:
     {
-      p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception);
+      double
+        cx[4],
+        cy[4];
+
+      p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
+        exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
@@ -4233,53 +4756,47 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         }
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
-        PointInfo
-          delta,
-          epsilon;
+        register ssize_t
+          j;
 
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
-        delta.x=x-x_offset;
-        delta.y=y-y_offset;
-        epsilon.x=1.0-delta.x;
-        epsilon.y=1.0-delta.y;
-        pixels[0]=(MagickRealType) p[0*GetPixelChannels(source)+i];
-        pixels[1]=(MagickRealType) p[1*GetPixelChannels(source)+i];
-        pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
-        pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
         if ((traits & BlendPixelTrait) == 0)
+          for (j=0; j < 16; j++)
           {
-            gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
-            gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-            pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
-              delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*
-              pixels[3])));
-            continue;
+            alpha[j]=1.0;
+            pixels[j]=(double) p[j*GetPixelChannels(source)+i];
           }
-        alpha[0]=QuantumScale*GetPixelAlpha(source,p+0*
-          GetPixelChannels(source));
-        alpha[1]=QuantumScale*GetPixelAlpha(source,p+1*
-          GetPixelChannels(source));
-        alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
-          GetPixelChannels(source));
-        alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
-          GetPixelChannels(source));
-        pixels[0]*=alpha[0];
-        pixels[1]*=alpha[1];
-        pixels[2]*=alpha[2];
-        pixels[3]*=alpha[3];
-        gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
-          (epsilon.x*alpha[2]+delta.x*alpha[3])));
-        gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-        pixel[channel]=ClampToQuantum(gamma*(epsilon.y*(epsilon.x*pixels[0]+
-          delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+delta.x*pixels[3])));
+        else
+          for (j=0; j < 16; j++)
+          {
+            alpha[j]=QuantumScale*GetPixelAlpha(source,p+j*
+              GetPixelChannels(source));
+            pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
+          }
+        CatromWeights((double) (x-x_offset),&cx);
+        CatromWeights((double) (y-y_offset),&cy);
+        gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
+          MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
+          alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
+          alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
+          alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
+          cx[2]*alpha[14]+cx[3]*alpha[15])));
+        SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
+          pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
+          (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
+          cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
+          pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
+          pixels[14]+cx[3]*pixels[15]))),pixel);
       }
       break;
     }
+#if 0
+    /* deprecated useless and very slow interpolator */
     case FilterInterpolatePixel:
     {
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
@@ -4294,9 +4811,9 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         RectangleInfo
           geometry;
 
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
@@ -4310,22 +4827,24 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
             status=MagickFalse;
             continue;
           }
-        filter_source=ResizeImage(excerpt_source,1,1,source->filter,
-          source->blur,exception);
+        filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception);
         excerpt_source=DestroyImage(excerpt_source);
         if (filter_source == (Image *) NULL)
           continue;
-        filter_view=AcquireCacheView(filter_source);
+        filter_view=AcquireVirtualCacheView(filter_source,exception);
         p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
         if (p == (const Quantum *) NULL)
           status=MagickFalse;
         else
-          pixel[channel]=p[i];
+          {
+            SetPixelChannel(destination,channel,p[i],pixel);
+          }
         filter_view=DestroyCacheView(filter_view);
         filter_source=DestroyImage(filter_source);
       }
       break;
     }
+#endif
     case IntegerInterpolatePixel:
     {
       p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
@@ -4336,20 +4855,21 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         }
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
-        pixel[channel]=p[i];
+        SetPixelChannel(destination,channel,p[i],pixel);
       }
       break;
     }
-    case NearestNeighborInterpolatePixel:
+    case NearestInterpolatePixel:
     {
-      p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x),
-        NearestNeighbor(y),1,1,exception);
+      x_offset=(ssize_t) floor(x+0.5);
+      y_offset=(ssize_t) floor(y+0.5);
+      p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
@@ -4357,13 +4877,13 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         }
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
-        pixel[channel]=p[i];
+        SetPixelChannel(destination,channel,p[i],pixel);
       }
       break;
     }
@@ -4381,101 +4901,106 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
           delta,
           luminance;
 
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
-       pixels[0]=(MagickRealType) p[0*GetPixelChannels(source)+i];
-       pixels[1]=(MagickRealType) p[1*GetPixelChannels(source)+i];
-       pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i];
-       pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i];
-       if ((traits & BlendPixelTrait) == 0)
-         {
-           alpha[0]=1.0;
-           alpha[1]=1.0;
-           alpha[2]=1.0;
-           alpha[3]=1.0;
-         }
-       else
-         {
-           alpha[0]=QuantumScale*GetPixelAlpha(source,p+0*
-             GetPixelChannels(source));
-           alpha[1]=QuantumScale*GetPixelAlpha(source,p+1*
-             GetPixelChannels(source));
-           alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
-             GetPixelChannels(source));
-           alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
-             GetPixelChannels(source));
-         }
-       delta.x=x-x_offset;
-       delta.y=y-y_offset;
-       luminance.x=GetPixelLuminance(source,p)-(double)
-         GetPixelLuminance(source,p+3*GetPixelChannels(source));
-       luminance.y=GetPixelLuminance(source,p+1*GetPixelChannels(source))-
-         (double) GetPixelLuminance(source,p+2*GetPixelChannels(source));
-       if (fabs(luminance.x) < fabs(luminance.y))
-         {
-           /*
-             Diagonal 0-3 NW-SE.
-           */
-           if (delta.x <= delta.y)
-             {
-               /*
-                 Bottom-left triangle (pixel: 2, diagonal: 0-3).
-               */
-               delta.y=1.0-delta.y;
-               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
-               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-               pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
-                 pixels[2],pixels[3],pixels[0]));
-             }
-           else
-             {
-               /*
-                 Top-right triangle (pixel: 1, diagonal: 0-3).
-               */
-               delta.x=1.0-delta.x;
-               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
-               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-               pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
-                 pixels[1],pixels[0],pixels[3]));
-             }
-         }
-       else
-         {
-           /*
-             Diagonal 1-2 NE-SW.
-           */
-           if (delta.x <= (1.0-delta.y))
-             {
-               /*
-                 Top-left triangle (pixel: 0, diagonal: 1-2).
-               */
-               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
-               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-               pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
-                 pixels[0],pixels[1],pixels[2]));
-             }
-           else
-             {
-               /*
-                 Bottom-right triangle (pixel: 3, diagonal: 1-2).
-               */
-               delta.x=1.0-delta.x;
-               delta.y=1.0-delta.y;
-               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
-               gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-               pixel[channel]=ClampToQuantum(gamma*MeshInterpolate(&delta,
-                 pixels[3],pixels[2],pixels[1]));
-             }
-         }
+        pixels[0]=(double) p[i];
+        pixels[1]=(double) p[GetPixelChannels(source)+i];
+        pixels[2]=(double) p[2*GetPixelChannels(source)+i];
+        pixels[3]=(double) p[3*GetPixelChannels(source)+i];
+        if ((traits & BlendPixelTrait) == 0)
+          {
+            alpha[0]=1.0;
+            alpha[1]=1.0;
+            alpha[2]=1.0;
+            alpha[3]=1.0;
+          }
+        else
+          {
+            alpha[0]=QuantumScale*GetPixelAlpha(source,p);
+            alpha[1]=QuantumScale*GetPixelAlpha(source,p+
+              GetPixelChannels(source));
+            alpha[2]=QuantumScale*GetPixelAlpha(source,p+2*
+              GetPixelChannels(source));
+            alpha[3]=QuantumScale*GetPixelAlpha(source,p+3*
+              GetPixelChannels(source));
+          }
+        delta.x=x-x_offset;
+        delta.y=y-y_offset;
+        luminance.x=fabs((double)(
+              GetPixelLuminance(source,p)
+               -GetPixelLuminance(source,p+3*GetPixelChannels(source))));
+        luminance.y=fabs((double)(
+              GetPixelLuminance(source,p+GetPixelChannels(source))
+               -GetPixelLuminance(source,p+2*GetPixelChannels(source))));
+        if (luminance.x < luminance.y)
+          {
+            /*
+              Diagonal 0-3 NW-SE.
+            */
+            if (delta.x <= delta.y)
+              {
+                /*
+                  Bottom-left triangle (pixel: 2, diagonal: 0-3).
+                */
+                delta.y=1.0-delta.y;
+                gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
+                gamma=MagickEpsilonReciprocal(gamma);
+                SetPixelChannel(destination,channel,ClampToQuantum(gamma*
+                  MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel);
+              }
+            else
+              {
+                /*
+                  Top-right triangle (pixel: 1, diagonal: 0-3).
+                */
+                delta.x=1.0-delta.x;
+                gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
+                gamma=MagickEpsilonReciprocal(gamma);
+                SetPixelChannel(destination,channel,ClampToQuantum(gamma*
+                  MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel);
+              }
+          }
+        else
+          {
+            /*
+              Diagonal 1-2 NE-SW.
+            */
+            if (delta.x <= (1.0-delta.y))
+              {
+                /*
+                  Top-left triangle (pixel: 0, diagonal: 1-2).
+                */
+                gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
+                gamma=MagickEpsilonReciprocal(gamma);
+                SetPixelChannel(destination,channel,ClampToQuantum(gamma*
+                  MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel);
+              }
+            else
+              {
+                /*
+                  Bottom-right triangle (pixel: 3, diagonal: 1-2).
+                */
+                delta.x=1.0-delta.x;
+                delta.y=1.0-delta.y;
+                gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
+                gamma=MagickEpsilonReciprocal(gamma);
+                SetPixelChannel(destination,channel,ClampToQuantum(gamma*
+                  MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel);
+              }
+          }
       }
       break;
     }
     case SplineInterpolatePixel:
     {
+      double
+        cx[4],
+        cy[4];
+
       p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4,
         exception);
       if (p == (const Quantum *) NULL)
@@ -4485,26 +5010,12 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
         }
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
-        double
-          sum;
-
-        MagickRealType
-          dx,
-          dy;
-
-        PointInfo
-          delta;
-
         register ssize_t
           j;
 
-        ssize_t
-          k,
-          n;
-
-        traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        channel=GetPixelChannelChannel(source,i);
+        traits=GetPixelChannelTraits(source,channel);
+        destination_traits=GetPixelChannelTraits(destination,channel);
         if ((traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
@@ -4512,7 +5023,7 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
           for (j=0; j < 16; j++)
           {
             alpha[j]=1.0;
-            pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i];
+            pixels[j]=(double) p[j*GetPixelChannels(source)+i];
           }
         else
           for (j=0; j < 16; j++)
@@ -4521,23 +5032,20 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
               GetPixelChannels(source));
             pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i];
           }
-        delta.x=x-x_offset;
-        delta.y=y-y_offset;
-        sum=0.0;
-        n=0;
-        for (j=(-1); j < 3L; j++)
-        {
-          dy=CubicWeightingFunction((MagickRealType) j-delta.y);
-          for (k=(-1); k < 3L; k++)
-          {
-            dx=CubicWeightingFunction(delta.x-(MagickRealType) k);
-            gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 :
-              alpha[n]);
-            sum+=gamma*dx*dy*pixels[n];
-            n++;
-          }
-        }
-        pixel[channel]=ClampToQuantum(sum);
+        SplineWeights((double) (x-x_offset),&cx);
+        SplineWeights((double) (y-y_offset),&cy);
+        gamma=((traits & BlendPixelTrait) ? (double) (1.0) :
+          MagickEpsilonReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]*
+          alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]*
+          alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]*
+          alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+
+          cx[2]*alpha[14]+cx[3]*alpha[15])));
+        SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]*
+          pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]*
+          (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+
+          cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]*
+          pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]*
+          pixels[14]+cx[3]*pixels[15]))),pixel);
       }
       break;
     }
@@ -4560,6 +5068,8 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
 %  floating point coordinate and the pixels surrounding that coordinate.  No
 %  pixel area resampling, or scaling of the result is performed.
 %
+%  Interpolation is restricted to just RGBKA channels.
+%
 %  The format of the InterpolatePixelInfo method is:
 %
 %      MagickBooleanType InterpolatePixelInfo(const Image *image,
@@ -4584,18 +5094,18 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source,
 */
 
 static inline void AlphaBlendPixelInfo(const Image *image,
-  const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha)
+  const Quantum *pixel,PixelInfo *pixel_info,double *alpha)
 {
-  if (image->matte == MagickFalse)
+  if (image->alpha_trait != BlendPixelTrait)
     {
       *alpha=1.0;
-      pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
-      pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
-      pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
+      pixel_info->red=(double) GetPixelRed(image,pixel);
+      pixel_info->green=(double) GetPixelGreen(image,pixel);
+      pixel_info->blue=(double) GetPixelBlue(image,pixel);
       pixel_info->black=0.0;
       if (image->colorspace == CMYKColorspace)
-        pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
-      pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
+        pixel_info->black=(double) GetPixelBlack(image,pixel);
+      pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
       return;
     }
   *alpha=QuantumScale*GetPixelAlpha(image,pixel);
@@ -4605,48 +5115,7 @@ static inline void AlphaBlendPixelInfo(const Image *image,
   pixel_info->black=0.0;
   if (image->colorspace == CMYKColorspace)
     pixel_info->black=(*alpha*GetPixelBlack(image,pixel));
-  pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
-}
-
-static void BicubicInterpolate(const PixelInfo *pixels,const double dx,
-  PixelInfo *pixel)
-{
-  MagickRealType
-    dx2,
-    p,
-    q,
-    r,
-    s;
-
-  dx2=dx*dx;
-  p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red);
-  q=(pixels[0].red-pixels[1].red)-p;
-  r=pixels[2].red-pixels[0].red;
-  s=pixels[1].red;
-  pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
-  p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green);
-  q=(pixels[0].green-pixels[1].green)-p;
-  r=pixels[2].green-pixels[0].green;
-  s=pixels[1].green;
-  pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
-  p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue);
-  q=(pixels[0].blue-pixels[1].blue)-p;
-  r=pixels[2].blue-pixels[0].blue;
-  s=pixels[1].blue;
-  pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
-  p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha);
-  q=(pixels[0].alpha-pixels[1].alpha)-p;
-  r=pixels[2].alpha-pixels[0].alpha;
-  s=pixels[1].alpha;
-  pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
-  if (pixel->colorspace == CMYKColorspace)
-    {
-      p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black);
-      q=(pixels[0].black-pixels[1].black)-p;
-      r=pixels[2].black-pixels[0].black;
-      s=pixels[1].black;
-      pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s;
-    }
+  pixel_info->alpha=(double) GetPixelAlpha(image,pixel);
 }
 
 MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
@@ -4656,7 +5125,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
   MagickBooleanType
     status;
 
-  MagickRealType
+  double
     alpha[16],
     gamma;
 
@@ -4673,104 +5142,74 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
     x_offset,
     y_offset;
 
+  PixelInterpolateMethod
+    interpolate;
+
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   assert(image_view != (CacheView *) NULL);
   status=MagickTrue;
   x_offset=(ssize_t) floor(x);
   y_offset=(ssize_t) floor(y);
-  switch (method == UndefinedInterpolatePixel ? image->interpolate : method)
+  interpolate = method;
+  if ( interpolate == UndefinedInterpolatePixel )
+    interpolate = image->interpolate;
+  switch (interpolate)
   {
-    case AverageInterpolatePixel:
+    case AverageInterpolatePixel:        /* nearest 4 neighbours */
+    case Average9InterpolatePixel:       /* nearest 9 neighbours */
+    case Average16InterpolatePixel:      /* nearest 16 neighbours */
     {
-      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
+      size_t
+        count=2; /* size of the area to average - default nearest 4 */
+
+      if (interpolate == Average9InterpolatePixel)
+        {
+          count=3;
+          x_offset=(ssize_t) (floor(x+0.5)-1);
+          y_offset=(ssize_t) (floor(y+0.5)-1);
+        }
+      else if (interpolate == Average16InterpolatePixel)
+        {
+          count=4;
+          x_offset--;
+          y_offset--;
+        }
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count,
         exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
-      AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
-      AlphaBlendPixelInfo(image,p+1*GetPixelChannels(image),pixels+1,alpha+1);
-      AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
-      AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
-      AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
-      AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
-      AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
-      AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
-      AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
-      AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
-      AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
-        10);
-      AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
-        11);
-      AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
-        12);
-      AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
-        13);
-      AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
-        14);
-      AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
-        15);
       pixel->red=0.0;
       pixel->green=0.0;
       pixel->blue=0.0;
       pixel->black=0.0;
       pixel->alpha=0.0;
-      for (i=0; i < 16L; i++)
+      count*=count;         /* number of pixels - square of size */
+      for (i=0; i < (ssize_t) count; i++)
       {
-        gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]);
-        pixel->red+=gamma*0.0625*pixels[i].red;
-        pixel->green+=gamma*0.0625*pixels[i].green;
-        pixel->blue+=gamma*0.0625*pixels[i].blue;
-        if (image->colorspace == CMYKColorspace)
-          pixel->black+=gamma*0.0625*pixels[i].black;
-        pixel->alpha+=0.0625*pixels[i].alpha;
+        AlphaBlendPixelInfo(image,p,pixels,alpha);
+        gamma=MagickEpsilonReciprocal(alpha[0]);
+        pixel->red   += gamma*pixels[0].red;
+        pixel->green += gamma*pixels[0].green;
+        pixel->blue  += gamma*pixels[0].blue;
+        pixel->black += gamma*pixels[0].black;
+        pixel->alpha +=       pixels[0].alpha;
+        p += GetPixelChannels(image);
       }
+      gamma=1.0/count;   /* average weighting of each pixel in area */
+      pixel->red   *= gamma;
+      pixel->green *= gamma;
+      pixel->blue  *= gamma;
+      pixel->black *= gamma;
+      pixel->alpha *= gamma;
       break;
     }
-    case BicubicInterpolatePixel:
+    case BackgroundInterpolatePixel:
     {
-      PixelInfo
-        u[4];
-
-      PointInfo
-        delta;
-
-      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
-        exception);
-      if (p == (const Quantum *) NULL)
-        {
-          status=MagickFalse;
-          break;
-        }
-      AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
-      AlphaBlendPixelInfo(image,p+1*GetPixelChannels(image),pixels+1,alpha+1);
-      AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
-      AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
-      AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
-      AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
-      AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
-      AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
-      AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
-      AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
-      AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
-        10);
-      AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
-        11);
-      AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
-        12);
-      AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
-        13);
-      AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
-        14);
-      AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
-        15);
-      delta.x=x-x_offset;
-      delta.y=y-y_offset;
-      for (i=0; i < 4L; i++)
-        BicubicInterpolate(pixels+4*i,delta.x,u+i);
-      BicubicInterpolate(u,delta.y,pixel);
+      *pixel = image->background_color;  /* Copy PixelInfo Structure  */
       break;
     }
     case BilinearInterpolatePixel:
@@ -4786,17 +5225,15 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
           status=MagickFalse;
           break;
         }
-      AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
-      AlphaBlendPixelInfo(image,p+1*GetPixelChannels(image),pixels+1,alpha+1);
-      AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
-      AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
+      for (i=0; i < 4L; i++)
+        AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
       delta.x=x-x_offset;
       delta.y=y-y_offset;
       epsilon.x=1.0-delta.x;
       epsilon.y=1.0-delta.y;
       gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y*
         (epsilon.x*alpha[2]+delta.x*alpha[3])));
-      gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+      gamma=MagickEpsilonReciprocal(gamma);
       pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x*
         pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red));
       pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x*
@@ -4810,12 +5247,122 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
           pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x*
           pixels[3].black));
       gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x)));
-      gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+      gamma=MagickEpsilonReciprocal(gamma);
       pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x*
         pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x*
         pixels[3].alpha));
       break;
     }
+    case BlendInterpolatePixel:
+    {
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception);
+      if (p == (const Quantum *) NULL)
+        {
+          status=MagickFalse;
+          break;
+        }
+      for (i=0; i < 4L; i++)
+        AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
+      gamma=1.0;    /* number of pixels blended together (its variable) */
+      for (i=0; i <= 1L; i++) {
+        if ( y-y_offset >= 0.75 ) {       /* take right pixels */
+          alpha[i]  = alpha[i+2];
+          pixels[i] = pixels[i+2];
+        }
+        else if ( y-y_offset > 0.25 ) {
+          gamma = 2.0;                    /* blend both pixels in row */
+          alpha[i]        += alpha[i+2];  /* add up alpha weights */
+          pixels[i].red   += pixels[i+2].red;
+          pixels[i].green += pixels[i+2].green;
+          pixels[i].blue  += pixels[i+2].blue;
+          pixels[i].black += pixels[i+2].black;
+          pixels[i].alpha += pixels[i+2].alpha;
+        }
+      }
+      if ( x-x_offset >= 0.75 ) {
+        alpha[0]  = alpha[1];
+        pixels[0] = pixels[1];
+      }
+      else if ( x-x_offset > 0.25 ) {
+        gamma *= 2.0;                     /* blend both rows */
+        alpha[0]        += alpha[1];      /* add up alpha weights */
+        pixels[0].red   += pixels[1].red;
+        pixels[0].green += pixels[1].green;
+        pixels[0].blue  += pixels[1].blue;
+        pixels[0].black += pixels[1].black;
+        pixels[0].alpha += pixels[1].alpha;
+      }
+      gamma = 1.0/gamma;
+      alpha[0]=MagickEpsilonReciprocal(alpha[0]);
+      pixel->red   = alpha[0]*pixels[0].red;
+      pixel->green = alpha[0]*pixels[0].green; /* divide by sum of alpha */
+      pixel->blue  = alpha[0]*pixels[0].blue;
+      pixel->black = alpha[0]*pixels[0].black;
+      pixel->alpha =    gamma*pixels[0].alpha; /* divide by number of pixels */
+      break;
+    }
+    case CatromInterpolatePixel:
+    {
+      double
+        cx[4],
+        cy[4];
+
+      p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
+        exception);
+      if (p == (const Quantum *) NULL)
+        {
+          status=MagickFalse;
+          break;
+        }
+      for (i=0; i < 16L; i++)
+        AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
+      CatromWeights((double) (x-x_offset),&cx);
+      CatromWeights((double) (y-y_offset),&cy);
+      pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
+        pixels[1].red+cx[2]*pixels[2].red+cx[3]*
+        pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
+        pixels[5].red+cx[2]*pixels[6].red+cx[3]*
+        pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
+        pixels[9].red+cx[2]*pixels[10].red+cx[3]*
+        pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
+        pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
+      pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
+        pixels[1].green+cx[2]*pixels[2].green+cx[3]*
+        pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
+        pixels[5].green+cx[2]*pixels[6].green+cx[3]*
+        pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
+        pixels[9].green+cx[2]*pixels[10].green+cx[3]*
+        pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
+        pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
+      pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
+        pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
+        pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
+        pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
+        pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
+        pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
+        pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
+        pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
+      if (image->colorspace == CMYKColorspace)
+        pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
+          pixels[1].black+cx[2]*pixels[2].black+cx[3]*
+          pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
+          pixels[5].black+cx[2]*pixels[6].black+cx[3]*
+          pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
+          pixels[9].black+cx[2]*pixels[10].black+cx[3]*
+          pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
+          pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
+      pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
+        pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
+        pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
+        pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
+        pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
+        pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
+        pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
+        pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
+      break;
+    }
+#if 0
+    /* deprecated useless and very slow interpolator */
     case FilterInterpolatePixel:
     {
       CacheView
@@ -4838,19 +5385,19 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
           status=MagickFalse;
           break;
         }
-      filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur,
-        exception);
+      filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception);
       excerpt_image=DestroyImage(excerpt_image);
       if (filter_image == (Image *) NULL)
         break;
-      filter_view=AcquireCacheView(filter_image);
+      filter_view=AcquireVirtualCacheView(filter_image,exception);
       p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception);
       if (p != (const Quantum *) NULL)
-        SetPixelInfo(image,p,pixel);
+        GetPixelInfoPixel(image,p,pixel);
       filter_view=DestroyCacheView(filter_view);
       filter_image=DestroyImage(filter_image);
       break;
     }
+#endif
     case IntegerInterpolatePixel:
     {
       p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
@@ -4859,7 +5406,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
           status=MagickFalse;
           break;
         }
-      SetPixelInfo(image,p,pixel);
+      GetPixelInfoPixel(image,p,pixel);
       break;
     }
     case MeshInterpolatePixel:
@@ -4878,10 +5425,10 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
       delta.y=y-y_offset;
       luminance.x=GetPixelLuminance(image,p)-(double)
         GetPixelLuminance(image,p+3*GetPixelChannels(image));
-      luminance.y=GetPixelLuminance(image,p+1*GetPixelChannels(image))-(double)
+      luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double)
         GetPixelLuminance(image,p+2*GetPixelChannels(image));
       AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
-      AlphaBlendPixelInfo(image,p+1*GetPixelChannels(image),pixels+1,alpha+1);
+      AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1);
       AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
       AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
       if (fabs(luminance.x) < fabs(luminance.y))
@@ -4896,7 +5443,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
               */
               delta.y=1.0-delta.y;
               gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red,
                 pixels[3].red,pixels[0].red);
               pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green,
@@ -4917,7 +5464,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
               */
               delta.x=1.0-delta.x;
               gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red,
                 pixels[0].red,pixels[3].red);
               pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green,
@@ -4943,7 +5490,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
                 Top-left triangle (pixel: 0, diagonal: 1-2).
               */
               gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red,
                 pixels[1].red,pixels[2].red);
               pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green,
@@ -4965,7 +5512,7 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
               delta.x=1.0-delta.x;
               delta.y=1.0-delta.y;
               gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]);
-              gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+              gamma=MagickEpsilonReciprocal(gamma);
               pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red,
                 pixels[2].red,pixels[1].red);
               pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green,
@@ -4982,30 +5529,24 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
         }
       break;
     }
-    case NearestNeighborInterpolatePixel:
+    case NearestInterpolatePixel:
     {
-      p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x),
-        NearestNeighbor(y),1,1,exception);
+      x_offset=(ssize_t) floor(x+0.5);
+      y_offset=(ssize_t) floor(y+0.5);
+      p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception);
       if (p == (const Quantum *) NULL)
         {
           status=MagickFalse;
           break;
         }
-      SetPixelInfo(image,p,pixel);
+      GetPixelInfoPixel(image,p,pixel);
       break;
     }
     case SplineInterpolatePixel:
     {
-      MagickRealType
-        dx,
-        dy;
-
-      PointInfo
-        delta;
-
-      ssize_t
-        j,
-        n;
+      double
+        cx[4],
+        cy[4];
 
       p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4,
         exception);
@@ -5014,52 +5555,51 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
           status=MagickFalse;
           break;
         }
-      AlphaBlendPixelInfo(image,p,pixels+0,alpha+0);
-      AlphaBlendPixelInfo(image,p+1*GetPixelChannels(image),pixels+1,alpha+1);
-      AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2);
-      AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3);
-      AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4);
-      AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5);
-      AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6);
-      AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7);
-      AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8);
-      AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9);
-      AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+
-        10);
-      AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+
-        11);
-      AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+
-        12);
-      AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+
-        13);
-      AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+
-        14);
-      AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+
-        15);
-      pixel->red=0.0;
-      pixel->green=0.0;
-      pixel->blue=0.0;
-      pixel->black=0.0;
-      pixel->alpha=0.0;
-      delta.x=x-x_offset;
-      delta.y=y-y_offset;
-      n=0;
-      for (i=(-1); i < 3L; i++)
-      {
-        dy=CubicWeightingFunction((MagickRealType) i-delta.y);
-        for (j=(-1); j < 3L; j++)
-        {
-          dx=CubicWeightingFunction(delta.x-(MagickRealType) j);
-          gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]);
-          pixel->red+=gamma*dx*dy*pixels[n].red;
-          pixel->green+=gamma*dx*dy*pixels[n].green;
-          pixel->blue+=gamma*dx*dy*pixels[n].blue;
-          if (image->colorspace == CMYKColorspace)
-            pixel->black+=gamma*dx*dy*pixels[n].black;
-          pixel->alpha+=dx*dy*pixels[n].alpha;
-          n++;
-        }
-      }
+      for (i=0; i < 16L; i++)
+        AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i);
+      SplineWeights((double) (x-x_offset),&cx);
+      SplineWeights((double) (y-y_offset),&cy);
+      pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*
+        pixels[1].red+cx[2]*pixels[2].red+cx[3]*
+        pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]*
+        pixels[5].red+cx[2]*pixels[6].red+cx[3]*
+        pixels[7].red)+cy[2]*(cx[0]*pixels[8].red+cx[1]*
+        pixels[9].red+cx[2]*pixels[10].red+cx[3]*
+        pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*
+        pixels[13].red+cx[2]*pixels[14].red+cx[3]*pixels[15].red));
+      pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*
+        pixels[1].green+cx[2]*pixels[2].green+cx[3]*
+        pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+cx[1]*
+        pixels[5].green+cx[2]*pixels[6].green+cx[3]*
+        pixels[7].green)+cy[2]*(cx[0]*pixels[8].green+cx[1]*
+        pixels[9].green+cx[2]*pixels[10].green+cx[3]*
+        pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+cx[1]*
+        pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green));
+      pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*
+        pixels[1].blue+cx[2]*pixels[2].blue+cx[3]*
+        pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]*
+        pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*
+        pixels[7].blue)+cy[2]*(cx[0]*pixels[8].blue+cx[1]*
+        pixels[9].blue+cx[2]*pixels[10].blue+cx[3]*
+        pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*
+        pixels[13].blue+cx[2]*pixels[14].blue+cx[3]*pixels[15].blue));
+      if (image->colorspace == CMYKColorspace)
+        pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*
+          pixels[1].black+cx[2]*pixels[2].black+cx[3]*
+          pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+cx[1]*
+          pixels[5].black+cx[2]*pixels[6].black+cx[3]*
+          pixels[7].black)+cy[2]*(cx[0]*pixels[8].black+cx[1]*
+          pixels[9].black+cx[2]*pixels[10].black+cx[3]*
+          pixels[11].black)+cy[3]*(cx[0]*pixels[12].black+cx[1]*
+          pixels[13].black+cx[2]*pixels[14].black+cx[3]*pixels[15].black));
+      pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*
+        pixels[1].alpha+cx[2]*pixels[2].alpha+cx[3]*
+        pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+cx[1]*
+        pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*
+        pixels[7].alpha)+cy[2]*(cx[0]*pixels[8].alpha+cx[1]*
+        pixels[9].alpha+cx[2]*pixels[10].alpha+cx[3]*
+        pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+cx[1]*
+        pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha));
       break;
     }
   }
@@ -5083,41 +5623,42 @@ MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image,
 %
 %  The format of the IsFuzzyEquivalencePixel method is:
 %
-%      void IsFuzzyEquivalencePixel(const Image *image,const Quantum *p,
-%        const Quantum *q)
+%      void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p,
+%        const Image *destination,const Quantum *q)
 %
 %  A description of each parameter follows:
 %
-%    o image: the image.
+%    o source: the source image.
 %
 %    o p: Pixel p.
 %
+%    o destination: the destination image.
+%
 %    o q: Pixel q.
 %
 */
-MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
-  const Quantum *p,const Quantum *q)
+MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source,
+  const Quantum *p,const Image *destination,const Quantum *q)
 {
-  MagickRealType
+  double
     fuzz,
     pixel;
 
-  register MagickRealType
+  register double
     distance,
     scale;
 
-  fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*
-    MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2);
+  fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax(
+    destination->fuzz,(double) MagickSQ1_2);
   scale=1.0;
   distance=0.0;
-  if (image->matte != MagickFalse)
+  if (source->alpha_trait == BlendPixelTrait)
     {
       /*
         Transparencies are involved - set alpha distance
       */
-      pixel=(MagickRealType) ((image->matte != MagickFalse ?
-        GetPixelAlpha(image,p) : OpaqueAlpha)-(image->matte != MagickFalse ?
-        GetPixelAlpha(image,q) : OpaqueAlpha));
+      pixel=GetPixelAlpha(source,p)-(double)
+        GetPixelAlpha(destination,q);
       distance=pixel*pixel;
       if (distance > fuzz)
         return(MagickFalse);
@@ -5125,8 +5666,8 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
         Generate a alpha scaling factor to generate a 4D cone on colorspace
         Note that if one color is transparent, distance has no color component.
       */
-      scale=QuantumScale*GetPixelAlpha(image,p);
-      scale*=QuantumScale*GetPixelAlpha(image,q);
+      scale=QuantumScale*GetPixelAlpha(source,p);
+      scale*=QuantumScale*GetPixelAlpha(destination,q);
       if (scale <= MagickEpsilon)
         return(MagickTrue);
     }
@@ -5135,10 +5676,10 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
   */
   distance*=3.0;  /* rescale appropriately */
   fuzz*=3.0;
-  pixel=GetPixelRed(image,p)-(MagickRealType) GetPixelRed(image,q);
-  if ((image->colorspace == HSLColorspace) ||
-      (image->colorspace == HSBColorspace) ||
-      (image->colorspace == HWBColorspace))
+  pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q);
+  if ((source->colorspace == HSLColorspace) ||
+      (source->colorspace == HSBColorspace) ||
+      (source->colorspace == HWBColorspace))
     {
       /*
         Compute an arc distance for hue.  It should be a vector angle of
@@ -5151,11 +5692,11 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
   distance+=scale*pixel*pixel;
   if (distance > fuzz)
     return(MagickFalse);
-  pixel=GetPixelGreen(image,p)-(MagickRealType) GetPixelGreen(image,q);
+  pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q);
   distance+=scale*pixel*pixel;
   if (distance > fuzz)
     return(MagickFalse);
-  pixel=GetPixelBlue(image,p)-(MagickRealType) GetPixelBlue(image,q);
+  pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q);
   distance+=scale*pixel*pixel;
   if (distance > fuzz)
     return(MagickFalse);
@@ -5177,13 +5718,13 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
 %  colors is less than the specified distance in a linear three (or four)
 %  dimensional color space.
 %
-%  This implements the equivalent of...
-%    fuzz < sqrt( color_distance^2 * u.a*v.a  + alpha_distance^2 )
+%  This implements the equivalent of:
+%    fuzz < sqrt(color_distance^2 * u.a*v.a  + alpha_distance^2)
 %
 %  Which produces a multi-dimensional cone for that colorspace along the
 %  transparency vector.
 %
-%  For example for an RGB
+%  For example for an RGB:
 %    color_distance^2  = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3
 %
 %  See http://www.imagemagick.org/Usage/bugs/fuzz_distance/
@@ -5209,44 +5750,44 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *image,
 MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
   const PixelInfo *q)
 {
-  MagickRealType
+  double
     fuzz,
     pixel;
 
-  register MagickRealType
+  register double
     scale,
     distance;
 
   if ((p->fuzz == 0.0) && (q->fuzz == 0.0))
     return(IsPixelInfoEquivalent(p,q));
   if (p->fuzz == 0.0)
-    fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*
-      MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2);
+    fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
+      (double) MagickSQ1_2);
   else if (q->fuzz == 0.0)
-    fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*
-      MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2);
+    fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,
+      (double) MagickSQ1_2);
   else
-    fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*
-      MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2);
+    fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,
+      (double) MagickSQ1_2);
   scale=1.0;
   distance=0.0;
-  if ((p->matte != MagickFalse) || (q->matte != MagickFalse))
+  if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait))
     {
       /*
         Transparencies are involved - set alpha distance.
       */
-      pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)-
-        (q->matte != MagickFalse ? q->alpha : OpaqueAlpha);
+      pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)-
+        (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha);
       distance=pixel*pixel;
       if (distance > fuzz)
         return(MagickFalse);
       /*
         Generate a alpha scaling factor to generate a 4D cone on colorspace.
-        Note that if one color is transparent, distance has no color component.
+        If one color is transparent, distance has no color component.
       */
-      if (p->matte != MagickFalse)
+      if (p->alpha_trait == BlendPixelTrait)
         scale=(QuantumScale*p->alpha);
-      if (q->matte != MagickFalse)
+      if (q->alpha_trait == BlendPixelTrait)
         scale*=(QuantumScale*q->alpha);
       if (scale <= MagickEpsilon )
         return(MagickTrue);
@@ -5260,8 +5801,8 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
       distance+=pixel*pixel*scale;
       if (distance > fuzz)
         return(MagickFalse);
-      scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black));
-      scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black));
+      scale*=(double) (QuantumScale*(QuantumRange-p->black));
+      scale*=(double) (QuantumScale*(QuantumRange-q->black));
     }
   /*
     RGB or CMY color cube.
@@ -5272,10 +5813,10 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
   if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) ||
       (p->colorspace == HWBColorspace))
     {
-      /* This calculates a arc distance for hue
-         Really if should be a vector angle of 'S'/'W' length
-         with 'L'/'B' forming appropriate cones.
-         In other words this is a hack - Anthony
+      /*
+        This calculates a arc distance for hue-- it should be a vector angle
+        of 'S'/'W' length with 'L'/'B' forming appropriate cones.  In other
+        words this is a hack - Anthony.
       */
       if (fabs((double) pixel) > (QuantumRange/2))
         pixel-=QuantumRange;
@@ -5300,124 +5841,27 @@ MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I s F u z z y E q u i v a l e n c e P i x e l P a c k e t                 %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  IsFuzzyEquivalencePixelPacket() returns MagickTrue if the distance between
-%  two pixels is less than the specified distance in a linear three (or four)
-%  dimensional color space.
-%
-%  The format of the IsFuzzyEquivalencePixelPacket method is:
-%
-%      void IsFuzzyEquivalencePixelPacket(const Image *image,
-%        const PixelPacket *p,const PixelPacket *q)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o p: Pixel p.
-%
-%    o q: Pixel q.
-%
-*/
-MagickExport MagickBooleanType IsFuzzyEquivalencePixelPacket(const Image *image,
-  const PixelPacket *p,const PixelPacket *q)
-{
-  MagickRealType
-    fuzz,
-    pixel;
-
-  register MagickRealType
-    distance,
-    scale;
-
-  if ((image->fuzz == 0.0) && (image->matte == MagickFalse))
-    return(IsPixelPacketEquivalent(p,q));
-  fuzz=MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2)*
-    MagickMax(image->fuzz,(MagickRealType) MagickSQ1_2);
-  scale=1.0;
-  distance=0.0;
-  if (image->matte != MagickFalse)
-    {
-      /*
-        Transparencies are involved - set alpha distance
-      */
-      pixel=(MagickRealType) ((image->matte != MagickFalse ? p->alpha :
-        OpaqueAlpha)-(image->matte != MagickFalse ? q->alpha : OpaqueAlpha));
-      distance=pixel*pixel;
-      if (distance > fuzz)
-        return(MagickFalse);
-      /*
-        Generate a alpha scaling factor to generate a 4D cone on colorspace
-        Note that if one color is transparent, distance has no color component.
-      */
-      scale=QuantumScale*p->alpha;
-      scale*=QuantumScale*q->alpha;
-      if (scale <= MagickEpsilon)
-        return(MagickTrue);
-    }
-  /*
-    RGB or CMY color cube
-  */
-  distance*=3.0;  /* rescale appropriately */
-  fuzz*=3.0;
-  pixel=p->red-(MagickRealType) q->red;
-  if ((image->colorspace == HSLColorspace) ||
-      (image->colorspace == HSBColorspace) ||
-      (image->colorspace == HWBColorspace))
-    {
-      /*
-        Compute an arc distance for hue.  It should be a vector angle of
-        'S'/'W' length with 'L'/'B' forming appropriate cones.
-      */
-      if (fabs((double) pixel) > (QuantumRange/2))
-        pixel-=QuantumRange;
-      pixel*=2;
-    }
-  distance+=scale*pixel*pixel;
-  if (distance > fuzz)
-    return(MagickFalse);
-  pixel=(MagickRealType) p->green-q->green;
-  distance+=scale*pixel*pixel;
-  if (distance > fuzz)
-    return(MagickFalse);
-  pixel=(MagickRealType) p->blue-q->blue;
-  distance+=scale*pixel*pixel;
-  if (distance > fuzz)
-    return(MagickFalse);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%   S e t P i x e l C h a n n e l M a p                                       %
+%   S e t P i x e l C h a n n e l M a p M a s k                               %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  SetPixelChannelMap() sets the pixel channel map from the specified channel
-%  mask.
+%  SetPixelChannelMask() sets the pixel channel map from the specified
+%  channel mask.
 %
-%  The format of the SetPixelChannelMap method is:
+%  The format of the SetPixelChannelMask method is:
 %
-%      void SetPixelChannelMap(Image *image,const ChannelType channel_mask)
+%      void SetPixelChannelMask(Image *image,const ChannelType channel_mask)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o mask: the channel mask.
+%    o channel_mask: the channel mask.
 %
 */
-MagickExport void SetPixelChannelMap(Image *image,
+MagickExport void SetPixelChannelMask(Image *image,
   const ChannelType channel_mask)
 {
 #define GetChannelBit(mask,bit)  (((size_t) (mask) >> (size_t) (bit)) & 0x01)
@@ -5425,14 +5869,27 @@ MagickExport void SetPixelChannelMap(Image *image,
   register ssize_t
     i;
 
-  image->sync=channel_mask == DefaultChannels ? MagickTrue : MagickFalse;
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \
+      image->filename,channel_mask); \
+  image->channel_mask=channel_mask;
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-    SetPixelChannelMapTraits(image,(PixelChannel) i,
-      GetChannelBit(channel_mask,i) != 0 ? UpdatePixelTrait : CopyPixelTrait);
-  for ( ; i < MaxPixelChannels; i++)
-    SetPixelChannelMapTraits(image,(PixelChannel) i,UndefinedPixelTrait);
+  {
+    PixelChannel
+      channel;
+
+    channel=GetPixelChannelChannel(image,i);
+    SetPixelChannelTraits(image,channel,
+      GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait :
+      image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ?
+      UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait));
+  }
   if (image->storage_class == PseudoClass)
-    SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait);
+    SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait);
+  if (image->mask != MagickFalse)
+    SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait);
+  if (image->debug != MagickFalse)
+    LogPixelChannels(image);
 }
 \f
 /*
@@ -5440,35 +5897,31 @@ MagickExport void SetPixelChannelMap(Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   S e t P i x e l C h a n n e l M a s k                                     %
+%   S e t P i x e l M e t a C h a n n e l s                                   %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  SetPixelChannelMask() sets the pixel channel mask from the specified
-%  channel mask.
+%  SetPixelMetaChannels() sets the image meta channels.
 %
-%  The format of the SetPixelChannelMask method is:
+%  The format of the SetPixelMetaChannels method is:
 %
-%      ChannelType SetPixelChannelMask(Image *image,
-%        const ChannelType channel_mask)
+%      MagickBooleanType SetPixelMetaChannels(Image *image,
+%        const size_t number_meta_channels,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel_mask: the channel mask.
+%    o number_meta_channels:  the number of meta channels.
+%
+%    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport ChannelType SetPixelChannelMask(Image *image,
-  const ChannelType channel_mask)
+MagickExport MagickBooleanType SetPixelMetaChannels(Image *image,
+  const size_t number_meta_channels,ExceptionInfo *exception)
 {
-  ChannelType
-    mask;
-
-  mask=image->channel_mask;
-  image->channel_mask=channel_mask;
-  SetPixelChannelMap(image,channel_mask);
-  return(mask);
+  image->number_meta_channels=number_meta_channels;
+  return(SyncImagePixelCache(image,exception));
 }