2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % X X W W IIIII N N DDDD OOO W W %
7 % X X W W I NN N D D O O W W %
8 % X W W I N N N D D O O W W %
9 % X X W W W I N NN D D O O W W W %
10 % X X W W IIIII N N DDDD OOO W W %
13 % MagickCore X11 Utility Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/animate.h"
44 #include "magick/artifact.h"
45 #include "magick/blob.h"
46 #include "magick/cache.h"
47 #include "magick/client.h"
48 #include "magick/color.h"
49 #include "magick/color-private.h"
50 #include "magick/colormap.h"
51 #include "magick/composite.h"
52 #include "magick/display.h"
53 #include "magick/exception.h"
54 #include "magick/exception-private.h"
55 #include "magick/geometry.h"
56 #include "magick/identify.h"
57 #include "magick/image.h"
58 #include "magick/image-private.h"
59 #include "magick/list.h"
60 #include "magick/locale_.h"
61 #include "magick/log.h"
62 #include "magick/magick.h"
63 #include "magick/memory_.h"
64 #include "magick/monitor.h"
65 #include "magick/option.h"
66 #include "magick/PreRvIcccm.h"
67 #include "magick/quantize.h"
68 #include "magick/quantum.h"
69 #include "magick/quantum-private.h"
70 #include "magick/resource_.h"
71 #include "magick/resize.h"
72 #include "magick/shear.h"
73 #include "magick/statistic.h"
74 #include "magick/string_.h"
75 #include "magick/string-private.h"
76 #include "magick/transform.h"
77 #include "magick/utility.h"
78 #include "magick/widget.h"
79 #include "magick/xwindow.h"
80 #include "magick/xwindow-private.h"
81 #include "magick/version.h"
85 #if defined(MAGICKCORE_X11_DELEGATE)
86 #include <X11/Xproto.h>
87 #include <X11/Xlocale.h>
88 #if defined(MAGICK_HAVE_POLL)
89 # include <sys/poll.h>
91 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
92 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
93 # include <machine/param.h>
97 #include <X11/extensions/XShm.h>
99 #if defined(MAGICKCORE_HAVE_SHAPE)
100 #include <X11/extensions/shape.h>
106 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
107 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
109 #define XGammaPixel(map,color) (size_t) (map->base_pixel+ \
110 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
112 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
114 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
116 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
117 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
119 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
120 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
122 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
123 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
124 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
125 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
127 #define AccentuateModulate ScaleCharToQuantum(80)
128 #define HighlightModulate ScaleCharToQuantum(125)
129 #define ShadowModulate ScaleCharToQuantum(135)
130 #define DepthModulate ScaleCharToQuantum(185)
131 #define TroughModulate ScaleCharToQuantum(110)
133 #define XLIB_ILLEGAL_ACCESS 1
135 #undef NorthWestGravity
137 #undef NorthEastGravity
141 #undef SouthWestGravity
143 #undef SouthEastGravity
150 #define XFD_SET fd_set
154 Enumeration declarations.
168 Typedef declarations.
170 typedef struct _DiversityPacket
185 Constant declaractions.
187 static MagickBooleanType
188 xerror_alert = MagickFalse;
194 *XVisualClassName(const int);
196 static MagickRealType
201 static MagickBooleanType
202 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
205 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
207 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
211 XSelectWindow(Display *,RectangleInfo *);
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % D e s t r o y X R e s o u r c e s %
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % DestroyXResources() destroys any X resources.
226 % The format of the DestroyXResources method is:
228 % void DestroyXResources()
230 % A description of each parameter follows:
233 MagickExport void DestroyXResources(void)
242 *magick_windows[MaxXWindows];
248 windows=XSetWindows((XWindows *) ~0);
249 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
252 magick_windows[number_windows++]=(&windows->context);
253 magick_windows[number_windows++]=(&windows->group_leader);
254 magick_windows[number_windows++]=(&windows->backdrop);
255 magick_windows[number_windows++]=(&windows->icon);
256 magick_windows[number_windows++]=(&windows->image);
257 magick_windows[number_windows++]=(&windows->info);
258 magick_windows[number_windows++]=(&windows->magnify);
259 magick_windows[number_windows++]=(&windows->pan);
260 magick_windows[number_windows++]=(&windows->command);
261 magick_windows[number_windows++]=(&windows->widget);
262 magick_windows[number_windows++]=(&windows->popup);
263 magick_windows[number_windows++]=(&windows->context);
264 for (i=0; i < (int) number_windows; i++)
266 if (magick_windows[i]->mapped != MagickFalse)
268 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
269 magick_windows[i]->screen);
270 magick_windows[i]->mapped=MagickFalse;
272 if (magick_windows[i]->name != (char *) NULL)
273 magick_windows[i]->name=(char *)
274 RelinquishMagickMemory(magick_windows[i]->name);
275 if (magick_windows[i]->icon_name != (char *) NULL)
276 magick_windows[i]->icon_name=(char *)
277 RelinquishMagickMemory(magick_windows[i]->icon_name);
278 if (magick_windows[i]->cursor != (Cursor) NULL)
280 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
281 magick_windows[i]->cursor=(Cursor) NULL;
283 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
285 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
286 magick_windows[i]->busy_cursor=(Cursor) NULL;
288 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
290 (void) XFreePixmap(windows->display,
291 magick_windows[i]->highlight_stipple);
292 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
294 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
296 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
297 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
299 if (magick_windows[i]->ximage != (XImage *) NULL)
301 XDestroyImage(magick_windows[i]->ximage);
302 magick_windows[i]->ximage=(XImage *) NULL;
304 if (magick_windows[i]->pixmap != (Pixmap) NULL)
306 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
307 magick_windows[i]->pixmap=(Pixmap) NULL;
309 if (magick_windows[i]->id != (Window) NULL)
311 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
312 magick_windows[i]->id=(Window) NULL;
314 if (magick_windows[i]->destroy != MagickFalse)
316 if (magick_windows[i]->image != (Image *) NULL)
318 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
319 magick_windows[i]->image=NewImageList();
321 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
323 (void) XFreePixmap(windows->display,
324 magick_windows[i]->matte_pixmap);
325 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
328 if (magick_windows[i]->segment_info != (void *) NULL)
330 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
334 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
335 if (segment_info != (XShmSegmentInfo *) NULL)
336 if (segment_info[0].shmid >= 0)
338 if (segment_info[0].shmaddr != NULL)
339 (void) shmdt(segment_info[0].shmaddr);
340 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
341 segment_info[0].shmaddr=NULL;
342 segment_info[0].shmid=(-1);
345 magick_windows[i]->segment_info=(void *)
346 RelinquishMagickMemory(magick_windows[i]->segment_info);
349 windows->icon_resources=(XResourceInfo *)
350 RelinquishMagickMemory(windows->icon_resources);
351 if (windows->icon_pixel != (XPixelInfo *) NULL)
353 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
354 windows->icon_pixel->pixels=(unsigned long *)
355 RelinquishMagickMemory(windows->icon_pixel->pixels);
356 if (windows->icon_pixel->annotate_context != (GC) NULL)
357 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
358 windows->icon_pixel=(XPixelInfo *)
359 RelinquishMagickMemory(windows->icon_pixel);
361 if (windows->pixel_info != (XPixelInfo *) NULL)
363 if (windows->pixel_info->pixels != (unsigned long *) NULL)
364 windows->pixel_info->pixels=(unsigned long *)
365 RelinquishMagickMemory(windows->pixel_info->pixels);
366 if (windows->pixel_info->annotate_context != (GC) NULL)
367 XFreeGC(windows->display,windows->pixel_info->annotate_context);
368 if (windows->pixel_info->widget_context != (GC) NULL)
369 XFreeGC(windows->display,windows->pixel_info->widget_context);
370 if (windows->pixel_info->highlight_context != (GC) NULL)
371 XFreeGC(windows->display,windows->pixel_info->highlight_context);
372 windows->pixel_info=(XPixelInfo *)
373 RelinquishMagickMemory(windows->pixel_info);
375 if (windows->font_info != (XFontStruct *) NULL)
377 XFreeFont(windows->display,windows->font_info);
378 windows->font_info=(XFontStruct *) NULL;
380 if (windows->class_hints != (XClassHint *) NULL)
382 if (windows->class_hints->res_name != (char *) NULL)
383 XFree(windows->class_hints->res_name);
384 if (windows->class_hints->res_class != (char *) NULL)
385 XFree(windows->class_hints->res_class);
386 XFree(windows->class_hints);
387 windows->class_hints=(XClassHint *) NULL;
389 if (windows->manager_hints != (XWMHints *) NULL)
391 XFree(windows->manager_hints);
392 windows->manager_hints=(XWMHints *) NULL;
394 if (windows->map_info != (XStandardColormap *) NULL)
396 XFree(windows->map_info);
397 windows->map_info=(XStandardColormap *) NULL;
399 if (windows->icon_map != (XStandardColormap *) NULL)
401 XFree(windows->icon_map);
402 windows->icon_map=(XStandardColormap *) NULL;
404 if (windows->visual_info != (XVisualInfo *) NULL)
406 XFree(windows->visual_info);
407 windows->visual_info=(XVisualInfo *) NULL;
409 if (windows->icon_visual != (XVisualInfo *) NULL)
411 XFree(windows->icon_visual);
412 windows->icon_visual=(XVisualInfo *) NULL;
414 (void) XSetWindows((XWindows *) NULL);
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 % X A n n o t a t e I m a g e %
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 % XAnnotateImage() annotates the image with text.
430 % The format of the XAnnotateImage method is:
432 % MagickBooleanType XAnnotateImage(Display *display,
433 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
435 % A description of each parameter follows:
437 % o display: Specifies a connection to an X server; returned from
440 % o pixel: Specifies a pointer to a XPixelInfo structure.
442 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
444 % o image: the image.
447 MagickExport MagickBooleanType XAnnotateImage(Display *display,
448 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
487 Initialize annotated image.
489 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
490 assert(display != (Display *) NULL);
491 assert(pixel != (XPixelInfo *) NULL);
492 assert(annotate_info != (XAnnotateInfo *) NULL);
493 assert(image != (Image *) NULL);
495 Initialize annotated pixmap.
497 root_window=XRootWindow(display,XDefaultScreen(display));
498 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
499 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
500 annotate_info->height,depth);
501 if (annotate_pixmap == (Pixmap) NULL)
504 Initialize graphics info.
506 context_values.background=0;
507 context_values.foreground=(size_t) (~0);
508 context_values.font=annotate_info->font_info->fid;
509 annotate_context=XCreateGC(display,root_window,(unsigned long)
510 (GCBackground | GCFont | GCForeground),&context_values);
511 if (annotate_context == (GC) NULL)
516 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
517 (int) annotate_info->font_info->ascent,annotate_info->text,
518 (int) strlen(annotate_info->text));
519 (void) XFreeGC(display,annotate_context);
521 Initialize annotated X image.
523 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
524 annotate_info->height,AllPlanes,ZPixmap);
525 if (annotate_ximage == (XImage *) NULL)
527 (void) XFreePixmap(display,annotate_pixmap);
529 Initialize annotated image.
531 annotate_image=AcquireImage((ImageInfo *) NULL);
532 if (annotate_image == (Image *) NULL)
534 annotate_image->columns=annotate_info->width;
535 annotate_image->rows=annotate_info->height;
537 Transfer annotated X image to image.
539 width=(unsigned int) image->columns;
540 height=(unsigned int) image->rows;
543 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
544 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
545 &annotate_image->background_color,&image->exception);
546 if (annotate_info->stencil == ForegroundStencil)
547 annotate_image->matte=MagickTrue;
548 exception=(&image->exception);
549 annotate_view=AcquireCacheView(annotate_image);
550 for (y=0; y < (int) annotate_image->rows; y++)
558 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
559 annotate_image->columns,1,exception);
560 if (q == (PixelPacket *) NULL)
562 for (x=0; x < (int) annotate_image->columns; x++)
564 SetOpacityPixelComponent(q,OpaqueOpacity);
565 if (XGetPixel(annotate_ximage,x,y) == 0)
568 Set this pixel to the background color.
570 q->red=ScaleShortToQuantum(pixel->box_color.red);
571 q->green=ScaleShortToQuantum(pixel->box_color.green);
572 q->blue=ScaleShortToQuantum(pixel->box_color.blue);
573 if ((annotate_info->stencil == ForegroundStencil) ||
574 (annotate_info->stencil == OpaqueStencil))
575 q->opacity=(Quantum) TransparentOpacity;
580 Set this pixel to the pen color.
582 q->red=ScaleShortToQuantum(pixel->pen_color.red);
583 q->green=ScaleShortToQuantum(pixel->pen_color.green);
584 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
585 if (annotate_info->stencil == BackgroundStencil)
586 q->opacity=(Quantum) TransparentOpacity;
590 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
593 annotate_view=DestroyCacheView(annotate_view);
594 XDestroyImage(annotate_ximage);
596 Determine annotate geometry.
598 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
599 if ((width != (unsigned int) annotate_image->columns) ||
600 (height != (unsigned int) annotate_image->rows))
603 image_geometry[MaxTextExtent];
608 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
610 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
612 if (annotate_info->degrees != 0.0)
627 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
628 if (rotate_image == (Image *) NULL)
630 annotate_image=DestroyImage(annotate_image);
631 annotate_image=rotate_image;
633 Annotation is relative to the degree of rotation.
635 normalized_degrees=annotate_info->degrees;
636 while (normalized_degrees < -45.0)
637 normalized_degrees+=360.0;
638 for (rotations=0; normalized_degrees > 45.0; rotations++)
639 normalized_degrees-=90.0;
640 switch (rotations % 4)
650 x-=(int) annotate_image->columns/2;
651 y+=(int) annotate_image->columns/2;
659 x=x-(int) annotate_image->columns;
667 x=x-(int) annotate_image->columns/2;
668 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
674 Composite text onto the image.
676 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
678 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
679 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
681 annotate_image=DestroyImage(annotate_image);
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % X B e s t F o n t %
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696 % XBestFont() returns the "best" font. "Best" is defined as a font specified
697 % in the X resource database or a font such that the text width displayed
698 % with the font does not exceed the specified maximum width.
700 % The format of the XBestFont method is:
702 % XFontStruct *XBestFont(Display *display,
703 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
705 % A description of each parameter follows:
707 % o font: XBestFont returns a pointer to a XFontStruct structure.
709 % o display: Specifies a connection to an X server; returned from
712 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
714 % o text_font: True is font should be mono-spaced (typewriter style).
718 static char **FontToList(char *font)
733 if (font == (char *) NULL)
734 return((char **) NULL);
736 Convert string to an ASCII list.
739 for (p=font; *p != '\0'; p++)
740 if ((*p == ':') || (*p == ';') || (*p == ','))
742 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
743 if (fontlist == (char **) NULL)
745 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
747 return((char **) NULL);
750 for (i=0; i < (int) fonts; i++)
752 for (q=p; *q != '\0'; q++)
753 if ((*q == ':') || (*q == ';') || (*q == ','))
755 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
756 sizeof(*fontlist[i]));
757 if (fontlist[i] == (char *) NULL)
759 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
761 return((char **) NULL);
763 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
766 fontlist[i]=(char *) NULL;
770 MagickExport XFontStruct *XBestFont(Display *display,
771 const XResourceInfo *resource_info,const MagickBooleanType text_font)
776 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
777 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
778 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
779 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
780 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
781 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
788 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
789 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
790 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
804 font_info=(XFontStruct *) NULL;
805 font_name=resource_info->font;
806 if (text_font != MagickFalse)
807 font_name=resource_info->text_font;
808 if ((font_name != (char *) NULL) && (*font_name != '\0'))
817 Load preferred font specified in the X resource database.
819 fontlist=FontToList(font_name);
820 if (fontlist != (char **) NULL)
822 for (i=0; fontlist[i] != (char *) NULL; i++)
824 if (font_info == (XFontStruct *) NULL)
825 font_info=XLoadQueryFont(display,fontlist[i]);
826 fontlist[i]=DestroyString(fontlist[i]);
828 fontlist=(char **) RelinquishMagickMemory(fontlist);
830 if (font_info == (XFontStruct *) NULL)
831 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
834 Load fonts from list of fonts until one is found.
837 if (text_font != MagickFalse)
839 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
841 while (*p != (char *) NULL)
843 if (font_info != (XFontStruct *) NULL)
845 font_info=XLoadQueryFont(display,(char *) *p);
852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % X B e s t I c o n S i z e %
860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
863 % size that maintains the aspect ratio of the image. If the window manager
864 % has preferred icon sizes, one of the preferred sizes is used.
866 % The format of the XBestIconSize method is:
868 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
870 % A description of each parameter follows:
872 % o display: Specifies a connection to an X server; returned from
875 % o image: the image.
878 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
902 Determine if the window manager has specified preferred icon sizes.
904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
905 assert(display != (Display *) NULL);
906 assert(window != (XWindowInfo *) NULL);
907 assert(image != (Image *) NULL);
908 window->width=MaxIconSize;
909 window->height=MaxIconSize;
910 icon_size=(XIconSize *) NULL;
912 root_window=XRootWindow(display,window->screen);
913 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
914 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
916 if (icon_size == (XIconSize *) NULL)
919 Window manager does not restrict icon size.
921 icon_size=XAllocIconSize();
922 if (icon_size == (XIconSize *) NULL)
924 ThrowXWindowFatalException(ResourceLimitError,
925 "MemoryAllocationFailed",image->filename);
928 icon_size->min_width=1;
929 icon_size->max_width=MaxIconSize;
930 icon_size->min_height=1;
931 icon_size->max_height=MaxIconSize;
932 icon_size->width_inc=1;
933 icon_size->height_inc=1;
936 Determine aspect ratio of image.
938 width=(unsigned int) image->columns;
939 height=(unsigned int) image->rows;
941 if (window->crop_geometry)
942 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
944 Look for an icon size that maintains the aspect ratio of image.
946 scale_factor=(MagickRealType) icon_size->max_width/width;
947 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
948 scale_factor=(MagickRealType) icon_size->max_height/height;
949 icon_width=(unsigned int) icon_size->min_width;
950 while ((int) icon_width < icon_size->max_width)
952 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
954 icon_width+=icon_size->width_inc;
956 icon_height=(unsigned int) icon_size->min_height;
957 while ((int) icon_height < icon_size->max_height)
959 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
961 icon_height+=icon_size->height_inc;
963 (void) XFree((void *) icon_size);
964 window->width=icon_width;
965 window->height=icon_height;
969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % X B e s t P i x e l %
977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % XBestPixel() returns a pixel from an array of pixels that is closest to the
980 % requested color. If the color array is NULL, the colors are obtained from
983 % The format of the XBestPixel method is:
985 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
986 % unsigned int number_colors,XColor *color)
988 % A description of each parameter follows:
990 % o pixel: XBestPixel returns the pixel value closest to the requested
993 % o display: Specifies a connection to an X server; returned from
996 % o colormap: Specifies the ID of the X server colormap.
998 % o colors: Specifies an array of XColor structures.
1000 % o number_colors: Specifies the number of XColor structures in the
1001 % color definition array.
1003 % o color: Specifies the desired RGB value to find in the colors array.
1006 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1007 XColor *colors,unsigned int number_colors,XColor *color)
1018 register MagickRealType
1029 Find closest representation for the requested RGB color.
1031 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1032 assert(display != (Display *) NULL);
1033 assert(color != (XColor *) NULL);
1034 status=XAllocColor(display,colormap,color);
1035 if (status != False)
1037 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1038 if (query_server != MagickFalse)
1041 Read X server colormap.
1043 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1044 if (colors == (XColor *) NULL)
1046 ThrowXWindowFatalException(ResourceLimitError,
1047 "MemoryAllocationFailed","...");
1050 for (i=0; i < (int) number_colors; i++)
1051 colors[i].pixel=(size_t) i;
1052 if (number_colors > 256)
1054 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1056 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1059 for (i=0; i < (int) number_colors; i++)
1061 pixel.red=colors[i].red-(MagickRealType) color->red;
1062 distance=pixel.red*pixel.red;
1063 if (distance > min_distance)
1065 pixel.green=colors[i].green-(MagickRealType) color->green;
1066 distance+=pixel.green*pixel.green;
1067 if (distance > min_distance)
1069 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1070 distance+=pixel.blue*pixel.blue;
1071 if (distance > min_distance)
1073 min_distance=distance;
1074 color->pixel=colors[i].pixel;
1077 (void) XAllocColor(display,colormap,&colors[j]);
1078 if (query_server != MagickFalse)
1079 colors=(XColor *) RelinquishMagickMemory(colors);
1083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % X B e s t V i s u a l I n f o %
1091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 % XBestVisualInfo() returns visual information for a visual that is the "best"
1094 % the server supports. "Best" is defined as:
1096 % 1. Restrict the visual list to those supported by the default screen.
1098 % 2. If a visual type is specified, restrict the visual list to those of
1101 % 3. If a map type is specified, choose the visual that matches the id
1102 % specified by the Standard Colormap.
1104 % 4 From the list of visuals, choose one that can display the most
1105 % simultaneous colors. If more than one visual can display the same
1106 % number of simultaneous colors, one is chosen based on a rank.
1108 % The format of the XBestVisualInfo method is:
1110 % XVisualInfo *XBestVisualInfo(Display *display,
1111 % XStandardColormap *map_info,XResourceInfo *resource_info)
1113 % A description of each parameter follows:
1115 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1118 % o display: Specifies a connection to an X server; returned from
1121 % o map_info: If map_type is specified, this structure is initialized
1122 % with info from the Standard Colormap.
1124 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1128 static inline int MagickMax(const int x,const int y)
1135 static inline size_t MagickMin(const unsigned int x,
1136 const unsigned int y)
1143 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1144 XStandardColormap *map_info,XResourceInfo *resource_info)
1146 #define MaxStandardColormaps 7
1147 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1148 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1149 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1150 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1176 Restrict visual search by screen number.
1178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1179 assert(display != (Display *) NULL);
1180 assert(map_info != (XStandardColormap *) NULL);
1181 assert(resource_info != (XResourceInfo *) NULL);
1182 map_type=resource_info->map_type;
1183 visual_type=resource_info->visual_type;
1184 visual_mask=VisualScreenMask;
1185 visual_template.screen=XDefaultScreen(display);
1186 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1188 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1189 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1190 visual_mask|=VisualDepthMask;
1191 if (visual_type != (char *) NULL)
1194 Restrict visual search by class or visual id.
1196 if (LocaleCompare("staticgray",visual_type) == 0)
1198 visual_mask|=VisualClassMask;
1199 visual_template.klass=StaticGray;
1202 if (LocaleCompare("grayscale",visual_type) == 0)
1204 visual_mask|=VisualClassMask;
1205 visual_template.klass=GrayScale;
1208 if (LocaleCompare("staticcolor",visual_type) == 0)
1210 visual_mask|=VisualClassMask;
1211 visual_template.klass=StaticColor;
1214 if (LocaleCompare("pseudocolor",visual_type) == 0)
1216 visual_mask|=VisualClassMask;
1217 visual_template.klass=PseudoColor;
1220 if (LocaleCompare("truecolor",visual_type) == 0)
1222 visual_mask|=VisualClassMask;
1223 visual_template.klass=TrueColor;
1226 if (LocaleCompare("directcolor",visual_type) == 0)
1228 visual_mask|=VisualClassMask;
1229 visual_template.klass=DirectColor;
1232 if (LocaleCompare("default",visual_type) == 0)
1234 visual_mask|=VisualIDMask;
1235 visual_template.visualid=XVisualIDFromVisual(
1236 XDefaultVisual(display,XDefaultScreen(display)));
1239 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1241 visual_mask|=VisualIDMask;
1242 visual_template.visualid=
1243 strtol(visual_type,(char **) NULL,0);
1246 ThrowXWindowFatalException(XServerError,
1247 "UnrecognizedVisualSpecifier",visual_type);
1250 Get all visuals that meet our criteria so far.
1253 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1255 visual_mask=VisualScreenMask | VisualIDMask;
1256 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1259 Failed to get visual; try using the default visual.
1261 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1263 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1264 XDefaultScreen(display)));
1265 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1267 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1268 return((XVisualInfo *) NULL);
1269 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1270 XVisualClassName(visual_list->klass));
1272 resource_info->color_recovery=MagickFalse;
1273 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1279 map_name[MaxTextExtent];
1295 Choose a visual associated with a standard colormap.
1297 root_window=XRootWindow(display,XDefaultScreen(display));
1299 if (LocaleCompare(map_type,"list") != 0)
1302 User specified Standard Colormap.
1304 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1305 "RGB_%s_MAP",map_type);
1306 LocaleUpper(map_name);
1307 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1308 if (map_property != (Atom) NULL)
1309 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1315 *colormap[MaxStandardColormaps]=
1317 "_HP_RGB_SMOOTH_MAP_LIST",
1327 Choose a standard colormap from a list.
1329 for (i=0; i < MaxStandardColormaps; i++)
1331 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1332 if (map_property == (Atom) NULL)
1334 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1336 if (status != False)
1339 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1341 if (status == False)
1343 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1345 return((XVisualInfo *) NULL);
1348 Search all Standard Colormaps and visuals for ids that match.
1350 *map_info=map_list[0];
1351 #if !defined(PRE_R4_ICCCM)
1352 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1353 for (i=0; i < number_maps; i++)
1354 for (j=0; j < number_visuals; j++)
1355 if (map_list[i].visualid ==
1356 XVisualIDFromVisual(visual_list[j].visual))
1358 *map_info=map_list[i];
1359 visual_template.visualid=XVisualIDFromVisual(
1360 visual_list[j].visual);
1363 if (map_info->visualid != visual_template.visualid)
1365 ThrowXWindowFatalException(XServerError,
1366 "UnableToMatchVisualToStandardColormap",map_type);
1367 return((XVisualInfo *) NULL);
1370 if (map_info->colormap == (Colormap) NULL)
1372 ThrowXWindowFatalException(XServerError,
1373 "StandardColormapIsNotInitialized",map_type);
1374 return((XVisualInfo *) NULL);
1376 (void) XFree((void *) map_list);
1380 static const unsigned int
1395 Pick one visual that displays the most simultaneous colors.
1397 visual_info=visual_list;
1399 for (i=1; i < number_visuals; i++)
1402 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1405 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1406 if (rank[p->klass] > rank[visual_info->klass])
1409 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1411 (void) XFree((void *) visual_list);
1413 Retrieve only one visual by its screen & id number.
1415 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1417 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1418 return((XVisualInfo *) NULL);
1419 return(visual_info);
1423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1427 % X C h e c k D e f i n e C u r s o r %
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1433 % XCheckDefineCursor() prevents cursor changes on the root window.
1435 % The format of the XXCheckDefineCursor method is:
1437 % XCheckDefineCursor(display,window,cursor)
1439 % A description of each parameter follows:
1441 % o display: Specifies a connection to an X server; returned from
1444 % o window: the window.
1446 % o cursor: the cursor.
1449 MagickExport int XCheckDefineCursor(Display *display,Window window,
1452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1453 assert(display != (Display *) NULL);
1454 if (window == XRootWindow(display,XDefaultScreen(display)))
1456 return(XDefineCursor(display,window,cursor));
1460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 % X C h e c k R e f r e s h W i n d o w s %
1468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1470 % XCheckRefreshWindows() checks the X server for exposure events for a
1471 % particular window and updates the areassociated with the exposure event.
1473 % The format of the XCheckRefreshWindows method is:
1475 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1477 % A description of each parameter follows:
1479 % o display: Specifies a connection to an X server; returned from
1482 % o windows: Specifies a pointer to a XWindows structure.
1485 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1493 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1494 assert(display != (Display *) NULL);
1495 assert(windows != (XWindows *) NULL);
1496 XDelay(display,SuspendTime);
1497 id=windows->command.id;
1498 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1499 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1500 id=windows->image.id;
1501 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1502 XRefreshWindow(display,&windows->image,&event);
1503 XDelay(display,SuspendTime << 1);
1504 id=windows->command.id;
1505 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1506 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1507 id=windows->image.id;
1508 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1509 XRefreshWindow(display,&windows->image,&event);
1513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1517 % X C l i e n t M e s s a g e %
1521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1524 % initialized with a particular protocol type and atom.
1526 % The format of the XClientMessage function is:
1528 % XClientMessage(display,window,protocol,reason,timestamp)
1530 % A description of each parameter follows:
1532 % o display: Specifies a pointer to the Display structure; returned from
1535 % o window: Specifies a pointer to a Window structure.
1537 % o protocol: Specifies an atom value.
1539 % o reason: Specifies an atom value which is the reason to send.
1541 % o timestamp: Specifies a value of type Time.
1544 MagickExport void XClientMessage(Display *display,const Window window,
1545 const Atom protocol,const Atom reason,const Time timestamp)
1550 assert(display != (Display *) NULL);
1551 client_event.type=ClientMessage;
1552 client_event.window=window;
1553 client_event.message_type=protocol;
1554 client_event.format=32;
1555 client_event.data.l[0]=(long) reason;
1556 client_event.data.l[1]=(long) timestamp;
1557 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565 + X C l i e n t W i n d o w %
1569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 % XClientWindow() finds a window, at or below the specified window, which has
1572 % a WM_STATE property. If such a window is found, it is returned, otherwise
1573 % the argument window is returned.
1575 % The format of the XClientWindow function is:
1577 % client_window=XClientWindow(display,target_window)
1579 % A description of each parameter follows:
1581 % o client_window: XClientWindow returns a window, at or below the specified
1582 % window, which has a WM_STATE property otherwise the argument
1583 % target_window is returned.
1585 % o display: Specifies a pointer to the Display structure; returned from
1588 % o target_window: Specifies the window to find a WM_STATE property.
1591 static Window XClientWindow(Display *display,Window target_window)
1613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1614 assert(display != (Display *) NULL);
1615 state=XInternAtom(display,"WM_STATE",MagickTrue);
1616 if (state == (Atom) NULL)
1617 return(target_window);
1619 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1620 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1621 if ((status == Success) && (type != (Atom) NULL))
1622 return(target_window);
1623 client_window=XWindowByProperty(display,target_window,state);
1624 if (client_window == (Window) NULL)
1625 return(target_window);
1626 return(client_window);
1630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1634 + X C o m p o n e n t T e r m i n u s %
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % XComponentTerminus() destroys the module component.
1642 % The format of the XComponentTerminus method is:
1644 % XComponentTerminus(void)
1647 MagickExport void XComponentTerminus(void)
1649 DestroyXResources();
1653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1657 % X C o n f i g u r e I m a g e C o l o r m a p %
1661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663 % XConfigureImageColormap() creates a new X colormap.
1665 % The format of the XConfigureImageColormap method is:
1667 % void XConfigureImageColormap(Display *display,
1668 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1670 % A description of each parameter follows:
1672 % o display: Specifies a connection to an X server; returned from
1675 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1677 % o windows: Specifies a pointer to a XWindows structure.
1679 % o image: the image.
1682 MagickExport void XConfigureImageColormap(Display *display,
1683 XResourceInfo *resource_info,XWindows *windows,Image *image)
1689 Make standard colormap.
1691 XSetCursorState(display,windows,MagickTrue);
1692 XCheckRefreshWindows(display,windows);
1693 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1694 windows->map_info,windows->pixel_info);
1695 colormap=windows->map_info->colormap;
1696 (void) XSetWindowColormap(display,windows->image.id,colormap);
1697 (void) XSetWindowColormap(display,windows->command.id,colormap);
1698 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1699 if (windows->magnify.mapped != MagickFalse)
1700 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1701 if (windows->pan.mapped != MagickFalse)
1702 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1703 XSetCursorState(display,windows,MagickFalse);
1704 XClientMessage(display,windows->image.id,windows->im_protocols,
1705 windows->im_update_colormap,CurrentTime);
1709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1713 % X C o n s t r a i n W i n d o w P o s i t i o n %
1717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1719 % XConstrainWindowPosition() assures a window is positioned within the X
1720 % server boundaries.
1722 % The format of the XConstrainWindowPosition method is:
1724 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1726 % A description of each parameter follows:
1728 % o display: Specifies a pointer to the Display structure; returned from
1731 % o window_info: Specifies a pointer to a XWindowInfo structure.
1734 MagickExport void XConstrainWindowPosition(Display *display,
1735 XWindowInfo *window_info)
1740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1741 assert(display != (Display *) NULL);
1742 assert(window_info != (XWindowInfo *) NULL);
1743 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1744 if (window_info->x < 0)
1747 if (window_info->x > (int) limit)
1748 window_info->x=(int) limit;
1749 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1750 if (window_info->y < 0)
1753 if (window_info->y > limit)
1754 window_info->y=limit;
1758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1768 % XDelay() suspends program execution for the number of milliseconds
1771 % The format of the Delay method is:
1773 % void XDelay(Display *display,const size_t milliseconds)
1775 % A description of each parameter follows:
1777 % o display: Specifies a pointer to the Display structure; returned from
1780 % o milliseconds: Specifies the number of milliseconds to delay before
1784 MagickExport void XDelay(Display *display,const size_t milliseconds)
1786 assert(display != (Display *) NULL);
1787 (void) XFlush(display);
1788 MagickDelay(milliseconds);
1792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1796 % X D e s t r o y R e s o u r c e I n f o %
1800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1802 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1805 % The format of the XDestroyResourceInfo method is:
1807 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1809 % A description of each parameter follows:
1811 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1814 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1816 if (resource_info->image_geometry != (char *) NULL)
1817 resource_info->image_geometry=(char *)
1818 RelinquishMagickMemory(resource_info->image_geometry);
1819 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1820 resource_info->quantize_info=DestroyQuantizeInfo(
1821 resource_info->quantize_info);
1822 if (resource_info->client_name != (char *) NULL)
1823 resource_info->client_name=(char *)
1824 RelinquishMagickMemory(resource_info->client_name);
1825 if (resource_info->name != (char *) NULL)
1826 resource_info->name=DestroyString(resource_info->name);
1827 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1835 % X D e s t r o y W i n d o w C o l o r s %
1839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1841 % XDestroyWindowColors() frees X11 color resources previously saved on a
1842 % window by XRetainWindowColors or programs like xsetroot.
1844 % The format of the XDestroyWindowColors method is:
1846 % void XDestroyWindowColors(Display *display,Window window)
1848 % A description of each parameter follows:
1850 % o display: Specifies a connection to an X server; returned from
1853 % o window: Specifies a pointer to a Window structure.
1856 MagickExport void XDestroyWindowColors(Display *display,Window window)
1876 If there are previous resources on the root window, destroy them.
1878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1879 assert(display != (Display *) NULL);
1880 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1881 if (property == (Atom) NULL)
1883 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1887 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1888 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1889 if (status != Success)
1891 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1893 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1894 (void) XDeleteProperty(display,window,property);
1897 (void) XFree((void *) data);
1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1905 % X D i s p l a y I m a g e I n f o %
1909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1911 % XDisplayImageInfo() displays information about an X image.
1913 % The format of the XDisplayImageInfo method is:
1915 % void XDisplayImageInfo(Display *display,
1916 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1919 % A description of each parameter follows:
1921 % o display: Specifies a connection to an X server; returned from
1924 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1926 % o windows: Specifies a pointer to a XWindows structure.
1928 % o undo_image: the undo image.
1930 % o image: the image.
1933 MagickExport void XDisplayImageInfo(Display *display,
1934 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1938 filename[MaxTextExtent],
1961 Write info about the X server to a file.
1963 assert(display != (Display *) NULL);
1964 assert(resource_info != (XResourceInfo *) NULL);
1965 assert(windows != (XWindows *) NULL);
1966 assert(image != (Image *) NULL);
1968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1970 unique_file=AcquireUniqueFileResource(filename);
1971 if (unique_file != -1)
1972 file=fdopen(unique_file,"w");
1973 if ((unique_file == -1) || (file == (FILE *) NULL))
1975 XNoticeWidget(display,windows,"Unable to display image info",filename);
1978 if (resource_info->gamma_correct != MagickFalse)
1979 if (resource_info->display_gamma != (char *) NULL)
1980 (void) fprintf(file,"Display\n gamma: %s\n\n",
1981 resource_info->display_gamma);
1983 Write info about the X image to a file.
1985 (void) fprintf(file,"X\n visual: %s\n",
1986 XVisualClassName((int) windows->image.storage_class));
1987 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
1988 if (windows->visual_info->colormap_size != 0)
1989 (void) fprintf(file," colormap size: %d\n",
1990 windows->visual_info->colormap_size);
1991 if (resource_info->colormap== SharedColormap)
1992 (void) fprintf(file," colormap type: Shared\n");
1994 (void) fprintf(file," colormap type: Private\n");
1995 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
1996 windows->image.ximage->height);
1997 if (windows->image.crop_geometry != (char *) NULL)
1998 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
1999 if (windows->image.pixmap == (Pixmap) NULL)
2000 (void) fprintf(file," type: X Image\n");
2002 (void) fprintf(file," type: Pixmap\n");
2003 if (windows->image.shape != MagickFalse)
2004 (void) fprintf(file," non-rectangular shape: True\n");
2006 (void) fprintf(file," non-rectangular shape: False\n");
2007 if (windows->image.shared_memory != MagickFalse)
2008 (void) fprintf(file," shared memory: True\n");
2010 (void) fprintf(file," shared memory: False\n");
2011 (void) fprintf(file,"\n");
2012 if (resource_info->font != (char *) NULL)
2013 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2014 if (resource_info->text_font != (char *) NULL)
2015 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2017 Write info about the undo cache to a file.
2020 for (levels=0; undo_image != (Image *) NULL; levels++)
2022 number_pixels=undo_image->list->columns*undo_image->list->rows;
2023 bytes+=number_pixels*sizeof(PixelPacket);
2024 undo_image=GetPreviousImageInList(undo_image);
2026 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2027 (void) fprintf(file," bytes: %.20gmb\n",(double) ((bytes+(1 << 19)) >> 20));
2028 (void) fprintf(file," limit: %.20gmb\n\n",(double)
2029 resource_info->undo_cache);
2031 Write info about the image to a file.
2033 (void) IdentifyImage(image,file,MagickTrue);
2034 (void) fclose(file);
2035 text=FileToString(filename,~0,&image->exception);
2036 (void) RelinquishUniqueFileResource(filename);
2037 if (text == (char *) NULL)
2039 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2040 "UnableToDisplayImageInfo");
2043 textlist=StringToList(text);
2044 if (textlist != (char **) NULL)
2047 title[MaxTextExtent];
2050 Display information about the image in the Text View widget.
2052 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2053 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2055 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2056 (char const **) textlist);
2057 for (i=0; textlist[i] != (char *) NULL; i++)
2058 textlist[i]=DestroyString(textlist[i]);
2059 textlist=(char **) RelinquishMagickMemory(textlist);
2061 text=DestroyString(text);
2065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2069 + X D i t h e r I m a g e %
2073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2075 % XDitherImage() dithers the reference image as required by the HP Color
2076 % Recovery algorithm. The color values are quantized to 3 bits of red and
2077 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2078 % standard colormap.
2080 % The format of the XDitherImage method is:
2082 % void XDitherImage(Image *image,XImage *ximage)
2084 % A description of each parameter follows:
2086 % o image: the image.
2088 % o ximage: Specifies a pointer to a XImage structure; returned from
2092 static void XDitherImage(Image *image,XImage *ximage)
2094 static const short int
2097 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2098 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2100 dither_green[2][16]=
2102 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2103 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2107 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2108 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2124 register const PixelPacket
2144 Allocate and initialize dither maps.
2146 for (i=0; i < 2; i++)
2147 for (j=0; j < 16; j++)
2149 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2151 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2152 sizeof(*green_map));
2153 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2155 if ((red_map[i][j] == (unsigned char *) NULL) ||
2156 (green_map[i][j] == (unsigned char *) NULL) ||
2157 (blue_map[i][j] == (unsigned char *) NULL))
2159 ThrowXWindowFatalException(ResourceLimitError,
2160 "MemoryAllocationFailed",image->filename);
2165 Initialize dither tables.
2167 for (i=0; i < 2; i++)
2168 for (j=0; j < 16; j++)
2169 for (x=0; x < 256; x++)
2174 value+=dither_red[i][j];
2175 red_map[i][j][x]=(unsigned char)
2176 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2180 value+=dither_green[i][j];
2181 green_map[i][j][x]=(unsigned char)
2182 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2186 value+=((size_t) dither_blue[i][j] << 1);
2187 blue_map[i][j][x]=(unsigned char)
2188 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2193 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2194 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2198 image_view=AcquireCacheView(image);
2199 for (y=0; y < (int) image->rows; y++)
2201 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2203 if (p == (const PixelPacket *) NULL)
2205 for (x=0; x < (int) image->columns; x++)
2207 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2208 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2209 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2210 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2211 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2212 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2213 pixel=(size_t) (((size_t) color.red & 0xe0) |
2214 (((size_t) color.green & 0xe0) >> 3) |
2215 (((size_t) color.blue & 0xc0) >> 6));
2227 image_view=DestroyCacheView(image_view);
2229 Free allocated memory.
2231 for (i=0; i < 2; i++)
2232 for (j=0; j < 16; j++)
2234 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2235 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2236 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2245 % X D r a w I m a g e %
2249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2251 % XDrawImage() draws a line on the image.
2253 % The format of the XDrawImage method is:
2255 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2257 % A description of each parameter follows:
2259 % o display: Specifies a connection to an X server; returned from
2262 % o pixel: Specifies a pointer to a XPixelInfo structure.
2264 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2266 % o image: the image.
2269 MagickExport MagickBooleanType XDrawImage(Display *display,
2270 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2309 Initialize drawd image.
2311 assert(display != (Display *) NULL);
2312 assert(pixel != (XPixelInfo *) NULL);
2313 assert(draw_info != (XDrawInfo *) NULL);
2314 assert(image != (Image *) NULL);
2315 if (image->debug != MagickFalse)
2316 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2318 Initialize drawd pixmap.
2320 root_window=XRootWindow(display,XDefaultScreen(display));
2321 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2322 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2323 draw_info->height,depth);
2324 if (draw_pixmap == (Pixmap) NULL)
2325 return(MagickFalse);
2327 Initialize graphics info.
2329 context_values.background=(size_t) (~0);
2330 context_values.foreground=0;
2331 context_values.line_width=(int) draw_info->line_width;
2332 draw_context=XCreateGC(display,root_window,(size_t)
2333 (GCBackground | GCForeground | GCLineWidth),&context_values);
2334 if (draw_context == (GC) NULL)
2335 return(MagickFalse);
2339 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2342 Draw line to pixmap.
2344 (void) XSetBackground(display,draw_context,0);
2345 (void) XSetForeground(display,draw_context,(size_t) (~0));
2346 if (draw_info->stipple != (Pixmap) NULL)
2348 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2349 (void) XSetStipple(display,draw_context,draw_info->stipple);
2351 switch (draw_info->element)
2356 (void) XDrawLines(display,draw_pixmap,draw_context,
2357 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2363 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2364 draw_info->line_info.y1,draw_info->line_info.x2,
2365 draw_info->line_info.y2);
2368 case RectangleElement:
2370 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2371 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2372 (unsigned int) draw_info->rectangle_info.width,
2373 (unsigned int) draw_info->rectangle_info.height);
2376 case FillRectangleElement:
2378 (void) XFillRectangle(display,draw_pixmap,draw_context,
2379 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2380 (unsigned int) draw_info->rectangle_info.width,
2381 (unsigned int) draw_info->rectangle_info.height);
2385 case EllipseElement:
2387 (void) XDrawArc(display,draw_pixmap,draw_context,
2388 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2389 (unsigned int) draw_info->rectangle_info.width,
2390 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2393 case FillCircleElement:
2394 case FillEllipseElement:
2396 (void) XFillArc(display,draw_pixmap,draw_context,
2397 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2398 (unsigned int) draw_info->rectangle_info.width,
2399 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2402 case PolygonElement:
2407 coordinate_info=draw_info->coordinate_info;
2408 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2409 (int) draw_info->number_coordinates,CoordModeOrigin);
2410 (void) XDrawLine(display,draw_pixmap,draw_context,
2411 coordinate_info[draw_info->number_coordinates-1].x,
2412 coordinate_info[draw_info->number_coordinates-1].y,
2413 coordinate_info[0].x,coordinate_info[0].y);
2416 case FillPolygonElement:
2418 (void) XFillPolygon(display,draw_pixmap,draw_context,
2419 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2424 (void) XFreeGC(display,draw_context);
2428 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2429 draw_info->height,AllPlanes,ZPixmap);
2430 if (draw_ximage == (XImage *) NULL)
2431 return(MagickFalse);
2432 (void) XFreePixmap(display,draw_pixmap);
2434 Initialize draw image.
2436 draw_image=AcquireImage((ImageInfo *) NULL);
2437 if (draw_image == (Image *) NULL)
2438 return(MagickFalse);
2439 draw_image->columns=draw_info->width;
2440 draw_image->rows=draw_info->height;
2442 Transfer drawn X image to image.
2444 width=(unsigned int) image->columns;
2445 height=(unsigned int) image->rows;
2448 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2449 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
2450 &draw_image->background_color,&image->exception);
2451 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2452 return(MagickFalse);
2453 draw_image->matte=MagickTrue;
2454 exception=(&image->exception);
2455 draw_view=AcquireCacheView(draw_image);
2456 for (y=0; y < (int) draw_image->rows; y++)
2461 register PixelPacket
2464 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2466 if (q == (PixelPacket *) NULL)
2468 for (x=0; x < (int) draw_image->columns; x++)
2470 if (XGetPixel(draw_ximage,x,y) == 0)
2473 Set this pixel to the background color.
2475 *q=draw_image->background_color;
2476 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2477 TransparentOpacity : OpaqueOpacity);
2482 Set this pixel to the pen color.
2484 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2485 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2486 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2487 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2488 OpaqueOpacity : TransparentOpacity);
2492 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2495 draw_view=DestroyCacheView(draw_view);
2496 XDestroyImage(draw_ximage);
2498 Determine draw geometry.
2500 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2501 if ((width != (unsigned int) draw_image->columns) ||
2502 (height != (unsigned int) draw_image->rows))
2505 image_geometry[MaxTextExtent];
2510 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2512 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2514 if (draw_info->degrees != 0.0)
2528 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2529 if (rotate_image == (Image *) NULL)
2530 return(MagickFalse);
2531 draw_image=DestroyImage(draw_image);
2532 draw_image=rotate_image;
2534 Annotation is relative to the degree of rotation.
2536 normalized_degrees=draw_info->degrees;
2537 while (normalized_degrees < -45.0)
2538 normalized_degrees+=360.0;
2539 for (rotations=0; normalized_degrees > 45.0; rotations++)
2540 normalized_degrees-=90.0;
2541 switch (rotations % 4)
2551 x=x-(int) draw_image->columns/2;
2552 y=y+(int) draw_image->columns/2;
2560 x=x-(int) draw_image->columns;
2568 x=x-(int) draw_image->columns/2;
2569 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2575 Composite text onto the image.
2577 draw_view=AcquireCacheView(draw_image);
2578 for (y=0; y < (int) draw_image->rows; y++)
2583 register PixelPacket
2586 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2588 if (q == (PixelPacket *) NULL)
2590 for (x=0; x < (int) draw_image->columns; x++)
2592 if (q->opacity != (Quantum) TransparentOpacity)
2593 SetOpacityPixelComponent(q,OpaqueOpacity);
2596 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2599 draw_view=DestroyCacheView(draw_view);
2600 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2601 if (draw_info->stencil == TransparentStencil)
2602 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2607 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2611 draw_image=DestroyImage(draw_image);
2616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2626 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2627 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2628 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2631 % The format of the XError function is:
2633 % XError(display,error)
2635 % A description of each parameter follows:
2637 % o display: Specifies a pointer to the Display structure; returned from
2640 % o error: Specifies the error event.
2644 #if defined(__cplusplus) || defined(c_plusplus)
2648 MagickExport int XError(Display *display,XErrorEvent *error)
2650 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2651 assert(display != (Display *) NULL);
2652 assert(error != (XErrorEvent *) NULL);
2653 xerror_alert=MagickTrue;
2654 switch (error->request_code)
2658 if ((int) error->error_code == BadDrawable)
2659 return(MagickFalse);
2662 case X_GetWindowAttributes:
2665 if ((int) error->error_code == BadWindow)
2666 return(MagickFalse);
2671 if ((int) error->error_code == BadValue)
2672 return(MagickFalse);
2679 #if defined(__cplusplus) || defined(c_plusplus)
2684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2688 % X F r e e R e s o u r c e s %
2692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2694 % XFreeResources() frees X11 resources.
2696 % The format of the XFreeResources method is:
2698 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2699 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2700 % XResourceInfo *resource_info,XWindowInfo *window_info)
2701 % resource_info,window_info)
2703 % A description of each parameter follows:
2705 % o display: Specifies a connection to an X server; returned from
2708 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2709 % returned from XGetVisualInfo.
2711 % o map_info: If map_type is specified, this structure is initialized
2712 % with info from the Standard Colormap.
2714 % o pixel: Specifies a pointer to a XPixelInfo structure.
2716 % o font_info: Specifies a pointer to a XFontStruct structure.
2718 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2720 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2723 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2724 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2725 XResourceInfo *resource_info,XWindowInfo *window_info)
2727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2728 assert(display != (Display *) NULL);
2729 assert(resource_info != (XResourceInfo *) NULL);
2730 if (window_info != (XWindowInfo *) NULL)
2735 if (window_info->ximage != (XImage *) NULL)
2736 XDestroyImage(window_info->ximage);
2737 if (window_info->id != (Window) NULL)
2740 Free destroy window and free cursors.
2742 if (window_info->id != XRootWindow(display,visual_info->screen))
2743 (void) XDestroyWindow(display,window_info->id);
2744 if (window_info->annotate_context != (GC) NULL)
2745 (void) XFreeGC(display,window_info->annotate_context);
2746 if (window_info->highlight_context != (GC) NULL)
2747 (void) XFreeGC(display,window_info->highlight_context);
2748 if (window_info->widget_context != (GC) NULL)
2749 (void) XFreeGC(display,window_info->widget_context);
2750 if (window_info->cursor != (Cursor) NULL)
2751 (void) XFreeCursor(display,window_info->cursor);
2752 window_info->cursor=(Cursor) NULL;
2753 if (window_info->busy_cursor != (Cursor) NULL)
2754 (void) XFreeCursor(display,window_info->busy_cursor);
2755 window_info->busy_cursor=(Cursor) NULL;
2761 if (font_info != (XFontStruct *) NULL)
2762 (void) XFreeFont(display,font_info);
2763 if (map_info != (XStandardColormap *) NULL)
2766 Free X Standard Colormap.
2768 if (resource_info->map_type == (char *) NULL)
2769 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2770 (void) XFree((void *) map_info);
2775 if (visual_info != (XVisualInfo *) NULL)
2776 (void) XFree((void *) visual_info);
2777 if (resource_info->close_server != MagickFalse)
2778 (void) XCloseDisplay(display);
2782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2786 % X F r e e S t a n d a r d C o l o r m a p %
2790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2792 % XFreeStandardColormap() frees an X11 colormap.
2794 % The format of the XFreeStandardColormap method is:
2796 % void XFreeStandardColormap(Display *display,
2797 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2798 % XPixelInfo *pixel)
2800 % A description of each parameter follows:
2802 % o display: Specifies a connection to an X server; returned from
2805 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2806 % returned from XGetVisualInfo.
2808 % o map_info: If map_type is specified, this structure is initialized
2809 % with info from the Standard Colormap.
2811 % o pixel: Specifies a pointer to a XPixelInfo structure.
2814 MagickExport void XFreeStandardColormap(Display *display,
2815 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2820 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2821 assert(display != (Display *) NULL);
2822 assert(visual_info != (XVisualInfo *) NULL);
2823 assert(map_info != (XStandardColormap *) NULL);
2824 (void) XFlush(display);
2825 if (map_info->colormap != (Colormap) NULL)
2827 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2828 (void) XFreeColormap(display,map_info->colormap);
2830 if (pixel != (XPixelInfo *) NULL)
2831 if ((visual_info->klass != TrueColor) &&
2832 (visual_info->klass != DirectColor))
2833 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2834 (int) pixel->colors,0);
2836 map_info->colormap=(Colormap) NULL;
2837 if (pixel != (XPixelInfo *) NULL)
2839 if (pixel->pixels != (unsigned long *) NULL)
2840 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2841 pixel->pixels=(unsigned long *) NULL;
2846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2850 % X G e t A n n o t a t e I n f o %
2854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2856 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2858 % The format of the XGetAnnotateInfo method is:
2860 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2862 % A description of each parameter follows:
2864 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2867 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2870 Initialize annotate structure.
2872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2873 assert(annotate_info != (XAnnotateInfo *) NULL);
2876 annotate_info->width=0;
2877 annotate_info->height=0;
2878 annotate_info->stencil=ForegroundStencil;
2879 annotate_info->degrees=0.0;
2880 annotate_info->font_info=(XFontStruct *) NULL;
2881 annotate_info->text=(char *) NULL;
2882 *annotate_info->geometry='\0';
2883 annotate_info->previous=(XAnnotateInfo *) NULL;
2884 annotate_info->next=(XAnnotateInfo *) NULL;
2885 (void) XSupportsLocale();
2886 (void) XSetLocaleModifiers("");
2890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894 % X G e t M a p I n f o %
2898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2900 % XGetMapInfo() initializes the XStandardColormap structure.
2902 % The format of the XStandardColormap method is:
2904 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2905 % XStandardColormap *map_info)
2907 % A description of each parameter follows:
2909 % o colormap: Specifies the ID of the X server colormap.
2911 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2912 % returned from XGetVisualInfo.
2914 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2917 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2918 const Colormap colormap,XStandardColormap *map_info)
2921 Initialize map info.
2923 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2924 assert(visual_info != (XVisualInfo *) NULL);
2925 assert(map_info != (XStandardColormap *) NULL);
2926 map_info->colormap=colormap;
2927 map_info->red_max=visual_info->red_mask;
2928 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2929 if (map_info->red_max != 0)
2930 while ((map_info->red_max & 0x01) == 0)
2932 map_info->red_max>>=1;
2933 map_info->red_mult<<=1;
2935 map_info->green_max=visual_info->green_mask;
2936 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2937 if (map_info->green_max != 0)
2938 while ((map_info->green_max & 0x01) == 0)
2940 map_info->green_max>>=1;
2941 map_info->green_mult<<=1;
2943 map_info->blue_max=visual_info->blue_mask;
2944 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2945 if (map_info->blue_max != 0)
2946 while ((map_info->blue_max & 0x01) == 0)
2948 map_info->blue_max>>=1;
2949 map_info->blue_mult<<=1;
2951 map_info->base_pixel=0;
2955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2959 % X G e t P i x e l I n f o %
2963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2965 % XGetPixelPacket() initializes the PixelPacket structure.
2967 % The format of the XGetPixelPacket method is:
2969 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2970 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2971 % Image *image,XPixelInfo *pixel)
2974 % A description of each parameter follows:
2976 % o display: Specifies a connection to an X server; returned from
2979 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2980 % returned from XGetVisualInfo.
2982 % o map_info: If map_type is specified, this structure is initialized
2983 % with info from the Standard Colormap.
2985 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2987 % o image: the image.
2989 % o pixel: Specifies a pointer to a XPixelInfo structure.
2992 MagickExport void XGetPixelPacket(Display *display,
2993 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2994 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
2997 *PenColors[MaxNumberPens]=
2999 "#000000000000", /* black */
3000 "#00000000ffff", /* blue */
3001 "#0000ffffffff", /* cyan */
3002 "#0000ffff0000", /* green */
3003 "#bdbdbdbdbdbd", /* gray */
3004 "#ffff00000000", /* red */
3005 "#ffff0000ffff", /* magenta */
3006 "#ffffffff0000", /* yellow */
3007 "#ffffffffffff", /* white */
3008 "#bdbdbdbdbdbd", /* gray */
3009 "#bdbdbdbdbdbd" /* gray */
3025 Initialize pixel info.
3027 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3028 assert(display != (Display *) NULL);
3029 assert(visual_info != (XVisualInfo *) NULL);
3030 assert(map_info != (XStandardColormap *) NULL);
3031 assert(resource_info != (XResourceInfo *) NULL);
3032 assert(pixel != (XPixelInfo *) NULL);
3034 if (image != (Image *) NULL)
3035 if (image->storage_class == PseudoClass)
3036 pixel->colors=(ssize_t) image->colors;
3037 packets=(unsigned int)
3038 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3039 if (pixel->pixels != (unsigned long *) NULL)
3040 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3041 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3042 sizeof(pixel->pixels));
3043 if (pixel->pixels == (unsigned long *) NULL)
3044 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3047 Set foreground color.
3049 colormap=map_info->colormap;
3050 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3051 &pixel->foreground_color);
3052 status=XParseColor(display,colormap,resource_info->foreground_color,
3053 &pixel->foreground_color);
3054 if (status == False)
3055 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3056 resource_info->foreground_color);
3057 pixel->foreground_color.pixel=
3058 XStandardPixel(map_info,&pixel->foreground_color);
3059 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3061 Set background color.
3063 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3064 status=XParseColor(display,colormap,resource_info->background_color,
3065 &pixel->background_color);
3066 if (status == False)
3067 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3068 resource_info->background_color);
3069 pixel->background_color.pixel=
3070 XStandardPixel(map_info,&pixel->background_color);
3071 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3075 (void) XParseColor(display,colormap,(char *) BorderColor,
3076 &pixel->border_color);
3077 status=XParseColor(display,colormap,resource_info->border_color,
3078 &pixel->border_color);
3079 if (status == False)
3080 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3081 resource_info->border_color);
3082 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3083 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3087 pixel->matte_color=pixel->background_color;
3088 if (resource_info->matte_color != (char *) NULL)
3091 Matte color is specified as a X resource or command line argument.
3093 status=XParseColor(display,colormap,resource_info->matte_color,
3094 &pixel->matte_color);
3095 if (status == False)
3096 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3097 resource_info->matte_color);
3098 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3099 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3102 Set highlight color.
3104 pixel->highlight_color.red=(unsigned short) ((
3105 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3106 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3107 pixel->highlight_color.green=(unsigned short) ((
3108 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3109 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3110 pixel->highlight_color.blue=(unsigned short) ((
3111 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3112 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3113 pixel->highlight_color.pixel=
3114 XStandardPixel(map_info,&pixel->highlight_color);
3115 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3119 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3120 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3121 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3122 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3123 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3124 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3125 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3126 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3130 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3131 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3132 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3133 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3134 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3135 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3136 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3137 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3141 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3142 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3143 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3144 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3145 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3146 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3147 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3148 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3152 for (i=0; i < MaxNumberPens; i++)
3154 (void) XParseColor(display,colormap,(char *) PenColors[i],
3155 &pixel->pen_colors[i]);
3156 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3157 &pixel->pen_colors[i]);
3158 if (status == False)
3159 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3160 resource_info->pen_colors[i]);
3161 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3162 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3164 pixel->box_color=pixel->background_color;
3165 pixel->pen_color=pixel->foreground_color;
3168 if (image != (Image *) NULL)
3170 if ((resource_info->gamma_correct != MagickFalse) &&
3171 (image->gamma != 0.0))
3180 Initialize map relative to display and image gamma.
3182 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3183 red_gamma=geometry_info.rho;
3184 green_gamma=geometry_info.sigma;
3185 if ((flags & SigmaValue) == 0)
3186 green_gamma=red_gamma;
3187 blue_gamma=geometry_info.xi;
3188 if ((flags & XiValue) == 0)
3189 blue_gamma=red_gamma;
3190 red_gamma*=image->gamma;
3191 green_gamma*=image->gamma;
3192 blue_gamma*=image->gamma;
3194 if (image->storage_class == PseudoClass)
3197 Initialize pixel array for images of type PseudoClass.
3199 for (i=0; i < (ssize_t) image->colors; i++)
3201 XGammaPixel(map_info,image->colormap+i);
3202 for (i=0; i < MaxNumberPens; i++)
3203 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3204 pixel->colors+=MaxNumberPens;
3210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3214 % X G e t R e s o u r c e C l a s s %
3218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3220 % XGetResourceClass() queries the X server for the specified resource name or
3221 % class. If the resource name or class is not defined in the database, the
3222 % supplied default value is returned.
3224 % The format of the XGetResourceClass method is:
3226 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3227 % const char *keyword,char *resource_default)
3229 % A description of each parameter follows:
3231 % o database: Specifies a resource database; returned from
3232 % XrmGetStringDatabase.
3234 % o client_name: Specifies the application name used to retrieve resource
3235 % info from the X server database.
3237 % o keyword: Specifies the keyword of the value being retrieved.
3239 % o resource_default: Specifies the default value to return if the query
3240 % fails to find the specified keyword/class.
3243 MagickExport char *XGetResourceClass(XrmDatabase database,
3244 const char *client_name,const char *keyword,char *resource_default)
3247 resource_class[MaxTextExtent],
3248 resource_name[MaxTextExtent];
3259 if (database == (XrmDatabase) NULL)
3260 return(resource_default);
3261 *resource_name='\0';
3262 *resource_class='\0';
3263 if (keyword != (char *) NULL)
3270 Initialize resource keyword and class.
3272 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3273 client_name,keyword);
3274 c=(int) (*client_name);
3275 if ((c >= XK_a) && (c <= XK_z))
3278 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3279 c-=(XK_agrave-XK_Agrave);
3281 if ((c >= XK_oslash) && (c <= XK_thorn))
3282 c-=(XK_oslash-XK_Ooblique);
3284 if ((k >= XK_a) && (k <= XK_z))
3287 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3288 k-=(XK_agrave-XK_Agrave);
3290 if ((k >= XK_oslash) && (k <= XK_thorn))
3291 k-=(XK_oslash-XK_Ooblique);
3292 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3293 client_name+1,k,keyword+1);
3295 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3297 if (status == False)
3298 return(resource_default);
3299 return(resource_value.addr);
3303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3307 % X G e t R e s o u r c e D a t a b a s e %
3311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3313 % XGetResourceDatabase() creates a new resource database and initializes it.
3315 % The format of the XGetResourceDatabase method is:
3317 % XrmDatabase XGetResourceDatabase(Display *display,
3318 % const char *client_name)
3320 % A description of each parameter follows:
3322 % o database: XGetResourceDatabase() returns the database after it is
3325 % o display: Specifies a connection to an X server; returned from
3328 % o client_name: Specifies the application name used to retrieve resource
3329 % info from the X server database.
3332 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3333 const char *client_name)
3336 filename[MaxTextExtent];
3348 if (display == (Display *) NULL)
3349 return((XrmDatabase) NULL);
3350 assert(client_name != (char *) NULL);
3352 Initialize resource database.
3355 (void) XGetDefault(display,(char *) client_name,"dummy");
3356 resource_database=XrmGetDatabase(display);
3358 Combine application database.
3360 if (client_name != (char *) NULL)
3363 Get basename of client.
3365 p=client_name+(strlen(client_name)-1);
3366 while ((p > client_name) && (*p != '/'))
3371 c=(int) (*client_name);
3372 if ((c >= XK_a) && (c <= XK_z))
3375 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3376 c-=(XK_agrave-XK_Agrave);
3378 if ((c >= XK_oslash) && (c <= XK_thorn))
3379 c-=(XK_oslash-XK_Ooblique);
3380 #if defined(X11_APPLICATION_PATH)
3381 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3382 X11_APPLICATION_PATH,c,client_name+1);
3383 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3385 if (XResourceManagerString(display) != (char *) NULL)
3388 Combine server database.
3390 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3391 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3394 Merge user preferences database.
3396 #if defined(X11_PREFERENCES_PATH)
3397 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3398 X11_PREFERENCES_PATH,client_name);
3399 ExpandFilename(filename);
3400 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3402 return(resource_database);
3406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3410 % X G e t R e s o u r c e I n f o %
3414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3416 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3418 % The format of the XGetResourceInfo method is:
3420 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3421 % const char *client_name,XResourceInfo *resource_info)
3423 % A description of each parameter follows:
3425 % o image_info: the image info.
3427 % o database: Specifies a resource database; returned from
3428 % XrmGetStringDatabase.
3430 % o client_name: Specifies the application name used to retrieve
3431 % resource info from the X server database.
3433 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3436 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3437 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3444 Initialize resource info fields.
3446 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3447 assert(resource_info != (XResourceInfo *) NULL);
3448 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3449 resource_info->resource_database=database;
3450 resource_info->image_info=(ImageInfo *) image_info;
3451 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3452 XMagickProgressMonitor,(void *) NULL);
3453 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3454 resource_info->close_server=MagickTrue;
3455 resource_info->client_name=AcquireString(client_name);
3456 resource_value=XGetResourceClass(database,client_name,"backdrop",
3458 resource_info->backdrop=IsMagickTrue(resource_value);
3459 resource_info->background_color=XGetResourceInstance(database,client_name,
3460 "background",(char *) "#d6d6d6d6d6d6");
3461 resource_info->border_color=XGetResourceInstance(database,client_name,
3462 "borderColor",BorderColor);
3463 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3465 resource_info->border_width=(unsigned int) StringToUnsignedLong(resource_value);
3466 resource_value=XGetResourceClass(database,client_name,"colormap",
3468 resource_info->colormap=UndefinedColormap;
3469 if (LocaleCompare("private",resource_value) == 0)
3470 resource_info->colormap=PrivateColormap;
3471 if (LocaleCompare("shared",resource_value) == 0)
3472 resource_info->colormap=SharedColormap;
3473 if (resource_info->colormap == UndefinedColormap)
3474 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3476 resource_value=XGetResourceClass(database,client_name,
3477 "colorRecovery",(char *) "False");
3478 resource_info->color_recovery=IsMagickTrue(resource_value);
3479 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3481 resource_info->confirm_exit=IsMagickTrue(resource_value);
3482 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3484 resource_info->confirm_edit=IsMagickTrue(resource_value);
3485 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3486 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3487 resource_info->display_gamma=XGetResourceClass(database,client_name,
3488 "displayGamma",(char *) "2.2");
3489 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3491 resource_info->display_warnings=IsMagickTrue(resource_value);
3492 resource_info->font=XGetResourceClass(database,client_name,"font",
3494 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3495 resource_info->font);
3496 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3498 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3499 (char *) "variable");
3500 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3502 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3504 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3505 (char *) "7x13bold");
3506 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3507 (char *) "8x13bold");
3508 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3509 (char *) "9x15bold");
3510 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3512 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3514 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3516 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3518 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3519 "foreground",ForegroundColor);
3520 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3522 resource_info->gamma_correct=IsMagickTrue(resource_value);
3523 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3524 client_name,"geometry",(char *) NULL));
3525 resource_value=XGetResourceClass(database,client_name,"gravity",
3527 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3528 MagickFalse,resource_value);
3529 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3530 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3531 "iconGeometry",(char *) NULL);
3532 resource_value=XGetResourceClass(database,client_name,"iconic",
3534 resource_info->iconic=IsMagickTrue(resource_value);
3535 resource_value=XGetResourceClass(database,client_name,"immutable",
3536 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3538 resource_info->immutable=IsMagickTrue(resource_value);
3539 resource_value=XGetResourceClass(database,client_name,"magnify",
3541 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3542 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3544 resource_info->matte_color=XGetResourceInstance(database,client_name,
3545 "mattecolor",(char *) NULL);
3546 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3547 "name",(char *) NULL));
3548 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3550 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3552 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3554 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3556 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3558 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3560 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3561 (char *) "magenta");
3562 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3564 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3566 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3568 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3570 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3571 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3572 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3573 resource_info->quantum=StringToLong(resource_value);
3574 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3575 "font",(char *) "fixed");
3576 resource_info->text_font=XGetResourceClass(database,client_name,
3577 "textFontList",resource_info->text_font);
3578 resource_info->title=XGetResourceClass(database,client_name,"title",
3580 resource_value=XGetResourceClass(database,client_name,"undoCache",
3582 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3583 resource_value=XGetResourceClass(database,client_name,"update",
3585 resource_info->update=IsMagickTrue(resource_value);
3586 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3588 resource_info->use_pixmap=IsMagickTrue(resource_value);
3589 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3591 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3592 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3594 resource_info->window_group=XGetResourceClass(database,client_name,
3595 "windowGroup",(char *) NULL);
3596 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3598 resource_info->write_filename=XGetResourceClass(database,client_name,
3599 "writeFilename",(char *) NULL);
3603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3607 % X G e t R e s o u r c e I n s t a n c e %
3611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3613 % XGetResourceInstance() queries the X server for the specified resource name.
3614 % If the resource name is not defined in the database, the supplied default
3615 % value is returned.
3617 % The format of the XGetResourceInstance method is:
3619 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3620 % const char *keyword,const char *resource_default)
3622 % A description of each parameter follows:
3624 % o database: Specifies a resource database; returned from
3625 % XrmGetStringDatabase.
3627 % o client_name: Specifies the application name used to retrieve
3628 % resource info from the X server database.
3630 % o keyword: Specifies the keyword of the value being retrieved.
3632 % o resource_default: Specifies the default value to return if the query
3633 % fails to find the specified keyword/class.
3636 MagickExport char *XGetResourceInstance(XrmDatabase database,
3637 const char *client_name,const char *keyword,const char *resource_default)
3641 resource_name[MaxTextExtent];
3649 if (database == (XrmDatabase) NULL)
3650 return((char *) resource_default);
3651 *resource_name='\0';
3652 if (keyword != (char *) NULL)
3653 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3655 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3657 if (status == False)
3658 return((char *) resource_default);
3659 return(resource_value.addr);
3663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3667 % X G e t S c r e e n D e n s i t y %
3671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3673 % XGetScreenDensity() returns the density of the X server screen in
3676 % The format of the XGetScreenDensity method is:
3678 % char *XGetScreenDensity(Display *display)
3680 % A description of each parameter follows:
3682 % o density: XGetScreenDensity() returns the density of the X screen in
3685 % o display: Specifies a connection to an X server; returned from
3689 MagickExport char *XGetScreenDensity(Display *display)
3692 density[MaxTextExtent];
3699 Set density as determined by screen size.
3701 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3702 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3703 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3704 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3705 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,
3707 return(GetPageGeometry(density));
3711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3715 + X G e t S u b w i n d o w %
3719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3721 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3722 % pointer and a button press.
3724 % The format of the XGetSubwindow method is:
3726 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3728 % A description of each parameter follows:
3730 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3731 % otherwise the subwindow is returned.
3733 % o display: Specifies a connection to an X server; returned from
3736 % o window: Specifies a pointer to a Window.
3738 % o x: the x coordinate of the pointer relative to the origin of the
3741 % o y: the y coordinate of the pointer relative to the origin of the
3745 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3758 assert(display != (Display *) NULL);
3759 source_window=XRootWindow(display,XDefaultScreen(display));
3760 if (window == (Window) NULL)
3761 return(source_window);
3762 target_window=window;
3765 status=XTranslateCoordinates(display,source_window,window,x,y,
3766 &x_offset,&y_offset,&target_window);
3769 if (target_window == (Window) NULL)
3771 source_window=window;
3772 window=target_window;
3776 if (target_window == (Window) NULL)
3777 target_window=window;
3778 return(target_window);
3782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3786 % X G e t W i n d o w C o l o r %
3790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3792 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3795 % The format of the XGetWindowColor method is:
3797 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3800 % A description of each parameter follows:
3802 % o display: Specifies a connection to an X server; returned from
3805 % o windows: Specifies a pointer to a XWindows structure.
3807 % o name: the name of the color if found in the X Color Database is
3808 % returned in this character string.
3811 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3812 XWindows *windows,char *name)
3843 Choose a pixel from the X server.
3845 assert(display != (Display *) NULL);
3846 assert(name != (char *) NULL);
3847 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3849 target_window=XSelectWindow(display,&crop_info);
3850 if (target_window == (Window) NULL)
3851 return(MagickFalse);
3852 root_window=XRootWindow(display,XDefaultScreen(display));
3853 client_window=target_window;
3854 if (target_window != root_window)
3862 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3863 if (status != False)
3865 client_window=XClientWindow(display,target_window);
3866 target_window=client_window;
3870 Verify window is viewable.
3872 status=XGetWindowAttributes(display,target_window,&window_attributes);
3873 if ((status == False) || (window_attributes.map_state != IsViewable))
3874 return(MagickFalse);
3878 (void) XTranslateCoordinates(display,root_window,target_window,
3879 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3880 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3881 if (ximage == (XImage *) NULL)
3882 return(MagickFalse);
3883 color.pixel=XGetPixel(ximage,0,0);
3884 XDestroyImage(ximage);
3886 Match color against the color database.
3888 (void) XQueryColor(display,window_attributes.colormap,&color);
3889 pixel.red=ScaleShortToQuantum(color.red);
3890 pixel.green=ScaleShortToQuantum(color.green);
3891 pixel.blue=ScaleShortToQuantum(color.blue);
3892 pixel.opacity=OpaqueOpacity;
3893 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3894 &windows->image.image->exception);
3899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3903 + X G e t W i n d o w I m a g e %
3907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3909 % XGetWindowImage() reads an image from the target X window and returns it.
3910 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3911 % target image with each child image in an optimized fashion. Any child
3912 % window that have the same visual, colormap, and are contained by its parent
3915 % The format of the XGetWindowImage method is:
3917 % Image *XGetWindowImage(Display *display,const Window window,
3918 % const unsigned int borders,const unsigned int level)
3920 % A description of each parameter follows:
3922 % o display: Specifies a connection to an X server; returned from
3925 % o window: Specifies the window to obtain the image from.
3927 % o borders: Specifies whether borders pixels are to be saved with
3930 % o level: Specifies an unsigned integer representing the level of
3931 % decent in the window hierarchy. This value must be zero or one on
3932 % the initial call to XGetWindowImage. A value of zero returns after
3933 % one call. A value of one causes the function to descend the window
3934 % hierarchy and overlay the target image with each subwindow image.
3937 static Image *XGetWindowImage(Display *display,const Window window,
3938 const unsigned int borders,const unsigned int level)
3940 typedef struct _ColormapInfo
3948 struct _ColormapInfo
3952 typedef struct _WindowInfo
3984 register IndexPacket
3991 *colormap_info = (ColormapInfo *) NULL;
4011 Verify window is viewable.
4013 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4014 assert(display != (Display *) NULL);
4015 status=XGetWindowAttributes(display,window,&window_attributes);
4016 if ((status == False) || (window_attributes.map_state != IsViewable))
4017 return((Image *) NULL);
4019 Cropping rectangle is relative to root window.
4021 root_window=XRootWindow(display,XDefaultScreen(display));
4022 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4024 crop_info.x=(ssize_t) x_offset;
4025 crop_info.y=(ssize_t) y_offset;
4026 crop_info.width=(size_t) window_attributes.width;
4027 crop_info.height=(size_t) window_attributes.height;
4028 if (borders != MagickFalse)
4031 Include border in image.
4033 crop_info.x-=(ssize_t) window_attributes.border_width;
4034 crop_info.y-=(ssize_t) window_attributes.border_width;
4035 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4036 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4039 Crop to root window.
4041 if (crop_info.x < 0)
4043 crop_info.width+=crop_info.x;
4046 if (crop_info.y < 0)
4048 crop_info.height+=crop_info.y;
4051 display_width=XDisplayWidth(display,XDefaultScreen(display));
4052 if ((int) (crop_info.x+crop_info.width) > display_width)
4053 crop_info.width=(size_t) (display_width-crop_info.x);
4054 display_height=XDisplayHeight(display,XDefaultScreen(display));
4055 if ((int) (crop_info.y+crop_info.height) > display_height)
4056 crop_info.height=(size_t) (display_height-crop_info.y);
4058 Initialize window info attributes.
4060 if (number_windows >= max_windows)
4063 Allocate or resize window info buffer.
4066 if (window_info == (WindowInfo *) NULL)
4067 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4068 sizeof(*window_info));
4070 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4071 max_windows,sizeof(*window_info));
4073 if (window_info == (WindowInfo *) NULL)
4075 ThrowXWindowFatalException(ResourceLimitError,
4076 "MemoryAllocationFailed","...");
4077 return((Image *) NULL);
4079 id=number_windows++;
4080 window_info[id].window=window;
4081 window_info[id].visual=window_attributes.visual;
4082 window_info[id].colormap=window_attributes.colormap;
4083 window_info[id].bounds.x1=(short) crop_info.x;
4084 window_info[id].bounds.y1=(short) crop_info.y;
4085 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4086 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4087 crop_info.x-=x_offset;
4088 crop_info.y-=y_offset;
4089 window_info[id].crop_info=crop_info;
4099 Descend the window hierarchy.
4101 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4102 &children,&number_children);
4103 for (i=0; i < id; i++)
4104 if ((window_info[i].window == window_info[id].parent) &&
4105 (window_info[i].visual == window_info[id].visual) &&
4106 (window_info[i].colormap == window_info[id].colormap))
4108 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4109 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4110 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4111 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4114 Eliminate windows not circumscribed by their parent.
4120 if ((status == True) && (number_children != 0))
4122 for (i=0; i < (int) number_children; i++)
4123 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4124 (void) XFree((void *) children);
4152 register PixelPacket
4168 Get X image for each window in the list.
4170 image=NewImageList();
4171 for (id=0; id < number_windows; id++)
4174 Does target window intersect top level window?
4177 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4178 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4179 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4180 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4181 MagickTrue : MagickFalse;
4183 Is target window contained by another window with the same colormap?
4185 for (j=0; j < id; j++)
4186 if ((window_info[id].visual == window_info[j].visual) &&
4187 (window_info[id].colormap == window_info[j].colormap))
4189 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4190 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4191 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4192 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4196 if ((window_info[id].visual != window_info[j].visual) ||
4197 (window_info[id].colormap != window_info[j].colormap))
4199 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4200 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4201 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4202 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4205 if (import == MagickFalse)
4210 ximage=XGetImage(display,window_info[id].window,(int)
4211 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4212 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4213 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4214 if (ximage == (XImage *) NULL)
4217 Initialize window colormap.
4220 colors=(XColor *) NULL;
4221 if (window_info[id].colormap != (Colormap) NULL)
4227 Search colormap list for window colormap.
4229 number_colors=(unsigned int) window_info[id].visual->map_entries;
4230 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4231 if (p->colormap == window_info[id].colormap)
4233 if (p == (ColormapInfo *) NULL)
4236 Get the window colormap.
4238 colors=(XColor *) AcquireQuantumMemory(number_colors,
4240 if (colors == (XColor *) NULL)
4242 XDestroyImage(ximage);
4243 return((Image *) NULL);
4245 if ((window_info[id].visual->klass != DirectColor) &&
4246 (window_info[id].visual->klass != TrueColor))
4247 for (i=0; i < (int) number_colors; i++)
4249 colors[i].pixel=(size_t) i;
4263 DirectColor or TrueColor visual.
4268 red_bit=window_info[id].visual->red_mask &
4269 (~(window_info[id].visual->red_mask)+1);
4270 green_bit=window_info[id].visual->green_mask &
4271 (~(window_info[id].visual->green_mask)+1);
4272 blue_bit=window_info[id].visual->blue_mask &
4273 (~(window_info[id].visual->blue_mask)+1);
4274 for (i=0; i < (int) number_colors; i++)
4276 colors[i].pixel=(unsigned long) (red | green | blue);
4279 if (red > window_info[id].visual->red_mask)
4282 if (green > window_info[id].visual->green_mask)
4285 if (blue > window_info[id].visual->blue_mask)
4289 (void) XQueryColors(display,window_info[id].colormap,colors,
4290 (int) number_colors);
4292 Append colormap to colormap list.
4294 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4295 if (p == (ColormapInfo *) NULL)
4296 return((Image *) NULL);
4297 p->colormap=window_info[id].colormap;
4299 p->next=colormap_info;
4305 Allocate image structure.
4307 composite_image=AcquireImage((ImageInfo *) NULL);
4308 if (composite_image == (Image *) NULL)
4310 XDestroyImage(ximage);
4311 return((Image *) NULL);
4314 Convert X image to MIFF format.
4316 if ((window_info[id].visual->klass != TrueColor) &&
4317 (window_info[id].visual->klass != DirectColor))
4318 composite_image->storage_class=PseudoClass;
4319 composite_image->columns=(size_t) ximage->width;
4320 composite_image->rows=(size_t) ximage->height;
4321 exception=(&composite_image->exception);
4322 composite_view=AcquireCacheView(composite_image);
4323 switch (composite_image->storage_class)
4341 Determine shift and mask for red, green, and blue.
4343 red_mask=window_info[id].visual->red_mask;
4345 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4350 green_mask=window_info[id].visual->green_mask;
4352 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4357 blue_mask=window_info[id].visual->blue_mask;
4359 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4365 Convert X image to DirectClass packets.
4367 if ((number_colors != 0) &&
4368 (window_info[id].visual->klass == DirectColor))
4369 for (y=0; y < (int) composite_image->rows; y++)
4371 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4372 composite_image->columns,1,exception);
4373 if (q == (PixelPacket *) NULL)
4375 for (x=0; x < (int) composite_image->columns; x++)
4377 pixel=XGetPixel(ximage,x,y);
4378 index=(pixel >> red_shift) & red_mask;
4379 q->red=ScaleShortToQuantum(colors[index].red);
4380 index=(pixel >> green_shift) & green_mask;
4381 q->green=ScaleShortToQuantum(colors[index].green);
4382 index=(pixel >> blue_shift) & blue_mask;
4383 q->blue=ScaleShortToQuantum(colors[index].blue);
4386 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4390 for (y=0; y < (int) composite_image->rows; y++)
4392 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4393 composite_image->columns,1,exception);
4394 if (q == (PixelPacket *) NULL)
4396 for (x=0; x < (int) composite_image->columns; x++)
4398 pixel=XGetPixel(ximage,x,y);
4399 color=(pixel >> red_shift) & red_mask;
4400 color=(65535UL*color)/red_mask;
4401 q->red=ScaleShortToQuantum((unsigned short) color);
4402 color=(pixel >> green_shift) & green_mask;
4403 color=(65535UL*color)/green_mask;
4404 q->green=ScaleShortToQuantum((unsigned short) color);
4405 color=(pixel >> blue_shift) & blue_mask;
4406 color=(65535UL*color)/blue_mask;
4407 q->blue=ScaleShortToQuantum((unsigned short) color);
4410 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4420 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4422 XDestroyImage(ximage);
4423 composite_image=DestroyImage(composite_image);
4424 return((Image *) NULL);
4426 for (i=0; i < (int) composite_image->colors; i++)
4428 composite_image->colormap[colors[i].pixel].red=
4429 ScaleShortToQuantum(colors[i].red);
4430 composite_image->colormap[colors[i].pixel].green=
4431 ScaleShortToQuantum(colors[i].green);
4432 composite_image->colormap[colors[i].pixel].blue=
4433 ScaleShortToQuantum(colors[i].blue);
4436 Convert X image to PseudoClass packets.
4438 for (y=0; y < (int) composite_image->rows; y++)
4440 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4441 composite_image->columns,1,exception);
4442 if (q == (PixelPacket *) NULL)
4444 indexes=GetCacheViewAuthenticIndexQueue(composite_view);
4445 for (x=0; x < (int) composite_image->columns; x++)
4447 index=(IndexPacket) XGetPixel(ximage,x,y);
4449 *q++=composite_image->colormap[(ssize_t) index];
4451 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4457 composite_view=DestroyCacheView(composite_view);
4458 XDestroyImage(ximage);
4459 if (image == (Image *) NULL)
4461 image=composite_image;
4465 Composite any children in back-to-front order.
4467 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4468 &x_offset,&y_offset,&child);
4469 x_offset-=(int) crop_info.x;
4472 y_offset-=(int) crop_info.y;
4475 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4476 x_offset,(ssize_t) y_offset);
4479 Relinquish resources.
4481 while (colormap_info != (ColormapInfo *) NULL)
4483 next=colormap_info->next;
4484 colormap_info->colors=(XColor *)
4485 RelinquishMagickMemory(colormap_info->colors);
4486 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4490 Relinquish resources and restore initial state.
4492 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4495 colormap_info=(ColormapInfo *) NULL;
4498 return((Image *) NULL);
4502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4506 % X G e t W i n d o w I n f o %
4510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4512 % XGetWindowInfo() initializes the XWindowInfo structure.
4514 % The format of the XGetWindowInfo method is:
4516 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4517 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4518 % XResourceInfo *resource_info,XWindowInfo *window)
4519 % resource_info,window)
4521 % A description of each parameter follows:
4523 % o display: Specifies a connection to an X server; returned from
4526 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4527 % returned from XGetVisualInfo.
4529 % o map_info: If map_type is specified, this structure is initialized
4530 % with info from the Standard Colormap.
4532 % o pixel: Specifies a pointer to a XPixelInfo structure.
4534 % o font_info: Specifies a pointer to a XFontStruct structure.
4536 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4539 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4540 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4541 XResourceInfo *resource_info,XWindowInfo *window)
4544 Initialize window info.
4546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4547 assert(display != (Display *) NULL);
4548 assert(visual_info != (XVisualInfo *) NULL);
4549 assert(map_info != (XStandardColormap *) NULL);
4550 assert(pixel != (XPixelInfo *) NULL);
4551 assert(resource_info != (XResourceInfo *) NULL);
4552 assert(window != (XWindowInfo *) NULL);
4553 if (window->id != (Window) NULL)
4555 if (window->cursor != (Cursor) NULL)
4556 (void) XFreeCursor(display,window->cursor);
4557 if (window->busy_cursor != (Cursor) NULL)
4558 (void) XFreeCursor(display,window->busy_cursor);
4559 if (window->highlight_stipple != (Pixmap) NULL)
4560 (void) XFreePixmap(display,window->highlight_stipple);
4561 if (window->shadow_stipple != (Pixmap) NULL)
4562 (void) XFreePixmap(display,window->shadow_stipple);
4563 if (window->name == (char *) NULL)
4564 window->name=AcquireString("");
4565 if (window->icon_name == (char *) NULL)
4566 window->icon_name=AcquireString("");
4571 Initialize these attributes just once.
4573 window->id=(Window) NULL;
4574 if (window->name == (char *) NULL)
4575 window->name=AcquireString("");
4576 if (window->icon_name == (char *) NULL)
4577 window->icon_name=AcquireString("");
4578 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4579 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4580 window->ximage=(XImage *) NULL;
4581 window->matte_image=(XImage *) NULL;
4582 window->pixmap=(Pixmap) NULL;
4583 window->matte_pixmap=(Pixmap) NULL;
4584 window->mapped=MagickFalse;
4585 window->stasis=MagickFalse;
4586 window->shared_memory=MagickTrue;
4587 window->segment_info=(void *) NULL;
4588 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4593 if (window->segment_info == (void *) NULL)
4594 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4595 segment_info=(XShmSegmentInfo *) window->segment_info;
4596 segment_info[0].shmid=(-1);
4597 segment_info[0].shmaddr=(char *) NULL;
4598 segment_info[1].shmid=(-1);
4599 segment_info[1].shmaddr=(char *) NULL;
4604 Initialize these attributes every time function is called.
4606 window->screen=visual_info->screen;
4607 window->root=XRootWindow(display,visual_info->screen);
4608 window->visual=visual_info->visual;
4609 window->storage_class=(unsigned int) visual_info->klass;
4610 window->depth=(unsigned int) visual_info->depth;
4611 window->visual_info=visual_info;
4612 window->map_info=map_info;
4613 window->pixel_info=pixel;
4614 window->font_info=font_info;
4615 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4616 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4617 window->geometry=(char *) NULL;
4618 window->icon_geometry=(char *) NULL;
4619 if (resource_info->icon_geometry != (char *) NULL)
4620 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4621 window->crop_geometry=(char *) NULL;
4622 window->flags=(size_t) PSize;
4625 window->min_width=1;
4626 window->min_height=1;
4627 window->width_inc=1;
4628 window->height_inc=1;
4629 window->border_width=resource_info->border_width;
4630 window->annotate_context=pixel->annotate_context;
4631 window->highlight_context=pixel->highlight_context;
4632 window->widget_context=pixel->widget_context;
4633 window->shadow_stipple=(Pixmap) NULL;
4634 window->highlight_stipple=(Pixmap) NULL;
4635 window->use_pixmap=MagickTrue;
4636 window->immutable=MagickFalse;
4637 window->shape=MagickFalse;
4639 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4640 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4641 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4642 window->attributes.background_pixel=pixel->background_color.pixel;
4643 window->attributes.background_pixmap=(Pixmap) NULL;
4644 window->attributes.bit_gravity=ForgetGravity;
4645 window->attributes.backing_store=WhenMapped;
4646 window->attributes.save_under=MagickTrue;
4647 window->attributes.border_pixel=pixel->border_color.pixel;
4648 window->attributes.colormap=map_info->colormap;
4649 window->attributes.cursor=window->cursor;
4650 window->attributes.do_not_propagate_mask=NoEventMask;
4651 window->attributes.event_mask=NoEventMask;
4652 window->attributes.override_redirect=MagickFalse;
4653 window->attributes.win_gravity=NorthWestGravity;
4654 window->orphan=MagickFalse;
4658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4662 % X H i g h l i g h t E l l i p s e %
4666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4668 % XHighlightEllipse() puts a border on the X server around a region defined by
4671 % The format of the XHighlightEllipse method is:
4673 % void XHighlightEllipse(Display *display,Window window,
4674 % GC annotate_context,const RectangleInfo *highlight_info)
4676 % A description of each parameter follows:
4678 % o display: Specifies a connection to an X server; returned from
4681 % o window: Specifies a pointer to a Window structure.
4683 % o annotate_context: Specifies a pointer to a GC structure.
4685 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4686 % contains the extents of any highlighting rectangle.
4689 MagickExport void XHighlightEllipse(Display *display,Window window,
4690 GC annotate_context,const RectangleInfo *highlight_info)
4692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4693 assert(display != (Display *) NULL);
4694 assert(window != (Window) NULL);
4695 assert(annotate_context != (GC) NULL);
4696 assert(highlight_info != (RectangleInfo *) NULL);
4697 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4699 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4700 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4701 (unsigned int) highlight_info->height-1,0,360*64);
4702 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4703 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4704 (unsigned int) highlight_info->height-3,0,360*64);
4708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4712 % X H i g h l i g h t L i n e %
4716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4718 % XHighlightLine() puts a border on the X server around a region defined by
4721 % The format of the XHighlightLine method is:
4723 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4724 % const XSegment *highlight_info)
4726 % A description of each parameter follows:
4728 % o display: Specifies a connection to an X server; returned from
4731 % o window: Specifies a pointer to a Window structure.
4733 % o annotate_context: Specifies a pointer to a GC structure.
4735 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4736 % contains the extents of any highlighting rectangle.
4739 MagickExport void XHighlightLine(Display *display,Window window,
4740 GC annotate_context,const XSegment *highlight_info)
4742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4743 assert(display != (Display *) NULL);
4744 assert(window != (Window) NULL);
4745 assert(annotate_context != (GC) NULL);
4746 assert(highlight_info != (XSegment *) NULL);
4747 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4748 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4756 % X H i g h l i g h t R e c t a n g l e %
4760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4762 % XHighlightRectangle() puts a border on the X server around a region defined
4763 % by highlight_info.
4765 % The format of the XHighlightRectangle method is:
4767 % void XHighlightRectangle(Display *display,Window window,
4768 % GC annotate_context,const RectangleInfo *highlight_info)
4770 % A description of each parameter follows:
4772 % o display: Specifies a connection to an X server; returned from
4775 % o window: Specifies a pointer to a Window structure.
4777 % o annotate_context: Specifies a pointer to a GC structure.
4779 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4780 % contains the extents of any highlighting rectangle.
4783 MagickExport void XHighlightRectangle(Display *display,Window window,
4784 GC annotate_context,const RectangleInfo *highlight_info)
4786 assert(display != (Display *) NULL);
4787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4788 assert(window != (Window) NULL);
4789 assert(annotate_context != (GC) NULL);
4790 assert(highlight_info != (RectangleInfo *) NULL);
4791 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4793 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4794 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4795 (unsigned int) highlight_info->height-1);
4796 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4797 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4798 (unsigned int) highlight_info->height-3);
4802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4806 % X I m p o r t I m a g e %
4810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4812 % XImportImage() reads an image from an X window.
4814 % The format of the XImportImage method is:
4816 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4818 % A description of each parameter follows:
4820 % o image_info: the image info.
4822 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4825 MagickExport Image *XImportImage(const ImageInfo *image_info,
4826 XImportInfo *ximage_info)
4859 Open X server connection.
4861 assert(image_info != (const ImageInfo *) NULL);
4862 assert(image_info->signature == MagickSignature);
4863 if (image_info->debug != MagickFalse)
4864 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4865 image_info->filename);
4866 assert(ximage_info != (XImportInfo *) NULL);
4867 display=XOpenDisplay(image_info->server_name);
4868 if (display == (Display *) NULL)
4870 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4871 XDisplayName(image_info->server_name));
4872 return((Image *) NULL);
4875 Set our forgiving exception handler.
4877 (void) XSetErrorHandler(XError);
4879 Select target window.
4885 root=XRootWindow(display,XDefaultScreen(display));
4886 target=(Window) NULL;
4887 if ((image_info->filename != (char *) NULL) &&
4888 (*image_info->filename != '\0'))
4890 if (LocaleCompare(image_info->filename,"root") == 0)
4895 Select window by ID or name.
4897 if (isdigit((unsigned char) *image_info->filename) != 0)
4898 target=XWindowByID(display,root,(Window)
4899 strtol(image_info->filename,(char **) NULL,0));
4900 if (target == (Window) NULL)
4901 target=XWindowByName(display,root,image_info->filename);
4902 if (target == (Window) NULL)
4903 ThrowXWindowFatalException(XServerError,
4904 "NoWindowWithSpecifiedIDExists",image_info->filename);
4908 If target window is not defined, interactively select one.
4910 prior_target=target;
4911 if (target == (Window) NULL)
4912 target=XSelectWindow(display,&crop_info);
4913 if (target == (Window) NULL)
4914 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4915 image_info->filename);
4916 client=target; /* obsolete */
4922 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4923 if (status != False)
4931 Find window manager frame.
4933 status=XQueryTree(display,target,&root,&parent,&children,&d);
4934 if ((status != False) && (children != (Window *) NULL))
4935 (void) XFree((char *) children);
4936 if ((status == False) || (parent == (Window) NULL) ||
4944 client=XClientWindow(display,target);
4945 if (ximage_info->frame == MagickFalse)
4947 if ((ximage_info->frame == MagickFalse) &&
4948 (prior_target != MagickFalse))
4949 target=prior_target;
4950 XDelay(display,SuspendTime << 4);
4953 if (ximage_info->screen)
4965 Obtain window image directly from screen.
4967 status=XGetWindowAttributes(display,target,&window_attributes);
4968 if (status == False)
4970 ThrowXWindowFatalException(XServerError,
4971 "UnableToReadXWindowAttributes",image_info->filename);
4972 (void) XCloseDisplay(display);
4973 return((Image *) NULL);
4975 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4976 crop_info.x=(ssize_t) x;
4977 crop_info.y=(ssize_t) y;
4978 crop_info.width=(size_t) window_attributes.width;
4979 crop_info.height=(size_t) window_attributes.height;
4980 if (ximage_info->borders != 0)
4983 Include border in image.
4985 crop_info.x-=window_attributes.border_width;
4986 crop_info.y-=window_attributes.border_width;
4987 crop_info.width+=window_attributes.border_width << 1;
4988 crop_info.height+=window_attributes.border_width << 1;
4993 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4996 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4997 if ((status == True) && (number_windows > 0))
4999 ximage_info->descend=MagickTrue;
5000 (void) XFree ((char *) children);
5002 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5003 if (number_colormaps > 0)
5005 if (number_colormaps > 1)
5006 ximage_info->descend=MagickTrue;
5007 (void) XFree((char *) colormaps);
5010 Alert the user not to alter the screen.
5012 if (ximage_info->silent == MagickFalse)
5013 (void) XBell(display,0);
5015 Get image by window id.
5017 (void) XGrabServer(display);
5018 image=XGetWindowImage(display,target,ximage_info->borders,
5019 ximage_info->descend ? 1U : 0U);
5020 (void) XUngrabServer(display);
5021 if (image == (Image *) NULL)
5022 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5023 image_info->filename)
5026 (void) CopyMagickString(image->filename,image_info->filename,
5028 if ((crop_info.width != 0) && (crop_info.height != 0))
5035 Crop image as defined by the cropping rectangle.
5037 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5038 if (clone_image != (Image *) NULL)
5040 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5041 if (crop_image != (Image *) NULL)
5043 image=DestroyImage(image);
5048 status=XGetWMName(display,target,&window_name);
5051 if ((image_info->filename != (char *) NULL) &&
5052 (*image_info->filename == '\0'))
5053 (void) CopyMagickString(image->filename,(char *) window_name.value,
5054 (size_t) window_name.nitems+1);
5055 (void) XFree((void *) window_name.value);
5058 if (ximage_info->silent == MagickFalse)
5061 Alert the user we're done.
5063 (void) XBell(display,0);
5064 (void) XBell(display,0);
5066 (void) XCloseDisplay(display);
5071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5075 % X I n i t i a l i z e W i n d o w s %
5079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5081 % XInitializeWindows() initializes the XWindows structure.
5083 % The format of the XInitializeWindows method is:
5085 % XWindows *XInitializeWindows(Display *display,
5086 % XResourceInfo *resource_info)
5088 % A description of each parameter follows:
5090 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5092 % o display: Specifies a connection to an X server; returned from
5095 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5098 MagickExport XWindows *XInitializeWindows(Display *display,
5099 XResourceInfo *resource_info)
5108 Allocate windows structure.
5110 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5111 if (windows == (XWindows *) NULL)
5113 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5115 return((XWindows *) NULL);
5117 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5118 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5119 sizeof(*windows->pixel_info));
5120 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5121 sizeof(*windows->icon_pixel));
5122 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5123 sizeof(*windows->icon_resources));
5124 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5125 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5126 (windows->icon_resources == (XResourceInfo *) NULL))
5128 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5130 return((XWindows *) NULL);
5133 Initialize windows structure.
5135 windows->display=display;
5136 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5137 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5138 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5139 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5140 windows->im_remote_command=
5141 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5142 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5143 windows->im_update_colormap=
5144 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5145 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5146 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5147 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5148 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5149 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5150 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5151 (void) XSynchronize(display,IsWindows95());
5153 if (IsEventLogging())
5155 (void) XSynchronize(display,MagickTrue);
5156 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5157 GetMagickVersion((size_t *) NULL));
5158 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5159 (void) LogMagickEvent(X11Event,GetMagickModule(),
5160 " Window Manager: 0x%lx",windows->wm_protocols);
5161 (void) LogMagickEvent(X11Event,GetMagickModule(),
5162 " delete window: 0x%lx",windows->wm_delete_window);
5163 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5164 windows->wm_take_focus);
5165 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5166 windows->im_protocols);
5167 (void) LogMagickEvent(X11Event,GetMagickModule(),
5168 " remote command: 0x%lx",windows->im_remote_command);
5169 (void) LogMagickEvent(X11Event,GetMagickModule(),
5170 " update widget: 0x%lx",windows->im_update_widget);
5171 (void) LogMagickEvent(X11Event,GetMagickModule(),
5172 " update colormap: 0x%lx",windows->im_update_colormap);
5173 (void) LogMagickEvent(X11Event,GetMagickModule(),
5174 " former image: 0x%lx",windows->im_former_image);
5175 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5176 windows->im_next_image);
5177 (void) LogMagickEvent(X11Event,GetMagickModule(),
5178 " retain colors: 0x%lx",windows->im_retain_colors);
5179 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5181 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5182 windows->dnd_protocols);
5185 Allocate standard colormap.
5187 windows->map_info=XAllocStandardColormap();
5188 windows->icon_map=XAllocStandardColormap();
5189 if ((windows->map_info == (XStandardColormap *) NULL) ||
5190 (windows->icon_map == (XStandardColormap *) NULL))
5191 ThrowXWindowFatalException(ResourceLimitFatalError,
5192 "MemoryAllocationFailed","...");
5193 windows->map_info->colormap=(Colormap) NULL;
5194 windows->icon_map->colormap=(Colormap) NULL;
5195 windows->pixel_info->pixels=(unsigned long *) NULL;
5196 windows->pixel_info->annotate_context=(GC) NULL;
5197 windows->pixel_info->highlight_context=(GC) NULL;
5198 windows->pixel_info->widget_context=(GC) NULL;
5199 windows->font_info=(XFontStruct *) NULL;
5200 windows->icon_pixel->annotate_context=(GC) NULL;
5201 windows->icon_pixel->pixels=(unsigned long *) NULL;
5205 *windows->icon_resources=(*resource_info);
5206 windows->icon_resources->visual_type=(char *) "default";
5207 windows->icon_resources->colormap=SharedColormap;
5208 windows->visual_info=
5209 XBestVisualInfo(display,windows->map_info,resource_info);
5210 windows->icon_visual=
5211 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5212 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5213 (windows->icon_visual == (XVisualInfo *) NULL))
5214 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5215 resource_info->visual_type);
5216 if (IsEventLogging())
5218 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5219 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5220 windows->visual_info->visualid);
5221 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5222 XVisualClassName(windows->visual_info->klass));
5223 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5224 windows->visual_info->depth);
5225 (void) LogMagickEvent(X11Event,GetMagickModule(),
5226 " size of colormap: %d entries",windows->visual_info->colormap_size);
5227 (void) LogMagickEvent(X11Event,GetMagickModule(),
5228 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5229 windows->visual_info->red_mask,windows->visual_info->green_mask,
5230 windows->visual_info->blue_mask);
5231 (void) LogMagickEvent(X11Event,GetMagickModule(),
5232 " significant bits in color: %d bits",
5233 windows->visual_info->bits_per_rgb);
5236 Allocate class and manager hints.
5238 windows->class_hints=XAllocClassHint();
5239 windows->manager_hints=XAllocWMHints();
5240 if ((windows->class_hints == (XClassHint *) NULL) ||
5241 (windows->manager_hints == (XWMHints *) NULL))
5242 ThrowXWindowFatalException(ResourceLimitFatalError,
5243 "MemoryAllocationFailed","...");
5245 Determine group leader if we have one.
5247 root_window=XRootWindow(display,windows->visual_info->screen);
5248 windows->group_leader.id=(Window) NULL;
5249 if (resource_info->window_group != (char *) NULL)
5251 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5252 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5253 strtol((char *) resource_info->window_group,(char **) NULL,0));
5254 if (windows->group_leader.id == (Window) NULL)
5255 windows->group_leader.id=
5256 XWindowByName(display,root_window,resource_info->window_group);
5262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5266 % X M a k e C u r s o r %
5270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5272 % XMakeCursor() creates a crosshairs X11 cursor.
5274 % The format of the XMakeCursor method is:
5276 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5277 % char *background_color,char *foreground_color)
5279 % A description of each parameter follows:
5281 % o display: Specifies a connection to an X server; returned from
5284 % o window: Specifies the ID of the window for which the cursor is
5287 % o colormap: Specifies the ID of the colormap from which the background
5288 % and foreground color will be retrieved.
5290 % o background_color: Specifies the color to use for the cursor background.
5292 % o foreground_color: Specifies the color to use for the cursor foreground.
5295 MagickExport Cursor XMakeCursor(Display *display,Window window,
5296 Colormap colormap,char *background_color,char *foreground_color)
5298 #define scope_height 17
5299 #define scope_x_hot 8
5300 #define scope_y_hot 8
5301 #define scope_width 17
5303 static const unsigned char
5306 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5307 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5308 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5309 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5310 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5314 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5315 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5316 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5317 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5318 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5332 assert(display != (Display *) NULL);
5333 assert(window != (Window) NULL);
5334 assert(colormap != (Colormap) NULL);
5335 assert(background_color != (char *) NULL);
5336 assert(foreground_color != (char *) NULL);
5337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5338 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5340 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5341 scope_width,scope_height);
5342 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5344 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5345 return((Cursor) NULL);
5347 (void) XParseColor(display,colormap,background_color,&background);
5348 (void) XParseColor(display,colormap,foreground_color,&foreground);
5349 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5350 scope_x_hot,scope_y_hot);
5351 (void) XFreePixmap(display,source);
5352 (void) XFreePixmap(display,mask);
5357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5361 % X M a k e I m a g e %
5365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5367 % XMakeImage() creates an X11 image. If the image size differs from the X11
5368 % image size, the image is first resized.
5370 % The format of the XMakeImage method is:
5372 % MagickBooleanType XMakeImage(Display *display,
5373 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5374 % unsigned int width,unsigned int height)
5376 % A description of each parameter follows:
5378 % o display: Specifies a connection to an X server; returned from
5381 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5383 % o window: Specifies a pointer to a XWindowInfo structure.
5385 % o image: the image.
5387 % o width: Specifies the width in pixels of the rectangular area to
5390 % o height: Specifies the height in pixels of the rectangular area to
5394 MagickExport MagickBooleanType XMakeImage(Display *display,
5395 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5396 unsigned int width,unsigned int height)
5398 #define CheckOverflowException(length,width,height) \
5399 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5413 assert(display != (Display *) NULL);
5414 assert(resource_info != (XResourceInfo *) NULL);
5415 assert(window != (XWindowInfo *) NULL);
5417 assert(height != 0);
5418 if ((window->width == 0) || (window->height == 0))
5419 return(MagickFalse);
5421 Apply user transforms to the image.
5423 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5424 (void) XFlush(display);
5425 depth=(int) window->depth;
5426 if (window->destroy)
5427 window->image=DestroyImage(window->image);
5428 window->image=image;
5429 window->destroy=MagickFalse;
5430 if (window->image != (Image *) NULL)
5432 if (window->crop_geometry != (char *) NULL)
5443 window->image->page.x=0;
5444 window->image->page.y=0;
5445 (void) ParsePageGeometry(window->image,window->crop_geometry,
5446 &crop_info,&image->exception);
5447 crop_image=CropImage(window->image,&crop_info,&image->exception);
5448 if (crop_image != (Image *) NULL)
5450 if (window->image != image)
5451 window->image=DestroyImage(window->image);
5452 window->image=crop_image;
5453 window->destroy=MagickTrue;
5456 if ((width != (unsigned int) window->image->columns) ||
5457 (height != (unsigned int) window->image->rows))
5465 resize_image=NewImageList();
5466 if (window->pixel_info->colors != 0)
5467 resize_image=SampleImage(window->image,width,height,
5470 resize_image=ThumbnailImage(window->image,width,height,
5472 if (resize_image != (Image *) NULL)
5474 if (window->image != image)
5475 window->image=DestroyImage(window->image);
5476 window->image=resize_image;
5477 window->destroy=MagickTrue;
5480 width=(unsigned int) window->image->columns;
5481 assert((size_t) width == window->image->columns);
5482 height=(unsigned int) window->image->rows;
5483 assert((size_t) height == window->image->rows);
5488 ximage=(XImage *) NULL;
5489 format=(depth == 1) ? XYBitmap : ZPixmap;
5490 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5491 if (window->shared_memory != MagickFalse)
5496 segment_info=(XShmSegmentInfo *) window->segment_info;
5497 segment_info[1].shmid=(-1);
5498 segment_info[1].shmaddr=(char *) NULL;
5499 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5500 (char *) NULL,&segment_info[1],width,height);
5501 if (ximage == (XImage *) NULL)
5502 window->shared_memory=MagickFalse;
5503 length=(size_t) ximage->bytes_per_line*ximage->height;
5504 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5505 window->shared_memory=MagickFalse;
5506 if (window->shared_memory != MagickFalse)
5507 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5508 if (window->shared_memory != MagickFalse)
5509 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5510 if (segment_info[1].shmid < 0)
5511 window->shared_memory=MagickFalse;
5512 if (window->shared_memory != MagickFalse)
5513 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5516 if (ximage != (XImage *) NULL)
5517 XDestroyImage(ximage);
5518 ximage=(XImage *) NULL;
5519 if (segment_info[1].shmaddr)
5521 (void) shmdt(segment_info[1].shmaddr);
5522 segment_info[1].shmaddr=(char *) NULL;
5524 if (segment_info[1].shmid >= 0)
5526 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5527 segment_info[1].shmid=(-1);
5533 Allocate X image pixel data.
5535 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5536 if (window->shared_memory)
5544 (void) XSync(display,MagickFalse);
5545 xerror_alert=MagickFalse;
5546 segment_info=(XShmSegmentInfo *) window->segment_info;
5547 ximage->data=segment_info[1].shmaddr;
5548 segment_info[1].readOnly=MagickFalse;
5549 status=XShmAttach(display,&segment_info[1]);
5550 if (status != False)
5551 (void) XSync(display,MagickFalse);
5552 if ((status == False) || (xerror_alert != MagickFalse))
5554 window->shared_memory=MagickFalse;
5555 if (status != False)
5556 XShmDetach(display,&segment_info[1]);
5557 if (ximage != (XImage *) NULL)
5560 XDestroyImage(ximage);
5561 ximage=(XImage *) NULL;
5563 if (segment_info[1].shmid >= 0)
5565 if (segment_info[1].shmaddr != NULL)
5566 (void) shmdt(segment_info[1].shmaddr);
5567 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5568 segment_info[1].shmid=(-1);
5569 segment_info[1].shmaddr=(char *) NULL;
5574 if (window->shared_memory == MagickFalse)
5575 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5576 (char *) NULL,width,height,XBitmapPad(display),0);
5577 if (ximage == (XImage *) NULL)
5580 Unable to create X image.
5582 (void) XCheckDefineCursor(display,window->id,window->cursor);
5583 return(MagickFalse);
5585 length=(size_t) ximage->bytes_per_line*ximage->height;
5586 if (IsEventLogging())
5588 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5589 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5590 ximage->width,ximage->height);
5591 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5593 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5594 ximage->byte_order);
5595 (void) LogMagickEvent(X11Event,GetMagickModule(),
5596 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5597 ximage->bitmap_bit_order,ximage->bitmap_pad);
5598 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5600 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5601 ximage->bytes_per_line);
5602 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5603 ximage->bits_per_pixel);
5604 (void) LogMagickEvent(X11Event,GetMagickModule(),
5605 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5606 ximage->green_mask,ximage->blue_mask);
5608 if (window->shared_memory == MagickFalse)
5610 if (ximage->format != XYBitmap)
5611 ximage->data=(char *) AcquireQuantumMemory((size_t)
5612 ximage->bytes_per_line,(size_t) ximage->height);
5614 ximage->data=(char *) AcquireQuantumMemory((size_t)
5615 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5617 if (ximage->data == (char *) NULL)
5620 Unable to allocate pixel data.
5622 XDestroyImage(ximage);
5623 ximage=(XImage *) NULL;
5624 (void) XCheckDefineCursor(display,window->id,window->cursor);
5625 return(MagickFalse);
5627 if (window->ximage != (XImage *) NULL)
5630 Destroy previous X image.
5632 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5633 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5634 if (window->segment_info != (XShmSegmentInfo *) NULL)
5639 segment_info=(XShmSegmentInfo *) window->segment_info;
5640 if (segment_info[0].shmid >= 0)
5642 (void) XSync(display,MagickFalse);
5643 (void) XShmDetach(display,&segment_info[0]);
5644 (void) XSync(display,MagickFalse);
5645 if (segment_info[0].shmaddr != (char *) NULL)
5646 (void) shmdt(segment_info[0].shmaddr);
5647 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5648 segment_info[0].shmid=(-1);
5649 segment_info[0].shmaddr=(char *) NULL;
5650 window->ximage->data=(char *) NULL;
5654 if (window->ximage->data != (char *) NULL)
5655 free(window->ximage->data);
5656 window->ximage->data=(char *) NULL;
5657 XDestroyImage(window->ximage);
5658 window->ximage=(XImage *) NULL;
5660 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5661 if (window->segment_info != (XShmSegmentInfo *) NULL)
5666 segment_info=(XShmSegmentInfo *) window->segment_info;
5667 segment_info[0]=segment_info[1];
5670 window->ximage=ximage;
5671 matte_image=(XImage *) NULL;
5672 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5673 if ((window->image->matte != MagickFalse) &&
5674 ((int) width <= XDisplayWidth(display,window->screen)) &&
5675 ((int) height <= XDisplayHeight(display,window->screen)))
5680 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5681 (char *) NULL,width,height,XBitmapPad(display),0);
5682 if (IsEventLogging())
5684 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5685 (void) LogMagickEvent(X11Event,GetMagickModule(),
5686 " width, height: %dx%d",matte_image->width,matte_image->height);
5688 if (matte_image != (XImage *) NULL)
5691 Allocate matte image pixel data.
5693 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5694 matte_image->bytes_per_line*matte_image->depth,
5695 (size_t) matte_image->height);
5696 if (matte_image->data == (char *) NULL)
5698 XDestroyImage(matte_image);
5699 matte_image=(XImage *) NULL;
5703 if (window->matte_image != (XImage *) NULL)
5708 if (window->matte_image->data != (char *) NULL)
5709 free(window->matte_image->data);
5710 window->matte_image->data=(char *) NULL;
5711 XDestroyImage(window->matte_image);
5712 window->matte_image=(XImage *) NULL;
5714 window->matte_image=matte_image;
5715 if (window->matte_pixmap != (Pixmap) NULL)
5717 (void) XFreePixmap(display,window->matte_pixmap);
5718 window->matte_pixmap=(Pixmap) NULL;
5719 #if defined(MAGICKCORE_HAVE_SHAPE)
5720 if (window->shape != MagickFalse)
5721 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5724 window->stasis=MagickFalse;
5726 Convert pixels to X image data.
5728 if (window->image != (Image *) NULL)
5730 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5731 (ximage->bitmap_bit_order == LSBFirst)))
5732 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5735 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5738 if (window->matte_image != (XImage *) NULL)
5741 Create matte pixmap.
5743 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5744 if (window->matte_pixmap != (Pixmap) NULL)
5753 Copy matte image to matte pixmap.
5755 context_values.background=1;
5756 context_values.foreground=0;
5757 graphics_context=XCreateGC(display,window->matte_pixmap,
5758 (size_t) (GCBackground | GCForeground),&context_values);
5759 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5760 window->matte_image,0,0,0,0,width,height);
5761 (void) XFreeGC(display,graphics_context);
5762 #if defined(MAGICKCORE_HAVE_SHAPE)
5763 if (window->shape != MagickFalse)
5764 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5765 window->matte_pixmap,ShapeSet);
5769 (void) XMakePixmap(display,resource_info,window);
5773 (void) XCheckDefineCursor(display,window->id,window->cursor);
5778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5782 + X M a k e I m a g e L S B F i r s t %
5786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5788 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5789 % pixels are copied in least-significant bit and byte first order. The
5790 % server's scanline pad is respected. Rather than using one or two general
5791 % cases, many special cases are found here to help speed up the image
5794 % The format of the XMakeImageLSBFirst method is:
5796 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5798 % A description of each parameter follows:
5800 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5802 % o window: Specifies a pointer to a XWindowInfo structure.
5804 % o image: the image.
5806 % o ximage: Specifies a pointer to a XImage structure; returned from
5809 % o matte_image: Specifies a pointer to a XImage structure; returned from
5813 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5814 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5825 register const IndexPacket
5828 register const PixelPacket
5834 register unsigned char
5851 assert(resource_info != (XResourceInfo *) NULL);
5852 assert(window != (XWindowInfo *) NULL);
5853 assert(image != (Image *) NULL);
5854 if (image->debug != MagickFalse)
5855 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5857 if ((window->immutable == MagickFalse) &&
5858 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5861 size[MaxTextExtent];
5869 image_info=AcquireImageInfo();
5870 (void) CopyMagickString(image_info->filename,
5871 resource_info->image_info->texture != (char *) NULL ?
5872 resource_info->image_info->texture : "pattern:checkerboard",
5874 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
5875 image->columns,(double) image->rows);
5876 image_info->size=ConstantString(size);
5877 pattern=ReadImage(image_info,&image->exception);
5878 image_info=DestroyImageInfo(image_info);
5879 if (pattern != (Image *) NULL)
5881 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5882 if (canvas != (Image *) NULL)
5883 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5884 pattern=DestroyImage(pattern);
5887 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5888 ximage->bits_per_pixel) >> 3));
5889 map_info=window->map_info;
5890 pixels=window->pixel_info->pixels;
5891 q=(unsigned char *) ximage->data;
5893 canvas_view=AcquireCacheView(canvas);
5894 if (ximage->format == XYBitmap)
5896 register unsigned short
5904 Convert canvas to big-endian bitmap.
5906 background=(unsigned char)
5907 (XPixelIntensity(&window->pixel_info->foreground_color) <
5908 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5909 foreground=(unsigned char)
5910 (XPixelIntensity(&window->pixel_info->background_color) <
5911 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5912 polarity=(unsigned short) ((PixelIntensityToQuantum(
5913 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5914 if (canvas->colors == 2)
5915 polarity=PixelIntensity(&canvas->colormap[0]) <
5916 PixelIntensity(&canvas->colormap[1]);
5917 for (y=0; y < (int) canvas->rows; y++)
5919 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5920 &canvas->exception);
5921 if (p == (const PixelPacket *) NULL)
5923 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5926 for (x=0; x < (int) canvas->columns; x++)
5929 if (indexes[x] == (IndexPacket) polarity)
5947 if (window->pixel_info->colors != 0)
5948 switch (ximage->bits_per_pixel)
5952 register unsigned int
5956 Convert to 2 bit color-mapped X canvas.
5958 for (y=0; y < (int) canvas->rows; y++)
5960 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
5961 canvas->columns,1,&canvas->exception);
5962 if (p == (const PixelPacket *) NULL)
5964 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5966 for (x=0; x < (int) canvas->columns; x++)
5968 pixel=pixels[(ssize_t) indexes[x]] & 0x0f;
5973 *q=(unsigned char) pixel;
5979 *q|=(unsigned char) (pixel << 2);
5985 *q|=(unsigned char) (pixel << 4);
5991 *q|=(unsigned char) (pixel << 6);
6004 register unsigned int
6008 Convert to 4 bit color-mapped X canvas.
6010 for (y=0; y < (int) canvas->rows; y++)
6012 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6013 canvas->columns,1,&canvas->exception);
6014 if (p == (const PixelPacket *) NULL)
6016 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6018 for (x=0; x < (int) canvas->columns; x++)
6020 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6025 *q=(unsigned char) pixel;
6031 *q|=(unsigned char) (pixel << 4);
6046 Convert to 8 bit color-mapped X canvas.
6048 if (resource_info->color_recovery &&
6049 resource_info->quantize_info->dither)
6051 XDitherImage(canvas,ximage);
6054 for (y=0; y < (int) canvas->rows; y++)
6056 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6057 canvas->columns,1,&canvas->exception);
6058 if (p == (const PixelPacket *) NULL)
6060 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6061 for (x=0; x < (int) canvas->columns; x++)
6063 pixel=pixels[(ssize_t) indexes[x]];
6064 *q++=(unsigned char) pixel;
6075 register unsigned int
6079 channel[sizeof(size_t)];
6082 Convert to multi-byte color-mapped X canvas.
6084 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6085 for (y=0; y < (int) canvas->rows; y++)
6087 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6088 canvas->columns,1,&canvas->exception);
6089 if (p == (const PixelPacket *) NULL)
6091 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6092 for (x=0; x < (int) canvas->columns; x++)
6094 pixel=pixels[(ssize_t) indexes[x]];
6095 for (k=0; k < (int) bytes_per_pixel; k++)
6097 channel[k]=(unsigned char) pixel;
6100 for (k=0; k < (int) bytes_per_pixel; k++)
6109 switch (ximage->bits_per_pixel)
6113 register unsigned int
6117 Convert to contiguous 2 bit continuous-tone X canvas.
6119 for (y=0; y < (int) canvas->rows; y++)
6122 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6123 canvas->columns,1,&canvas->exception);
6124 if (p == (const PixelPacket *) NULL)
6126 for (x=0; x < (int) canvas->columns; x++)
6128 pixel=XGammaPixel(map_info,p);
6134 *q=(unsigned char) pixel;
6140 *q|=(unsigned char) (pixel << 2);
6146 *q|=(unsigned char) (pixel << 4);
6152 *q|=(unsigned char) (pixel << 6);
6166 register unsigned int
6170 Convert to contiguous 4 bit continuous-tone X canvas.
6172 for (y=0; y < (int) canvas->rows; y++)
6174 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6175 canvas->columns,1,&canvas->exception);
6176 if (p == (const PixelPacket *) NULL)
6179 for (x=0; x < (int) canvas->columns; x++)
6181 pixel=XGammaPixel(map_info,p);
6187 *q=(unsigned char) pixel;
6193 *q|=(unsigned char) (pixel << 4);
6209 Convert to contiguous 8 bit continuous-tone X canvas.
6211 if (resource_info->color_recovery &&
6212 resource_info->quantize_info->dither)
6214 XDitherImage(canvas,ximage);
6217 for (y=0; y < (int) canvas->rows; y++)
6219 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6220 canvas->columns,1,&canvas->exception);
6221 if (p == (const PixelPacket *) NULL)
6223 for (x=0; x < (int) canvas->columns; x++)
6225 pixel=XGammaPixel(map_info,p);
6226 *q++=(unsigned char) pixel;
6235 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6236 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6237 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6238 (map_info->blue_mult == 1))
6241 Convert to 32 bit continuous-tone X canvas.
6243 for (y=0; y < (int) canvas->rows; y++)
6245 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6246 canvas->columns,1,&canvas->exception);
6247 if (p == (const PixelPacket *) NULL)
6249 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6250 (blue_gamma != 1.0))
6253 Gamma correct canvas.
6255 for (x=(int) canvas->columns-1; x >= 0; x--)
6257 *q++=ScaleQuantumToChar(XBlueGamma(
6258 GetBluePixelComponent(p)));
6259 *q++=ScaleQuantumToChar(XGreenGamma(
6260 GetGreenPixelComponent(p)));
6261 *q++=ScaleQuantumToChar(XRedGamma(
6262 GetRedPixelComponent(p)));
6268 for (x=(int) canvas->columns-1; x >= 0; x--)
6270 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6271 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6272 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6279 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6280 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6281 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6282 (map_info->blue_mult == 65536L))
6285 Convert to 32 bit continuous-tone X canvas.
6287 for (y=0; y < (int) canvas->rows; y++)
6289 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6290 canvas->columns,1,&canvas->exception);
6291 if (p == (const PixelPacket *) NULL)
6293 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6294 (blue_gamma != 1.0))
6297 Gamma correct canvas.
6299 for (x=(int) canvas->columns-1; x >= 0; x--)
6301 *q++=ScaleQuantumToChar(XRedGamma(
6302 GetRedPixelComponent(p)));
6303 *q++=ScaleQuantumToChar(XGreenGamma(
6304 GetGreenPixelComponent(p)));
6305 *q++=ScaleQuantumToChar(XBlueGamma(
6306 GetBluePixelComponent(p)));
6312 for (x=(int) canvas->columns-1; x >= 0; x--)
6314 *q++=ScaleQuantumToChar((Quantum)
6315 GetRedPixelComponent(p));
6316 *q++=ScaleQuantumToChar((Quantum)
6317 GetGreenPixelComponent(p));
6318 *q++=ScaleQuantumToChar((Quantum)
6319 GetBluePixelComponent(p));
6330 register unsigned int
6334 channel[sizeof(size_t)];
6337 Convert to multi-byte continuous-tone X canvas.
6339 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6340 for (y=0; y < (int) canvas->rows; y++)
6342 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6343 canvas->columns,1,&canvas->exception);
6344 if (p == (PixelPacket *) NULL)
6346 for (x=0; x < (int) canvas->columns; x++)
6348 pixel=XGammaPixel(map_info,p);
6349 for (k=0; k < (int) bytes_per_pixel; k++)
6351 channel[k]=(unsigned char) pixel;
6354 for (k=0; k < (int) bytes_per_pixel; k++)
6364 if (matte_image != (XImage *) NULL)
6367 Initialize matte canvas.
6369 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6370 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6371 q=(unsigned char *) matte_image->data;
6372 for (y=0; y < (int) canvas->rows; y++)
6374 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6375 &canvas->exception);
6376 if (p == (const PixelPacket *) NULL)
6380 for (x=(int) canvas->columns-1; x >= 0; x--)
6383 if (p->opacity > (QuantumRange/2))
6399 canvas_view=DestroyCacheView(canvas_view);
6400 if (canvas != image)
6401 canvas=DestroyImage(canvas);
6405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6409 + X M a k e I m a g e M S B F i r s t %
6413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6415 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6416 % image pixels are copied in most-significant bit and byte first order. The
6417 % server's scanline pad is also respected. Rather than using one or two
6418 % general cases, many special cases are found here to help speed up the image
6421 % The format of the XMakeImageMSBFirst method is:
6423 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6425 % A description of each parameter follows:
6427 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6429 % o window: Specifies a pointer to a XWindowInfo structure.
6431 % o image: the image.
6433 % o ximage: Specifies a pointer to a XImage structure; returned from
6436 % o matte_image: Specifies a pointer to a XImage structure; returned from
6440 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6441 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6455 register const IndexPacket
6458 register const PixelPacket
6461 register unsigned char
6478 assert(resource_info != (XResourceInfo *) NULL);
6479 assert(window != (XWindowInfo *) NULL);
6480 assert(image != (Image *) NULL);
6481 if (image->debug != MagickFalse)
6482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6484 if ((window->immutable != MagickFalse) &&
6485 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6488 size[MaxTextExtent];
6496 image_info=AcquireImageInfo();
6497 (void) CopyMagickString(image_info->filename,
6498 resource_info->image_info->texture != (char *) NULL ?
6499 resource_info->image_info->texture : "pattern:checkerboard",
6501 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
6502 image->columns,(double) image->rows);
6503 image_info->size=ConstantString(size);
6504 pattern=ReadImage(image_info,&image->exception);
6505 image_info=DestroyImageInfo(image_info);
6506 if (pattern != (Image *) NULL)
6508 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6509 if (canvas != (Image *) NULL)
6510 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6511 pattern=DestroyImage(pattern);
6514 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6515 ((ximage->width*ximage->bits_per_pixel) >> 3));
6516 map_info=window->map_info;
6517 pixels=window->pixel_info->pixels;
6518 q=(unsigned char *) ximage->data;
6520 canvas_view=AcquireCacheView(canvas);
6521 if (ximage->format == XYBitmap)
6523 register unsigned short
6531 Convert canvas to big-endian bitmap.
6533 background=(unsigned char)
6534 (XPixelIntensity(&window->pixel_info->foreground_color) <
6535 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6536 foreground=(unsigned char)
6537 (XPixelIntensity(&window->pixel_info->background_color) <
6538 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6539 polarity=(unsigned short) ((PixelIntensityToQuantum(
6540 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6541 if (canvas->colors == 2)
6542 polarity=PixelIntensity(&canvas->colormap[0]) <
6543 PixelIntensity(&canvas->colormap[1]);
6544 for (y=0; y < (int) canvas->rows; y++)
6546 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6547 &canvas->exception);
6548 if (p == (const PixelPacket *) NULL)
6550 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6553 for (x=(int) canvas->columns-1; x >= 0; x--)
6556 if (indexes[x] == (IndexPacket) polarity)
6574 if (window->pixel_info->colors != 0)
6575 switch (ximage->bits_per_pixel)
6579 register unsigned int
6583 Convert to 2 bit color-mapped X canvas.
6585 for (y=0; y < (int) canvas->rows; y++)
6587 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6588 canvas->columns,1,&canvas->exception);
6589 if (p == (const PixelPacket *) NULL)
6591 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6593 for (x=0; x < (int) canvas->columns; x++)
6595 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6600 *q=(unsigned char) (pixel << 6);
6606 *q|=(unsigned char) (pixel << 4);
6612 *q|=(unsigned char) (pixel << 2);
6618 *q|=(unsigned char) pixel;
6631 register unsigned int
6635 Convert to 4 bit color-mapped X canvas.
6637 for (y=0; y < (int) canvas->rows; y++)
6639 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6640 canvas->columns,1,&canvas->exception);
6641 if (p == (const PixelPacket *) NULL)
6643 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6645 for (x=0; x < (int) canvas->columns; x++)
6647 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6652 *q=(unsigned char) (pixel << 4);
6658 *q|=(unsigned char) pixel;
6673 Convert to 8 bit color-mapped X canvas.
6675 if (resource_info->color_recovery &&
6676 resource_info->quantize_info->dither)
6678 XDitherImage(canvas,ximage);
6681 for (y=0; y < (int) canvas->rows; y++)
6683 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6684 canvas->columns,1,&canvas->exception);
6685 if (p == (const PixelPacket *) NULL)
6687 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6688 for (x=0; x < (int) canvas->columns; x++)
6690 pixel=pixels[(ssize_t) indexes[x]];
6691 *q++=(unsigned char) pixel;
6702 register unsigned int
6706 channel[sizeof(size_t)];
6709 Convert to 8 bit color-mapped X canvas.
6711 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6712 for (y=0; y < (int) canvas->rows; y++)
6714 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6715 canvas->columns,1,&canvas->exception);
6716 if (p == (const PixelPacket *) NULL)
6718 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6719 for (x=0; x < (int) canvas->columns; x++)
6721 pixel=pixels[(ssize_t) indexes[x]];
6722 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6724 channel[k]=(unsigned char) pixel;
6727 for (k=0; k < (int) bytes_per_pixel; k++)
6736 switch (ximage->bits_per_pixel)
6740 register unsigned int
6744 Convert to 4 bit continuous-tone X canvas.
6746 for (y=0; y < (int) canvas->rows; y++)
6748 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6749 canvas->columns,1,&canvas->exception);
6750 if (p == (const PixelPacket *) NULL)
6753 for (x=(int) canvas->columns-1; x >= 0; x--)
6755 pixel=XGammaPixel(map_info,p);
6761 *q=(unsigned char) (pixel << 6);
6767 *q|=(unsigned char) (pixel << 4);
6773 *q|=(unsigned char) (pixel << 2);
6779 *q|=(unsigned char) pixel;
6793 register unsigned int
6797 Convert to 4 bit continuous-tone X canvas.
6799 for (y=0; y < (int) canvas->rows; y++)
6801 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6802 canvas->columns,1,&canvas->exception);
6803 if (p == (const PixelPacket *) NULL)
6806 for (x=(int) canvas->columns-1; x >= 0; x--)
6808 pixel=XGammaPixel(map_info,p);
6814 *q=(unsigned char) (pixel << 4);
6820 *q|=(unsigned char) pixel;
6836 Convert to 8 bit continuous-tone X canvas.
6838 if (resource_info->color_recovery &&
6839 resource_info->quantize_info->dither)
6841 XDitherImage(canvas,ximage);
6844 for (y=0; y < (int) canvas->rows; y++)
6846 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6847 canvas->columns,1,&canvas->exception);
6848 if (p == (const PixelPacket *) NULL)
6850 for (x=(int) canvas->columns-1; x >= 0; x--)
6852 pixel=XGammaPixel(map_info,p);
6853 *q++=(unsigned char) pixel;
6862 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6863 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6864 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6865 (map_info->blue_mult == 1))
6868 Convert to 32 bit continuous-tone X canvas.
6870 for (y=0; y < (int) canvas->rows; y++)
6872 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6873 canvas->columns,1,&canvas->exception);
6874 if (p == (const PixelPacket *) NULL)
6876 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6877 (blue_gamma != 1.0))
6880 Gamma correct canvas.
6882 for (x=(int) canvas->columns-1; x >= 0; x--)
6885 *q++=ScaleQuantumToChar(XRedGamma(
6886 GetRedPixelComponent(p)));
6887 *q++=ScaleQuantumToChar(XGreenGamma(
6888 GetGreenPixelComponent(p)));
6889 *q++=ScaleQuantumToChar(XBlueGamma(
6890 GetBluePixelComponent(p)));
6895 for (x=(int) canvas->columns-1; x >= 0; x--)
6898 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6899 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6900 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6906 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6907 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6908 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6909 (map_info->blue_mult == 65536L))
6912 Convert to 32 bit continuous-tone X canvas.
6914 for (y=0; y < (int) canvas->rows; y++)
6916 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6917 canvas->columns,1,&canvas->exception);
6918 if (p == (const PixelPacket *) NULL)
6920 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6921 (blue_gamma != 1.0))
6924 Gamma correct canvas.
6926 for (x=(int) canvas->columns-1; x >= 0; x--)
6929 *q++=ScaleQuantumToChar(XBlueGamma(
6930 GetBluePixelComponent(p)));
6931 *q++=ScaleQuantumToChar(XGreenGamma(
6932 GetGreenPixelComponent(p)));
6933 *q++=ScaleQuantumToChar(XRedGamma(
6934 GetRedPixelComponent(p)));
6939 for (x=(int) canvas->columns-1; x >= 0; x--)
6942 *q++=ScaleQuantumToChar((Quantum)
6943 GetBluePixelComponent(p));
6944 *q++=ScaleQuantumToChar((Quantum)
6945 GetGreenPixelComponent(p));
6946 *q++=ScaleQuantumToChar((Quantum)
6947 GetRedPixelComponent(p));
6957 register unsigned int
6961 channel[sizeof(size_t)];
6964 Convert to multi-byte continuous-tone X canvas.
6966 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6967 for (y=0; y < (int) canvas->rows; y++)
6969 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6970 canvas->columns,1,&canvas->exception);
6971 if (p == (const PixelPacket *) NULL)
6973 for (x=(int) canvas->columns-1; x >= 0; x--)
6975 pixel=XGammaPixel(map_info,p);
6976 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6978 channel[k]=(unsigned char) pixel;
6981 for (k=0; k < (int) bytes_per_pixel; k++)
6991 if (matte_image != (XImage *) NULL)
6994 Initialize matte canvas.
6996 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6997 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6998 q=(unsigned char *) matte_image->data;
6999 for (y=0; y < (int) canvas->rows; y++)
7001 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7002 &canvas->exception);
7003 if (p == (const PixelPacket *) NULL)
7007 for (x=(int) canvas->columns-1; x >= 0; x--)
7010 if (p->opacity > (QuantumRange/2))
7026 canvas_view=DestroyCacheView(canvas_view);
7027 if (canvas != image)
7028 canvas=DestroyImage(canvas);
7032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7036 % X M a k e M a g n i f y I m a g e %
7040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7042 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7044 % The format of the XMakeMagnifyImage method is:
7046 % void XMakeMagnifyImage(display,windows)
7048 % A description of each parameter follows:
7050 % o display: Specifies a connection to an X server; returned from
7053 % o windows: Specifies a pointer to a XWindows structure.
7056 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7059 tuple[MaxTextExtent];
7076 register unsigned char
7081 previous_magnify = 0;
7099 Check boundary conditions.
7101 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7102 assert(display != (Display *) NULL);
7103 assert(windows != (XWindows *) NULL);
7105 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7107 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7109 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7111 while (magnify > windows->magnify.width)
7113 while (magnify > windows->magnify.height)
7115 if (magnify != previous_magnify)
7124 New magnify factor: update magnify window name.
7127 while ((1 << i) <= (int) magnify)
7129 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7130 "Magnify %.20gX",(double) i);
7131 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7132 if (status != False)
7134 XSetWMName(display,windows->magnify.id,&window_name);
7135 XSetWMIconName(display,windows->magnify.id,&window_name);
7136 (void) XFree((void *) window_name.value);
7139 previous_magnify=magnify;
7140 ximage=windows->image.ximage;
7141 width=(unsigned int) windows->magnify.ximage->width;
7142 height=(unsigned int) windows->magnify.ximage->height;
7143 if ((windows->magnify.x < 0) ||
7144 (windows->magnify.x >= windows->image.ximage->width))
7145 windows->magnify.x=windows->image.ximage->width >> 1;
7146 x=windows->magnify.x-((width/magnify) >> 1);
7150 if (x > (int) (ximage->width-(width/magnify)))
7151 x=ximage->width-width/magnify;
7152 if ((windows->magnify.y < 0) ||
7153 (windows->magnify.y >= windows->image.ximage->height))
7154 windows->magnify.y=windows->image.ximage->height >> 1;
7155 y=windows->magnify.y-((height/magnify) >> 1);
7159 if (y > (int) (ximage->height-(height/magnify)))
7160 y=ximage->height-height/magnify;
7161 q=(unsigned char *) windows->magnify.ximage->data;
7162 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7163 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7164 if (ximage->bits_per_pixel < 8)
7166 register unsigned char
7173 register unsigned int
7179 pixel_info=windows->magnify.pixel_info;
7180 switch (ximage->bitmap_bit_order)
7185 Magnify little-endian bitmap.
7189 if (ximage->format == XYBitmap)
7191 background=(unsigned char)
7192 (XPixelIntensity(&pixel_info->foreground_color) <
7193 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7194 foreground=(unsigned char)
7195 (XPixelIntensity(&pixel_info->background_color) <
7196 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7197 if (windows->magnify.depth > 1)
7198 Swap(background,foreground);
7200 for (i=0; i < (ssize_t) height; i+=magnify)
7203 Propogate pixel magnify rows.
7205 for (j=0; j < magnify; j++)
7207 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7208 ((x*ximage->bits_per_pixel) >> 3);
7209 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7212 for (k=0; k < width; k+=magnify)
7215 Propogate pixel magnify columns.
7217 for (l=0; l < magnify; l++)
7220 Propogate each bit plane.
7222 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7225 if (*p & (0x01 << (p_bit+plane)))
7238 p_bit+=ximage->bits_per_pixel;
7245 *q=byte >> (8-q_bit);
7257 Magnify big-endian bitmap.
7261 if (ximage->format == XYBitmap)
7263 background=(unsigned char)
7264 (XPixelIntensity(&pixel_info->foreground_color) <
7265 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7266 foreground=(unsigned char)
7267 (XPixelIntensity(&pixel_info->background_color) <
7268 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7269 if (windows->magnify.depth > 1)
7270 Swap(background,foreground);
7272 for (i=0; i < (ssize_t) height; i+=magnify)
7275 Propogate pixel magnify rows.
7277 for (j=0; j < magnify; j++)
7279 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7280 ((x*ximage->bits_per_pixel) >> 3);
7281 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7284 for (k=0; k < width; k+=magnify)
7287 Propogate pixel magnify columns.
7289 for (l=0; l < magnify; l++)
7292 Propogate each bit plane.
7294 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7297 if (*p & (0x80 >> (p_bit+plane)))
7310 p_bit+=ximage->bits_per_pixel;
7317 *q=byte << (8-q_bit);
7328 switch (ximage->bits_per_pixel)
7334 Magnify 8 bit X image.
7336 for (i=0; i < (ssize_t) height; i+=magnify)
7339 Propogate pixel magnify rows.
7341 for (j=0; j < magnify; j++)
7343 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7344 ((x*ximage->bits_per_pixel) >> 3);
7345 for (k=0; k < width; k+=magnify)
7348 Propogate pixel magnify columns.
7350 for (l=0; l < magnify; l++)
7362 register unsigned int
7367 Magnify multi-byte X image.
7369 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7370 for (i=0; i < (ssize_t) height; i+=magnify)
7373 Propogate pixel magnify rows.
7375 for (j=0; j < magnify; j++)
7377 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7378 ((x*ximage->bits_per_pixel) >> 3);
7379 for (k=0; k < width; k+=magnify)
7382 Propogate pixel magnify columns.
7384 for (l=0; l < magnify; l++)
7385 for (m=0; m < bytes_per_pixel; m++)
7397 Copy X image to magnify pixmap.
7399 x=windows->magnify.x-((width/magnify) >> 1);
7401 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7403 if (x > (int) (ximage->width-(width/magnify)))
7404 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7407 y=windows->magnify.y-((height/magnify) >> 1);
7409 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7411 if (y > (int) (ximage->height-(height/magnify)))
7412 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7415 if ((x != 0) || (y != 0))
7416 (void) XFillRectangle(display,windows->magnify.pixmap,
7417 windows->magnify.annotate_context,0,0,width,height);
7418 (void) XPutImage(display,windows->magnify.pixmap,
7419 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7421 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7422 (magnify <= (height >> 1))))
7428 Highlight center pixel.
7430 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7431 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7432 highlight_info.width=magnify;
7433 highlight_info.height=magnify;
7434 (void) XDrawRectangle(display,windows->magnify.pixmap,
7435 windows->magnify.highlight_context,(int) highlight_info.x,
7436 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7437 (unsigned int) highlight_info.height-1);
7439 (void) XDrawRectangle(display,windows->magnify.pixmap,
7440 windows->magnify.annotate_context,(int) highlight_info.x+1,
7441 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7442 (unsigned int) highlight_info.height-3);
7445 Show center pixel color.
7447 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7448 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7449 &windows->image.image->exception);
7450 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7451 windows->magnify.x,windows->magnify.y);
7452 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7453 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7454 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7455 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7456 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7457 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7458 if (pixel.colorspace == CMYKColorspace)
7460 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7461 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7463 if (pixel.matte != MagickFalse)
7465 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7466 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7468 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7469 height=(unsigned int) windows->magnify.font_info->ascent+
7470 windows->magnify.font_info->descent;
7471 x=windows->magnify.font_info->max_bounds.width >> 1;
7472 y=windows->magnify.font_info->ascent+(height >> 2);
7473 (void) XDrawImageString(display,windows->magnify.pixmap,
7474 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7475 GetColorTuple(&pixel,MagickTrue,tuple);
7477 (void) XDrawImageString(display,windows->magnify.pixmap,
7478 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7479 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7480 &windows->image.image->exception);
7482 (void) XDrawImageString(display,windows->magnify.pixmap,
7483 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7485 Refresh magnify window.
7487 magnify_window=windows->magnify;
7490 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7498 % X M a k e P i x m a p %
7502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7504 % XMakePixmap() creates an X11 pixmap.
7506 % The format of the XMakePixmap method is:
7508 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7509 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7510 % XPixelInfo *pixel)
7512 % A description of each parameter follows:
7514 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7516 % o display: Specifies a connection to an X server; returned from
7519 % o window: Specifies a pointer to a XWindowInfo structure.
7522 static MagickBooleanType XMakePixmap(Display *display,
7523 const XResourceInfo *resource_info,XWindowInfo *window)
7529 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7530 assert(display != (Display *) NULL);
7531 assert(resource_info != (XResourceInfo *) NULL);
7532 assert(window != (XWindowInfo *) NULL);
7533 if (window->pixmap != (Pixmap) NULL)
7536 Destroy previous X pixmap.
7538 (void) XFreePixmap(display,window->pixmap);
7539 window->pixmap=(Pixmap) NULL;
7541 if (window->use_pixmap == MagickFalse)
7542 return(MagickFalse);
7543 if (window->ximage == (XImage *) NULL)
7544 return(MagickFalse);
7546 Display busy cursor.
7548 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7549 (void) XFlush(display);
7553 width=(unsigned int) window->ximage->width;
7554 height=(unsigned int) window->ximage->height;
7555 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7556 if (window->pixmap == (Pixmap) NULL)
7559 Unable to allocate pixmap.
7561 (void) XCheckDefineCursor(display,window->id,window->cursor);
7562 return(MagickFalse);
7565 Copy X image to pixmap.
7567 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7568 if (window->shared_memory)
7569 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7570 window->ximage,0,0,0,0,width,height,MagickTrue);
7572 if (window->shared_memory == MagickFalse)
7573 (void) XPutImage(display,window->pixmap,window->annotate_context,
7574 window->ximage,0,0,0,0,width,height);
7575 if (IsEventLogging())
7577 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7578 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7584 (void) XCheckDefineCursor(display,window->id,window->cursor);
7589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7593 % X M a k e S t a n d a r d C o l o r m a p %
7597 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7599 % XMakeStandardColormap() creates an X11 Standard Colormap.
7601 % The format of the XMakeStandardColormap method is:
7603 % XMakeStandardColormap(display,visual_info,resource_info,image,
7606 % A description of each parameter follows:
7608 % o display: Specifies a connection to an X server; returned from
7611 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7612 % returned from XGetVisualInfo.
7614 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7616 % o image: the image.
7618 % o map_info: If a Standard Colormap type is specified, this structure is
7619 % initialized with info from the Standard Colormap.
7621 % o pixel: Specifies a pointer to a XPixelInfo structure.
7625 #if defined(__cplusplus) || defined(c_plusplus)
7629 static inline MagickRealType DiversityPixelIntensity(
7630 const DiversityPacket *pixel)
7635 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7639 static int IntensityCompare(const void *x,const void *y)
7648 color_1=(DiversityPacket *) x;
7649 color_2=(DiversityPacket *) y;
7650 diversity=(int) (DiversityPixelIntensity(color_2)-
7651 DiversityPixelIntensity(color_1));
7655 static int PopularityCompare(const void *x,const void *y)
7661 color_1=(DiversityPacket *) x;
7662 color_2=(DiversityPacket *) y;
7663 return((int) color_2->count-(int) color_1->count);
7666 #if defined(__cplusplus) || defined(c_plusplus)
7670 static inline Quantum ScaleXToQuantum(const size_t x,
7673 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7676 MagickExport void XMakeStandardColormap(Display *display,
7677 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7678 XStandardColormap *map_info,XPixelInfo *pixel)
7686 register IndexPacket
7707 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7708 assert(display != (Display *) NULL);
7709 assert(visual_info != (XVisualInfo *) NULL);
7710 assert(map_info != (XStandardColormap *) NULL);
7711 assert(resource_info != (XResourceInfo *) NULL);
7712 assert(pixel != (XPixelInfo *) NULL);
7713 exception=(&image->exception);
7714 if (resource_info->map_type != (char *) NULL)
7717 Standard Colormap is already defined (i.e. xstdcmap).
7719 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7721 number_colors=(unsigned int) (map_info->base_pixel+
7722 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7723 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7724 if ((image->matte == MagickFalse) &&
7725 (resource_info->color_recovery == MagickFalse) &&
7726 resource_info->quantize_info->dither &&
7727 (number_colors < MaxColormapSize))
7732 register PixelPacket
7736 Improve image appearance with error diffusion.
7738 affinity_image=AcquireImage((ImageInfo *) NULL);
7739 if (affinity_image == (Image *) NULL)
7740 ThrowXWindowFatalException(ResourceLimitFatalError,
7741 "UnableToDitherImage",image->filename);
7742 affinity_image->columns=number_colors;
7743 affinity_image->rows=1;
7745 Initialize colormap image.
7747 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7749 if (q != (PixelPacket *) NULL)
7751 for (i=0; i < (ssize_t) number_colors; i++)
7754 if (map_info->red_max != 0)
7755 q->red=ScaleXToQuantum((size_t) (i/
7756 map_info->red_mult),map_info->red_max);
7757 q->green=(Quantum) 0;
7758 if (map_info->green_max != 0)
7759 q->green=ScaleXToQuantum((size_t) ((i/
7760 map_info->green_mult) % (map_info->green_max+1)),
7761 map_info->green_max);
7762 q->blue=(Quantum) 0;
7763 if (map_info->blue_max != 0)
7764 q->blue=ScaleXToQuantum((size_t) (i %
7765 map_info->green_mult),map_info->blue_max);
7766 q->opacity=(Quantum) TransparentOpacity;
7769 (void) SyncAuthenticPixels(affinity_image,exception);
7770 (void) RemapImage(resource_info->quantize_info,image,
7773 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7775 (void) SetImageStorageClass(image,DirectClass);
7776 affinity_image=DestroyImage(affinity_image);
7778 if (IsEventLogging())
7780 (void) LogMagickEvent(X11Event,GetMagickModule(),
7781 "Standard Colormap:");
7782 (void) LogMagickEvent(X11Event,GetMagickModule(),
7783 " colormap id: 0x%lx",map_info->colormap);
7784 (void) LogMagickEvent(X11Event,GetMagickModule(),
7785 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7786 map_info->green_max,map_info->blue_max);
7787 (void) LogMagickEvent(X11Event,GetMagickModule(),
7788 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7789 map_info->green_mult,map_info->blue_mult);
7793 if ((visual_info->klass != DirectColor) &&
7794 (visual_info->klass != TrueColor))
7795 if ((image->storage_class == DirectClass) ||
7796 ((int) image->colors > visual_info->colormap_size))
7802 Image has more colors than the visual supports.
7804 quantize_info=(*resource_info->quantize_info);
7805 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7806 (void) QuantizeImage(&quantize_info,image);
7809 Free previous and create new colormap.
7811 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7812 colormap=XDefaultColormap(display,visual_info->screen);
7813 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7814 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7815 visual_info->visual,visual_info->klass == DirectColor ?
7816 AllocAll : AllocNone);
7817 if (colormap == (Colormap) NULL)
7818 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7821 Initialize the map and pixel info structures.
7823 XGetMapInfo(visual_info,colormap,map_info);
7824 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7826 Allocating colors in server colormap is based on visual class.
7828 switch (visual_info->klass)
7834 Define Standard Colormap for StaticGray or StaticColor visual.
7836 number_colors=image->colors;
7837 colors=(XColor *) AcquireQuantumMemory((size_t)
7838 visual_info->colormap_size,sizeof(*colors));
7839 if (colors == (XColor *) NULL)
7840 ThrowXWindowFatalException(ResourceLimitFatalError,
7841 "UnableToCreateColormap",image->filename);
7843 color.flags=(char) (DoRed | DoGreen | DoBlue);
7844 for (i=0; i < (ssize_t) image->colors; i++)
7846 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7847 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7848 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7849 if (visual_info->klass != StaticColor)
7851 gray_value=(unsigned short) XPixelIntensity(&color);
7852 color.red=gray_value;
7853 color.green=gray_value;
7854 color.blue=gray_value;
7856 status=XAllocColor(display,colormap,&color);
7857 if (status == False)
7859 colormap=XCopyColormapAndFree(display,colormap);
7860 (void) XAllocColor(display,colormap,&color);
7862 pixel->pixels[i]=color.pixel;
7874 Define Standard Colormap for GrayScale or PseudoColor visual.
7876 number_colors=image->colors;
7877 colors=(XColor *) AcquireQuantumMemory((size_t)
7878 visual_info->colormap_size,sizeof(*colors));
7879 if (colors == (XColor *) NULL)
7880 ThrowXWindowFatalException(ResourceLimitFatalError,
7881 "UnableToCreateColormap",image->filename);
7883 Preallocate our GUI colors.
7885 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7886 (void) XAllocColor(display,colormap,&pixel->background_color);
7887 (void) XAllocColor(display,colormap,&pixel->border_color);
7888 (void) XAllocColor(display,colormap,&pixel->matte_color);
7889 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7890 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7891 (void) XAllocColor(display,colormap,&pixel->depth_color);
7892 (void) XAllocColor(display,colormap,&pixel->trough_color);
7893 for (i=0; i < MaxNumberPens; i++)
7894 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7896 Determine if image colors will "fit" into X server colormap.
7898 colormap_type=resource_info->colormap;
7899 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7900 NULL,0,pixel->pixels,(unsigned int) image->colors);
7901 if (status != False)
7902 colormap_type=PrivateColormap;
7903 if (colormap_type == SharedColormap)
7924 Define Standard colormap for shared GrayScale or PseudoColor visual.
7926 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7927 sizeof(*diversity));
7928 if (diversity == (DiversityPacket *) NULL)
7929 ThrowXWindowFatalException(ResourceLimitFatalError,
7930 "UnableToCreateColormap",image->filename);
7931 for (i=0; i < (ssize_t) image->colors; i++)
7933 diversity[i].red=image->colormap[i].red;
7934 diversity[i].green=image->colormap[i].green;
7935 diversity[i].blue=image->colormap[i].blue;
7936 diversity[i].index=(unsigned short) i;
7937 diversity[i].count=0;
7939 image_view=AcquireCacheView(image);
7940 for (y=0; y < (int) image->rows; y++)
7945 register const PixelPacket
7948 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7949 image->columns,1,exception);
7950 if (p == (const PixelPacket *) NULL)
7952 indexes=GetCacheViewAuthenticIndexQueue(image_view);
7953 for (x=(int) image->columns-1; x >= 0; x--)
7954 diversity[(ssize_t) indexes[x]].count++;
7956 image_view=DestroyCacheView(image_view);
7958 Sort colors by decreasing intensity.
7960 qsort((void *) diversity,image->colors,sizeof(*diversity),
7962 for (i=0; i < (ssize_t) image->colors; )
7964 diversity[i].count<<=4; /* increase this colors popularity */
7965 i+=MagickMax((int) (image->colors >> 4),2);
7967 diversity[image->colors-1].count<<=4;
7968 qsort((void *) diversity,image->colors,sizeof(*diversity),
7974 color.flags=(char) (DoRed | DoGreen | DoBlue);
7975 for (i=0; i < (ssize_t) image->colors; i++)
7977 index=diversity[i].index;
7979 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7981 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7983 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7984 if (visual_info->klass != PseudoColor)
7986 gray_value=(unsigned short) XPixelIntensity(&color);
7987 color.red=gray_value;
7988 color.green=gray_value;
7989 color.blue=gray_value;
7991 status=XAllocColor(display,colormap,&color);
7992 if (status == False)
7994 pixel->pixels[index]=color.pixel;
7998 Read X server colormap.
8000 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8001 visual_info->colormap_size,sizeof(*server_colors));
8002 if (server_colors == (XColor *) NULL)
8003 ThrowXWindowFatalException(ResourceLimitFatalError,
8004 "UnableToCreateColormap",image->filename);
8005 for (x=visual_info->colormap_size-1; x >= 0; x--)
8006 server_colors[x].pixel=(size_t) x;
8007 (void) XQueryColors(display,colormap,server_colors,
8008 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8010 Select remaining colors from X server colormap.
8012 for (; i < (ssize_t) image->colors; i++)
8014 index=diversity[i].index;
8016 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8018 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8020 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8021 if (visual_info->klass != PseudoColor)
8023 gray_value=(unsigned short) XPixelIntensity(&color);
8024 color.red=gray_value;
8025 color.green=gray_value;
8026 color.blue=gray_value;
8028 XBestPixel(display,colormap,server_colors,(unsigned int)
8029 visual_info->colormap_size,&color);
8030 pixel->pixels[index]=color.pixel;
8033 if ((int) image->colors < visual_info->colormap_size)
8036 Fill up colors array-- more choices for pen colors.
8038 retain_colors=MagickMin((unsigned int)
8039 (visual_info->colormap_size-image->colors),256);
8040 for (i=0; i < (ssize_t) retain_colors; i++)
8041 *p++=server_colors[i];
8042 number_colors+=retain_colors;
8044 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8045 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8049 Define Standard colormap for private GrayScale or PseudoColor visual.
8051 if (status == False)
8054 Not enough colormap entries in the colormap-- Create a new colormap.
8056 colormap=XCreateColormap(display,
8057 XRootWindow(display,visual_info->screen),visual_info->visual,
8059 if (colormap == (Colormap) NULL)
8060 ThrowXWindowFatalException(ResourceLimitFatalError,
8061 "UnableToCreateColormap",image->filename);
8062 map_info->colormap=colormap;
8063 if ((int) image->colors < visual_info->colormap_size)
8066 Retain colors from the default colormap to help lessens the
8067 effects of colormap flashing.
8069 retain_colors=MagickMin((unsigned int)
8070 (visual_info->colormap_size-image->colors),256);
8071 p=colors+image->colors;
8072 for (i=0; i < (ssize_t) retain_colors; i++)
8074 p->pixel=(unsigned long) i;
8077 (void) XQueryColors(display,
8078 XDefaultColormap(display,visual_info->screen),
8079 colors+image->colors,(int) retain_colors);
8081 Transfer colors from default to private colormap.
8083 (void) XAllocColorCells(display,colormap,MagickFalse,
8084 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8086 p=colors+image->colors;
8087 for (i=0; i < (ssize_t) retain_colors; i++)
8089 p->pixel=pixel->pixels[i];
8092 (void) XStoreColors(display,colormap,colors+image->colors,
8093 (int) retain_colors);
8094 number_colors+=retain_colors;
8096 (void) XAllocColorCells(display,colormap,MagickFalse,
8097 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8101 Store the image colormap.
8104 color.flags=(char) (DoRed | DoGreen | DoBlue);
8105 for (i=0; i < (ssize_t) image->colors; i++)
8107 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8108 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8109 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8110 if (visual_info->klass != PseudoColor)
8112 gray_value=(unsigned short) XPixelIntensity(&color);
8113 color.red=gray_value;
8114 color.green=gray_value;
8115 color.blue=gray_value;
8117 color.pixel=pixel->pixels[i];
8120 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8131 Define Standard Colormap for TrueColor or DirectColor visual.
8133 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8134 (map_info->green_max*map_info->green_mult)+
8135 (map_info->blue_max*map_info->blue_mult)+1);
8136 linear_colormap=(number_colors > 4096) ||
8137 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8138 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8139 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8140 MagickTrue : MagickFalse;
8141 if (linear_colormap != MagickFalse)
8142 number_colors=(size_t) visual_info->colormap_size;
8144 Allocate color array.
8146 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8147 if (colors == (XColor *) NULL)
8148 ThrowXWindowFatalException(ResourceLimitFatalError,
8149 "UnableToCreateColormap",image->filename);
8151 Initialize linear color ramp.
8154 color.flags=(char) (DoRed | DoGreen | DoBlue);
8155 if (linear_colormap != MagickFalse)
8156 for (i=0; i < (ssize_t) number_colors; i++)
8158 color.blue=(unsigned short) 0;
8159 if (map_info->blue_max != 0)
8160 color.blue=(unsigned short) ((size_t)
8161 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8162 color.green=color.blue;
8163 color.red=color.blue;
8164 color.pixel=XStandardPixel(map_info,&color);
8168 for (i=0; i < (ssize_t) number_colors; i++)
8170 color.red=(unsigned short) 0;
8171 if (map_info->red_max != 0)
8172 color.red=(unsigned short) ((size_t)
8173 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8174 color.green=(unsigned int) 0;
8175 if (map_info->green_max != 0)
8176 color.green=(unsigned short) ((size_t)
8177 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8178 map_info->green_max));
8179 color.blue=(unsigned short) 0;
8180 if (map_info->blue_max != 0)
8181 color.blue=(unsigned short) ((size_t)
8182 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8183 color.pixel=XStandardPixel(map_info,&color);
8186 if ((visual_info->klass == DirectColor) &&
8187 (colormap != XDefaultColormap(display,visual_info->screen)))
8188 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8190 for (i=0; i < (ssize_t) number_colors; i++)
8191 (void) XAllocColor(display,colormap,&colors[i]);
8195 if ((visual_info->klass != DirectColor) &&
8196 (visual_info->klass != TrueColor))
8199 Set foreground, background, border, etc. pixels.
8201 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8202 &pixel->foreground_color);
8203 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8204 &pixel->background_color);
8205 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8208 Foreground and background colors must differ.
8210 pixel->background_color.red=(~pixel->foreground_color.red);
8211 pixel->background_color.green=
8212 (~pixel->foreground_color.green);
8213 pixel->background_color.blue=
8214 (~pixel->foreground_color.blue);
8215 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8216 &pixel->background_color);
8218 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8219 &pixel->border_color);
8220 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8221 &pixel->matte_color);
8222 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8223 &pixel->highlight_color);
8224 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8225 &pixel->shadow_color);
8226 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8227 &pixel->depth_color);
8228 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8229 &pixel->trough_color);
8230 for (i=0; i < MaxNumberPens; i++)
8232 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8233 &pixel->pen_colors[i]);
8234 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8236 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8238 colors=(XColor *) RelinquishMagickMemory(colors);
8239 if (IsEventLogging())
8241 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8242 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8243 map_info->colormap);
8244 (void) LogMagickEvent(X11Event,GetMagickModule(),
8245 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8246 map_info->green_max,map_info->blue_max);
8247 (void) LogMagickEvent(X11Event,GetMagickModule(),
8248 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8249 map_info->green_mult,map_info->blue_mult);
8254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8258 % X M a k e W i n d o w %
8262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8264 % XMakeWindow() creates an X11 window.
8266 % The format of the XMakeWindow method is:
8268 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8269 % XClassHint *class_hint,XWMHints *manager_hints,
8270 % XWindowInfo *window_info)
8272 % A description of each parameter follows:
8274 % o display: Specifies a connection to an X server; returned from
8277 % o parent: Specifies the parent window_info.
8279 % o argv: Specifies the application's argument list.
8281 % o argc: Specifies the number of arguments.
8283 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8285 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8287 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8290 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8291 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8292 XWindowInfo *window_info)
8294 #define MinWindowSize 64
8302 static XTextProperty
8313 Set window info hints.
8315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8316 assert(display != (Display *) NULL);
8317 assert(window_info != (XWindowInfo *) NULL);
8318 size_hints=XAllocSizeHints();
8319 if (size_hints == (XSizeHints *) NULL)
8320 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8321 size_hints->flags=(int) window_info->flags;
8322 size_hints->x=window_info->x;
8323 size_hints->y=window_info->y;
8324 size_hints->width=(int) window_info->width;
8325 size_hints->height=(int) window_info->height;
8326 if (window_info->immutable != MagickFalse)
8329 Window size cannot be changed.
8331 size_hints->min_width=size_hints->width;
8332 size_hints->min_height=size_hints->height;
8333 size_hints->max_width=size_hints->width;
8334 size_hints->max_height=size_hints->height;
8335 size_hints->flags|=PMinSize;
8336 size_hints->flags|=PMaxSize;
8341 Window size can be changed.
8343 size_hints->min_width=(int) window_info->min_width;
8344 size_hints->min_height=(int) window_info->min_height;
8345 size_hints->flags|=PResizeInc;
8346 size_hints->width_inc=(int) window_info->width_inc;
8347 size_hints->height_inc=(int) window_info->height_inc;
8348 #if !defined(PRE_R4_ICCCM)
8349 size_hints->flags|=PBaseSize;
8350 size_hints->base_width=size_hints->width_inc;
8351 size_hints->base_height=size_hints->height_inc;
8354 gravity=NorthWestGravity;
8355 if (window_info->geometry != (char *) NULL)
8358 default_geometry[MaxTextExtent],
8359 geometry[MaxTextExtent];
8368 User specified geometry.
8370 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8371 size_hints->width,size_hints->height);
8372 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8374 while (strlen(p) != 0)
8376 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8379 (void) CopyMagickString(p,p+1,MaxTextExtent);
8381 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8382 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8383 &size_hints->width,&size_hints->height,&gravity);
8384 if ((flags & WidthValue) && (flags & HeightValue))
8385 size_hints->flags|=USSize;
8386 if ((flags & XValue) && (flags & YValue))
8388 size_hints->flags|=USPosition;
8389 window_info->x=size_hints->x;
8390 window_info->y=size_hints->y;
8393 #if !defined(PRE_R4_ICCCM)
8394 size_hints->win_gravity=gravity;
8395 size_hints->flags|=PWinGravity;
8397 if (window_info->id == (Window) NULL)
8398 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8399 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8400 window_info->border_width,(int) window_info->depth,InputOutput,
8401 window_info->visual,(unsigned long) window_info->mask,
8402 &window_info->attributes);
8415 Window already exists; change relevant attributes.
8417 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8418 window_info->mask,&window_info->attributes);
8419 mask=ConfigureNotify;
8420 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8421 window_changes.x=window_info->x;
8422 window_changes.y=window_info->y;
8423 window_changes.width=(int) window_info->width;
8424 window_changes.height=(int) window_info->height;
8425 mask=(MagickStatusType) (CWWidth | CWHeight);
8426 if (window_info->flags & USPosition)
8428 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8429 mask,&window_changes);
8431 if (window_info->id == (Window) NULL)
8432 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8434 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8435 if (status == False)
8436 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8438 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8439 if (status == False)
8440 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8441 window_info->icon_name);
8442 if (window_info->icon_geometry != (char *) NULL)
8450 User specified icon geometry.
8452 size_hints->flags|=USPosition;
8453 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8454 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8455 &manager_hints->icon_y,&width,&height,&gravity);
8456 if ((flags & XValue) && (flags & YValue))
8457 manager_hints->flags|=IconPositionHint;
8459 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8460 size_hints,manager_hints,class_hint);
8461 if (window_name.value != (void *) NULL)
8463 (void) XFree((void *) window_name.value);
8464 window_name.value=(unsigned char *) NULL;
8465 window_name.nitems=0;
8467 if (icon_name.value != (void *) NULL)
8469 (void) XFree((void *) icon_name.value);
8470 icon_name.value=(unsigned char *) NULL;
8473 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8474 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8475 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8476 (void) XFree((void *) size_hints);
8477 if (window_info->shape != MagickFalse)
8479 #if defined(MAGICKCORE_HAVE_SHAPE)
8485 Can we apply a non-rectangular shaping mask?
8489 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8490 window_info->shape=MagickFalse;
8492 window_info->shape=MagickFalse;
8495 if (window_info->shared_memory)
8497 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8499 Can we use shared memory with this window?
8501 if (XShmQueryExtension(display) == 0)
8502 window_info->shared_memory=MagickFalse;
8504 window_info->shared_memory=MagickFalse;
8507 window_info->image=NewImageList();
8508 window_info->destroy=MagickFalse;
8512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8516 % X M a g i c k P r o g r e s s M o n i t o r %
8520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8522 % XMagickProgressMonitor() displays the progress a task is making in
8523 % completing a task.
8525 % The format of the XMagickProgressMonitor method is:
8527 % void XMagickProgressMonitor(const char *task,
8528 % const MagickOffsetType quantum,const MagickSizeType span,
8529 % void *client_data)
8531 % A description of each parameter follows:
8533 % o task: Identifies the task in progress.
8535 % o quantum: Specifies the quantum position within the span which represents
8536 % how much progress has been made in completing a task.
8538 % o span: Specifies the span relative to completing a task.
8540 % o client_data: Pointer to any client data.
8544 static const char *GetLocaleMonitorMessage(const char *text)
8547 message[MaxTextExtent],
8556 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8558 if (p != (char *) NULL)
8560 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8561 locale_message=GetLocaleMessage(message);
8562 if (locale_message == message)
8564 return(locale_message);
8567 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8568 const MagickOffsetType quantum,const MagickSizeType span,
8569 void *magick_unused(client_data))
8574 windows=XSetWindows((XWindows *) ~0);
8575 if (windows == (XWindows *) NULL)
8577 if (windows->info.mapped != MagickFalse)
8578 XProgressMonitorWidget(windows->display,windows,
8579 GetLocaleMonitorMessage(tag),quantum,span);
8584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8588 % X Q u e r y C o l o r D a t a b a s e %
8592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8594 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8597 % The format of the XQueryColorDatabase method is:
8599 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8601 % A description of each parameter follows:
8603 % o target: Specifies the color to lookup in the X color database.
8605 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8606 % color is returned as this value.
8609 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8616 *display = (Display *) NULL;
8625 Initialize color return value.
8627 assert(color != (XColor *) NULL);
8631 color->flags=(char) (DoRed | DoGreen | DoBlue);
8632 if ((target == (char *) NULL) || (*target == '\0'))
8633 target="#ffffffffffff";
8635 Let the X server define the color for us.
8637 if (display == (Display *) NULL)
8638 display=XOpenDisplay((char *) NULL);
8639 if (display == (Display *) NULL)
8641 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8642 return(MagickFalse);
8644 colormap=XDefaultColormap(display,XDefaultScreen(display));
8645 status=XParseColor(display,colormap,(char *) target,&xcolor);
8646 if (status == False)
8647 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8650 color->red=xcolor.red;
8651 color->green=xcolor.green;
8652 color->blue=xcolor.blue;
8653 color->flags=xcolor.flags;
8655 return(status != False ? MagickTrue : MagickFalse);
8659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8663 % X Q u e r y P o s i t i o n %
8667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8669 % XQueryPosition() gets the pointer coordinates relative to a window.
8671 % The format of the XQueryPosition method is:
8673 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8675 % A description of each parameter follows:
8677 % o display: Specifies a connection to an X server; returned from
8680 % o window: Specifies a pointer to a Window.
8682 % o x: Return the x coordinate of the pointer relative to the origin of the
8685 % o y: Return the y coordinate of the pointer relative to the origin of the
8689 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8701 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8702 assert(display != (Display *) NULL);
8703 assert(window != (Window) NULL);
8704 assert(x != (int *) NULL);
8705 assert(y != (int *) NULL);
8706 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8715 % X R e f r e s h W i n d o w %
8719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8721 % XRefreshWindow() refreshes an image in a X window.
8723 % The format of the XRefreshWindow method is:
8725 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8726 % const XEvent *event)
8728 % A description of each parameter follows:
8730 % o display: Specifies a connection to an X server; returned from
8733 % o window: Specifies a pointer to a XWindowInfo structure.
8735 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8736 % the entire image is refreshed.
8739 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8740 const XEvent *event)
8750 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8751 assert(display != (Display *) NULL);
8752 assert(window != (XWindowInfo *) NULL);
8753 if (window->ximage == (XImage *) NULL)
8755 if (event != (XEvent *) NULL)
8758 Determine geometry from expose event.
8762 width=(unsigned int) event->xexpose.width;
8763 height=(unsigned int) event->xexpose.height;
8771 Refresh entire window; discard outstanding expose events.
8775 width=window->width;
8776 height=window->height;
8777 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8778 if (window->matte_pixmap != (Pixmap) NULL)
8780 #if defined(MAGICKCORE_HAVE_SHAPE)
8781 if (window->shape != MagickFalse)
8782 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8783 window->matte_pixmap,ShapeSet);
8788 Check boundary conditions.
8790 if ((window->ximage->width-(x+window->x)) < (int) width)
8791 width=(unsigned int) (window->ximage->width-(x+window->x));
8792 if ((window->ximage->height-(y+window->y)) < (int) height)
8793 height=(unsigned int) (window->ximage->height-(y+window->y));
8797 if (window->matte_pixmap != (Pixmap) NULL)
8798 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8799 if (window->pixmap != (Pixmap) NULL)
8801 if (window->depth > 1)
8802 (void) XCopyArea(display,window->pixmap,window->id,
8803 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8805 (void) XCopyPlane(display,window->pixmap,window->id,
8806 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8811 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8812 if (window->shared_memory)
8813 (void) XShmPutImage(display,window->id,window->annotate_context,
8814 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8816 if (window->shared_memory == MagickFalse)
8817 (void) XPutImage(display,window->id,window->annotate_context,
8818 window->ximage,x+window->x,y+window->y,x,y,width,height);
8820 if (window->matte_pixmap != (Pixmap) NULL)
8821 (void) XSetClipMask(display,window->annotate_context,None);
8822 (void) XFlush(display);
8826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8830 % X R e m o t e C o m m a n d %
8834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8836 % XRemoteCommand() forces a remote display(1) to display the specified
8839 % The format of the XRemoteCommand method is:
8841 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8842 % const char *filename)
8844 % A description of each parameter follows:
8846 % o display: Specifies a connection to an X server; returned from
8849 % o window: Specifies the name or id of an X window.
8851 % o filename: the name of the image filename to display.
8854 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8855 const char *window,const char *filename)
8864 assert(filename != (char *) NULL);
8865 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8866 if (display == (Display *) NULL)
8867 display=XOpenDisplay((char *) NULL);
8868 if (display == (Display *) NULL)
8870 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8871 return(MagickFalse);
8873 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8874 remote_window=(Window) NULL;
8875 root_window=XRootWindow(display,XDefaultScreen(display));
8876 if (window != (char *) NULL)
8879 Search window hierarchy and identify any clients by name or ID.
8881 if (isdigit((unsigned char) *window) != 0)
8882 remote_window=XWindowByID(display,root_window,(Window)
8883 strtol((char *) window,(char **) NULL,0));
8884 if (remote_window == (Window) NULL)
8885 remote_window=XWindowByName(display,root_window,window);
8887 if (remote_window == (Window) NULL)
8888 remote_window=XWindowByProperty(display,root_window,remote_atom);
8889 if (remote_window == (Window) NULL)
8891 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8893 return(MagickFalse);
8896 Send remote command.
8898 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8899 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8900 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8901 (void) XSync(display,MagickFalse);
8906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8910 % X R e t a i n W i n d o w C o l o r s %
8914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8916 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8917 % the colors associated with an image displayed on the window.
8919 % The format of the XRetainWindowColors method is:
8921 % void XRetainWindowColors(Display *display,const Window window)
8923 % A description of each parameter follows:
8925 % o display: Specifies a connection to an X server; returned from
8928 % o window: Specifies a pointer to a XWindowInfo structure.
8931 MagickExport void XRetainWindowColors(Display *display,const Window window)
8940 Put property on the window.
8942 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8943 assert(display != (Display *) NULL);
8944 assert(window != (Window) NULL);
8945 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8946 if (property == (Atom) NULL)
8948 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8952 pixmap=XCreatePixmap(display,window,1,1,1);
8953 if (pixmap == (Pixmap) NULL)
8955 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8958 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8959 (unsigned char *) &pixmap,1);
8960 (void) XSetCloseDownMode(display,RetainPermanent);
8964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8968 % X S e l e c t W i n d o w %
8972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8974 % XSelectWindow() allows a user to select a window using the mouse. If the
8975 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8976 % is returned in the crop_info structure.
8978 % The format of the XSelectWindow function is:
8980 % target_window=XSelectWindow(display,crop_info)
8982 % A description of each parameter follows:
8984 % o window: XSelectWindow returns the window id.
8986 % o display: Specifies a pointer to the Display structure; returned from
8989 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8990 % contains the extents of any cropping rectangle.
8993 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8995 #define MinimumCropArea (unsigned int) 9
9022 Initialize graphic context.
9024 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9025 assert(display != (Display *) NULL);
9026 assert(crop_info != (RectangleInfo *) NULL);
9027 root_window=XRootWindow(display,XDefaultScreen(display));
9028 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9029 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9030 context_values.function=GXinvert;
9031 context_values.plane_mask=
9032 context_values.background ^ context_values.foreground;
9033 context_values.subwindow_mode=IncludeInferiors;
9034 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9035 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9036 if (annotate_context == (GC) NULL)
9037 return(MagickFalse);
9039 Grab the pointer using target cursor.
9041 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9042 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9043 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9044 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9045 GrabModeAsync,root_window,target_cursor,CurrentTime);
9046 if (status != GrabSuccess)
9048 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9049 return((Window) NULL);
9055 crop_info->height=0;
9057 target_window=(Window) NULL;
9062 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9063 (void) XDrawRectangle(display,root_window,annotate_context,
9064 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9065 (unsigned int) crop_info->height-1);
9067 Allow another event.
9069 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9070 (void) XWindowEvent(display,root_window,ButtonPressMask |
9071 ButtonReleaseMask | ButtonMotionMask,&event);
9072 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9073 (void) XDrawRectangle(display,root_window,annotate_context,
9074 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9075 (unsigned int) crop_info->height-1);
9080 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9081 event.xbutton.x,event.xbutton.y);
9082 if (target_window == (Window) NULL)
9083 target_window=root_window;
9084 x_offset=event.xbutton.x_root;
9085 y_offset=event.xbutton.y_root;
9086 crop_info->x=(ssize_t) x_offset;
9087 crop_info->y=(ssize_t) y_offset;
9089 crop_info->height=0;
9101 Discard pending button motion events.
9103 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9104 crop_info->x=(ssize_t) event.xmotion.x;
9105 crop_info->y=(ssize_t) event.xmotion.y;
9107 Check boundary conditions.
9109 if ((int) crop_info->x < x_offset)
9110 crop_info->width=(size_t) (x_offset-crop_info->x);
9113 crop_info->width=(size_t) (crop_info->x-x_offset);
9114 crop_info->x=(ssize_t) x_offset;
9116 if ((int) crop_info->y < y_offset)
9117 crop_info->height=(size_t) (y_offset-crop_info->y);
9120 crop_info->height=(size_t) (crop_info->y-y_offset);
9121 crop_info->y=(ssize_t) y_offset;
9127 } while ((target_window == (Window) NULL) || (presses > 0));
9128 (void) XUngrabPointer(display,CurrentTime);
9129 (void) XFreeCursor(display,target_cursor);
9130 (void) XFreeGC(display,annotate_context);
9131 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9134 crop_info->height=0;
9136 if ((crop_info->width != 0) && (crop_info->height != 0))
9137 target_window=root_window;
9138 return(target_window);
9142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9146 % X S e t C u r s o r S t a t e %
9150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9152 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9153 % reset to their default.
9155 % The format of the XXSetCursorState method is:
9157 % XSetCursorState(display,windows,const MagickStatusType state)
9159 % A description of each parameter follows:
9161 % o display: Specifies a connection to an X server; returned from
9164 % o windows: Specifies a pointer to a XWindows structure.
9166 % o state: An unsigned integer greater than 0 sets the cursor state
9167 % to busy, otherwise the cursor are reset to their default.
9170 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9171 const MagickStatusType state)
9173 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9174 assert(display != (Display *) NULL);
9175 assert(windows != (XWindows *) NULL);
9178 (void) XCheckDefineCursor(display,windows->image.id,
9179 windows->image.busy_cursor);
9180 (void) XCheckDefineCursor(display,windows->pan.id,
9181 windows->pan.busy_cursor);
9182 (void) XCheckDefineCursor(display,windows->magnify.id,
9183 windows->magnify.busy_cursor);
9184 (void) XCheckDefineCursor(display,windows->command.id,
9185 windows->command.busy_cursor);
9189 (void) XCheckDefineCursor(display,windows->image.id,
9190 windows->image.cursor);
9191 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9192 (void) XCheckDefineCursor(display,windows->magnify.id,
9193 windows->magnify.cursor);
9194 (void) XCheckDefineCursor(display,windows->command.id,
9195 windows->command.cursor);
9196 (void) XCheckDefineCursor(display,windows->command.id,
9197 windows->widget.cursor);
9198 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9200 windows->info.mapped=MagickFalse;
9204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9208 % X S e t W i n d o w s %
9212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9214 % XSetWindows() sets the X windows structure if the windows info is specified.
9215 % Otherwise the current windows structure is returned.
9217 % The format of the XSetWindows method is:
9219 % XWindows *XSetWindows(XWindows *windows_info)
9221 % A description of each parameter follows:
9223 % o windows_info: Initialize the Windows structure with this information.
9226 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9229 *windows = (XWindows *) NULL;
9231 if (windows_info != (XWindows *) ~0)
9233 windows=(XWindows *) RelinquishMagickMemory(windows);
9234 windows=windows_info;
9239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9243 % X U s e r P r e f e r e n c e s %
9247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9249 % XUserPreferences() saves the preferences in a configuration file in the
9250 % users' home directory.
9252 % The format of the XUserPreferences method is:
9254 % void XUserPreferences(XResourceInfo *resource_info)
9256 % A description of each parameter follows:
9258 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9261 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9263 #if defined(X11_PREFERENCES_PATH)
9265 cache[MaxTextExtent],
9266 filename[MaxTextExtent],
9267 specifier[MaxTextExtent];
9274 preferences_database;
9277 Save user preferences to the client configuration file.
9279 assert(resource_info != (XResourceInfo *) NULL);
9280 client_name=GetClientName();
9281 preferences_database=XrmGetStringDatabase("");
9282 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9283 value=resource_info->backdrop ? "True" : "False";
9284 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9285 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9286 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9287 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9288 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9290 value=resource_info->confirm_exit ? "True" : "False";
9291 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9292 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9294 value=resource_info->confirm_edit ? "True" : "False";
9295 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9296 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9298 value=resource_info->display_warnings ? "True" : "False";
9299 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9300 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9301 value=resource_info->quantize_info->dither ? "True" : "False";
9302 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9303 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9305 value=resource_info->gamma_correct ? "True" : "False";
9306 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9307 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9308 (void) FormatMagickString(cache,MaxTextExtent,"%.20g",(double)
9309 resource_info->undo_cache);
9310 XrmPutStringResource(&preferences_database,specifier,cache);
9311 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9312 value=resource_info->use_pixmap ? "True" : "False";
9313 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9314 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9315 X11_PREFERENCES_PATH,client_name);
9316 ExpandFilename(filename);
9317 XrmPutFileDatabase(preferences_database,filename);
9322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9326 % X V i s u a l C l a s s N a m e %
9330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9332 % XVisualClassName() returns the visual class name as a character string.
9334 % The format of the XVisualClassName method is:
9336 % char *XVisualClassName(const int visual_class)
9338 % A description of each parameter follows:
9340 % o visual_type: XVisualClassName returns the visual class as a character
9343 % o class: Specifies the visual class.
9346 static const char *XVisualClassName(const int visual_class)
9348 switch (visual_class)
9350 case StaticGray: return("StaticGray");
9351 case GrayScale: return("GrayScale");
9352 case StaticColor: return("StaticColor");
9353 case PseudoColor: return("PseudoColor");
9354 case TrueColor: return("TrueColor");
9355 case DirectColor: return("DirectColor");
9357 return("unknown visual class");
9361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9369 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9371 % XWarning() displays a warning reason in a Notice widget.
9373 % The format of the XWarning method is:
9375 % void XWarning(const unsigned int warning,const char *reason,
9376 % const char *description)
9378 % A description of each parameter follows:
9380 % o warning: Specifies the numeric warning category.
9382 % o reason: Specifies the reason to display before terminating the
9385 % o description: Specifies any description to the reason.
9388 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9389 const char *reason,const char *description)
9392 text[MaxTextExtent];
9397 if (reason == (char *) NULL)
9399 (void) CopyMagickString(text,reason,MaxTextExtent);
9400 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9401 windows=XSetWindows((XWindows *) ~0);
9402 XNoticeWidget(windows->display,windows,text,(char *) description);
9406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9410 % X W i n d o w B y I D %
9414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9416 % XWindowByID() locates a child window with a given ID. If not window with
9417 % the given name is found, 0 is returned. Only the window specified and its
9418 % subwindows are searched.
9420 % The format of the XWindowByID function is:
9422 % child=XWindowByID(display,window,id)
9424 % A description of each parameter follows:
9426 % o child: XWindowByID returns the window with the specified
9427 % id. If no windows are found, XWindowByID returns 0.
9429 % o display: Specifies a pointer to the Display structure; returned from
9432 % o id: Specifies the id of the window to locate.
9435 MagickExport Window XWindowByID(Display *display,const Window root_window,
9455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9456 assert(display != (Display *) NULL);
9457 assert(root_window != (Window) NULL);
9459 return(XSelectWindow(display,&rectangle_info));
9460 if (root_window == id)
9461 return(root_window);
9462 status=XQueryTree(display,root_window,&child,&child,&children,
9464 if (status == False)
9465 return((Window) NULL);
9466 window=(Window) NULL;
9467 for (i=0; i < (int) number_children; i++)
9470 Search each child and their children.
9472 window=XWindowByID(display,children[i],id);
9473 if (window != (Window) NULL)
9476 if (children != (Window *) NULL)
9477 (void) XFree((void *) children);
9482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9486 % X W i n d o w B y N a m e %
9490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9492 % XWindowByName() locates a window with a given name on a display. If no
9493 % window with the given name is found, 0 is returned. If more than one window
9494 % has the given name, the first one is returned. Only root and its children
9497 % The format of the XWindowByName function is:
9499 % window=XWindowByName(display,root_window,name)
9501 % A description of each parameter follows:
9503 % o window: XWindowByName returns the window id.
9505 % o display: Specifies a pointer to the Display structure; returned from
9508 % o root_window: Specifies the id of the root window.
9510 % o name: Specifies the name of the window to locate.
9513 MagickExport Window XWindowByName(Display *display,const Window root_window,
9533 assert(display != (Display *) NULL);
9534 assert(root_window != (Window) NULL);
9535 assert(name != (char *) NULL);
9536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9537 if (XGetWMName(display,root_window,&window_name) != 0)
9538 if (LocaleCompare((char *) window_name.value,name) == 0)
9539 return(root_window);
9540 status=XQueryTree(display,root_window,&child,&child,&children,
9542 if (status == False)
9543 return((Window) NULL);
9544 window=(Window) NULL;
9545 for (i=0; i < (int) number_children; i++)
9548 Search each child and their children.
9550 window=XWindowByName(display,children[i],name);
9551 if (window != (Window) NULL)
9554 if (children != (Window *) NULL)
9555 (void) XFree((void *) children);
9560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9564 % X W i n d o w B y P r o p e r y %
9568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9570 % XWindowByProperty() locates a child window with a given property. If not
9571 % window with the given name is found, 0 is returned. If more than one window
9572 % has the given property, the first one is returned. Only the window
9573 % specified and its subwindows are searched.
9575 % The format of the XWindowByProperty function is:
9577 % child=XWindowByProperty(display,window,property)
9579 % A description of each parameter follows:
9581 % o child: XWindowByProperty returns the window id with the specified
9582 % property. If no windows are found, XWindowByProperty returns 0.
9584 % o display: Specifies a pointer to the Display structure; returned from
9587 % o property: Specifies the property of the window to locate.
9590 MagickExport Window XWindowByProperty(Display *display,const Window window,
9591 const Atom property)
9619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9620 assert(display != (Display *) NULL);
9621 assert(window != (Window) NULL);
9622 assert(property != (Atom) NULL);
9623 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9624 if (status == False)
9625 return((Window) NULL);
9627 child=(Window) NULL;
9628 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9630 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9631 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9633 (void) XFree((void *) data);
9634 if ((status == Success) && (type != (Atom) NULL))
9637 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9638 child=XWindowByProperty(display,children[i],property);
9639 if (children != (Window *) NULL)
9640 (void) XFree((void *) children);
9646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9650 % X I m p o r t I m a g e %
9654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9656 % XImportImage() reads an image from an X window.
9658 % The format of the XImportImage method is:
9660 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9662 % A description of each parameter follows:
9664 % o image_info: the image info..
9666 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9669 MagickExport Image *XImportImage(const ImageInfo *image_info,
9670 XImportInfo *ximage_info)
9672 assert(image_info != (const ImageInfo *) NULL);
9673 assert(image_info->signature == MagickSignature);
9674 if (image_info->debug != MagickFalse)
9675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9676 image_info->filename);
9677 assert(ximage_info != (XImportInfo *) NULL);
9678 return((Image *) NULL);
9683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9687 + X C o m p o n e n t G e n e s i s %
9691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9693 % XComponentGenesis() instantiates the X component.
9695 % The format of the XComponentGenesis method is:
9697 % MagickBooleanType XComponentGenesis(void)
9700 MagickExport MagickBooleanType XComponentGenesis(void)
9706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9710 % X G e t I m p o r t I n f o %
9714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9716 % XGetImportInfo() initializes the XImportInfo structure.
9718 % The format of the XGetImportInfo method is:
9720 % void XGetImportInfo(XImportInfo *ximage_info)
9722 % A description of each parameter follows:
9724 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9727 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9729 assert(ximage_info != (XImportInfo *) NULL);
9730 ximage_info->frame=MagickFalse;
9731 ximage_info->borders=MagickFalse;
9732 ximage_info->screen=MagickFalse;
9733 ximage_info->descend=MagickTrue;
9734 ximage_info->silent=MagickFalse;