]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/xwindow.c
(no commit message)
[imagemagick] / MagickCore / xwindow.c
index 7584f3a3fee11600fb533dd0c266b9e74648089f..95d8ba1f3c5a635327f6eeb6a9d0387078253d12 100644 (file)
 %                       MagickCore X11 Utility Methods                        %
 %                                                                             %
 %                               Software Design                               %
-%                                 John Cristy                                 %
+%                                    Cristy                                   %
 %                                  July 1992                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 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  %
@@ -764,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;
@@ -778,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));
@@ -850,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.
@@ -943,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;
@@ -1065,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++)
@@ -1265,7 +1263,7 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
                           strtol(visual_type,(char **) NULL,0);
                       }
                     else
-                      ThrowXWindowFatalException(XServerError,
+                      ThrowXWindowException(XServerError,
                         "UnrecognizedVisualSpecifier",visual_type);
     }
   /*
@@ -1280,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;
@@ -1318,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)
         {
           /*
@@ -1362,7 +1360,7 @@ MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
         }
       if (status == False)
         {
-          ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
+          ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
             map_type);
           return((XVisualInfo *) NULL);
         }
@@ -1384,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);
@@ -1906,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;
     }
@@ -2062,7 +2060,7 @@ MagickPrivate void XDisplayImageInfo(Display *display,
   */
   (void) IdentifyImage(image,file,MagickTrue,exception);
   (void) fclose(file);
-  text=FileToString(filename,~0,exception);
+  text=FileToString(filename,~0UL,exception);
   (void) RelinquishUniqueFileResource(filename);
   if (text == (char *) NULL)
     {
@@ -2188,8 +2186,8 @@ static void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
           (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;
         }
     }
@@ -3095,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);
@@ -3107,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);
@@ -3120,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);
@@ -3136,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);
@@ -3199,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);
@@ -3518,7 +3516,7 @@ 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");
@@ -4122,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++;
@@ -4155,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.
@@ -4221,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)) ?
@@ -4234,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;
         /*
@@ -4448,17 +4434,20 @@ 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);
                 }
                 status=SyncCacheViewAuthenticPixels(composite_view,exception);
@@ -4930,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);
     }
@@ -4957,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);
         }
     }
   /*
@@ -4974,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)
@@ -5029,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);
         }
@@ -5081,7 +5070,7 @@ MagickExport Image *XImportImage(const ImageInfo *image_info,
     ximage_info->descend ? 1U : 0U,exception);
   (void) XUngrabServer(display);
   if (image == (Image *) NULL)
-    ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
+    ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
       image_info->filename)
   else
     {
@@ -5250,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;
@@ -5301,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.
   */
@@ -5310,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)
@@ -5403,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);
@@ -5527,10 +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,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,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)
@@ -5670,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)
     {
@@ -5752,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);
@@ -6139,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.
           */
@@ -6157,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;
@@ -6391,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.
                 */
@@ -6409,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;
@@ -7701,7 +7690,7 @@ static inline double DiversityPixelIntensity(
   double
     intensity;
 
-  intensity=0.298839f*pixel->red+0.586811f*pixel->green+0.114350f*pixel->blue;
+  intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
   return(intensity);
 }
 
@@ -7814,19 +7803,17 @@ 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);
@@ -8079,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);
@@ -8705,13 +8692,13 @@ MagickPrivate MagickBooleanType XQueryColorCompliance(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;
@@ -8753,7 +8740,8 @@ MagickPrivate MagickBooleanType XQueryColorCompliance(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,
@@ -8945,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)
@@ -8974,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                                     %
 %                                                                             %
 %                                                                             %
@@ -9012,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,
@@ -9112,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);
     }
   /*
@@ -9737,7 +9946,7 @@ MagickPrivate Window XWindowByProperty(Display *display,const Window window,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickPrivate Image *XImportImage(const ImageInfo *image_info,
+MagickExport Image *XImportImage(const ImageInfo *image_info,
   XImportInfo *ximage_info,ExceptionInfo *exception)
 {
   assert(image_info != (const ImageInfo *) NULL);
@@ -9750,6 +9959,51 @@ MagickPrivate Image *XImportImage(const ImageInfo *image_info,
   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
 /*