]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/xwindow.c
(no commit message)
[imagemagick] / MagickCore / xwindow.c
index 4304c161f69aa331e117399e19bed4a159f6deb7..95d8ba1f3c5a635327f6eeb6a9d0387078253d12 100644 (file)
 %                       MagickCore X11 Utility Methods                        %
 %                                                                             %
 %                               Software Design                               %
-%                                 John Cristy                                 %
+%                                    Cristy                                   %
 %                                  July 1992                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 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  %
@@ -49,7 +49,9 @@
 #include "MagickCore/color-private.h"
 #include "MagickCore/colormap.h"
 #include "MagickCore/composite.h"
+#include "MagickCore/constitute.h"
 #include "MagickCore/display.h"
+#include "MagickCore/distort.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
 #include "MagickCore/geometry.h"
@@ -62,6 +64,7 @@
 #include "MagickCore/magick.h"
 #include "MagickCore/memory_.h"
 #include "MagickCore/monitor.h"
+#include "MagickCore/nt-base-private.h"
 #include "MagickCore/option.h"
 #include "MagickCore/pixel-accessor.h"
 #include "MagickCore/PreRvIcccm.h"
 #include "MagickCore/quantum-private.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/resize.h"
-#include "MagickCore/shear.h"
 #include "MagickCore/statistic.h"
 #include "MagickCore/string_.h"
 #include "MagickCore/string-private.h"
 #include "MagickCore/transform.h"
+#include "MagickCore/token.h"
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 #include "MagickCore/widget.h"
@@ -203,7 +206,7 @@ static MagickBooleanType
 static const char
   *XVisualClassName(const int);
 
-static MagickRealType
+static double
   blue_gamma = 1.0,
   green_gamma = 1.0,
   red_gamma = 1.0;
@@ -213,9 +216,9 @@ static MagickBooleanType
 
 static void
   XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
-    XImage *,XImage *),
+    XImage *,XImage *,ExceptionInfo *),
   XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
-    XImage *,XImage *);
+    XImage *,XImage *,ExceptionInfo *);
 
 static Window
   XSelectWindow(Display *,RectangleInfo *);
@@ -390,9 +393,11 @@ MagickExport void DestroyXResources(void)
   if (windows->class_hints != (XClassHint *) NULL)
     {
       if (windows->class_hints->res_name != (char *) NULL)
-        XFree(windows->class_hints->res_name);
+        windows->class_hints->res_name=DestroyString(
+          windows->class_hints->res_name);
       if (windows->class_hints->res_class != (char *) NULL)
-        XFree(windows->class_hints->res_class);
+        windows->class_hints->res_class=DestroyString(
+          windows->class_hints->res_class);
       XFree(windows->class_hints);
       windows->class_hints=(XClassHint *) NULL;
     }
@@ -440,7 +445,8 @@ MagickExport void DestroyXResources(void)
 %  The format of the XAnnotateImage method is:
 %
 %      MagickBooleanType XAnnotateImage(Display *display,
-%        const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
+%        const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -453,9 +459,12 @@ MagickExport void DestroyXResources(void)
 %
 %    o image: the image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
-  const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
+  const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
+  ExceptionInfo *exception)
 {
   CacheView
     *annotate_view;
@@ -463,9 +472,6 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
   GC
     annotate_context;
 
-  ExceptionInfo
-    *exception;
-
   Image
     *annotate_image;
 
@@ -473,8 +479,8 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
     x,
     y;
 
-  MagickBooleanType
-    matte;
+  PixelTrait
+    alpha_trait;
 
   Pixmap
     annotate_pixmap;
@@ -538,7 +544,7 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
   /*
     Initialize annotated image.
   */
-  annotate_image=AcquireImage((ImageInfo *) NULL);
+  annotate_image=AcquireImage((ImageInfo *) NULL,exception);
   if (annotate_image == (Image *) NULL)
     return(MagickFalse);
   annotate_image->columns=annotate_info->width;
@@ -551,12 +557,11 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
   x=0;
   y=0;
   (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
-  (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
-    &annotate_image->background_color,&image->exception);
+  (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
+    (ssize_t) y,&annotate_image->background_color,exception);
   if (annotate_info->stencil == ForegroundStencil)
-    annotate_image->matte=MagickTrue;
-  exception=(&image->exception);
-  annotate_view=AcquireCacheView(annotate_image);
+    annotate_image->alpha_trait=BlendPixelTrait;
+  annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
   for (y=0; y < (int) annotate_image->rows; y++)
   {
     register int
@@ -623,7 +628,8 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
       */
       (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
         width,height);
-      (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
+      (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
+        exception);
     }
   if (annotate_info->degrees != 0.0)
     {
@@ -633,14 +639,13 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
       int
         rotations;
 
-      MagickRealType
+      double
         normalized_degrees;
 
       /*
         Rotate image.
       */
-      rotate_image=
-        RotateImage(annotate_image,annotate_info->degrees,&image->exception);
+      rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
       if (rotate_image == (Image *) NULL)
         return(MagickFalse);
       annotate_image=DestroyImage(annotate_image);
@@ -690,10 +695,11 @@ MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
     Composite text onto the image.
   */
   (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
-  matte=image->matte;
-  (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
-    OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
-  image->matte=matte;
+  alpha_trait=image->alpha_trait;
+  (void) CompositeImage(image,annotate_image,
+    annotate_image->alpha_trait == BlendPixelTrait ? OverCompositeOp :
+    CopyCompositeOp,MagickTrue,(ssize_t) x,(ssize_t) y,exception);
+  image->alpha_trait=alpha_trait;
   annotate_image=DestroyImage(annotate_image);
   return(MagickTrue);
 }
@@ -758,8 +764,7 @@ static char **FontToList(char *font)
   fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
   if (fontlist == (char **) NULL)
     {
-      ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
-        font);
+      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
       return((char **) NULL);
     }
   p=font;
@@ -772,8 +777,7 @@ static char **FontToList(char *font)
       sizeof(*fontlist[i]));
     if (fontlist[i] == (char *) NULL)
       {
-        ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
-          font);
+        ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
         return((char **) NULL);
       }
     (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
@@ -844,7 +848,7 @@ MagickPrivate XFontStruct *XBestFont(Display *display,
           fontlist=(char **) RelinquishMagickMemory(fontlist);
         }
       if (font_info == (XFontStruct *) NULL)
-        ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
+        ThrowXWindowException(XServerError,"UnableToLoadFont",font_name);
     }
   /*
     Load fonts from list of fonts until one is found.
@@ -898,7 +902,7 @@ MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
     i,
     number_sizes;
 
-  MagickRealType
+  double
     scale_factor;
 
   unsigned int
@@ -937,8 +941,8 @@ MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
       icon_size=XAllocIconSize();
       if (icon_size == (XIconSize *) NULL)
         {
-          ThrowXWindowFatalException(ResourceLimitError,
-            "MemoryAllocationFailed",image->filename);
+          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+            image->filename);
           return;
         }
       icon_size->min_width=1;
@@ -959,9 +963,9 @@ MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
   /*
     Look for an icon size that maintains the aspect ratio of image.
   */
-  scale_factor=(MagickRealType) icon_size->max_width/width;
-  if (scale_factor > ((MagickRealType) icon_size->max_height/height))
-    scale_factor=(MagickRealType) icon_size->max_height/height;
+  scale_factor=(double) icon_size->max_width/width;
+  if (scale_factor > ((double) icon_size->max_height/height))
+    scale_factor=(double) icon_size->max_height/height;
   icon_width=(unsigned int) icon_size->min_width;
   while ((int) icon_width < icon_size->max_width)
   {
@@ -1028,10 +1032,10 @@ MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
   PixelInfo
     pixel;
 
-  MagickRealType
+  double
     min_distance;
 
-  register MagickRealType
+  register double
     distance;
 
   register int
@@ -1059,8 +1063,8 @@ MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
       colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
       if (colors == (XColor *) NULL)
         {
-          ThrowXWindowFatalException(ResourceLimitError,
-            "MemoryAllocationFailed","...");
+          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+            "...");
           return;
         }
       for (i=0; i < (int) number_colors; i++)
@@ -1069,20 +1073,20 @@ MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
         number_colors=256;
       (void) XQueryColors(display,colormap,colors,(int) number_colors);
     }
-  min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
+  min_distance=3.0*((double) QuantumRange+1.0)*((double)
     QuantumRange+1.0);
   j=0;
   for (i=0; i < (int) number_colors; i++)
   {
-    pixel.red=colors[i].red-(MagickRealType) color->red;
+    pixel.red=colors[i].red-(double) color->red;
     distance=pixel.red*pixel.red;
     if (distance > min_distance)
       continue;
-    pixel.green=colors[i].green-(MagickRealType) color->green;
+    pixel.green=colors[i].green-(double) color->green;
     distance+=pixel.green*pixel.green;
     if (distance > min_distance)
       continue;
-    pixel.blue=colors[i].blue-(MagickRealType) color->blue;
+    pixel.blue=colors[i].blue-(double) color->blue;
     distance+=pixel.blue*pixel.blue;
     if (distance > min_distance)
       continue;
@@ -1259,7 +1263,7 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
                           strtol(visual_type,(char **) NULL,0);
                       }
                     else
-                      ThrowXWindowFatalException(XServerError,
+                      ThrowXWindowException(XServerError,
                         "UnrecognizedVisualSpecifier",visual_type);
     }
   /*
@@ -1274,15 +1278,14 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
       /*
         Failed to get visual;  try using the default visual.
       */
-      ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
-        visual_type);
+      ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
       visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
         XDefaultScreen(display)));
       visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
         &number_visuals);
       if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
         return((XVisualInfo *) NULL);
-      ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
+      ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
         XVisualClassName(visual_list->klass));
     }
   resource_info->color_recovery=MagickFalse;
@@ -1312,6 +1315,7 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
       */
       root_window=XRootWindow(display,XDefaultScreen(display));
       status=False;
+      number_maps=0;
       if (LocaleCompare(map_type,"list") != 0)
         {
           /*
@@ -1356,7 +1360,7 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
         }
       if (status == False)
         {
-          ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
+          ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
             map_type);
           return((XVisualInfo *) NULL);
         }
@@ -1378,15 +1382,15 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
             }
       if (map_info->visualid != visual_template.visualid)
         {
-          ThrowXWindowFatalException(XServerError,
+          ThrowXWindowException(XServerError,
             "UnableToMatchVisualToStandardColormap",map_type);
           return((XVisualInfo *) NULL);
         }
 #endif
       if (map_info->colormap == (Colormap) NULL)
         {
-          ThrowXWindowFatalException(XServerError,
-            "StandardColormapIsNotInitialized",map_type);
+          ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
+            map_type);
           return((XVisualInfo *) NULL);
         }
       (void) XFree((void *) map_list);
@@ -1681,7 +1685,8 @@ MagickPrivate void XComponentTerminus(void)
 %  The format of the XConfigureImageColormap method is:
 %
 %      void XConfigureImageColormap(Display *display,
-%        XResourceInfo *resource_info,XWindows *windows,Image *image)
+%        XResourceInfo *resource_info,XWindows *windows,Image *image,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1694,9 +1699,12 @@ MagickPrivate void XComponentTerminus(void)
 %
 %    o image: the image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickPrivate void XConfigureImageColormap(Display *display,
-  XResourceInfo *resource_info,XWindows *windows,Image *image)
+  XResourceInfo *resource_info,XWindows *windows,Image *image,
+  ExceptionInfo *exception)
 {
   Colormap
     colormap;
@@ -1707,7 +1715,7 @@ MagickPrivate void XConfigureImageColormap(Display *display,
   XSetCursorState(display,windows,MagickTrue);
   XCheckRefreshWindows(display,windows);
   XMakeStandardColormap(display,windows->visual_info,resource_info,image,
-    windows->map_info,windows->pixel_info);
+    windows->map_info,windows->pixel_info,exception);
   colormap=windows->map_info->colormap;
   (void) XSetWindowColormap(display,windows->image.id,colormap);
   (void) XSetWindowColormap(display,windows->command.id,colormap);
@@ -1896,7 +1904,7 @@ MagickPrivate void XDestroyWindowColors(Display *display,Window window)
   property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
   if (property == (Atom) NULL)
     {
-      ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
+      ThrowXWindowException(XServerError,"UnableToCreateProperty",
         "_XSETROOT_ID");
       return;
     }
@@ -1930,7 +1938,7 @@ MagickPrivate void XDestroyWindowColors(Display *display,Window window)
 %
 %      void XDisplayImageInfo(Display *display,
 %        const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
-%        Image *image)
+%        Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1945,10 +1953,12 @@ MagickPrivate void XDestroyWindowColors(Display *display,Window window)
 %
 %    o image: the image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickPrivate void XDisplayImageInfo(Display *display,
   const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
-  Image *image)
+  Image *image,ExceptionInfo *exception)
 {
   char
     filename[MaxTextExtent],
@@ -2037,7 +2047,7 @@ MagickPrivate void XDisplayImageInfo(Display *display,
   for (levels=0; undo_image != (Image *) NULL; levels++)
   {
     number_pixels=undo_image->list->columns*undo_image->list->rows;
-    bytes+=number_pixels*sizeof(PixelPacket);
+    bytes+=number_pixels*sizeof(PixelInfo);
     undo_image=GetPreviousImageInList(undo_image);
   }
   (void) FormatLocaleFile(file,"Undo Edit Cache\n  levels: %u\n",levels);
@@ -2048,9 +2058,9 @@ MagickPrivate void XDisplayImageInfo(Display *display,
   /*
     Write info about the image to a file.
   */
-  (void) IdentifyImage(image,file,MagickTrue,&image->exception);
+  (void) IdentifyImage(image,file,MagickTrue,exception);
   (void) fclose(file);
-  text=FileToString(filename,~0,&image->exception);
+  text=FileToString(filename,~0UL,exception);
   (void) RelinquishUniqueFileResource(filename);
   if (text == (char *) NULL)
     {
@@ -2097,7 +2107,7 @@ MagickPrivate void XDisplayImageInfo(Display *display,
 %
 %  The format of the XDitherImage method is:
 %
-%      void XDitherImage(Image *image,XImage *ximage)
+%      void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -2106,8 +2116,10 @@ MagickPrivate void XDisplayImageInfo(Display *display,
 %    o ximage: Specifies a pointer to a XImage structure;  returned from
 %      XCreateImage.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-static void XDitherImage(Image *image,XImage *ximage)
+static void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
 {
   static const short int
     dither_red[2][16]=
@@ -2133,7 +2145,7 @@ static void XDitherImage(Image *image,XImage *ximage)
     value,
     y;
 
-  PixelPacket
+  PixelInfo
     color;
 
   register char
@@ -2174,8 +2186,8 @@ static void XDitherImage(Image *image,XImage *ximage)
           (green_map[i][j] == (unsigned char *) NULL) ||
           (blue_map[i][j] == (unsigned char *) NULL))
         {
-          ThrowXWindowFatalException(ResourceLimitError,
-            "MemoryAllocationFailed",image->filename);
+          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+            image->filename);
           return;
         }
     }
@@ -2213,21 +2225,21 @@ static void XDitherImage(Image *image,XImage *ximage)
   i=0;
   j=0;
   q=ximage->data;
-  image_view=AcquireCacheView(image);
+  image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (int) image->rows; y++)
   {
     p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
-      &image->exception);
+      exception);
     if (p == (const Quantum *) NULL)
       break;
     for (x=0; x < (int) image->columns; x++)
     {
-      color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
-        ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
-      color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
-        ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
-      color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
-        ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
+      color.red=(double) ClampToQuantum((double) (red_map[i][j][
+        (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
+      color.green=(double) ClampToQuantum((double) (green_map[i][j][
+        (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
+      color.blue=(double) ClampToQuantum((double) (blue_map[i][j][
+        (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
       pixel=(size_t) (((size_t) color.red & 0xe0) |
         (((size_t) color.green & 0xe0) >> 3) |
         (((size_t) color.blue & 0xc0) >> 6));
@@ -2270,7 +2282,8 @@ static void XDitherImage(Image *image,XImage *ximage)
 %
 %  The format of the XDrawImage method is:
 %
-%    MagickBooleanType XDrawImage(display,pixel,draw_info,image)
+%    MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
+%      XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -2283,16 +2296,16 @@ static void XDitherImage(Image *image,XImage *ximage)
 %
 %    o image: the image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickPrivate MagickBooleanType XDrawImage(Display *display,
-  const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
+  const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
+  ExceptionInfo *exception)
 {
   CacheView
     *draw_view;
 
-  ExceptionInfo
-    *exception;
-
   GC
     draw_context;
 
@@ -2303,8 +2316,8 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
     x,
     y;
 
-  MagickBooleanType
-    matte;
+  PixelTrait
+    alpha_trait;
 
   Pixmap
     draw_pixmap;
@@ -2451,7 +2464,7 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
   /*
     Initialize draw image.
   */
-  draw_image=AcquireImage((ImageInfo *) NULL);
+  draw_image=AcquireImage((ImageInfo *) NULL,exception);
   if (draw_image == (Image *) NULL)
     return(MagickFalse);
   draw_image->columns=draw_info->width;
@@ -2464,13 +2477,12 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
   x=0;
   y=0;
   (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
-  (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
-    &draw_image->background_color,&image->exception);
-  if (SetImageStorageClass(draw_image,DirectClass,&image->exception) == MagickFalse)
+  (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
+    (ssize_t) y,&draw_image->background_color,exception);
+  if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
-  draw_image->matte=MagickTrue;
-  exception=(&image->exception);
-  draw_view=AcquireCacheView(draw_image);
+  draw_image->alpha_trait=BlendPixelTrait;
+  draw_view=AcquireAuthenticCacheView(draw_image,exception);
   for (y=0; y < (int) draw_image->rows; y++)
   {
     register int
@@ -2490,8 +2502,8 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
           /*
             Set this pixel to the background color.
           */
-          SetPixelPacket(draw_image,&draw_image->background_color,q);
-          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil == 
+          SetPixelInfoPixel(draw_image,&draw_image->background_color,q);
+          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
             OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
         }
       else
@@ -2530,7 +2542,8 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
       */
       (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
         width,height);
-      (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
+      (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
+        exception);
     }
   if (draw_info->degrees != 0.0)
     {
@@ -2540,13 +2553,13 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
       int
         rotations;
 
-      MagickRealType
+      double
         normalized_degrees;
 
       /*
         Rotate image.
       */
-      rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
+      rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
       if (rotate_image == (Image *) NULL)
         return(MagickFalse);
       draw_image=DestroyImage(draw_image);
@@ -2595,7 +2608,7 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
   /*
     Composite text onto the image.
   */
-  draw_view=AcquireCacheView(draw_image);
+  draw_view=AcquireAuthenticCacheView(draw_image,exception);
   for (y=0; y < (int) draw_image->rows; y++)
   {
     register int
@@ -2620,14 +2633,14 @@ MagickPrivate MagickBooleanType XDrawImage(Display *display,
   draw_view=DestroyCacheView(draw_view);
   (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
   if (draw_info->stencil == TransparentStencil)
-    (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
-      (ssize_t) y);
+    (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
+      (ssize_t) x,(ssize_t) y,exception);
   else
     {
-      matte=image->matte;
-      (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
-        (ssize_t) y);
-      image->matte=matte;
+      alpha_trait=image->alpha_trait;
+      (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
+        (ssize_t) x,(ssize_t) y,exception);
+      image->alpha_trait=alpha_trait;
     }
   draw_image=DestroyImage(draw_image);
   return(MagickTrue);
@@ -2986,7 +2999,7 @@ MagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  XGetPixelInfo() initializes the PixelPacket structure.
+%  XGetPixelInfo() initializes the PixelInfo structure.
 %
 %  The format of the XGetPixelInfo method is:
 %
@@ -3036,6 +3049,10 @@ MagickPrivate void XGetPixelInfo(Display *display,
   Colormap
     colormap;
 
+  extern const char
+    BorderColor[],
+    ForegroundColor[];
+
   register ssize_t
     i;
 
@@ -3076,7 +3093,7 @@ MagickPrivate void XGetPixelInfo(Display *display,
   status=XParseColor(display,colormap,resource_info->foreground_color,
     &pixel->foreground_color);
   if (status == False)
-    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
       resource_info->foreground_color);
   pixel->foreground_color.pixel=
     XStandardPixel(map_info,&pixel->foreground_color);
@@ -3088,7 +3105,7 @@ MagickPrivate void XGetPixelInfo(Display *display,
   status=XParseColor(display,colormap,resource_info->background_color,
     &pixel->background_color);
   if (status == False)
-    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
       resource_info->background_color);
   pixel->background_color.pixel=
     XStandardPixel(map_info,&pixel->background_color);
@@ -3101,7 +3118,7 @@ MagickPrivate void XGetPixelInfo(Display *display,
   status=XParseColor(display,colormap,resource_info->border_color,
     &pixel->border_color);
   if (status == False)
-    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
       resource_info->border_color);
   pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
   pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
@@ -3117,7 +3134,7 @@ MagickPrivate void XGetPixelInfo(Display *display,
       status=XParseColor(display,colormap,resource_info->matte_color,
         &pixel->matte_color);
       if (status == False)
-        ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+        ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
           resource_info->matte_color);
       pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
       pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
@@ -3140,33 +3157,33 @@ MagickPrivate void XGetPixelInfo(Display *display,
   /*
     Set shadow color.
   */
-  pixel->shadow_color.red=(unsigned short) (((MagickRealType)
+  pixel->shadow_color.red=(unsigned short) (((double)
     pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
-  pixel->shadow_color.green=(unsigned short) (((MagickRealType)
+  pixel->shadow_color.green=(unsigned short) (((double)
     pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
-  pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
+  pixel->shadow_color.blue=(unsigned short) (((double)
     pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
   pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
   pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
   /*
     Set depth color.
   */
-  pixel->depth_color.red=(unsigned short) (((MagickRealType)
+  pixel->depth_color.red=(unsigned short) (((double)
     pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
-  pixel->depth_color.green=(unsigned short) (((MagickRealType)
+  pixel->depth_color.green=(unsigned short) (((double)
     pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
-  pixel->depth_color.blue=(unsigned short) (((MagickRealType)
+  pixel->depth_color.blue=(unsigned short) (((double)
     pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
   pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
   pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
   /*
     Set trough color.
   */
-  pixel->trough_color.red=(unsigned short) (((MagickRealType)
+  pixel->trough_color.red=(unsigned short) (((double)
     pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
-  pixel->trough_color.green=(unsigned short) (((MagickRealType)
+  pixel->trough_color.green=(unsigned short) (((double)
     pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
-  pixel->trough_color.blue=(unsigned short) (((MagickRealType)
+  pixel->trough_color.blue=(unsigned short) (((double)
     pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
   pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
   pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
@@ -3180,7 +3197,7 @@ MagickPrivate void XGetPixelInfo(Display *display,
     status=XParseColor(display,colormap,resource_info->pen_colors[i],
       &pixel->pen_colors[i]);
     if (status == False)
-      ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
+      ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
         resource_info->pen_colors[i]);
     pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
     pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
@@ -3463,6 +3480,10 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
     *directory,
     *resource_value;
 
+  extern const char
+    BorderColor[],
+    ForegroundColor[];
+
   /*
     Initialize resource info fields.
   */
@@ -3478,7 +3499,7 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
   resource_info->client_name=AcquireString(client_name);
   resource_value=XGetResourceClass(database,client_name,"backdrop",
     (char *) "False");
-  resource_info->backdrop=IsMagickTrue(resource_value);
+  resource_info->backdrop=IsStringTrue(resource_value);
   resource_info->background_color=XGetResourceInstance(database,client_name,
     "background",(char *) "#d6d6d6d6d6d6");
   resource_info->border_color=XGetResourceInstance(database,client_name,
@@ -3495,24 +3516,24 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
   if (LocaleCompare("shared",resource_value) == 0)
     resource_info->colormap=SharedColormap;
   if (resource_info->colormap == UndefinedColormap)
-    ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
+    ThrowXWindowException(OptionError,"UnrecognizedColormapType",
       resource_value);
   resource_value=XGetResourceClass(database,client_name,
     "colorRecovery",(char *) "False");
-  resource_info->color_recovery=IsMagickTrue(resource_value);
+  resource_info->color_recovery=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"confirmExit",
     (char *) "False");
-  resource_info->confirm_exit=IsMagickTrue(resource_value);
+  resource_info->confirm_exit=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"confirmEdit",
     (char *) "False");
-  resource_info->confirm_edit=IsMagickTrue(resource_value);
+  resource_info->confirm_edit=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
   resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
   resource_info->display_gamma=XGetResourceClass(database,client_name,
     "displayGamma",(char *) "2.2");
   resource_value=XGetResourceClass(database,client_name,"displayWarnings",
     (char *) "True");
-  resource_info->display_warnings=IsMagickTrue(resource_value);
+  resource_info->display_warnings=IsStringTrue(resource_value);
   resource_info->font=XGetResourceClass(database,client_name,"font",
     (char *) NULL);
   resource_info->font=XGetResourceClass(database,client_name,"fontList",
@@ -3542,8 +3563,8 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
   resource_info->foreground_color=XGetResourceInstance(database,client_name,
     "foreground",ForegroundColor);
   resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
-    (char *) "True");
-  resource_info->gamma_correct=IsMagickTrue(resource_value);
+    (char *) "False");
+  resource_info->gamma_correct=IsStringTrue(resource_value);
   resource_info->image_geometry=ConstantString(XGetResourceClass(database,
     client_name,"geometry",(char *) NULL));
   resource_value=XGetResourceClass(database,client_name,"gravity",
@@ -3556,11 +3577,11 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
     "iconGeometry",(char *) NULL);
   resource_value=XGetResourceClass(database,client_name,"iconic",
     (char *) "False");
-  resource_info->iconic=IsMagickTrue(resource_value);
+  resource_info->iconic=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"immutable",
     LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
     (char *) "False");
-  resource_info->immutable=IsMagickTrue(resource_value);
+  resource_info->immutable=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"magnify",
     (char *) "3");
   resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
@@ -3603,17 +3624,17 @@ MagickExport void XGetResourceInfo(const ImageInfo *image_info,
   resource_info->title=XGetResourceClass(database,client_name,"title",
     (char *) NULL);
   resource_value=XGetResourceClass(database,client_name,"undoCache",
-    (char *) "16");
+    (char *) "256");
   resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
   resource_value=XGetResourceClass(database,client_name,"update",
     (char *) "False");
-  resource_info->update=IsMagickTrue(resource_value);
+  resource_info->update=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"usePixmap",
     (char *) "True");
-  resource_info->use_pixmap=IsMagickTrue(resource_value);
+  resource_info->use_pixmap=IsStringTrue(resource_value);
   resource_value=XGetResourceClass(database,client_name,"sharedMemory",
     (char *) "True");
-  resource_info->use_shared_memory=IsMagickTrue(resource_value);
+  resource_info->use_shared_memory=IsStringTrue(resource_value);
   resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
     (char *) NULL);
   resource_info->window_group=XGetResourceClass(database,client_name,
@@ -3820,7 +3841,7 @@ static Window XGetSubwindow(Display *display,Window window,int x,int y)
 %  The format of the XGetWindowColor method is:
 %
 %      MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
-%        char *name)
+%        char *name,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -3832,15 +3853,17 @@ static Window XGetSubwindow(Display *display,Window window,int x,int y)
 %    o name: the name of the color if found in the X Color Database is
 %      returned in this character string.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
-  XWindows *windows,char *name)
+  XWindows *windows,char *name,ExceptionInfo *exception)
 {
   int
     x,
     y;
 
-  PixelPacket
+  PixelInfo
     pixel;
 
   RectangleInfo
@@ -3911,12 +3934,12 @@ MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
     Match color against the color database.
   */
   (void) XQueryColor(display,window_attributes.colormap,&color);
-  pixel.red=ScaleShortToQuantum(color.red);
-  pixel.green=ScaleShortToQuantum(color.green);
-  pixel.blue=ScaleShortToQuantum(color.blue);
+  pixel.red=(double) ScaleShortToQuantum(color.red);
+  pixel.green=(double) ScaleShortToQuantum(color.green);
+  pixel.blue=(double) ScaleShortToQuantum(color.blue);
   pixel.alpha=OpaqueAlpha;
   (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
-    &windows->image.image->exception);
+    exception);
   return(MagickTrue);
 }
 \f
@@ -3940,7 +3963,8 @@ MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
 %  The format of the XGetWindowImage method is:
 %
 %      Image *XGetWindowImage(Display *display,const Window window,
-%        const unsigned int borders,const unsigned int level)
+%        const unsigned int borders,const unsigned int level,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -3958,9 +3982,11 @@ MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
 %      one call.  A value of one causes the function to descend the window
 %      hierarchy and overlay the target image with each subwindow image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 static Image *XGetWindowImage(Display *display,const Window window,
-  const unsigned int borders,const unsigned int level)
+  const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
 {
   typedef struct _ColormapInfo
   {
@@ -4094,8 +4120,7 @@ static Image *XGetWindowImage(Display *display,const Window window,
     }
   if (window_info == (WindowInfo *) NULL)
     {
-      ThrowXWindowFatalException(ResourceLimitError,
-        "MemoryAllocationFailed","...");
+      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
       return((Image *) NULL);
     }
   id=number_windows++;
@@ -4127,10 +4152,10 @@ static Image *XGetWindowImage(Display *display,const Window window,
             (window_info[i].visual == window_info[id].visual) &&
             (window_info[i].colormap == window_info[id].colormap))
           {
-            if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
-                (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
-                (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
-                (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
+            if ((window_info[id].bounds.x1 < window_info[i].bounds.x1) ||
+                (window_info[id].bounds.x2 > window_info[i].bounds.x2) ||
+                (window_info[id].bounds.y1 < window_info[i].bounds.y1) ||
+                (window_info[id].bounds.y2 > window_info[i].bounds.y2))
               {
                 /*
                   Eliminate windows not circumscribed by their parent.
@@ -4142,7 +4167,8 @@ static Image *XGetWindowImage(Display *display,const Window window,
       if ((status == True) && (number_children != 0))
         {
           for (i=0; i < (int) number_children; i++)
-            (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
+            (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
+              exception);
           (void) XFree((void *) children);
         }
     }
@@ -4154,9 +4180,6 @@ static Image *XGetWindowImage(Display *display,const Window window,
       ColormapInfo
         *next;
 
-      ExceptionInfo
-        *exception;
-
       Image
         *composite_image,
         *image;
@@ -4195,8 +4218,7 @@ static Image *XGetWindowImage(Display *display,const Window window,
         /*
           Does target window intersect top level window?
         */
-        import=
-          ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
+        import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
            (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
            (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
            (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
@@ -4208,22 +4230,12 @@ static Image *XGetWindowImage(Display *display,const Window window,
           if ((window_info[id].visual == window_info[j].visual) &&
               (window_info[id].colormap == window_info[j].colormap))
             {
-              if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
-                  (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
-                  (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
-                  (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
-                  import=MagickFalse;
+              if ((window_info[id].bounds.x1 >= window_info[j].bounds.x1) &&
+                  (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
+                  (window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
+                  (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
+                import=MagickFalse;
             }
-          else
-            if ((window_info[id].visual != window_info[j].visual) ||
-                (window_info[id].colormap != window_info[j].colormap))
-              {
-                if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
-                    (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
-                    (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
-                    (window_info[id].bounds.y1 < window_info[j].bounds.y2))
-                  import=MagickTrue;
-              }
         if (import == MagickFalse)
           continue;
         /*
@@ -4326,7 +4338,7 @@ static Image *XGetWindowImage(Display *display,const Window window,
         /*
           Allocate image structure.
         */
-        composite_image=AcquireImage((ImageInfo *) NULL);
+        composite_image=AcquireImage((ImageInfo *) NULL,exception);
         if (composite_image == (Image *) NULL)
           {
             XDestroyImage(ximage);
@@ -4340,8 +4352,7 @@ static Image *XGetWindowImage(Display *display,const Window window,
           composite_image->storage_class=PseudoClass;
         composite_image->columns=(size_t) ximage->width;
         composite_image->rows=(size_t) ximage->height;
-        exception=(&composite_image->exception);
-        composite_view=AcquireCacheView(composite_image);
+        composite_view=AcquireAuthenticCacheView(composite_image,exception);
         switch (composite_image->storage_class)
         {
           case DirectClass:
@@ -4408,7 +4419,8 @@ static Image *XGetWindowImage(Display *display,const Window window,
                     ScaleShortToQuantum(colors[index].blue),q);
                   q+=GetPixelChannels(composite_image);
                 }
-                if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
+                status=SyncCacheViewAuthenticPixels(composite_view,exception);
+                if (status == MagickFalse)
                   break;
               }
             else
@@ -4422,20 +4434,24 @@ static Image *XGetWindowImage(Display *display,const Window window,
                 {
                   pixel=XGetPixel(ximage,x,y);
                   color=(pixel >> red_shift) & red_mask;
-                  color=(65535UL*color)/red_mask;
-                  SetPixelRed(composite_image,
-                    ScaleShortToQuantum((unsigned short) color),q);
+                  if (red_mask != 0)
+                    color=(65535UL*color)/red_mask;
+                  SetPixelRed(composite_image,ScaleShortToQuantum(
+                    (unsigned short) color),q);
                   color=(pixel >> green_shift) & green_mask;
-                  color=(65535UL*color)/green_mask;
-                  SetPixelGreen(composite_image,
-                    ScaleShortToQuantum((unsigned short) color),q);
+                  if (green_mask != 0)
+                    color=(65535UL*color)/green_mask;
+                  SetPixelGreen(composite_image,ScaleShortToQuantum(
+                    (unsigned short) color),q);
                   color=(pixel >> blue_shift) & blue_mask;
-                  color=(65535UL*color)/blue_mask;
-                  SetPixelBlue(composite_image,
-                    ScaleShortToQuantum((unsigned short) color),q);
+                  if (blue_mask != 0)
+                    color=(65535UL*color)/blue_mask;
+                  SetPixelBlue(composite_image,ScaleShortToQuantum(
+                    (unsigned short) color),q);
                   q+=GetPixelChannels(composite_image);
                 }
-                if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
+                status=SyncCacheViewAuthenticPixels(composite_view,exception);
+                if (status == MagickFalse)
                   break;
               }
             break;
@@ -4445,7 +4461,9 @@ static Image *XGetWindowImage(Display *display,const Window window,
             /*
               Create colormap.
             */
-            if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
+            status=AcquireImageColormap(composite_image,number_colors,
+              exception);
+            if (status == MagickFalse)
               {
                 XDestroyImage(ximage);
                 composite_image=DestroyImage(composite_image);
@@ -4453,11 +4471,11 @@ static Image *XGetWindowImage(Display *display,const Window window,
               }
             for (i=0; i < (int) composite_image->colors; i++)
             {
-              composite_image->colormap[colors[i].pixel].red=
+              composite_image->colormap[colors[i].pixel].red=(double)
                 ScaleShortToQuantum(colors[i].red);
-              composite_image->colormap[colors[i].pixel].green=
+              composite_image->colormap[colors[i].pixel].green=(double)
                 ScaleShortToQuantum(colors[i].green);
-              composite_image->colormap[colors[i].pixel].blue=
+              composite_image->colormap[colors[i].pixel].blue=(double)
                 ScaleShortToQuantum(colors[i].blue);
             }
             /*
@@ -4473,11 +4491,12 @@ static Image *XGetWindowImage(Display *display,const Window window,
               {
                 index=(Quantum) XGetPixel(ximage,x,y);
                 SetPixelIndex(composite_image,index,q);
-                SetPixelPacket(composite_image,
+                SetPixelInfoPixel(composite_image,
                   composite_image->colormap+(ssize_t) index,q);
                 q+=GetPixelChannels(composite_image);
               }
-              if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
+              status=SyncCacheViewAuthenticPixels(composite_view,exception);
+              if (status == MagickFalse)
                 break;
             }
             break;
@@ -4501,8 +4520,9 @@ static Image *XGetWindowImage(Display *display,const Window window,
         y_offset-=(int) crop_info.y;
         if (y_offset < 0)
           y_offset=0;
-        (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
-          x_offset,(ssize_t) y_offset);
+        (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
+          (ssize_t) x_offset,(ssize_t) y_offset,exception);
+        composite_image=DestroyImage(composite_image);
       }
       /*
         Relinquish resources.
@@ -4510,8 +4530,8 @@ static Image *XGetWindowImage(Display *display,const Window window,
       while (colormap_info != (ColormapInfo *) NULL)
       {
         next=colormap_info->next;
-        colormap_info->colors=(XColor *)
-          RelinquishMagickMemory(colormap_info->colors);
+        colormap_info->colors=(XColor *) RelinquishMagickMemory(
+          colormap_info->colors);
         colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
         colormap_info=next;
       }
@@ -4842,7 +4862,8 @@ MagickPrivate void XHighlightRectangle(Display *display,Window window,
 %
 %  The format of the XImportImage method is:
 %
-%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
+%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -4850,9 +4871,11 @@ MagickPrivate void XHighlightRectangle(Display *display,Window window,
 %
 %    o ximage_info: Specifies a pointer to an XImportInfo structure.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport Image *XImportImage(const ImageInfo *image_info,
-  XImportInfo *ximage_info)
+  XImportInfo *ximage_info,ExceptionInfo *exception)
 {
   Colormap
     *colormaps;
@@ -4896,7 +4919,7 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
   display=XOpenDisplay(image_info->server_name);
   if (display == (Display *) NULL)
     {
-      ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
+      ThrowXWindowException(XServerError,"UnableToOpenXServer",
         XDisplayName(image_info->server_name));
       return((Image *) NULL);
     }
@@ -4923,14 +4946,14 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
           /*
             Select window by ID or name.
           */
-          if (isdigit((unsigned char) *image_info->filename) != 0)
+          if (isdigit((int) ((unsigned char) *image_info->filename)) != 0)
             target=XWindowByID(display,root,(Window)
               strtol(image_info->filename,(char **) NULL,0));
           if (target == (Window) NULL)
             target=XWindowByName(display,root,image_info->filename);
           if (target == (Window) NULL)
-            ThrowXWindowFatalException(XServerError,
-              "NoWindowWithSpecifiedIDExists",image_info->filename);
+            ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
+              image_info->filename);
         }
     }
   /*
@@ -4940,7 +4963,7 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
   if (target == (Window) NULL)
     target=XSelectWindow(display,&crop_info);
   if (target == (Window) NULL)
-    ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
+    ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
       image_info->filename);
   client=target;   /* obsolete */
   if (target != root)
@@ -4976,7 +4999,6 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
           if ((ximage_info->frame == MagickFalse) &&
               (prior_target != MagickFalse))
             target=prior_target;
-          XDelay(display,SuspendTime << 4);
         }
     }
   if (ximage_info->screen)
@@ -4996,8 +5018,8 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
       status=XGetWindowAttributes(display,target,&window_attributes);
       if (status == False)
         {
-          ThrowXWindowFatalException(XServerError,
-            "UnableToReadXWindowAttributes",image_info->filename);
+          ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
+            image_info->filename);
           (void) XCloseDisplay(display);
           return((Image *) NULL);
         }
@@ -5045,10 +5067,10 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
   */
   (void) XGrabServer(display);
   image=XGetWindowImage(display,target,ximage_info->borders,
-    ximage_info->descend ? 1U : 0U);
+    ximage_info->descend ? 1U : 0U,exception);
   (void) XUngrabServer(display);
   if (image == (Image *) NULL)
-    ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
+    ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
       image_info->filename)
   else
     {
@@ -5063,10 +5085,10 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
           /*
             Crop image as defined by the cropping rectangle.
           */
-          clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
+          clone_image=CloneImage(image,0,0,MagickTrue,exception);
           if (clone_image != (Image *) NULL)
             {
-              crop_image=CropImage(clone_image,&crop_info,&image->exception);
+              crop_image=CropImage(clone_image,&crop_info,exception);
               if (crop_image != (Image *) NULL)
                 {
                   image=DestroyImage(image);
@@ -5217,8 +5239,8 @@ MagickPrivate XWindows *XInitializeWindows(Display *display,
   windows->icon_map=XAllocStandardColormap();
   if ((windows->map_info == (XStandardColormap *) NULL) ||
       (windows->icon_map == (XStandardColormap *) NULL))
-    ThrowXWindowFatalException(ResourceLimitFatalError,
-      "MemoryAllocationFailed","...");
+    ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
+      "...");
   windows->map_info->colormap=(Colormap) NULL;
   windows->icon_map->colormap=(Colormap) NULL;
   windows->pixel_info->pixels=(unsigned long *) NULL;
@@ -5268,8 +5290,8 @@ MagickPrivate XWindows *XInitializeWindows(Display *display,
   windows->manager_hints=XAllocWMHints();
   if ((windows->class_hints == (XClassHint *) NULL) ||
       (windows->manager_hints == (XWMHints *) NULL))
-    ThrowXWindowFatalException(ResourceLimitFatalError,
-      "MemoryAllocationFailed","...");
+    ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
+      "...");
   /*
     Determine group leader if we have one.
   */
@@ -5277,7 +5299,7 @@ MagickPrivate XWindows *XInitializeWindows(Display *display,
   windows->group_leader.id=(Window) NULL;
   if (resource_info->window_group != (char *) NULL)
     {
-      if (isdigit((unsigned char) *resource_info->window_group) != 0)
+      if (isdigit((int) ((unsigned char) *resource_info->window_group)) != 0)
         windows->group_leader.id=XWindowByID(display,root_window,(Window)
           strtol((char *) resource_info->window_group,(char **) NULL,0));
       if (windows->group_leader.id == (Window) NULL)
@@ -5370,7 +5392,7 @@ MagickPrivate Cursor XMakeCursor(Display *display,Window window,
     scope_width,scope_height);
   if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
     {
-      ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
+      ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
       return((Cursor) NULL);
     }
   (void) XParseColor(display,colormap,background_color,&background);
@@ -5474,8 +5496,8 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
           window->image->page.x=0;
           window->image->page.y=0;
           (void) ParsePageGeometry(window->image,window->crop_geometry,
-            &crop_info,&image->exception);
-          crop_image=CropImage(window->image,&crop_info,&image->exception);
+            &crop_info,exception);
+          crop_image=CropImage(window->image,&crop_info,exception);
           if (crop_image != (Image *) NULL)
             {
               if (window->image != image)
@@ -5494,12 +5516,20 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
             Resize image.
           */
           resize_image=NewImageList();
-          if (window->pixel_info->colors != 0)
-            resize_image=SampleImage(window->image,width,height,
-              &image->exception);
+          if ((window->pixel_info->colors == 0) &&
+              (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
+              (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
+              resize_image=ResizeImage(window->image,width,height,
+                image->filter,exception);
           else
-            resize_image=ThumbnailImage(window->image,width,height,
-              &image->exception);
+            {
+              if (window->image->storage_class == PseudoClass)
+                resize_image=SampleImage(window->image,width,height,
+                  exception);
+              else
+                resize_image=ThumbnailImage(window->image,width,height,
+                  exception);
+            }
           if (resize_image != (Image *) NULL)
             {
               if (window->image != image)
@@ -5639,11 +5669,11 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
   if (window->shared_memory == MagickFalse)
     {
       if (ximage->format != XYBitmap)
-        ximage->data=(char *) AcquireQuantumMemory((size_t)
-          ximage->bytes_per_line,(size_t) ximage->height);
+        ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
+          ximage->height);
       else
-        ximage->data=(char *) AcquireQuantumMemory((size_t)
-          ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
+        ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
+          ximage->depth*ximage->height);
     }
   if (ximage->data == (char *) NULL)
     {
@@ -5701,7 +5731,7 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
   window->ximage=ximage;
   matte_image=(XImage *) NULL;
   if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
-    if ((window->image->matte != MagickFalse) &&
+    if ((window->image->alpha_trait == BlendPixelTrait) &&
         ((int) width <= XDisplayWidth(display,window->screen)) &&
         ((int) height <= XDisplayHeight(display,window->screen)))
       {
@@ -5721,9 +5751,9 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
             /*
               Allocate matte image pixel data.
             */
-            matte_image->data=(char *) AcquireQuantumMemory((size_t)
-              matte_image->bytes_per_line*matte_image->depth,
-              (size_t) matte_image->height);
+            matte_image->data=(char *) malloc((size_t)
+              matte_image->bytes_per_line*matte_image->depth*
+              matte_image->height);
             if (matte_image->data == (char *) NULL)
               {
                 XDestroyImage(matte_image);
@@ -5761,10 +5791,10 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
       if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
           (ximage->bitmap_bit_order == LSBFirst)))
         XMakeImageLSBFirst(resource_info,window,window->image,ximage,
-          matte_image);
+          matte_image,exception);
       else
         XMakeImageMSBFirst(resource_info,window,window->image,ximage,
-          matte_image);
+          matte_image,exception);
     }
   if (window->matte_image != (XImage *) NULL)
     {
@@ -5824,7 +5854,8 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
 %
 %  The format of the XMakeImageLSBFirst method is:
 %
-%      void XMakeImageLSBFirst(Display *display,XWindows *windows)
+%      void XMakeImageLSBFirst(Display *display,XWindows *windows,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -5840,9 +5871,12 @@ MagickPrivate MagickBooleanType XMakeImage(Display *display,
 %    o matte_image: Specifies a pointer to a XImage structure;  returned from
 %      XCreateImage.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
-  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
+  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
+  ExceptionInfo *exception)
 {
   CacheView
     *canvas_view;
@@ -5883,7 +5917,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   canvas=image;
   if ((window->immutable == MagickFalse) &&
-      (image->storage_class == DirectClass) && (image->matte != MagickFalse))
+      (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
     {
       char
         size[MaxTextExtent];
@@ -5902,13 +5936,14 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
       (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
         image->columns,(double) image->rows);
       image_info->size=ConstantString(size);
-      pattern=ReadImage(image_info,&image->exception);
+      pattern=ReadImage(image_info,exception);
       image_info=DestroyImageInfo(image_info);
       if (pattern != (Image *) NULL)
         {
-          canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
+          canvas=CloneImage(image,0,0,MagickTrue,exception);
           if (canvas != (Image *) NULL)
-            (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
+            (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
+              0,0,exception);
           pattern=DestroyImage(pattern);
         }
     }
@@ -5918,7 +5953,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
   pixels=window->pixel_info->pixels;
   q=(unsigned char *) ximage->data;
   x=0;
-  canvas_view=AcquireCacheView(canvas);
+  canvas_view=AcquireVirtualCacheView(canvas,exception);
   if (ximage->format == XYBitmap)
     {
       register unsigned short
@@ -5937,15 +5972,15 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
       foreground=(unsigned char)
         (XPixelIntensity(&window->pixel_info->background_color) <
          XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
-      polarity=(unsigned short) ((GetPixelPacketIntensity(
-        &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
+      polarity=(unsigned short) ((GetPixelInfoIntensity(
+        &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
       if (canvas->colors == 2)
-        polarity=GetPixelPacketIntensity(&canvas->colormap[0]) <
-          GetPixelPacketIntensity(&canvas->colormap[1]);
+        polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
+          GetPixelInfoIntensity(&canvas->colormap[1]);
       for (y=0; y < (int) canvas->rows; y++)
       {
         p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
-          &canvas->exception);
+          exception);
         if (p == (const Quantum *) NULL)
           break;
         bit=0;
@@ -5986,7 +6021,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6038,7 +6073,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6074,15 +6109,15 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
             Convert to 8 bit color-mapped X canvas.
           */
           if (resource_info->color_recovery &&
-              resource_info->quantize_info->dither)
+              resource_info->quantize_info->dither_method != NoDitherMethod)
             {
-              XDitherImage(canvas,ximage);
+              XDitherImage(canvas,ximage,exception);
               break;
             }
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
@@ -6103,9 +6138,6 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           register unsigned int
             bytes_per_pixel;
 
-          unsigned char
-            channel[sizeof(size_t)];
-
           /*
             Convert to multi-byte color-mapped X canvas.
           */
@@ -6113,7 +6145,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
@@ -6121,11 +6153,9 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
               pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
               for (k=0; k < (int) bytes_per_pixel; k++)
               {
-                channel[k]=(unsigned char) pixel;
+                *q++=(unsigned char) (pixel & 0xff);
                 pixel>>=8;
               }
-              for (k=0; k < (int) bytes_per_pixel; k++)
-                *q++=channel[k];
               p+=GetPixelChannels(canvas);
             }
             q+=scanline_pad;
@@ -6148,7 +6178,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           {
             nibble=0;
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
@@ -6200,7 +6230,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6237,15 +6267,15 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
             Convert to contiguous 8 bit continuous-tone X canvas.
           */
           if (resource_info->color_recovery &&
-              resource_info->quantize_info->dither)
+              resource_info->quantize_info->dither_method != NoDitherMethod)
             {
-              XDitherImage(canvas,ximage);
+              XDitherImage(canvas,ximage,exception);
               break;
             }
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
@@ -6271,7 +6301,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
               for (y=0; y < (int) canvas->rows; y++)
               {
                 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                  canvas->columns,1,&canvas->exception);
+                  canvas->columns,1,exception);
                 if (p == (const Quantum *) NULL)
                   break;
                 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
@@ -6295,12 +6325,9 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                   }
                 for (x=(int) canvas->columns-1; x >= 0; x--)
                 {
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelBlue(canvas,p));
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelGreen(canvas,p));
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelRed(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
                   *q++=0;
                   p+=GetPixelChannels(canvas);
                 }
@@ -6318,7 +6345,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                 for (y=0; y < (int) canvas->rows; y++)
                 {
                   p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                    canvas->columns,1,&canvas->exception);
+                    canvas->columns,1,exception);
                   if (p == (const Quantum *) NULL)
                     break;
                   if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
@@ -6342,12 +6369,9 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                     }
                   for (x=(int) canvas->columns-1; x >= 0; x--)
                   {
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelRed(canvas,p));
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelGreen(canvas,p));
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelBlue(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
                     *q++=0;
                     p+=GetPixelChannels(canvas);
                   }
@@ -6361,9 +6385,6 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                 register unsigned int
                   bytes_per_pixel;
 
-                unsigned char
-                  channel[sizeof(size_t)];
-
                 /*
                   Convert to multi-byte continuous-tone X canvas.
                 */
@@ -6371,7 +6392,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                 for (y=0; y < (int) canvas->rows; y++)
                 {
                   p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                    canvas->columns,1,&canvas->exception);
+                    canvas->columns,1,exception);
                   if (p == (const Quantum *) NULL)
                     break;
                   for (x=0; x < (int) canvas->columns; x++)
@@ -6379,11 +6400,9 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
                     pixel=XGammaPixel(canvas,map_info,p);
                     for (k=0; k < (int) bytes_per_pixel; k++)
                     {
-                      channel[k]=(unsigned char) pixel;
+                      *q++=(unsigned char) (pixel & 0xff);
                       pixel>>=8;
                     }
-                    for (k=0; k < (int) bytes_per_pixel; k++)
-                      *q++=channel[k];
                     p+=GetPixelChannels(canvas);
                   }
                   q+=scanline_pad;
@@ -6403,7 +6422,7 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
       for (y=0; y < (int) canvas->rows; y++)
       {
         p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
-          &canvas->exception);
+          exception);
         if (p == (const Quantum *) NULL)
           break;
         bit=0;
@@ -6451,7 +6470,8 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
 %
 %  The format of the XMakeImageMSBFirst method is:
 %
-%      XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
+%      XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -6467,9 +6487,12 @@ static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
 %    o matte_image: Specifies a pointer to a XImage structure;  returned from
 %      XCreateImage.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
-  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
+  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
+  ExceptionInfo *exception)
 {
   CacheView
     *canvas_view;
@@ -6510,7 +6533,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   canvas=image;
   if ((window->immutable != MagickFalse) &&
-      (image->storage_class == DirectClass) && (image->matte != MagickFalse))
+      (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
     {
       char
         size[MaxTextExtent];
@@ -6529,13 +6552,14 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
       (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
         image->columns,(double) image->rows);
       image_info->size=ConstantString(size);
-      pattern=ReadImage(image_info,&image->exception);
+      pattern=ReadImage(image_info,exception);
       image_info=DestroyImageInfo(image_info);
       if (pattern != (Image *) NULL)
         {
-          canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
+          canvas=CloneImage(image,0,0,MagickTrue,exception);
           if (canvas != (Image *) NULL)
-            (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
+            (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
+              0,0,exception);
           pattern=DestroyImage(pattern);
         }
     }
@@ -6545,7 +6569,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
   pixels=window->pixel_info->pixels;
   q=(unsigned char *) ximage->data;
   x=0;
-  canvas_view=AcquireCacheView(canvas);
+  canvas_view=AcquireVirtualCacheView(canvas,exception);
   if (ximage->format == XYBitmap)
     {
       register unsigned short
@@ -6564,15 +6588,15 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
       foreground=(unsigned char)
         (XPixelIntensity(&window->pixel_info->background_color) <
          XPixelIntensity(&window->pixel_info->foreground_color) ?  0x01 : 0x00);
-      polarity=(unsigned short) ((GetPixelPacketIntensity(
-        &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
+      polarity=(unsigned short) ((GetPixelInfoIntensity(
+        &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
       if (canvas->colors == 2)
-        polarity=GetPixelPacketIntensity(&canvas->colormap[0]) <
-          GetPixelPacketIntensity(&canvas->colormap[1]);
+        polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
+          GetPixelInfoIntensity(&canvas->colormap[1]);
       for (y=0; y < (int) canvas->rows; y++)
       {
         p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
-          &canvas->exception);
+          exception);
         if (p == (const Quantum *) NULL)
           break;
         bit=0;
@@ -6613,7 +6637,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6666,7 +6690,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6703,21 +6727,20 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
             Convert to 8 bit color-mapped X canvas.
           */
           if (resource_info->color_recovery &&
-              resource_info->quantize_info->dither)
+              resource_info->quantize_info->dither_method != NoDitherMethod)
             {
-              XDitherImage(canvas,ximage);
+              XDitherImage(canvas,ximage,exception);
               break;
             }
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
             {
-              pixel=pixels[(ssize_t)
-                GetPixelIndex(canvas,p)];
+              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
               *q++=(unsigned char) pixel;
               p+=GetPixelChannels(canvas);
             }
@@ -6743,7 +6766,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=0; x < (int) canvas->columns; x++)
@@ -6778,7 +6801,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6831,7 +6854,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             nibble=0;
@@ -6868,15 +6891,15 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
             Convert to 8 bit continuous-tone X canvas.
           */
           if (resource_info->color_recovery &&
-              resource_info->quantize_info->dither)
+              resource_info->quantize_info->dither_method != NoDitherMethod)
             {
-              XDitherImage(canvas,ximage);
+              XDitherImage(canvas,ximage,exception);
               break;
             }
           for (y=0; y < (int) canvas->rows; y++)
           {
             p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-              canvas->columns,1,&canvas->exception);
+              canvas->columns,1,exception);
             if (p == (const Quantum *) NULL)
               break;
             for (x=(int) canvas->columns-1; x >= 0; x--)
@@ -6902,7 +6925,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
               for (y=0; y < (int) canvas->rows; y++)
               {
                 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                  canvas->columns,1,&canvas->exception);
+                  canvas->columns,1,exception);
                 if (p == (const Quantum *) NULL)
                   break;
                 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
@@ -6927,12 +6950,9 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
                 for (x=(int) canvas->columns-1; x >= 0; x--)
                 {
                   *q++=0;
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelRed(canvas,p));
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelGreen(canvas,p));
-                  *q++=ScaleQuantumToChar((Quantum)
-                    GetPixelBlue(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
+                  *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
                   p+=GetPixelChannels(canvas);
                 }
               }
@@ -6949,7 +6969,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
                 for (y=0; y < (int) canvas->rows; y++)
                 {
                   p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                    canvas->columns,1,&canvas->exception);
+                    canvas->columns,1,exception);
                   if (p == (const Quantum *) NULL)
                     break;
                   if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
@@ -6974,12 +6994,9 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
                   for (x=(int) canvas->columns-1; x >= 0; x--)
                   {
                     *q++=0;
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelBlue(canvas,p));
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelGreen(canvas,p));
-                    *q++=ScaleQuantumToChar((Quantum)
-                      GetPixelRed(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
+                    *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
                     p+=GetPixelChannels(canvas);
                   }
                 }
@@ -7002,7 +7019,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
                 for (y=0; y < (int) canvas->rows; y++)
                 {
                   p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
-                    canvas->columns,1,&canvas->exception);
+                    canvas->columns,1,exception);
                   if (p == (const Quantum *) NULL)
                     break;
                   for (x=(int) canvas->columns-1; x >= 0; x--)
@@ -7034,7 +7051,7 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
       for (y=0; y < (int) canvas->rows; y++)
       {
         p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
-          &canvas->exception);
+          exception);
         if (p == (const Quantum *) NULL)
           break;
         bit=0;
@@ -7078,7 +7095,8 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
 %
 %  The format of the XMakeMagnifyImage method is:
 %
-%      void XMakeMagnifyImage(display,windows)
+%      void XMakeMagnifyImage(Display *display,XWindows *windows,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -7087,8 +7105,11 @@ static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
 %
 %    o windows: Specifies a pointer to a XWindows structure.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows)
+MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
+  ExceptionInfo *exception)
 {
   char
     tuple[MaxTextExtent];
@@ -7479,9 +7500,8 @@ MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows)
   /*
     Show center pixel color.
   */
-  (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
-    windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
-    &windows->image.image->exception);
+  (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
+    (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
   (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
     windows->magnify.x,windows->magnify.y);
   (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
@@ -7495,7 +7515,7 @@ MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows)
       (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
       ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
     }
-  if (pixel.matte != MagickFalse)
+  if (pixel.alpha_trait == BlendPixelTrait)
     {
       (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
       ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
@@ -7511,8 +7531,8 @@ MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows)
   y+=height;
   (void) XDrawImageString(display,windows->magnify.pixmap,
     windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
-  (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
-     &windows->image.image->exception);
+  (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
+    exception);
   y+=height;
   (void) XDrawImageString(display,windows->magnify.pixmap,
     windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
@@ -7635,8 +7655,9 @@ static MagickBooleanType XMakePixmap(Display *display,
 %
 %  The format of the XMakeStandardColormap method is:
 %
-%      XMakeStandardColormap(display,visual_info,resource_info,image,
-%        map_info,pixel)
+%      void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
+%        XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
+%        XPixelInfo *pixel,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -7655,19 +7676,21 @@ static MagickBooleanType XMakePixmap(Display *display,
 %
 %    o pixel: Specifies a pointer to a XPixelInfo structure.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
 
-static inline MagickRealType DiversityPixelIntensity(
+static inline double DiversityPixelIntensity(
   const DiversityPacket *pixel)
 {
-  MagickRealType
+  double
     intensity;
 
-  intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
+  intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
   return(intensity);
 }
 
@@ -7705,19 +7728,16 @@ static int PopularityCompare(const void *x,const void *y)
 static inline Quantum ScaleXToQuantum(const size_t x,
   const size_t scale)
 {
-  return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
+  return((Quantum) (((double) QuantumRange*x)/scale+0.5));
 }
 
 MagickPrivate void XMakeStandardColormap(Display *display,
   XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
-  XStandardColormap *map_info,XPixelInfo *pixel)
+  XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
 {
   Colormap
     colormap;
 
-  ExceptionInfo
-    *exception;
-
   register ssize_t
     i;
 
@@ -7742,7 +7762,6 @@ MagickPrivate void XMakeStandardColormap(Display *display,
   assert(map_info != (XStandardColormap *) NULL);
   assert(resource_info != (XResourceInfo *) NULL);
   assert(pixel != (XPixelInfo *) NULL);
-  exception=(&image->exception);
   if (resource_info->map_type != (char *) NULL)
     {
       /*
@@ -7753,9 +7772,9 @@ MagickPrivate void XMakeStandardColormap(Display *display,
       number_colors=(unsigned int) (map_info->base_pixel+
         (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
       if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
-        if ((image->matte == MagickFalse) &&
+        if ((image->alpha_trait != BlendPixelTrait) &&
             (resource_info->color_recovery == MagickFalse) &&
-            resource_info->quantize_info->dither &&
+            (resource_info->quantize_info->dither_method != NoDitherMethod) &&
             (number_colors < MaxColormapSize))
           {
             Image
@@ -7767,7 +7786,7 @@ MagickPrivate void XMakeStandardColormap(Display *display,
             /*
               Improve image appearance with error diffusion.
             */
-            affinity_image=AcquireImage((ImageInfo *) NULL);
+            affinity_image=AcquireImage((ImageInfo *) NULL,exception);
             if (affinity_image == (Image *) NULL)
               ThrowXWindowFatalException(ResourceLimitFatalError,
                 "UnableToDitherImage",image->filename);
@@ -7784,26 +7803,24 @@ MagickPrivate void XMakeStandardColormap(Display *display,
                 {
                   SetPixelRed(affinity_image,0,q);
                   if (map_info->red_max != 0)
-                    SetPixelRed(affinity_image,
-                      ScaleXToQuantum((size_t) (i/map_info->red_mult),
-                      map_info->red_max),q);
+                    SetPixelRed(affinity_image,ScaleXToQuantum((size_t)
+                      (i/map_info->red_mult),map_info->red_max),q);
                   SetPixelGreen(affinity_image,0,q);
                   if (map_info->green_max != 0)
-                    SetPixelGreen(affinity_image,
-                      ScaleXToQuantum((size_t) ((i/map_info->green_mult) %
-                      (map_info->green_max+1)),map_info->green_max),q);
+                    SetPixelGreen(affinity_image,ScaleXToQuantum((size_t)
+                      ((i/map_info->green_mult) % (map_info->green_max+1)),
+                      map_info->green_max),q);
                   SetPixelBlue(affinity_image,0,q);
                   if (map_info->blue_max != 0)
-                    SetPixelBlue(affinity_image,
-                      ScaleXToQuantum((size_t) (i % map_info->green_mult),
-                      map_info->blue_max),q);
+                    SetPixelBlue(affinity_image,ScaleXToQuantum((size_t)
+                      (i % map_info->green_mult),map_info->blue_max),q);
                   SetPixelAlpha(affinity_image,
                     TransparentAlpha,q);
                   q+=GetPixelChannels(affinity_image);
                 }
                 (void) SyncAuthenticPixels(affinity_image,exception);
                 (void) RemapImage(resource_info->quantize_info,image,
-                  affinity_image);
+                  affinity_image,exception);
               }
             XGetPixelInfo(display,visual_info,map_info,resource_info,image,
               pixel);
@@ -7838,7 +7855,7 @@ MagickPrivate void XMakeStandardColormap(Display *display,
         */
         quantize_info=(*resource_info->quantize_info);
         quantize_info.number_colors=(size_t) visual_info->colormap_size;
-        (void) QuantizeImage(&quantize_info,image);
+        (void) QuantizeImage(&quantize_info,image,exception);
       }
   /*
     Free previous and create new colormap.
@@ -7965,13 +7982,13 @@ MagickPrivate void XMakeStandardColormap(Display *display,
               "UnableToCreateColormap",image->filename);
           for (i=0; i < (ssize_t) image->colors; i++)
           {
-            diversity[i].red=image->colormap[i].red;
-            diversity[i].green=image->colormap[i].green;
-            diversity[i].blue=image->colormap[i].blue;
+            diversity[i].red=ClampToQuantum(image->colormap[i].red);
+            diversity[i].green=ClampToQuantum(image->colormap[i].green);
+            diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
             diversity[i].index=(unsigned short) i;
             diversity[i].count=0;
           }
-          image_view=AcquireCacheView(image);
+          image_view=AcquireAuthenticCacheView(image,exception);
           for (y=0; y < (int) image->rows; y++)
           {
             register int
@@ -8049,12 +8066,12 @@ MagickPrivate void XMakeStandardColormap(Display *display,
           for (; i < (ssize_t) image->colors; i++)
           {
             index=diversity[i].index;
-            color.red=
-              ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
-            color.green=
-              ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
-            color.blue=
-              ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
+            color.red=ScaleQuantumToShort(
+              XRedGamma(image->colormap[index].red));
+            color.green=ScaleQuantumToShort(
+              XGreenGamma(image->colormap[index].green));
+            color.blue=ScaleQuantumToShort(
+              XBlueGamma(image->colormap[index].blue));
             if (visual_info->klass != PseudoColor)
               {
                 gray_value=(unsigned short) XPixelIntensity(&color);
@@ -8628,22 +8645,22 @@ MagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  XQueryColorDatabase() looks up a RGB values for a color given in the target
+%  XQueryColorCompliance() looks up a RGB values for a color given in the target
 %  string.
 %
 %  The format of the XQueryColorDatabase method is:
 %
-%      MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
+%      MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
 %
 %  A description of each parameter follows:
 %
 %    o target: Specifies the color to lookup in the X color database.
 %
-%    o color: A pointer to an PixelPacket structure.  The RGB value of the target
+%    o color: A pointer to an PixelInfo structure.  The RGB value of the target
 %      color is returned as this value.
 %
 */
-MagickPrivate MagickBooleanType XQueryColorDatabase(const char *target,
+MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
   XColor *color)
 {
   Colormap
@@ -8675,13 +8692,13 @@ MagickPrivate MagickBooleanType XQueryColorDatabase(const char *target,
     display=XOpenDisplay((char *) NULL);
   if (display == (Display *) NULL)
     {
-      ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
+      ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
       return(MagickFalse);
     }
   colormap=XDefaultColormap(display,XDefaultScreen(display));
   status=XParseColor(display,colormap,(char *) target,&xcolor);
   if (status == False)
-    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
+    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
   else
     {
       color->red=xcolor.red;
@@ -8723,7 +8740,8 @@ MagickPrivate MagickBooleanType XQueryColorDatabase(const char *target,
 %      window.
 %
 */
-MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,int *y)
+MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,
+  int *y)
 {
   int
     x_root,
@@ -8915,7 +8933,7 @@ MagickExport MagickBooleanType XRemoteCommand(Display *display,
       /*
         Search window hierarchy and identify any clients by name or ID.
       */
-      if (isdigit((unsigned char) *window) != 0)
+      if (isdigit((int) ((unsigned char) *window)) != 0)
         remote_window=XWindowByID(display,root_window,(Window)
           strtol((char *) window,(char **) NULL,0));
       if (remote_window == (Window) NULL)
@@ -8944,6 +8962,227 @@ MagickExport MagickBooleanType XRemoteCommand(Display *display,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   X R e n d e r I m a g e                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  XRenderImage() renders text on the image with an X11 font.  It also returns
+%  the bounding box of the text relative to the image.
+%
+%  The format of the XRenderImage method is:
+%
+%      MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
+%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o draw_info: the draw info.
+%
+%    o offset: (x,y) location of text relative to image.
+%
+%    o metrics: bounding box of text.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickPrivate MagickBooleanType XRenderImage(Image *image,
+  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
+  ExceptionInfo *exception)
+{
+  const char
+    *client_name;
+
+  DrawInfo
+    cache_info;
+
+  Display
+    *display;
+
+  ImageInfo
+    *image_info;
+
+  MagickBooleanType
+    status;
+
+  size_t
+    height,
+    width;
+
+  XAnnotateInfo
+    annotate_info;
+
+  XFontStruct
+    *font_info;
+
+  XPixelInfo
+    pixel;
+
+  XResourceInfo
+    resource_info;
+
+  XrmDatabase
+    resource_database;
+
+  XStandardColormap
+    *map_info;
+
+  XVisualInfo
+    *visual_info;
+
+  /*
+    Open X server connection.
+  */
+  display=XOpenDisplay(draw_info->server_name);
+  if (display == (Display *) NULL)
+    {
+      ThrowXWindowException(XServerError,"UnableToOpenXServer",
+        draw_info->server_name);
+      return(MagickFalse);
+    }
+  /*
+    Get user defaults from X resource database.
+  */
+  (void) XSetErrorHandler(XError);
+  image_info=AcquireImageInfo();
+  client_name=GetClientName();
+  resource_database=XGetResourceDatabase(display,client_name);
+  XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
+  resource_info.close_server=MagickFalse;
+  resource_info.colormap=PrivateColormap;
+  resource_info.font=AcquireString(draw_info->font);
+  resource_info.background_color=AcquireString("#ffffffffffff");
+  resource_info.foreground_color=AcquireString("#000000000000");
+  map_info=XAllocStandardColormap();
+  if (map_info == (XStandardColormap *) NULL)
+    {
+      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+        image->filename);
+      return(MagickFalse);
+    }
+  /*
+    Initialize visual info.
+  */
+  visual_info=XBestVisualInfo(display,map_info,&resource_info);
+  if (visual_info == (XVisualInfo *) NULL)
+    {
+      ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
+      return(MagickFalse);
+    }
+  map_info->colormap=(Colormap) NULL;
+  pixel.pixels=(unsigned long *) NULL;
+  /*
+    Initialize Standard Colormap info.
+  */
+  XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
+    map_info);
+  XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL,
+    &pixel);
+  pixel.annotate_context=XDefaultGC(display,visual_info->screen);
+  /*
+    Initialize font info.
+  */
+  font_info=XBestFont(display,&resource_info,MagickFalse);
+  if (font_info == (XFontStruct *) NULL)
+    {
+      ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font);
+      return(MagickFalse);
+    }
+  if ((map_info == (XStandardColormap *) NULL) ||
+      (visual_info == (XVisualInfo *) NULL) ||
+      (font_info == (XFontStruct *) NULL))
+    {
+      XFreeResources(display,visual_info,map_info,&pixel,font_info,
+        &resource_info,(XWindowInfo *) NULL);
+      ThrowXWindowException(XServerError,"UnableToLoadFont",image->filename);
+      return(MagickFalse);
+    }
+  cache_info=(*draw_info);
+  /*
+    Initialize annotate info.
+  */
+  XGetAnnotateInfo(&annotate_info);
+  annotate_info.stencil=ForegroundStencil;
+  if (cache_info.font != draw_info->font)
+    {
+      /*
+        Type name has changed.
+      */
+      (void) XFreeFont(display,font_info);
+      (void) CloneString(&resource_info.font,draw_info->font);
+      font_info=XBestFont(display,&resource_info,MagickFalse);
+      if (font_info == (XFontStruct *) NULL)
+        {
+          ThrowXWindowException(XServerError,"UnableToLoadFont",
+            draw_info->font);
+          return(MagickFalse);
+        }
+    }
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
+      "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
+      draw_info->font : "none",draw_info->pointsize);
+  cache_info=(*draw_info);
+  annotate_info.font_info=font_info;
+  annotate_info.text=(char *) draw_info->text;
+  annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int)
+    strlen(draw_info->text));
+  annotate_info.height=(unsigned int) font_info->ascent+font_info->descent;
+  metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
+  metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
+  metrics->ascent=(double) font_info->ascent+4;
+  metrics->descent=(double) (-font_info->descent);
+  metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
+  metrics->height=font_info->ascent+font_info->descent;
+  metrics->max_advance=(double) font_info->max_bounds.width;
+  metrics->bounds.x1=0.0;
+  metrics->bounds.y1=metrics->descent;
+  metrics->bounds.x2=metrics->ascent+metrics->descent;
+  metrics->bounds.y2=metrics->ascent+metrics->descent;
+  metrics->underline_position=(-2.0);
+  metrics->underline_thickness=1.0;
+  if (draw_info->render == MagickFalse)
+    return(MagickTrue);
+  if (draw_info->fill.alpha == TransparentAlpha)
+    return(MagickTrue);
+  /*
+    Render fill color.
+  */
+  width=annotate_info.width;
+  height=annotate_info.height;
+  if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
+      (fabs(draw_info->affine.ry) >= MagickEpsilon))
+    {
+      if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
+          (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
+        annotate_info.degrees=(double) (180.0/MagickPI)*
+          atan2(draw_info->affine.rx,draw_info->affine.sx);
+    }
+  (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent,
+    "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height,
+    ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
+    draw_info->interline_spacing-0.5));
+  pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
+  pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
+  pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
+  status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
+  if (status == 0)
+    {
+      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
+        image->filename);
+      return(MagickFalse);
+    }
+  return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   X R e t a i n W i n d o w C o l o r s                                     %
 %                                                                             %
 %                                                                             %
@@ -8982,14 +9221,14 @@ MagickExport void XRetainWindowColors(Display *display,const Window window)
   property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
   if (property == (Atom) NULL)
     {
-      ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
+      ThrowXWindowException(XServerError,"UnableToCreateProperty",
         "_XSETROOT_ID");
       return;
     }
   pixmap=XCreatePixmap(display,window,1,1,1);
   if (pixmap == (Pixmap) NULL)
     {
-      ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
+      ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
       return;
     }
   (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
@@ -9082,7 +9321,7 @@ static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
     GrabModeAsync,root_window,target_cursor,CurrentTime);
   if (status != GrabSuccess)
     {
-      ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
+      ThrowXWindowException(XServerError,"UnableToGrabMouse","");
       return((Window) NULL);
     }
   /*
@@ -9335,7 +9574,8 @@ MagickPrivate void XUserPreferences(XResourceInfo *resource_info)
   value=resource_info->display_warnings ? "True" : "False";
   XrmPutStringResource(&preferences_database,specifier,(char *) value);
   (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
-  value=resource_info->quantize_info->dither ? "True" : "False";
+  value=resource_info->quantize_info->dither_method != NoDitherMethod ?
+    "True" : "False";
   XrmPutStringResource(&preferences_database,specifier,(char *) value);
   (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
     client_name);
@@ -9694,7 +9934,8 @@ MagickPrivate Window XWindowByProperty(Display *display,const Window window,
 %
 %  The format of the XImportImage method is:
 %
-%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
+%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -9702,9 +9943,11 @@ MagickPrivate Window XWindowByProperty(Display *display,const Window window,
 %
 %    o ximage_info: Specifies a pointer to an XImportInfo structure.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-MagickPrivate Image *XImportImage(const ImageInfo *image_info,
-  XImportInfo *ximage_info)
+MagickExport Image *XImportImage(const ImageInfo *image_info,
+  XImportInfo *ximage_info,ExceptionInfo *exception)
 {
   assert(image_info != (const ImageInfo *) NULL);
   assert(image_info->signature == MagickSignature);
@@ -9712,8 +9955,55 @@ MagickPrivate Image *XImportImage(const ImageInfo *image_info,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(ximage_info != (XImportInfo *) NULL);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
   return((Image *) NULL);
 }
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   X R e n d e r X 1 1                                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  XRenderImage() renders text on the image with an X11 font.  It also returns
+%  the bounding box of the text relative to the image.
+%
+%  The format of the XRenderImage method is:
+%
+%      MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
+%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o draw_info: the draw info.
+%
+%    o offset: (x,y) location of text relative to image.
+%
+%    o metrics: bounding box of text.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickPrivate MagickBooleanType XRenderImage(Image *image,
+  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
+  ExceptionInfo *exception)
+{
+  (void) draw_info;
+  (void) offset;
+  (void) metrics;
+  (void) ThrowMagickException(exception,GetMagickModule(),
+    MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)",
+    image->filename);
+  return(MagickFalse);
+}
 #endif
 \f
 /*