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-2010 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)
484 Initialize annotated image.
486 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
487 assert(display != (Display *) NULL);
488 assert(pixel != (XPixelInfo *) NULL);
489 assert(annotate_info != (XAnnotateInfo *) NULL);
490 assert(image != (Image *) NULL);
492 Initialize annotated pixmap.
494 root_window=XRootWindow(display,XDefaultScreen(display));
495 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
496 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
497 annotate_info->height,depth);
498 if (annotate_pixmap == (Pixmap) NULL)
501 Initialize graphics info.
503 context_values.background=0;
504 context_values.foreground=(size_t) (~0);
505 context_values.font=annotate_info->font_info->fid;
506 annotate_context=XCreateGC(display,root_window,(size_t)
507 GCBackground | GCFont | GCForeground,&context_values);
508 if (annotate_context == (GC) NULL)
513 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
514 (int) annotate_info->font_info->ascent,annotate_info->text,
515 (int) strlen(annotate_info->text));
516 (void) XFreeGC(display,annotate_context);
518 Initialize annotated X image.
520 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
521 annotate_info->height,AllPlanes,ZPixmap);
522 if (annotate_ximage == (XImage *) NULL)
524 (void) XFreePixmap(display,annotate_pixmap);
526 Initialize annotated image.
528 annotate_image=AcquireImage((ImageInfo *) NULL);
529 if (annotate_image == (Image *) NULL)
531 annotate_image->columns=annotate_info->width;
532 annotate_image->rows=annotate_info->height;
534 Transfer annotated X image to image.
536 width=(unsigned int) image->columns;
537 height=(unsigned int) image->rows;
540 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
541 (void) GetOneVirtualPixel(image,x,y,&annotate_image->background_color,
543 if (annotate_info->stencil == ForegroundStencil)
544 annotate_image->matte=MagickTrue;
545 exception=(&image->exception);
546 for (y=0; y < (int) annotate_image->rows; y++)
554 q=GetAuthenticPixels(annotate_image,0,y,annotate_image->columns,1,
556 if (q == (PixelPacket *) NULL)
558 for (x=0; x < (ssize_t) annotate_image->columns; x++)
560 SetOpacityPixelComponent(q,OpaqueOpacity);
561 if (XGetPixel(annotate_ximage,x,y) == 0)
564 Set this pixel to the background color.
566 q->red=ScaleShortToQuantum(pixel->box_color.red);
567 q->green=ScaleShortToQuantum(pixel->box_color.green);
568 q->blue=ScaleShortToQuantum(pixel->box_color.blue);
569 if ((annotate_info->stencil == ForegroundStencil) ||
570 (annotate_info->stencil == OpaqueStencil))
571 q->opacity=(Quantum) TransparentOpacity;
576 Set this pixel to the pen color.
578 q->red=ScaleShortToQuantum(pixel->pen_color.red);
579 q->green=ScaleShortToQuantum(pixel->pen_color.green);
580 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
581 if (annotate_info->stencil == BackgroundStencil)
582 q->opacity=(Quantum) TransparentOpacity;
586 if (SyncAuthenticPixels(annotate_image,exception) == MagickFalse)
589 XDestroyImage(annotate_ximage);
591 Determine annotate geometry.
593 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
594 if ((width != (unsigned int) annotate_image->columns) ||
595 (height != (unsigned int) annotate_image->rows))
598 image_geometry[MaxTextExtent];
603 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
605 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
607 if (annotate_info->degrees != 0.0)
622 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
623 if (rotate_image == (Image *) NULL)
625 annotate_image=DestroyImage(annotate_image);
626 annotate_image=rotate_image;
628 Annotation is relative to the degree of rotation.
630 normalized_degrees=annotate_info->degrees;
631 while (normalized_degrees < -45.0)
632 normalized_degrees+=360.0;
633 for (rotations=0; normalized_degrees > 45.0; rotations++)
634 normalized_degrees-=90.0;
635 switch (rotations % 4)
645 x-=(int) annotate_image->columns/2;
646 y+=(int) annotate_image->columns/2;
654 x=x-(int) annotate_image->columns;
662 x=x-(int) annotate_image->columns/2;
663 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
669 Composite text onto the image.
671 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
673 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
674 OverCompositeOp : CopyCompositeOp,annotate_image,x,y);
676 annotate_image=DestroyImage(annotate_image);
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 % X B e s t F o n t %
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 % XBestFont() returns the "best" font. "Best" is defined as a font specified
692 % in the X resource database or a font such that the text width displayed
693 % with the font does not exceed the specified maximum width.
695 % The format of the XBestFont method is:
697 % XFontStruct *XBestFont(Display *display,
698 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
700 % A description of each parameter follows:
702 % o font: XBestFont returns a pointer to a XFontStruct structure.
704 % o display: Specifies a connection to an X server; returned from
707 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
709 % o text_font: True is font should be mono-spaced (typewriter style).
713 static char **FontToList(char *font)
728 if (font == (char *) NULL)
729 return((char **) NULL);
731 Convert string to an ASCII list.
734 for (p=font; *p != '\0'; p++)
735 if ((*p == ':') || (*p == ';') || (*p == ','))
737 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
738 if (fontlist == (char **) NULL)
740 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
742 return((char **) NULL);
745 for (i=0; i < (int) fonts; i++)
747 for (q=p; *q != '\0'; q++)
748 if ((*q == ':') || (*q == ';') || (*q == ','))
750 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
751 sizeof(*fontlist[i]));
752 if (fontlist[i] == (char *) NULL)
754 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
756 return((char **) NULL);
758 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
761 fontlist[i]=(char *) NULL;
765 MagickExport XFontStruct *XBestFont(Display *display,
766 const XResourceInfo *resource_info,const MagickBooleanType text_font)
771 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
772 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
773 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
774 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
775 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
776 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
783 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
784 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
785 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
799 font_info=(XFontStruct *) NULL;
800 font_name=resource_info->font;
801 if (text_font != MagickFalse)
802 font_name=resource_info->text_font;
803 if ((font_name != (char *) NULL) && (*font_name != '\0'))
812 Load preferred font specified in the X resource database.
814 fontlist=FontToList(font_name);
815 if (fontlist != (char **) NULL)
817 for (i=0; fontlist[i] != (char *) NULL; i++)
819 if (font_info == (XFontStruct *) NULL)
820 font_info=XLoadQueryFont(display,fontlist[i]);
821 fontlist[i]=DestroyString(fontlist[i]);
823 fontlist=(char **) RelinquishMagickMemory(fontlist);
825 if (font_info == (XFontStruct *) NULL)
826 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
829 Load fonts from list of fonts until one is found.
832 if (text_font != MagickFalse)
834 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
836 while (*p != (char *) NULL)
838 if (font_info != (XFontStruct *) NULL)
840 font_info=XLoadQueryFont(display,(char *) *p);
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 % X B e s t I c o n S i z e %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
858 % size that maintains the aspect ratio of the image. If the window manager
859 % has preferred icon sizes, one of the preferred sizes is used.
861 % The format of the XBestIconSize method is:
863 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
865 % A description of each parameter follows:
867 % o display: Specifies a connection to an X server; returned from
870 % o image: the image.
873 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
897 Determine if the window manager has specified preferred icon sizes.
899 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
900 assert(display != (Display *) NULL);
901 assert(window != (XWindowInfo *) NULL);
902 assert(image != (Image *) NULL);
903 window->width=MaxIconSize;
904 window->height=MaxIconSize;
905 icon_size=(XIconSize *) NULL;
907 root_window=XRootWindow(display,window->screen);
908 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
909 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
911 if (icon_size == (XIconSize *) NULL)
914 Window manager does not restrict icon size.
916 icon_size=XAllocIconSize();
917 if (icon_size == (XIconSize *) NULL)
919 ThrowXWindowFatalException(ResourceLimitError,
920 "MemoryAllocationFailed",image->filename);
923 icon_size->min_width=1;
924 icon_size->max_width=MaxIconSize;
925 icon_size->min_height=1;
926 icon_size->max_height=MaxIconSize;
927 icon_size->width_inc=1;
928 icon_size->height_inc=1;
931 Determine aspect ratio of image.
933 width=(unsigned int) image->columns;
934 height=(unsigned int) image->rows;
936 if (window->crop_geometry)
937 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
939 Look for an icon size that maintains the aspect ratio of image.
941 scale_factor=(MagickRealType) icon_size->max_width/width;
942 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
943 scale_factor=(MagickRealType) icon_size->max_height/height;
944 icon_width=(unsigned int) icon_size->min_width;
945 while ((int) icon_width < icon_size->max_width)
947 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
949 icon_width+=icon_size->width_inc;
951 icon_height=(unsigned int) icon_size->min_height;
952 while ((int) icon_height < icon_size->max_height)
954 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
956 icon_height+=icon_size->height_inc;
958 (void) XFree((void *) icon_size);
959 window->width=icon_width;
960 window->height=icon_height;
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 % X B e s t P i x e l %
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974 % XBestPixel() returns a pixel from an array of pixels that is closest to the
975 % requested color. If the color array is NULL, the colors are obtained from
978 % The format of the XBestPixel method is:
980 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
981 % unsigned int number_colors,XColor *color)
983 % A description of each parameter follows:
985 % o pixel: XBestPixel returns the pixel value closest to the requested
988 % o display: Specifies a connection to an X server; returned from
991 % o colormap: Specifies the ID of the X server colormap.
993 % o colors: Specifies an array of XColor structures.
995 % o number_colors: Specifies the number of XColor structures in the
996 % color definition array.
998 % o color: Specifies the desired RGB value to find in the colors array.
1001 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1002 XColor *colors,unsigned int number_colors,XColor *color)
1013 register MagickRealType
1024 Find closest representation for the requested RGB color.
1026 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1027 assert(display != (Display *) NULL);
1028 assert(color != (XColor *) NULL);
1029 status=XAllocColor(display,colormap,color);
1030 if (status != False)
1032 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1033 if (query_server != MagickFalse)
1036 Read X server colormap.
1038 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1039 if (colors == (XColor *) NULL)
1041 ThrowXWindowFatalException(ResourceLimitError,
1042 "MemoryAllocationFailed","...");
1045 for (i=0; i < (int) number_colors; i++)
1046 colors[i].pixel=(size_t) i;
1047 if (number_colors > 256)
1049 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1051 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1054 for (i=0; i < (int) number_colors; i++)
1056 pixel.red=colors[i].red-(MagickRealType) color->red;
1057 distance=pixel.red*pixel.red;
1058 if (distance > min_distance)
1060 pixel.green=colors[i].green-(MagickRealType) color->green;
1061 distance+=pixel.green*pixel.green;
1062 if (distance > min_distance)
1064 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1065 distance+=pixel.blue*pixel.blue;
1066 if (distance > min_distance)
1068 min_distance=distance;
1069 color->pixel=colors[i].pixel;
1072 (void) XAllocColor(display,colormap,&colors[j]);
1073 if (query_server != MagickFalse)
1074 colors=(XColor *) RelinquishMagickMemory(colors);
1078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % X B e s t V i s u a l I n f o %
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % XBestVisualInfo() returns visual information for a visual that is the "best"
1089 % the server supports. "Best" is defined as:
1091 % 1. Restrict the visual list to those supported by the default screen.
1093 % 2. If a visual type is specified, restrict the visual list to those of
1096 % 3. If a map type is specified, choose the visual that matches the id
1097 % specified by the Standard Colormap.
1099 % 4 From the list of visuals, choose one that can display the most
1100 % simultaneous colors. If more than one visual can display the same
1101 % number of simultaneous colors, one is chosen based on a rank.
1103 % The format of the XBestVisualInfo method is:
1105 % XVisualInfo *XBestVisualInfo(Display *display,
1106 % XStandardColormap *map_info,XResourceInfo *resource_info)
1108 % A description of each parameter follows:
1110 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1113 % o display: Specifies a connection to an X server; returned from
1116 % o map_info: If map_type is specified, this structure is initialized
1117 % with info from the Standard Colormap.
1119 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1123 static inline int MagickMax(const int x,const int y)
1130 static inline size_t MagickMin(const unsigned int x,
1131 const unsigned int y)
1138 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1139 XStandardColormap *map_info,XResourceInfo *resource_info)
1141 #define MaxStandardColormaps 7
1142 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1143 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1144 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1145 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1168 Restrict visual search by screen number.
1170 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1171 assert(display != (Display *) NULL);
1172 assert(map_info != (XStandardColormap *) NULL);
1173 assert(resource_info != (XResourceInfo *) NULL);
1174 map_type=resource_info->map_type;
1175 visual_type=resource_info->visual_type;
1176 visual_mask=VisualScreenMask;
1177 visual_template.screen=XDefaultScreen(display);
1178 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1179 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1180 if (resource_info->colors <= (1UL << (size_t) visual_template.depth))
1181 visual_mask|=VisualDepthMask;
1182 if (visual_type != (char *) NULL)
1185 Restrict visual search by class or visual id.
1187 if (LocaleCompare("staticgray",visual_type) == 0)
1189 visual_mask|=VisualClassMask;
1190 visual_template.klass=StaticGray;
1193 if (LocaleCompare("grayscale",visual_type) == 0)
1195 visual_mask|=VisualClassMask;
1196 visual_template.klass=GrayScale;
1199 if (LocaleCompare("staticcolor",visual_type) == 0)
1201 visual_mask|=VisualClassMask;
1202 visual_template.klass=StaticColor;
1205 if (LocaleCompare("pseudocolor",visual_type) == 0)
1207 visual_mask|=VisualClassMask;
1208 visual_template.klass=PseudoColor;
1211 if (LocaleCompare("truecolor",visual_type) == 0)
1213 visual_mask|=VisualClassMask;
1214 visual_template.klass=TrueColor;
1217 if (LocaleCompare("directcolor",visual_type) == 0)
1219 visual_mask|=VisualClassMask;
1220 visual_template.klass=DirectColor;
1223 if (LocaleCompare("default",visual_type) == 0)
1225 visual_mask|=VisualIDMask;
1226 visual_template.visualid=XVisualIDFromVisual(
1227 XDefaultVisual(display,XDefaultScreen(display)));
1230 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1232 visual_mask|=VisualIDMask;
1233 visual_template.visualid=
1234 strtol(visual_type,(char **) NULL,0);
1237 ThrowXWindowFatalException(XServerError,
1238 "UnrecognizedVisualSpecifier",visual_type);
1241 Get all visuals that meet our criteria so far.
1244 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1246 visual_mask=VisualScreenMask | VisualIDMask;
1247 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1250 Failed to get visual; try using the default visual.
1252 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1254 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1255 XDefaultScreen(display)));
1256 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1258 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1259 return((XVisualInfo *) NULL);
1260 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1261 XVisualClassName(visual_list->klass));
1263 resource_info->color_recovery=MagickFalse;
1264 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1270 map_name[MaxTextExtent];
1286 Choose a visual associated with a standard colormap.
1288 root_window=XRootWindow(display,XDefaultScreen(display));
1290 if (LocaleCompare(map_type,"list") != 0)
1293 User specified Standard Colormap.
1295 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1296 "RGB_%s_MAP",map_type);
1297 LocaleUpper(map_name);
1298 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1299 if (map_property != (Atom) NULL)
1300 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1306 *colormap[MaxStandardColormaps]=
1308 "_HP_RGB_SMOOTH_MAP_LIST",
1318 Choose a standard colormap from a list.
1320 for (i=0; i < MaxStandardColormaps; i++)
1322 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1323 if (map_property == (Atom) NULL)
1325 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1327 if (status != False)
1330 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1332 if (status == False)
1334 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1336 return((XVisualInfo *) NULL);
1339 Search all Standard Colormaps and visuals for ids that match.
1341 *map_info=map_list[0];
1342 #if !defined(PRE_R4_ICCCM)
1343 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1344 for (i=0; i < number_maps; i++)
1345 for (j=0; j < number_visuals; j++)
1346 if (map_list[i].visualid ==
1347 XVisualIDFromVisual(visual_list[j].visual))
1349 *map_info=map_list[i];
1350 visual_template.visualid=XVisualIDFromVisual(
1351 visual_list[j].visual);
1354 if (map_info->visualid != visual_template.visualid)
1356 ThrowXWindowFatalException(XServerError,
1357 "UnableToMatchVisualToStandardColormap",map_type);
1358 return((XVisualInfo *) NULL);
1361 if (map_info->colormap == (Colormap) NULL)
1363 ThrowXWindowFatalException(XServerError,
1364 "StandardColormapIsNotInitialized",map_type);
1365 return((XVisualInfo *) NULL);
1367 (void) XFree((void *) map_list);
1371 static const unsigned int
1386 Pick one visual that displays the most simultaneous colors.
1388 visual_info=visual_list;
1390 for (i=1; i < number_visuals; i++)
1393 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1396 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1397 if (rank[p->klass] > rank[visual_info->klass])
1400 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1402 (void) XFree((void *) visual_list);
1404 Retrieve only one visual by its screen & id number.
1406 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1408 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1409 return((XVisualInfo *) NULL);
1410 return(visual_info);
1414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 % X C h e c k D e f i n e C u r s o r %
1422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1424 % XCheckDefineCursor() prevents cursor changes on the root window.
1426 % The format of the XXCheckDefineCursor method is:
1428 % XCheckDefineCursor(display,window,cursor)
1430 % A description of each parameter follows:
1432 % o display: Specifies a connection to an X server; returned from
1435 % o window: the window.
1437 % o cursor: the cursor.
1440 MagickExport int XCheckDefineCursor(Display *display,Window window,
1443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1444 assert(display != (Display *) NULL);
1445 if (window == XRootWindow(display,XDefaultScreen(display)))
1447 return(XDefineCursor(display,window,cursor));
1451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1455 % X C h e c k R e f r e s h W i n d o w s %
1459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 % XCheckRefreshWindows() checks the X server for exposure events for a
1462 % particular window and updates the areassociated with the exposure event.
1464 % The format of the XCheckRefreshWindows method is:
1466 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1468 % A description of each parameter follows:
1470 % o display: Specifies a connection to an X server; returned from
1473 % o windows: Specifies a pointer to a XWindows structure.
1476 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1485 assert(display != (Display *) NULL);
1486 assert(windows != (XWindows *) NULL);
1487 XDelay(display,SuspendTime);
1488 id=windows->command.id;
1489 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1490 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1491 id=windows->image.id;
1492 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1493 XRefreshWindow(display,&windows->image,&event);
1494 XDelay(display,SuspendTime << 1);
1495 id=windows->command.id;
1496 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1497 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1498 id=windows->image.id;
1499 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1500 XRefreshWindow(display,&windows->image,&event);
1504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1508 % X C l i e n t M e s s a g e %
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1515 % initialized with a particular protocol type and atom.
1517 % The format of the XClientMessage function is:
1519 % XClientMessage(display,window,protocol,reason,timestamp)
1521 % A description of each parameter follows:
1523 % o display: Specifies a pointer to the Display structure; returned from
1526 % o window: Specifies a pointer to a Window structure.
1528 % o protocol: Specifies an atom value.
1530 % o reason: Specifies an atom value which is the reason to send.
1532 % o timestamp: Specifies a value of type Time.
1535 MagickExport void XClientMessage(Display *display,const Window window,
1536 const Atom protocol,const Atom reason,const Time timestamp)
1541 assert(display != (Display *) NULL);
1542 client_event.type=ClientMessage;
1543 client_event.window=window;
1544 client_event.message_type=protocol;
1545 client_event.format=32;
1546 client_event.data.l[0]=(ssize_t) reason;
1547 client_event.data.l[1]=(ssize_t) timestamp;
1548 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1556 + X C l i e n t W i n d o w %
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 % XClientWindow() finds a window, at or below the specified window, which has
1563 % a WM_STATE property. If such a window is found, it is returned, otherwise
1564 % the argument window is returned.
1566 % The format of the XClientWindow function is:
1568 % client_window=XClientWindow(display,target_window)
1570 % A description of each parameter follows:
1572 % o client_window: XClientWindow returns a window, at or below the specified
1573 % window, which has a WM_STATE property otherwise the argument
1574 % target_window is returned.
1576 % o display: Specifies a pointer to the Display structure; returned from
1579 % o target_window: Specifies the window to find a WM_STATE property.
1582 static Window XClientWindow(Display *display,Window target_window)
1604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1605 assert(display != (Display *) NULL);
1606 state=XInternAtom(display,"WM_STATE",MagickTrue);
1607 if (state == (Atom) NULL)
1608 return(target_window);
1610 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1611 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1612 if ((status == Success) && (type != (Atom) NULL))
1613 return(target_window);
1614 client_window=XWindowByProperty(display,target_window,state);
1615 if (client_window == (Window) NULL)
1616 return(target_window);
1617 return(client_window);
1621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625 + X C o m p o n e n t T e r m i n u s %
1629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1631 % XComponentTerminus() destroys the module component.
1633 % The format of the XComponentTerminus method is:
1635 % XComponentTerminus(void)
1638 MagickExport void XComponentTerminus(void)
1640 DestroyXResources();
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 % X C o n f i g u r e I m a g e C o l o r m a p %
1652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654 % XConfigureImageColormap() creates a new X colormap.
1656 % The format of the XConfigureImageColormap method is:
1658 % void XConfigureImageColormap(Display *display,
1659 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1661 % A description of each parameter follows:
1663 % o display: Specifies a connection to an X server; returned from
1666 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1668 % o windows: Specifies a pointer to a XWindows structure.
1670 % o image: the image.
1673 MagickExport void XConfigureImageColormap(Display *display,
1674 XResourceInfo *resource_info,XWindows *windows,Image *image)
1680 Make standard colormap.
1682 XSetCursorState(display,windows,MagickTrue);
1683 XCheckRefreshWindows(display,windows);
1684 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1685 windows->map_info,windows->pixel_info);
1686 colormap=windows->map_info->colormap;
1687 (void) XSetWindowColormap(display,windows->image.id,colormap);
1688 (void) XSetWindowColormap(display,windows->command.id,colormap);
1689 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1690 if (windows->magnify.mapped != MagickFalse)
1691 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1692 if (windows->pan.mapped != MagickFalse)
1693 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1694 XSetCursorState(display,windows,MagickFalse);
1695 XClientMessage(display,windows->image.id,windows->im_protocols,
1696 windows->im_update_colormap,CurrentTime);
1700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1704 % X C o n s t r a i n W i n d o w P o s i t i o n %
1708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1710 % XConstrainWindowPosition() assures a window is positioned within the X
1711 % server boundaries.
1713 % The format of the XConstrainWindowPosition method is:
1715 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1717 % A description of each parameter follows:
1719 % o display: Specifies a pointer to the Display structure; returned from
1722 % o window_info: Specifies a pointer to a XWindowInfo structure.
1725 MagickExport void XConstrainWindowPosition(Display *display,
1726 XWindowInfo *window_info)
1731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1732 assert(display != (Display *) NULL);
1733 assert(window_info != (XWindowInfo *) NULL);
1734 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1735 if (window_info->x < 0)
1738 if (window_info->x > (int) limit)
1739 window_info->x=(int) limit;
1740 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1741 if (window_info->y < 0)
1744 if (window_info->y > limit)
1745 window_info->y=limit;
1749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1759 % XDelay() suspends program execution for the number of milliseconds
1762 % The format of the Delay method is:
1764 % void XDelay(Display *display,const size_t milliseconds)
1766 % A description of each parameter follows:
1768 % o display: Specifies a pointer to the Display structure; returned from
1771 % o milliseconds: Specifies the number of milliseconds to delay before
1775 MagickExport void XDelay(Display *display,const size_t milliseconds)
1777 assert(display != (Display *) NULL);
1778 (void) XFlush(display);
1779 if (milliseconds == 0)
1781 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1782 Sleep(milliseconds);
1788 timer=milliseconds/1000.0;
1791 #elif defined(MAGICKCORE_HAVE_USLEEP)
1792 usleep(1000*milliseconds);
1793 #elif defined(MAGICKCORE_HAVE_SELECT)
1798 timer.tv_sec=(ssize_t) milliseconds/1000;
1799 timer.tv_usec=(ssize_t) (milliseconds % 1000)*1000;
1800 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1802 #elif defined(MAGICKCORE_HAVE_POLL)
1803 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1804 #elif defined(__BEOS__)
1805 snooze(1000*milliseconds);
1807 # error "Time delay method not defined."
1812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1816 % X D e s t r o y R e s o u r c e I n f o %
1820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1822 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1825 % The format of the XDestroyResourceInfo method is:
1827 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1829 % A description of each parameter follows:
1831 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1834 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1836 if (resource_info->image_geometry != (char *) NULL)
1837 resource_info->image_geometry=(char *)
1838 RelinquishMagickMemory(resource_info->image_geometry);
1839 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1840 resource_info->quantize_info=DestroyQuantizeInfo(
1841 resource_info->quantize_info);
1842 if (resource_info->client_name != (char *) NULL)
1843 resource_info->client_name=(char *)
1844 RelinquishMagickMemory(resource_info->client_name);
1845 if (resource_info->name != (char *) NULL)
1846 resource_info->name=DestroyString(resource_info->name);
1847 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 % X D e s t r o y W i n d o w C o l o r s %
1859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861 % XDestroyWindowColors() frees X11 color resources previously saved on a
1862 % window by XRetainWindowColors or programs like xsetroot.
1864 % The format of the XDestroyWindowColors method is:
1866 % void XDestroyWindowColors(Display *display,Window window)
1868 % A description of each parameter follows:
1870 % o display: Specifies a connection to an X server; returned from
1873 % o window: Specifies a pointer to a Window structure.
1876 MagickExport void XDestroyWindowColors(Display *display,Window window)
1896 If there are previous resources on the root window, destroy them.
1898 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1899 assert(display != (Display *) NULL);
1900 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1901 if (property == (Atom) NULL)
1903 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1907 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1908 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1909 if (status != Success)
1911 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1913 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1914 (void) XDeleteProperty(display,window,property);
1917 (void) XFree((void *) data);
1921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1925 % X D i s p l a y I m a g e I n f o %
1929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 % XDisplayImageInfo() displays information about an X image.
1933 % The format of the XDisplayImageInfo method is:
1935 % void XDisplayImageInfo(Display *display,
1936 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1939 % A description of each parameter follows:
1941 % o display: Specifies a connection to an X server; returned from
1944 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1946 % o windows: Specifies a pointer to a XWindows structure.
1948 % o undo_image: the undo image.
1950 % o image: the image.
1953 MagickExport void XDisplayImageInfo(Display *display,
1954 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1958 filename[MaxTextExtent],
1981 Write info about the X server to a file.
1983 assert(display != (Display *) NULL);
1984 assert(resource_info != (XResourceInfo *) NULL);
1985 assert(windows != (XWindows *) NULL);
1986 assert(image != (Image *) NULL);
1988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1990 unique_file=AcquireUniqueFileResource(filename);
1991 if (unique_file != -1)
1992 file=fdopen(unique_file,"w");
1993 if ((unique_file == -1) || (file == (FILE *) NULL))
1995 XNoticeWidget(display,windows,"Unable to display image info",filename);
1998 if (resource_info->gamma_correct != MagickFalse)
1999 if (resource_info->display_gamma != (char *) NULL)
2000 (void) fprintf(file,"Display\n gamma: %s\n\n",
2001 resource_info->display_gamma);
2003 Write info about the X image to a file.
2005 (void) fprintf(file,"X\n visual: %s\n",
2006 XVisualClassName((int) windows->image.storage_class));
2007 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
2008 if (windows->visual_info->colormap_size != 0)
2009 (void) fprintf(file," colormap size: %d\n",
2010 windows->visual_info->colormap_size);
2011 if (resource_info->colormap== SharedColormap)
2012 (void) fprintf(file," colormap type: Shared\n");
2014 (void) fprintf(file," colormap type: Private\n");
2015 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
2016 windows->image.ximage->height);
2017 if (windows->image.crop_geometry != (char *) NULL)
2018 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
2019 if (windows->image.pixmap == (Pixmap) NULL)
2020 (void) fprintf(file," type: X Image\n");
2022 (void) fprintf(file," type: Pixmap\n");
2023 if (windows->image.shape != MagickFalse)
2024 (void) fprintf(file," non-rectangular shape: True\n");
2026 (void) fprintf(file," non-rectangular shape: False\n");
2027 if (windows->image.shared_memory != MagickFalse)
2028 (void) fprintf(file," shared memory: True\n");
2030 (void) fprintf(file," shared memory: False\n");
2031 (void) fprintf(file,"\n");
2032 if (resource_info->font != (char *) NULL)
2033 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2034 if (resource_info->text_font != (char *) NULL)
2035 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2037 Write info about the undo cache to a file.
2040 for (levels=0; undo_image != (Image *) NULL; levels++)
2042 number_pixels=undo_image->list->columns*undo_image->list->rows;
2043 bytes+=number_pixels*sizeof(PixelPacket);
2044 undo_image=GetPreviousImageInList(undo_image);
2046 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2047 (void) fprintf(file," bytes: %lumb\n",(unsigned long)
2048 ((bytes+(1 << 19)) >> 20));
2049 (void) fprintf(file," limit: %lumb\n\n",(unsigned long)
2050 resource_info->undo_cache);
2052 Write info about the image to a file.
2054 (void) IdentifyImage(image,file,MagickTrue);
2055 (void) fclose(file);
2056 text=FileToString(filename,~0,&image->exception);
2057 (void) RelinquishUniqueFileResource(filename);
2058 if (text == (char *) NULL)
2060 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2061 "UnableToDisplayImageInfo");
2064 textlist=StringToList(text);
2065 if (textlist != (char **) NULL)
2068 title[MaxTextExtent];
2071 Display information about the image in the Text View widget.
2073 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2074 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2076 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2077 (char const **) textlist);
2078 for (i=0; textlist[i] != (char *) NULL; i++)
2079 textlist[i]=DestroyString(textlist[i]);
2080 textlist=(char **) RelinquishMagickMemory(textlist);
2082 text=DestroyString(text);
2086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2090 + X D i t h e r I m a g e %
2094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2096 % XDitherImage() dithers the reference image as required by the HP Color
2097 % Recovery algorithm. The color values are quantized to 3 bits of red and
2098 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2099 % standard colormap.
2101 % The format of the XDitherImage method is:
2103 % void XDitherImage(Image *image,XImage *ximage)
2105 % A description of each parameter follows:
2107 % o image: the image.
2109 % o ximage: Specifies a pointer to a XImage structure; returned from
2113 static void XDitherImage(Image *image,XImage *ximage)
2115 static const short int
2118 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2119 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2121 dither_green[2][16]=
2123 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2124 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2128 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2129 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2144 register const PixelPacket
2164 Allocate and initialize dither maps.
2166 for (i=0; i < 2; i++)
2167 for (j=0; j < 16; j++)
2169 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2171 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2172 sizeof(*green_map));
2173 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2175 if ((red_map[i][j] == (unsigned char *) NULL) ||
2176 (green_map[i][j] == (unsigned char *) NULL) ||
2177 (blue_map[i][j] == (unsigned char *) NULL))
2179 ThrowXWindowFatalException(ResourceLimitError,
2180 "MemoryAllocationFailed",image->filename);
2185 Initialize dither tables.
2187 for (i=0; i < 2; i++)
2188 for (j=0; j < 16; j++)
2189 for (x=0; x < 256; x++)
2194 value+=dither_red[i][j];
2195 red_map[i][j][x]=(unsigned char)
2196 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2200 value+=dither_green[i][j];
2201 green_map[i][j][x]=(unsigned char)
2202 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2206 value+=((size_t) dither_blue[i][j] << 1);
2207 blue_map[i][j][x]=(unsigned char)
2208 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2213 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2214 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2218 for (y=0; y < (int) image->rows; y++)
2220 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2221 if (p == (const PixelPacket *) NULL)
2223 for (x=0; x < (int) image->columns; x++)
2225 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2226 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2227 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2228 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2229 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2230 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2231 pixel=(size_t) (((size_t) color.red & 0xe0) |
2232 (((size_t) color.green & 0xe0) >> 3) |
2233 (((size_t) color.blue & 0xc0) >> 6));
2246 Free allocated memory.
2248 for (i=0; i < 2; i++)
2249 for (j=0; j < 16; j++)
2251 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2252 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2253 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2262 % X D r a w I m a g e %
2266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2268 % XDrawImage() draws a line on the image.
2270 % The format of the XDrawImage method is:
2272 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2274 % A description of each parameter follows:
2276 % o display: Specifies a connection to an X server; returned from
2279 % o pixel: Specifies a pointer to a XPixelInfo structure.
2281 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2283 % o image: the image.
2286 MagickExport MagickBooleanType XDrawImage(Display *display,
2287 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2323 Initialize drawd image.
2325 assert(display != (Display *) NULL);
2326 assert(pixel != (XPixelInfo *) NULL);
2327 assert(draw_info != (XDrawInfo *) NULL);
2328 assert(image != (Image *) NULL);
2329 if (image->debug != MagickFalse)
2330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2332 Initialize drawd pixmap.
2334 root_window=XRootWindow(display,XDefaultScreen(display));
2335 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2336 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2337 draw_info->height,depth);
2338 if (draw_pixmap == (Pixmap) NULL)
2339 return(MagickFalse);
2341 Initialize graphics info.
2343 context_values.background=(size_t) (~0);
2344 context_values.foreground=0;
2345 context_values.line_width=(int) draw_info->line_width;
2346 draw_context=XCreateGC(display,root_window,(size_t)
2347 (GCBackground | GCForeground | GCLineWidth),&context_values);
2348 if (draw_context == (GC) NULL)
2349 return(MagickFalse);
2353 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2356 Draw line to pixmap.
2358 (void) XSetBackground(display,draw_context,0);
2359 (void) XSetForeground(display,draw_context,(size_t) (~0));
2360 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2361 (void) XSetStipple(display,draw_context,draw_info->stipple);
2362 switch (draw_info->element)
2367 (void) XDrawLines(display,draw_pixmap,draw_context,
2368 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2374 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2375 draw_info->line_info.y1,draw_info->line_info.x2,
2376 draw_info->line_info.y2);
2379 case RectangleElement:
2381 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2382 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2383 (unsigned int) draw_info->rectangle_info.width,
2384 (unsigned int) draw_info->rectangle_info.height);
2387 case FillRectangleElement:
2389 (void) XFillRectangle(display,draw_pixmap,draw_context,
2390 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2391 (unsigned int) draw_info->rectangle_info.width,
2392 (unsigned int) draw_info->rectangle_info.height);
2396 case EllipseElement:
2398 (void) XDrawArc(display,draw_pixmap,draw_context,
2399 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2400 (unsigned int) draw_info->rectangle_info.width,
2401 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2404 case FillCircleElement:
2405 case FillEllipseElement:
2407 (void) XFillArc(display,draw_pixmap,draw_context,
2408 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2409 (unsigned int) draw_info->rectangle_info.width,
2410 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2413 case PolygonElement:
2418 coordinate_info=draw_info->coordinate_info;
2419 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2420 (int) draw_info->number_coordinates,CoordModeOrigin);
2421 (void) XDrawLine(display,draw_pixmap,draw_context,
2422 coordinate_info[draw_info->number_coordinates-1].x,
2423 coordinate_info[draw_info->number_coordinates-1].y,
2424 coordinate_info[0].x,coordinate_info[0].y);
2427 case FillPolygonElement:
2429 (void) XFillPolygon(display,draw_pixmap,draw_context,
2430 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2435 (void) XFreeGC(display,draw_context);
2439 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2440 draw_info->height,AllPlanes,ZPixmap);
2441 if (draw_ximage == (XImage *) NULL)
2442 return(MagickFalse);
2443 (void) XFreePixmap(display,draw_pixmap);
2445 Initialize draw image.
2447 draw_image=AcquireImage((ImageInfo *) NULL);
2448 if (draw_image == (Image *) NULL)
2449 return(MagickFalse);
2450 draw_image->columns=draw_info->width;
2451 draw_image->rows=draw_info->height;
2453 Transfer drawn X image to image.
2455 width=(unsigned int) image->columns;
2456 height=(unsigned int) image->rows;
2459 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2460 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2462 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2463 return(MagickFalse);
2464 draw_image->matte=MagickTrue;
2465 exception=(&image->exception);
2466 for (y=0; y < (int) draw_image->rows; y++)
2471 register PixelPacket
2474 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2475 if (q == (PixelPacket *) NULL)
2477 for (x=0; x < (ssize_t) draw_image->columns; x++)
2479 if (XGetPixel(draw_ximage,x,y) == 0)
2482 Set this pixel to the background color.
2484 *q=draw_image->background_color;
2485 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2486 TransparentOpacity : OpaqueOpacity);
2491 Set this pixel to the pen color.
2493 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2494 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2495 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2496 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2497 OpaqueOpacity : TransparentOpacity);
2501 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2504 XDestroyImage(draw_ximage);
2506 Determine draw geometry.
2508 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2509 if ((width != (unsigned int) draw_image->columns) ||
2510 (height != (unsigned int) draw_image->rows))
2513 image_geometry[MaxTextExtent];
2518 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2520 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2522 if (draw_info->degrees != 0.0)
2536 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2537 if (rotate_image == (Image *) NULL)
2538 return(MagickFalse);
2539 draw_image=DestroyImage(draw_image);
2540 draw_image=rotate_image;
2542 Annotation is relative to the degree of rotation.
2544 normalized_degrees=draw_info->degrees;
2545 while (normalized_degrees < -45.0)
2546 normalized_degrees+=360.0;
2547 for (rotations=0; normalized_degrees > 45.0; rotations++)
2548 normalized_degrees-=90.0;
2549 switch (rotations % 4)
2559 x=x-(int) draw_image->columns/2;
2560 y=y+(int) draw_image->columns/2;
2568 x=x-(int) draw_image->columns;
2576 x=x-(int) draw_image->columns/2;
2577 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2583 Composite text onto the image.
2585 for (y=0; y < (int) draw_image->rows; y++)
2590 register PixelPacket
2593 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2594 if (q == (PixelPacket *) NULL)
2596 for (x=0; x < (ssize_t) draw_image->columns; x++)
2598 if (q->opacity != (Quantum) TransparentOpacity)
2599 SetOpacityPixelComponent(q,OpaqueOpacity);
2602 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2605 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2606 if (draw_info->stencil == TransparentStencil)
2607 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2611 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2614 draw_image=DestroyImage(draw_image);
2619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2629 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2630 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2631 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2634 % The format of the XError function is:
2636 % XError(display,error)
2638 % A description of each parameter follows:
2640 % o display: Specifies a pointer to the Display structure; returned from
2643 % o error: Specifies the error event.
2647 #if defined(__cplusplus) || defined(c_plusplus)
2651 MagickExport int XError(Display *display,XErrorEvent *error)
2653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2654 assert(display != (Display *) NULL);
2655 assert(error != (XErrorEvent *) NULL);
2656 xerror_alert=MagickTrue;
2657 switch (error->request_code)
2661 if ((int) error->error_code == BadDrawable)
2662 return(MagickFalse);
2665 case X_GetWindowAttributes:
2668 if ((int) error->error_code == BadWindow)
2669 return(MagickFalse);
2674 if ((int) error->error_code == BadValue)
2675 return(MagickFalse);
2682 #if defined(__cplusplus) || defined(c_plusplus)
2687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2691 % X F r e e R e s o u r c e s %
2695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2697 % XFreeResources() frees X11 resources.
2699 % The format of the XFreeResources method is:
2701 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2702 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2703 % XResourceInfo *resource_info,XWindowInfo *window_info)
2704 % resource_info,window_info)
2706 % A description of each parameter follows:
2708 % o display: Specifies a connection to an X server; returned from
2711 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2712 % returned from XGetVisualInfo.
2714 % o map_info: If map_type is specified, this structure is initialized
2715 % with info from the Standard Colormap.
2717 % o pixel: Specifies a pointer to a XPixelInfo structure.
2719 % o font_info: Specifies a pointer to a XFontStruct structure.
2721 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2723 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2726 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2727 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2728 XResourceInfo *resource_info,XWindowInfo *window_info)
2730 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2731 assert(display != (Display *) NULL);
2732 assert(resource_info != (XResourceInfo *) NULL);
2733 if (window_info != (XWindowInfo *) NULL)
2738 if (window_info->ximage != (XImage *) NULL)
2739 XDestroyImage(window_info->ximage);
2740 if (window_info->id != (Window) NULL)
2743 Free destroy window and free cursors.
2745 if (window_info->id != XRootWindow(display,visual_info->screen))
2746 (void) XDestroyWindow(display,window_info->id);
2747 if (window_info->annotate_context != (GC) NULL)
2748 (void) XFreeGC(display,window_info->annotate_context);
2749 if (window_info->highlight_context != (GC) NULL)
2750 (void) XFreeGC(display,window_info->highlight_context);
2751 if (window_info->widget_context != (GC) NULL)
2752 (void) XFreeGC(display,window_info->widget_context);
2753 if (window_info->cursor != (Cursor) NULL)
2754 (void) XFreeCursor(display,window_info->cursor);
2755 window_info->cursor=(Cursor) NULL;
2756 if (window_info->busy_cursor != (Cursor) NULL)
2757 (void) XFreeCursor(display,window_info->busy_cursor);
2758 window_info->busy_cursor=(Cursor) NULL;
2764 if (font_info != (XFontStruct *) NULL)
2765 (void) XFreeFont(display,font_info);
2766 if (map_info != (XStandardColormap *) NULL)
2769 Free X Standard Colormap.
2771 if (resource_info->map_type == (char *) NULL)
2772 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2773 (void) XFree((void *) map_info);
2778 if (visual_info != (XVisualInfo *) NULL)
2779 (void) XFree((void *) visual_info);
2780 if (resource_info->close_server != MagickFalse)
2781 (void) XCloseDisplay(display);
2785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2789 % X F r e e S t a n d a r d C o l o r m a p %
2793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2795 % XFreeStandardColormap() frees an X11 colormap.
2797 % The format of the XFreeStandardColormap method is:
2799 % void XFreeStandardColormap(Display *display,
2800 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2801 % XPixelInfo *pixel)
2803 % A description of each parameter follows:
2805 % o display: Specifies a connection to an X server; returned from
2808 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2809 % returned from XGetVisualInfo.
2811 % o map_info: If map_type is specified, this structure is initialized
2812 % with info from the Standard Colormap.
2814 % o pixel: Specifies a pointer to a XPixelInfo structure.
2817 MagickExport void XFreeStandardColormap(Display *display,
2818 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2824 assert(display != (Display *) NULL);
2825 assert(visual_info != (XVisualInfo *) NULL);
2826 assert(map_info != (XStandardColormap *) NULL);
2827 (void) XFlush(display);
2828 if (map_info->colormap != (Colormap) NULL)
2830 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2831 (void) XFreeColormap(display,map_info->colormap);
2833 if (pixel != (XPixelInfo *) NULL)
2834 if ((visual_info->klass != TrueColor) &&
2835 (visual_info->klass != DirectColor))
2836 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2837 (int) pixel->colors,0);
2839 map_info->colormap=(Colormap) NULL;
2840 if (pixel != (XPixelInfo *) NULL)
2842 if (pixel->pixels != (unsigned long *) NULL)
2843 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2844 pixel->pixels=(unsigned long *) NULL;
2849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2853 % X G e t A n n o t a t e I n f o %
2857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2859 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2861 % The format of the XGetAnnotateInfo method is:
2863 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2865 % A description of each parameter follows:
2867 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2870 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2873 Initialize annotate structure.
2875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2876 assert(annotate_info != (XAnnotateInfo *) NULL);
2879 annotate_info->width=0;
2880 annotate_info->height=0;
2881 annotate_info->stencil=ForegroundStencil;
2882 annotate_info->degrees=0.0;
2883 annotate_info->font_info=(XFontStruct *) NULL;
2884 annotate_info->text=(char *) NULL;
2885 *annotate_info->geometry='\0';
2886 annotate_info->previous=(XAnnotateInfo *) NULL;
2887 annotate_info->next=(XAnnotateInfo *) NULL;
2888 (void) XSupportsLocale();
2889 (void) XSetLocaleModifiers("");
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2897 % X G e t M a p I n f o %
2901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2903 % XGetMapInfo() initializes the XStandardColormap structure.
2905 % The format of the XStandardColormap method is:
2907 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2908 % XStandardColormap *map_info)
2910 % A description of each parameter follows:
2912 % o colormap: Specifies the ID of the X server colormap.
2914 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2915 % returned from XGetVisualInfo.
2917 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2920 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2921 const Colormap colormap,XStandardColormap *map_info)
2924 Initialize map info.
2926 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2927 assert(visual_info != (XVisualInfo *) NULL);
2928 assert(map_info != (XStandardColormap *) NULL);
2929 map_info->colormap=colormap;
2930 map_info->red_max=visual_info->red_mask;
2931 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2932 if (map_info->red_max != 0)
2933 while ((map_info->red_max & 0x01) == 0)
2935 map_info->red_max>>=1;
2936 map_info->red_mult<<=1;
2938 map_info->green_max=visual_info->green_mask;
2939 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2940 if (map_info->green_max != 0)
2941 while ((map_info->green_max & 0x01) == 0)
2943 map_info->green_max>>=1;
2944 map_info->green_mult<<=1;
2946 map_info->blue_max=visual_info->blue_mask;
2947 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2948 if (map_info->blue_max != 0)
2949 while ((map_info->blue_max & 0x01) == 0)
2951 map_info->blue_max>>=1;
2952 map_info->blue_mult<<=1;
2954 map_info->base_pixel=0;
2958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2962 % X G e t P i x e l I n f o %
2966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2968 % XGetPixelPacket() initializes the PixelPacket structure.
2970 % The format of the XGetPixelPacket method is:
2972 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2973 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2974 % Image *image,XPixelInfo *pixel)
2977 % A description of each parameter follows:
2979 % o display: Specifies a connection to an X server; returned from
2982 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2983 % returned from XGetVisualInfo.
2985 % o map_info: If map_type is specified, this structure is initialized
2986 % with info from the Standard Colormap.
2988 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2990 % o image: the image.
2992 % o pixel: Specifies a pointer to a XPixelInfo structure.
2995 MagickExport void XGetPixelPacket(Display *display,
2996 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2997 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3000 *PenColors[MaxNumberPens]=
3002 "#000000000000", /* black */
3003 "#00000000ffff", /* blue */
3004 "#0000ffffffff", /* cyan */
3005 "#0000ffff0000", /* green */
3006 "#bdbdbdbdbdbd", /* gray */
3007 "#ffff00000000", /* red */
3008 "#ffff0000ffff", /* magenta */
3009 "#ffffffff0000", /* yellow */
3010 "#ffffffffffff", /* white */
3011 "#bdbdbdbdbdbd", /* gray */
3012 "#bdbdbdbdbdbd" /* gray */
3028 Initialize pixel info.
3030 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3031 assert(display != (Display *) NULL);
3032 assert(visual_info != (XVisualInfo *) NULL);
3033 assert(map_info != (XStandardColormap *) NULL);
3034 assert(resource_info != (XResourceInfo *) NULL);
3035 assert(pixel != (XPixelInfo *) NULL);
3037 if (image != (Image *) NULL)
3038 if (image->storage_class == PseudoClass)
3039 pixel->colors=image->colors;
3040 packets=(unsigned int)
3041 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3042 if (pixel->pixels != (unsigned long *) NULL)
3043 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3044 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3045 sizeof(pixel->pixels));
3046 if (pixel->pixels == (unsigned long *) NULL)
3047 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3050 Set foreground color.
3052 colormap=map_info->colormap;
3053 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3054 &pixel->foreground_color);
3055 status=XParseColor(display,colormap,resource_info->foreground_color,
3056 &pixel->foreground_color);
3057 if (status == False)
3058 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3059 resource_info->foreground_color);
3060 pixel->foreground_color.pixel=
3061 XStandardPixel(map_info,&pixel->foreground_color);
3062 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3064 Set background color.
3066 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3067 status=XParseColor(display,colormap,resource_info->background_color,
3068 &pixel->background_color);
3069 if (status == False)
3070 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3071 resource_info->background_color);
3072 pixel->background_color.pixel=
3073 XStandardPixel(map_info,&pixel->background_color);
3074 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3078 (void) XParseColor(display,colormap,(char *) BorderColor,
3079 &pixel->border_color);
3080 status=XParseColor(display,colormap,resource_info->border_color,
3081 &pixel->border_color);
3082 if (status == False)
3083 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3084 resource_info->border_color);
3085 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3086 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3090 pixel->matte_color=pixel->background_color;
3091 if (resource_info->matte_color != (char *) NULL)
3094 Matte color is specified as a X resource or command line argument.
3096 status=XParseColor(display,colormap,resource_info->matte_color,
3097 &pixel->matte_color);
3098 if (status == False)
3099 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3100 resource_info->matte_color);
3101 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3102 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3105 Set highlight color.
3107 pixel->highlight_color.red=(unsigned short) ((
3108 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3109 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3110 pixel->highlight_color.green=(unsigned short) ((
3111 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3112 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3113 pixel->highlight_color.blue=(unsigned short) ((
3114 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3115 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3116 pixel->highlight_color.pixel=
3117 XStandardPixel(map_info,&pixel->highlight_color);
3118 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3122 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3123 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3124 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3125 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3126 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3127 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3128 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3129 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3133 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3134 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3135 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3136 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3137 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3138 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3139 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3140 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3144 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3145 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3146 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3147 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3148 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3149 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3150 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3151 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3155 for (i=0; i < MaxNumberPens; i++)
3157 (void) XParseColor(display,colormap,(char *) PenColors[i],
3158 &pixel->pen_colors[i]);
3159 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3160 &pixel->pen_colors[i]);
3161 if (status == False)
3162 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3163 resource_info->pen_colors[i]);
3164 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3165 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3167 pixel->box_color=pixel->background_color;
3168 pixel->pen_color=pixel->foreground_color;
3171 if (image != (Image *) NULL)
3173 if ((resource_info->gamma_correct != MagickFalse) &&
3174 (image->gamma != 0.0))
3183 Initialize map relative to display and image gamma.
3185 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3186 red_gamma=geometry_info.rho;
3187 green_gamma=geometry_info.sigma;
3188 if ((flags & SigmaValue) == 0)
3189 green_gamma=red_gamma;
3190 blue_gamma=geometry_info.xi;
3191 if ((flags & XiValue) == 0)
3192 blue_gamma=red_gamma;
3193 red_gamma*=image->gamma;
3194 green_gamma*=image->gamma;
3195 blue_gamma*=image->gamma;
3197 if (image->storage_class == PseudoClass)
3200 Initialize pixel array for images of type PseudoClass.
3202 for (i=0; i < (ssize_t) image->colors; i++)
3204 XGammaPixel(map_info,image->colormap+i);
3205 for (i=0; i < MaxNumberPens; i++)
3206 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3207 pixel->colors+=MaxNumberPens;
3213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3217 % X G e t R e s o u r c e C l a s s %
3221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3223 % XGetResourceClass() queries the X server for the specified resource name or
3224 % class. If the resource name or class is not defined in the database, the
3225 % supplied default value is returned.
3227 % The format of the XGetResourceClass method is:
3229 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3230 % const char *keyword,char *resource_default)
3232 % A description of each parameter follows:
3234 % o database: Specifies a resource database; returned from
3235 % XrmGetStringDatabase.
3237 % o client_name: Specifies the application name used to retrieve resource
3238 % info from the X server database.
3240 % o keyword: Specifies the keyword of the value being retrieved.
3242 % o resource_default: Specifies the default value to return if the query
3243 % fails to find the specified keyword/class.
3246 MagickExport char *XGetResourceClass(XrmDatabase database,
3247 const char *client_name,const char *keyword,char *resource_default)
3250 resource_class[MaxTextExtent],
3251 resource_name[MaxTextExtent];
3262 if (database == (XrmDatabase) NULL)
3263 return(resource_default);
3264 *resource_name='\0';
3265 *resource_class='\0';
3266 if (keyword != (char *) NULL)
3273 Initialize resource keyword and class.
3275 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3276 client_name,keyword);
3277 c=(int) (*client_name);
3278 if ((c >= XK_a) && (c <= XK_z))
3281 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3282 c-=(XK_agrave-XK_Agrave);
3284 if ((c >= XK_oslash) && (c <= XK_thorn))
3285 c-=(XK_oslash-XK_Ooblique);
3287 if ((k >= XK_a) && (k <= XK_z))
3290 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3291 k-=(XK_agrave-XK_Agrave);
3293 if ((k >= XK_oslash) && (k <= XK_thorn))
3294 k-=(XK_oslash-XK_Ooblique);
3295 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3296 client_name+1,k,keyword+1);
3298 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3300 if (status == False)
3301 return(resource_default);
3302 return(resource_value.addr);
3306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3310 % X G e t R e s o u r c e D a t a b a s e %
3314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3316 % XGetResourceDatabase() creates a new resource database and initializes it.
3318 % The format of the XGetResourceDatabase method is:
3320 % XrmDatabase XGetResourceDatabase(Display *display,
3321 % const char *client_name)
3323 % A description of each parameter follows:
3325 % o database: XGetResourceDatabase() returns the database after it is
3328 % o display: Specifies a connection to an X server; returned from
3331 % o client_name: Specifies the application name used to retrieve resource
3332 % info from the X server database.
3335 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3336 const char *client_name)
3339 filename[MaxTextExtent];
3351 if (display == (Display *) NULL)
3352 return((XrmDatabase) NULL);
3353 assert(client_name != (char *) NULL);
3355 Initialize resource database.
3358 (void) XGetDefault(display,(char *) client_name,"dummy");
3359 resource_database=XrmGetDatabase(display);
3361 Combine application database.
3363 if (client_name != (char *) NULL)
3366 Get basename of client.
3368 p=client_name+(strlen(client_name)-1);
3369 while ((p > client_name) && (*p != '/'))
3374 c=(int) (*client_name);
3375 if ((c >= XK_a) && (c <= XK_z))
3378 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3379 c-=(XK_agrave-XK_Agrave);
3381 if ((c >= XK_oslash) && (c <= XK_thorn))
3382 c-=(XK_oslash-XK_Ooblique);
3383 #if defined(X11_APPLICATION_PATH)
3384 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3385 X11_APPLICATION_PATH,c,client_name+1);
3386 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3388 if (XResourceManagerString(display) != (char *) NULL)
3391 Combine server database.
3393 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3394 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3397 Merge user preferences database.
3399 #if defined(X11_PREFERENCES_PATH)
3400 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3401 X11_PREFERENCES_PATH,client_name);
3402 ExpandFilename(filename);
3403 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3405 return(resource_database);
3409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3413 % X G e t R e s o u r c e I n f o %
3417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3419 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3421 % The format of the XGetResourceInfo method is:
3423 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3424 % const char *client_name,XResourceInfo *resource_info)
3426 % A description of each parameter follows:
3428 % o image_info: the image info.
3430 % o database: Specifies a resource database; returned from
3431 % XrmGetStringDatabase.
3433 % o client_name: Specifies the application name used to retrieve
3434 % resource info from the X server database.
3436 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3439 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3440 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3447 Initialize resource info fields.
3449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3450 assert(resource_info != (XResourceInfo *) NULL);
3451 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3452 resource_info->resource_database=database;
3453 resource_info->image_info=(ImageInfo *) image_info;
3454 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3455 XMagickProgressMonitor,(void *) NULL);
3456 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3457 resource_info->close_server=MagickTrue;
3458 resource_info->client_name=AcquireString(client_name);
3459 resource_value=XGetResourceClass(database,client_name,"backdrop",
3461 resource_info->backdrop=IsMagickTrue(resource_value);
3462 resource_info->background_color=XGetResourceInstance(database,client_name,
3463 "background",(char *) "#d6d6d6d6d6d6");
3464 resource_info->border_color=XGetResourceInstance(database,client_name,
3465 "borderColor",BorderColor);
3466 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3468 resource_info->border_width=(unsigned int) StringToUnsignedLong(resource_value);
3469 resource_value=XGetResourceClass(database,client_name,"colormap",
3471 resource_info->colormap=UndefinedColormap;
3472 if (LocaleCompare("private",resource_value) == 0)
3473 resource_info->colormap=PrivateColormap;
3474 if (LocaleCompare("shared",resource_value) == 0)
3475 resource_info->colormap=SharedColormap;
3476 if (resource_info->colormap == UndefinedColormap)
3477 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3479 resource_value=XGetResourceClass(database,client_name,
3480 "colorRecovery",(char *) "False");
3481 resource_info->color_recovery=IsMagickTrue(resource_value);
3482 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3484 resource_info->confirm_exit=IsMagickTrue(resource_value);
3485 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3487 resource_info->confirm_edit=IsMagickTrue(resource_value);
3488 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3489 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3490 resource_info->display_gamma=XGetResourceClass(database,client_name,
3491 "displayGamma",(char *) "2.2");
3492 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3494 resource_info->display_warnings=IsMagickTrue(resource_value);
3495 resource_info->font=XGetResourceClass(database,client_name,"font",
3497 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3498 resource_info->font);
3499 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3501 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3502 (char *) "variable");
3503 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3505 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3507 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3508 (char *) "7x13bold");
3509 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3510 (char *) "8x13bold");
3511 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3512 (char *) "9x15bold");
3513 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3515 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3517 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3519 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3521 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3522 "foreground",ForegroundColor);
3523 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3525 resource_info->gamma_correct=IsMagickTrue(resource_value);
3526 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3527 client_name,"geometry",(char *) NULL));
3528 resource_value=XGetResourceClass(database,client_name,"gravity",
3530 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3531 MagickFalse,resource_value);
3532 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3533 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3534 "iconGeometry",(char *) NULL);
3535 resource_value=XGetResourceClass(database,client_name,"iconic",
3537 resource_info->iconic=IsMagickTrue(resource_value);
3538 resource_value=XGetResourceClass(database,client_name,"immutable",
3539 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3541 resource_info->immutable=IsMagickTrue(resource_value);
3542 resource_value=XGetResourceClass(database,client_name,"magnify",
3544 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3545 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3547 resource_info->matte_color=XGetResourceInstance(database,client_name,
3548 "mattecolor",(char *) NULL);
3549 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3550 "name",(char *) NULL));
3551 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3553 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3555 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3557 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3559 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3561 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3563 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3564 (char *) "magenta");
3565 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3567 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3569 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3571 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3573 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3574 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3575 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3576 resource_info->quantum=StringToLong(resource_value);
3577 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3578 "font",(char *) "fixed");
3579 resource_info->text_font=XGetResourceClass(database,client_name,
3580 "textFontList",resource_info->text_font);
3581 resource_info->title=XGetResourceClass(database,client_name,"title",
3583 resource_value=XGetResourceClass(database,client_name,"undoCache",
3585 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3586 resource_value=XGetResourceClass(database,client_name,"update",
3588 resource_info->update=IsMagickTrue(resource_value);
3589 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3591 resource_info->use_pixmap=IsMagickTrue(resource_value);
3592 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3594 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3595 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3597 resource_info->window_group=XGetResourceClass(database,client_name,
3598 "windowGroup",(char *) NULL);
3599 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3601 resource_info->write_filename=XGetResourceClass(database,client_name,
3602 "writeFilename",(char *) NULL);
3606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3610 % X G e t R e s o u r c e I n s t a n c e %
3614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3616 % XGetResourceInstance() queries the X server for the specified resource name.
3617 % If the resource name is not defined in the database, the supplied default
3618 % value is returned.
3620 % The format of the XGetResourceInstance method is:
3622 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3623 % const char *keyword,const char *resource_default)
3625 % A description of each parameter follows:
3627 % o database: Specifies a resource database; returned from
3628 % XrmGetStringDatabase.
3630 % o client_name: Specifies the application name used to retrieve
3631 % resource info from the X server database.
3633 % o keyword: Specifies the keyword of the value being retrieved.
3635 % o resource_default: Specifies the default value to return if the query
3636 % fails to find the specified keyword/class.
3639 MagickExport char *XGetResourceInstance(XrmDatabase database,
3640 const char *client_name,const char *keyword,const char *resource_default)
3644 resource_name[MaxTextExtent];
3652 if (database == (XrmDatabase) NULL)
3653 return((char *) resource_default);
3654 *resource_name='\0';
3655 if (keyword != (char *) NULL)
3656 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3658 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3660 if (status == False)
3661 return((char *) resource_default);
3662 return(resource_value.addr);
3666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3670 % X G e t S c r e e n D e n s i t y %
3674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3676 % XGetScreenDensity() returns the density of the X server screen in
3679 % The format of the XGetScreenDensity method is:
3681 % char *XGetScreenDensity(Display *display)
3683 % A description of each parameter follows:
3685 % o density: XGetScreenDensity() returns the density of the X screen in
3688 % o display: Specifies a connection to an X server; returned from
3692 MagickExport char *XGetScreenDensity(Display *display)
3695 density[MaxTextExtent];
3702 Set density as determined by screen size.
3704 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3705 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3706 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3707 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3708 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,
3710 return(GetPageGeometry(density));
3714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3718 + X G e t S u b w i n d o w %
3722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3724 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3725 % pointer and a button press.
3727 % The format of the XGetSubwindow method is:
3729 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3731 % A description of each parameter follows:
3733 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3734 % otherwise the subwindow is returned.
3736 % o display: Specifies a connection to an X server; returned from
3739 % o window: Specifies a pointer to a Window.
3741 % o x: the x coordinate of the pointer relative to the origin of the
3744 % o y: the y coordinate of the pointer relative to the origin of the
3748 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3761 assert(display != (Display *) NULL);
3762 source_window=XRootWindow(display,XDefaultScreen(display));
3763 if (window == (Window) NULL)
3764 return(source_window);
3765 target_window=window;
3768 status=XTranslateCoordinates(display,source_window,window,x,y,
3769 &x_offset,&y_offset,&target_window);
3772 if (target_window == (Window) NULL)
3774 source_window=window;
3775 window=target_window;
3779 if (target_window == (Window) NULL)
3780 target_window=window;
3781 return(target_window);
3785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3789 % X G e t W i n d o w C o l o r %
3793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3795 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3798 % The format of the XGetWindowColor method is:
3800 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3803 % A description of each parameter follows:
3805 % o display: Specifies a connection to an X server; returned from
3808 % o windows: Specifies a pointer to a XWindows structure.
3810 % o name: the name of the color if found in the X Color Database is
3811 % returned in this character string.
3814 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3815 XWindows *windows,char *name)
3846 Choose a pixel from the X server.
3848 assert(display != (Display *) NULL);
3849 assert(name != (char *) NULL);
3850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3852 target_window=XSelectWindow(display,&crop_info);
3853 if (target_window == (Window) NULL)
3854 return(MagickFalse);
3855 root_window=XRootWindow(display,XDefaultScreen(display));
3856 client_window=target_window;
3857 if (target_window != root_window)
3865 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3866 if (status != False)
3868 client_window=XClientWindow(display,target_window);
3869 target_window=client_window;
3873 Verify window is viewable.
3875 status=XGetWindowAttributes(display,target_window,&window_attributes);
3876 if ((status == False) || (window_attributes.map_state != IsViewable))
3877 return(MagickFalse);
3881 (void) XTranslateCoordinates(display,root_window,target_window,
3882 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3883 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3884 if (ximage == (XImage *) NULL)
3885 return(MagickFalse);
3886 color.pixel=XGetPixel(ximage,0,0);
3887 XDestroyImage(ximage);
3889 Match color against the color database.
3891 (void) XQueryColor(display,window_attributes.colormap,&color);
3892 pixel.red=ScaleShortToQuantum(color.red);
3893 pixel.green=ScaleShortToQuantum(color.green);
3894 pixel.blue=ScaleShortToQuantum(color.blue);
3895 pixel.opacity=OpaqueOpacity;
3896 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3897 &windows->image.image->exception);
3902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3906 + X G e t W i n d o w I m a g e %
3910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3912 % XGetWindowImage() reads an image from the target X window and returns it.
3913 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3914 % target image with each child image in an optimized fashion. Any child
3915 % window that have the same visual, colormap, and are contained by its parent
3918 % The format of the XGetWindowImage method is:
3920 % Image *XGetWindowImage(Display *display,const Window window,
3921 % const unsigned int borders,const unsigned int level)
3923 % A description of each parameter follows:
3925 % o display: Specifies a connection to an X server; returned from
3928 % o window: Specifies the window to obtain the image from.
3930 % o borders: Specifies whether borders pixels are to be saved with
3933 % o level: Specifies an unsigned integer representing the level of
3934 % decent in the window hierarchy. This value must be zero or one on
3935 % the initial call to XGetWindowImage. A value of zero returns after
3936 % one call. A value of one causes the function to descend the window
3937 % hierarchy and overlay the target image with each subwindow image.
3940 static Image *XGetWindowImage(Display *display,const Window window,
3941 const unsigned int borders,const unsigned int level)
3943 typedef struct _ColormapInfo
3951 struct _ColormapInfo
3955 typedef struct _WindowInfo
3987 register IndexPacket
3994 *colormap_info = (ColormapInfo *) NULL;
4014 Verify window is viewable.
4016 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4017 assert(display != (Display *) NULL);
4018 status=XGetWindowAttributes(display,window,&window_attributes);
4019 if ((status == False) || (window_attributes.map_state != IsViewable))
4020 return((Image *) NULL);
4022 Cropping rectangle is relative to root window.
4024 root_window=XRootWindow(display,XDefaultScreen(display));
4025 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4027 crop_info.x=(ssize_t) x_offset;
4028 crop_info.y=(ssize_t) y_offset;
4029 crop_info.width=(size_t) window_attributes.width;
4030 crop_info.height=(size_t) window_attributes.height;
4031 if (borders != MagickFalse)
4034 Include border in image.
4036 crop_info.x-=(ssize_t) window_attributes.border_width;
4037 crop_info.y-=(ssize_t) window_attributes.border_width;
4038 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4039 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4042 Crop to root window.
4044 if (crop_info.x < 0)
4046 crop_info.width+=crop_info.x;
4049 if (crop_info.y < 0)
4051 crop_info.height+=crop_info.y;
4054 display_width=XDisplayWidth(display,XDefaultScreen(display));
4055 if ((int) (crop_info.x+crop_info.width) > display_width)
4056 crop_info.width=(size_t) (display_width-crop_info.x);
4057 display_height=XDisplayHeight(display,XDefaultScreen(display));
4058 if ((int) (crop_info.y+crop_info.height) > display_height)
4059 crop_info.height=(size_t) (display_height-crop_info.y);
4061 Initialize window info attributes.
4063 if (number_windows >= max_windows)
4066 Allocate or resize window info buffer.
4069 if (window_info == (WindowInfo *) NULL)
4070 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4071 sizeof(*window_info));
4073 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4074 max_windows,sizeof(*window_info));
4076 if (window_info == (WindowInfo *) NULL)
4078 ThrowXWindowFatalException(ResourceLimitError,
4079 "MemoryAllocationFailed","...");
4080 return((Image *) NULL);
4082 id=number_windows++;
4083 window_info[id].window=window;
4084 window_info[id].visual=window_attributes.visual;
4085 window_info[id].colormap=window_attributes.colormap;
4086 window_info[id].bounds.x1=(short) crop_info.x;
4087 window_info[id].bounds.y1=(short) crop_info.y;
4088 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4089 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4090 crop_info.x-=x_offset;
4091 crop_info.y-=y_offset;
4092 window_info[id].crop_info=crop_info;
4102 Descend the window hierarchy.
4104 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4105 &children,&number_children);
4106 for (i=0; i < id; i++)
4107 if ((window_info[i].window == window_info[id].parent) &&
4108 (window_info[i].visual == window_info[id].visual) &&
4109 (window_info[i].colormap == window_info[id].colormap))
4111 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4112 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4113 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4114 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4117 Eliminate windows not circumscribed by their parent.
4123 if ((status == True) && (number_children != 0))
4125 for (i=0; i < (int) number_children; i++)
4126 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4127 (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=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 *) AcquireAlignedMemory(1,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 switch (composite_image->storage_class)
4340 Determine shift and mask for red, green, and blue.
4342 red_mask=window_info[id].visual->red_mask;
4344 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4349 green_mask=window_info[id].visual->green_mask;
4351 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4356 blue_mask=window_info[id].visual->blue_mask;
4358 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4364 Convert X image to DirectClass packets.
4366 if ((number_colors != 0) &&
4367 (window_info[id].visual->klass == DirectColor))
4368 for (y=0; y < (int) composite_image->rows; y++)
4370 q=QueueAuthenticPixels(composite_image,0,y,
4371 composite_image->columns,1,exception);
4372 if (q == (PixelPacket *) NULL)
4374 for (x=0; x < (int) composite_image->columns; x++)
4376 pixel=XGetPixel(ximage,x,y);
4377 index=(pixel >> red_shift) & red_mask;
4378 q->red=ScaleShortToQuantum(colors[index].red);
4379 index=(pixel >> green_shift) & green_mask;
4380 q->green=ScaleShortToQuantum(colors[index].green);
4381 index=(pixel >> blue_shift) & blue_mask;
4382 q->blue=ScaleShortToQuantum(colors[index].blue);
4385 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4389 for (y=0; y < (int) composite_image->rows; y++)
4391 q=QueueAuthenticPixels(composite_image,0,y,
4392 composite_image->columns,1,exception);
4393 if (q == (PixelPacket *) NULL)
4395 for (x=0; x < (int) composite_image->columns; x++)
4397 pixel=XGetPixel(ximage,x,y);
4398 color=(pixel >> red_shift) & red_mask;
4399 color=(65535UL*color)/red_mask;
4400 q->red=ScaleShortToQuantum((unsigned short) color);
4401 color=(pixel >> green_shift) & green_mask;
4402 color=(65535UL*color)/green_mask;
4403 q->green=ScaleShortToQuantum((unsigned short) color);
4404 color=(pixel >> blue_shift) & blue_mask;
4405 color=(65535UL*color)/blue_mask;
4406 q->blue=ScaleShortToQuantum((unsigned short) color);
4409 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4419 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4421 XDestroyImage(ximage);
4422 composite_image=DestroyImage(composite_image);
4423 return((Image *) NULL);
4425 for (i=0; i < (int) composite_image->colors; i++)
4427 composite_image->colormap[colors[i].pixel].red=
4428 ScaleShortToQuantum(colors[i].red);
4429 composite_image->colormap[colors[i].pixel].green=
4430 ScaleShortToQuantum(colors[i].green);
4431 composite_image->colormap[colors[i].pixel].blue=
4432 ScaleShortToQuantum(colors[i].blue);
4435 Convert X image to PseudoClass packets.
4437 for (y=0; y < (int) composite_image->rows; y++)
4439 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4440 if (q == (PixelPacket *) NULL)
4442 indexes=GetAuthenticIndexQueue(composite_image);
4443 for (x=0; x < (int) composite_image->columns; x++)
4445 index=(IndexPacket) XGetPixel(ximage,x,y);
4447 *q++=composite_image->colormap[(ssize_t) index];
4449 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4455 XDestroyImage(ximage);
4456 if (image == (Image *) NULL)
4458 image=composite_image;
4462 Composite any children in back-to-front order.
4464 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4465 &x_offset,&y_offset,&child);
4466 x_offset-=(int) crop_info.x;
4469 y_offset-=(int) crop_info.y;
4472 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4476 Relinquish resources.
4478 while (colormap_info != (ColormapInfo *) NULL)
4480 next=colormap_info->next;
4481 colormap_info->colors=(XColor *)
4482 RelinquishMagickMemory(colormap_info->colors);
4483 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4487 Relinquish resources and restore initial state.
4489 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4492 colormap_info=(ColormapInfo *) NULL;
4495 return((Image *) NULL);
4499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4503 % X G e t W i n d o w I n f o %
4507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4509 % XGetWindowInfo() initializes the XWindowInfo structure.
4511 % The format of the XGetWindowInfo method is:
4513 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4514 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4515 % XResourceInfo *resource_info,XWindowInfo *window)
4516 % resource_info,window)
4518 % A description of each parameter follows:
4520 % o display: Specifies a connection to an X server; returned from
4523 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4524 % returned from XGetVisualInfo.
4526 % o map_info: If map_type is specified, this structure is initialized
4527 % with info from the Standard Colormap.
4529 % o pixel: Specifies a pointer to a XPixelInfo structure.
4531 % o font_info: Specifies a pointer to a XFontStruct structure.
4533 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4536 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4537 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4538 XResourceInfo *resource_info,XWindowInfo *window)
4541 Initialize window info.
4543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4544 assert(display != (Display *) NULL);
4545 assert(visual_info != (XVisualInfo *) NULL);
4546 assert(map_info != (XStandardColormap *) NULL);
4547 assert(pixel != (XPixelInfo *) NULL);
4548 assert(resource_info != (XResourceInfo *) NULL);
4549 assert(window != (XWindowInfo *) NULL);
4550 if (window->id != (Window) NULL)
4552 if (window->cursor != (Cursor) NULL)
4553 (void) XFreeCursor(display,window->cursor);
4554 if (window->busy_cursor != (Cursor) NULL)
4555 (void) XFreeCursor(display,window->busy_cursor);
4556 if (window->highlight_stipple != (Pixmap) NULL)
4557 (void) XFreePixmap(display,window->highlight_stipple);
4558 if (window->shadow_stipple != (Pixmap) NULL)
4559 (void) XFreePixmap(display,window->shadow_stipple);
4560 if (window->name == (char *) NULL)
4561 window->name=AcquireString("");
4562 if (window->icon_name == (char *) NULL)
4563 window->icon_name=AcquireString("");
4568 Initialize these attributes just once.
4570 window->id=(Window) NULL;
4571 if (window->name == (char *) NULL)
4572 window->name=AcquireString("");
4573 if (window->icon_name == (char *) NULL)
4574 window->icon_name=AcquireString("");
4575 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4576 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4577 window->ximage=(XImage *) NULL;
4578 window->matte_image=(XImage *) NULL;
4579 window->pixmap=(Pixmap) NULL;
4580 window->matte_pixmap=(Pixmap) NULL;
4581 window->mapped=MagickFalse;
4582 window->stasis=MagickFalse;
4583 window->shared_memory=MagickTrue;
4584 window->segment_info=(void *) NULL;
4585 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4590 if (window->segment_info == (void *) NULL)
4591 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4592 segment_info=(XShmSegmentInfo *) window->segment_info;
4593 segment_info[0].shmid=(-1);
4594 segment_info[0].shmaddr=(char *) NULL;
4595 segment_info[1].shmid=(-1);
4596 segment_info[1].shmaddr=(char *) NULL;
4601 Initialize these attributes every time function is called.
4603 window->screen=visual_info->screen;
4604 window->root=XRootWindow(display,visual_info->screen);
4605 window->visual=visual_info->visual;
4606 window->storage_class=(unsigned int) visual_info->klass;
4607 window->depth=(unsigned int) visual_info->depth;
4608 window->visual_info=visual_info;
4609 window->map_info=map_info;
4610 window->pixel_info=pixel;
4611 window->font_info=font_info;
4612 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4613 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4614 window->geometry=(char *) NULL;
4615 window->icon_geometry=(char *) NULL;
4616 if (resource_info->icon_geometry != (char *) NULL)
4617 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4618 window->crop_geometry=(char *) NULL;
4619 window->flags=(size_t) PSize;
4622 window->min_width=1;
4623 window->min_height=1;
4624 window->width_inc=1;
4625 window->height_inc=1;
4626 window->border_width=resource_info->border_width;
4627 window->annotate_context=pixel->annotate_context;
4628 window->highlight_context=pixel->highlight_context;
4629 window->widget_context=pixel->widget_context;
4630 window->shadow_stipple=(Pixmap) NULL;
4631 window->highlight_stipple=(Pixmap) NULL;
4632 window->use_pixmap=MagickTrue;
4633 window->immutable=MagickFalse;
4634 window->shape=MagickFalse;
4636 window->mask=(size_t) (CWBackingStore | CWBackPixel | CWBackPixmap |
4637 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4638 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4639 window->attributes.background_pixel=pixel->background_color.pixel;
4640 window->attributes.background_pixmap=(Pixmap) NULL;
4641 window->attributes.bit_gravity=ForgetGravity;
4642 window->attributes.backing_store=WhenMapped;
4643 window->attributes.save_under=MagickTrue;
4644 window->attributes.border_pixel=pixel->border_color.pixel;
4645 window->attributes.colormap=map_info->colormap;
4646 window->attributes.cursor=window->cursor;
4647 window->attributes.do_not_propagate_mask=NoEventMask;
4648 window->attributes.event_mask=NoEventMask;
4649 window->attributes.override_redirect=MagickFalse;
4650 window->attributes.win_gravity=NorthWestGravity;
4651 window->orphan=MagickFalse;
4655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4659 % X H i g h l i g h t E l l i p s e %
4663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4665 % XHighlightEllipse() puts a border on the X server around a region defined by
4668 % The format of the XHighlightEllipse method is:
4670 % void XHighlightEllipse(Display *display,Window window,
4671 % GC annotate_context,const RectangleInfo *highlight_info)
4673 % A description of each parameter follows:
4675 % o display: Specifies a connection to an X server; returned from
4678 % o window: Specifies a pointer to a Window structure.
4680 % o annotate_context: Specifies a pointer to a GC structure.
4682 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4683 % contains the extents of any highlighting rectangle.
4686 MagickExport void XHighlightEllipse(Display *display,Window window,
4687 GC annotate_context,const RectangleInfo *highlight_info)
4689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4690 assert(display != (Display *) NULL);
4691 assert(window != (Window) NULL);
4692 assert(annotate_context != (GC) NULL);
4693 assert(highlight_info != (RectangleInfo *) NULL);
4694 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4696 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4697 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4698 (unsigned int) highlight_info->height-1,0,360*64);
4699 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4700 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4701 (unsigned int) highlight_info->height-3,0,360*64);
4705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4709 % X H i g h l i g h t L i n e %
4713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4715 % XHighlightLine() puts a border on the X server around a region defined by
4718 % The format of the XHighlightLine method is:
4720 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4721 % const XSegment *highlight_info)
4723 % A description of each parameter follows:
4725 % o display: Specifies a connection to an X server; returned from
4728 % o window: Specifies a pointer to a Window structure.
4730 % o annotate_context: Specifies a pointer to a GC structure.
4732 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4733 % contains the extents of any highlighting rectangle.
4736 MagickExport void XHighlightLine(Display *display,Window window,
4737 GC annotate_context,const XSegment *highlight_info)
4739 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4740 assert(display != (Display *) NULL);
4741 assert(window != (Window) NULL);
4742 assert(annotate_context != (GC) NULL);
4743 assert(highlight_info != (XSegment *) NULL);
4744 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4745 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4753 % X H i g h l i g h t R e c t a n g l e %
4757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4759 % XHighlightRectangle() puts a border on the X server around a region defined
4760 % by highlight_info.
4762 % The format of the XHighlightRectangle method is:
4764 % void XHighlightRectangle(Display *display,Window window,
4765 % GC annotate_context,const RectangleInfo *highlight_info)
4767 % A description of each parameter follows:
4769 % o display: Specifies a connection to an X server; returned from
4772 % o window: Specifies a pointer to a Window structure.
4774 % o annotate_context: Specifies a pointer to a GC structure.
4776 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4777 % contains the extents of any highlighting rectangle.
4780 MagickExport void XHighlightRectangle(Display *display,Window window,
4781 GC annotate_context,const RectangleInfo *highlight_info)
4783 assert(display != (Display *) NULL);
4784 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4785 assert(window != (Window) NULL);
4786 assert(annotate_context != (GC) NULL);
4787 assert(highlight_info != (RectangleInfo *) NULL);
4788 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4790 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4791 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4792 (unsigned int) highlight_info->height-1);
4793 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4794 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4795 (unsigned int) highlight_info->height-3);
4799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4803 % X I m p o r t I m a g e %
4807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4809 % XImportImage() reads an image from an X window.
4811 % The format of the XImportImage method is:
4813 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4815 % A description of each parameter follows:
4817 % o image_info: the image info.
4819 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4822 MagickExport Image *XImportImage(const ImageInfo *image_info,
4823 XImportInfo *ximage_info)
4856 Open X server connection.
4858 assert(image_info != (const ImageInfo *) NULL);
4859 assert(image_info->signature == MagickSignature);
4860 if (image_info->debug != MagickFalse)
4861 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4862 image_info->filename);
4863 assert(ximage_info != (XImportInfo *) NULL);
4864 display=XOpenDisplay(image_info->server_name);
4865 if (display == (Display *) NULL)
4867 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4868 XDisplayName(image_info->server_name));
4869 return((Image *) NULL);
4872 Set our forgiving exception handler.
4874 (void) XSetErrorHandler(XError);
4876 Select target window.
4882 root=XRootWindow(display,XDefaultScreen(display));
4883 target=(Window) NULL;
4884 if ((image_info->filename != (char *) NULL) &&
4885 (*image_info->filename != '\0'))
4887 if (LocaleCompare(image_info->filename,"root") == 0)
4892 Select window by ID or name.
4894 if (isdigit((unsigned char) *image_info->filename) != 0)
4895 target=XWindowByID(display,root,(Window)
4896 strtol(image_info->filename,(char **) NULL,0));
4897 if (target == (Window) NULL)
4898 target=XWindowByName(display,root,image_info->filename);
4899 if (target == (Window) NULL)
4900 ThrowXWindowFatalException(XServerError,
4901 "NoWindowWithSpecifiedIDExists",image_info->filename);
4905 If target window is not defined, interactively select one.
4907 prior_target=target;
4908 if (target == (Window) NULL)
4909 target=XSelectWindow(display,&crop_info);
4910 if (target == (Window) NULL)
4911 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4912 image_info->filename);
4913 client=target; /* obsolete */
4919 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4920 if (status != False)
4928 Find window manager frame.
4930 status=XQueryTree(display,target,&root,&parent,&children,&d);
4931 if ((status != False) && (children != (Window *) NULL))
4932 (void) XFree((char *) children);
4933 if ((status == False) || (parent == (Window) NULL) ||
4941 client=XClientWindow(display,target);
4942 if (ximage_info->frame == MagickFalse)
4944 if ((ximage_info->frame == MagickFalse) &&
4945 (prior_target != MagickFalse))
4946 target=prior_target;
4947 XDelay(display,SuspendTime << 4);
4950 if (ximage_info->screen)
4962 Obtain window image directly from screen.
4964 status=XGetWindowAttributes(display,target,&window_attributes);
4965 if (status == False)
4967 ThrowXWindowFatalException(XServerError,
4968 "UnableToReadXWindowAttributes",image_info->filename);
4969 (void) XCloseDisplay(display);
4970 return((Image *) NULL);
4972 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4975 crop_info.width=(size_t) window_attributes.width;
4976 crop_info.height=(size_t) window_attributes.height;
4977 if (ximage_info->borders != 0)
4980 Include border in image.
4982 crop_info.x-=window_attributes.border_width;
4983 crop_info.y-=window_attributes.border_width;
4984 crop_info.width+=window_attributes.border_width << 1;
4985 crop_info.height+=window_attributes.border_width << 1;
4990 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4993 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4994 if ((status == True) && (number_windows > 0))
4996 ximage_info->descend=MagickTrue;
4997 (void) XFree ((char *) children);
4999 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5000 if (number_colormaps > 0)
5002 if (number_colormaps > 1)
5003 ximage_info->descend=MagickTrue;
5004 (void) XFree((char *) colormaps);
5007 Alert the user not to alter the screen.
5009 if (ximage_info->silent == MagickFalse)
5010 (void) XBell(display,0);
5012 Get image by window id.
5014 (void) XGrabServer(display);
5015 image=XGetWindowImage(display,target,ximage_info->borders,
5016 ximage_info->descend ? 1U : 0U);
5017 (void) XUngrabServer(display);
5018 if (image == (Image *) NULL)
5019 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5020 image_info->filename)
5023 (void) CopyMagickString(image->filename,image_info->filename,
5025 if ((crop_info.width != 0) && (crop_info.height != 0))
5032 Crop image as defined by the cropping rectangle.
5034 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5035 if (clone_image != (Image *) NULL)
5037 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5038 if (crop_image != (Image *) NULL)
5040 image=DestroyImage(image);
5045 status=XGetWMName(display,target,&window_name);
5048 if ((image_info->filename != (char *) NULL) &&
5049 (*image_info->filename == '\0'))
5050 (void) CopyMagickString(image->filename,(char *) window_name.value,
5051 (size_t) window_name.nitems+1);
5052 (void) XFree((void *) window_name.value);
5055 if (ximage_info->silent == MagickFalse)
5058 Alert the user we're done.
5060 (void) XBell(display,0);
5061 (void) XBell(display,0);
5063 (void) XCloseDisplay(display);
5068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5072 % X I n i t i a l i z e W i n d o w s %
5076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5078 % XInitializeWindows() initializes the XWindows structure.
5080 % The format of the XInitializeWindows method is:
5082 % XWindows *XInitializeWindows(Display *display,
5083 % XResourceInfo *resource_info)
5085 % A description of each parameter follows:
5087 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5089 % o display: Specifies a connection to an X server; returned from
5092 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5095 MagickExport XWindows *XInitializeWindows(Display *display,
5096 XResourceInfo *resource_info)
5105 Allocate windows structure.
5107 windows=(XWindows *) AcquireAlignedMemory(1,sizeof(*windows));
5108 if (windows == (XWindows *) NULL)
5110 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5112 return((XWindows *) NULL);
5114 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5115 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5116 sizeof(*windows->pixel_info));
5117 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5118 sizeof(*windows->icon_pixel));
5119 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5120 sizeof(*windows->icon_resources));
5121 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5122 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5123 (windows->icon_resources == (XResourceInfo *) NULL))
5125 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5127 return((XWindows *) NULL);
5130 Initialize windows structure.
5132 windows->display=display;
5133 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5134 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5135 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5136 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5137 windows->im_remote_command=
5138 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5139 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5140 windows->im_update_colormap=
5141 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5142 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5143 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5144 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5145 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5146 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5147 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5148 (void) XSynchronize(display,IsWindows95());
5150 if (IsEventLogging())
5152 (void) XSynchronize(display,MagickTrue);
5153 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5154 GetMagickVersion((size_t *) NULL));
5155 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5156 (void) LogMagickEvent(X11Event,GetMagickModule(),
5157 " Window Manager: 0x%lx",windows->wm_protocols);
5158 (void) LogMagickEvent(X11Event,GetMagickModule(),
5159 " delete window: 0x%lx",windows->wm_delete_window);
5160 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5161 windows->wm_take_focus);
5162 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5163 windows->im_protocols);
5164 (void) LogMagickEvent(X11Event,GetMagickModule(),
5165 " remote command: 0x%lx",windows->im_remote_command);
5166 (void) LogMagickEvent(X11Event,GetMagickModule(),
5167 " update widget: 0x%lx",windows->im_update_widget);
5168 (void) LogMagickEvent(X11Event,GetMagickModule(),
5169 " update colormap: 0x%lx",windows->im_update_colormap);
5170 (void) LogMagickEvent(X11Event,GetMagickModule(),
5171 " former image: 0x%lx",windows->im_former_image);
5172 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5173 windows->im_next_image);
5174 (void) LogMagickEvent(X11Event,GetMagickModule(),
5175 " retain colors: 0x%lx",windows->im_retain_colors);
5176 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5178 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5179 windows->dnd_protocols);
5182 Allocate standard colormap.
5184 windows->map_info=XAllocStandardColormap();
5185 windows->icon_map=XAllocStandardColormap();
5186 if ((windows->map_info == (XStandardColormap *) NULL) ||
5187 (windows->icon_map == (XStandardColormap *) NULL))
5188 ThrowXWindowFatalException(ResourceLimitFatalError,
5189 "MemoryAllocationFailed","...");
5190 windows->map_info->colormap=(Colormap) NULL;
5191 windows->icon_map->colormap=(Colormap) NULL;
5192 windows->pixel_info->pixels=(unsigned long *) NULL;
5193 windows->pixel_info->annotate_context=(GC) NULL;
5194 windows->pixel_info->highlight_context=(GC) NULL;
5195 windows->pixel_info->widget_context=(GC) NULL;
5196 windows->font_info=(XFontStruct *) NULL;
5197 windows->icon_pixel->annotate_context=(GC) NULL;
5198 windows->icon_pixel->pixels=(unsigned long *) NULL;
5202 *windows->icon_resources=(*resource_info);
5203 windows->icon_resources->visual_type=(char *) "default";
5204 windows->icon_resources->colormap=SharedColormap;
5205 windows->visual_info=
5206 XBestVisualInfo(display,windows->map_info,resource_info);
5207 windows->icon_visual=
5208 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5209 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5210 (windows->icon_visual == (XVisualInfo *) NULL))
5211 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5212 resource_info->visual_type);
5213 if (IsEventLogging())
5215 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5216 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5217 windows->visual_info->visualid);
5218 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5219 XVisualClassName(windows->visual_info->klass));
5220 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5221 windows->visual_info->depth);
5222 (void) LogMagickEvent(X11Event,GetMagickModule(),
5223 " size of colormap: %d entries",windows->visual_info->colormap_size);
5224 (void) LogMagickEvent(X11Event,GetMagickModule(),
5225 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5226 windows->visual_info->red_mask,windows->visual_info->green_mask,
5227 windows->visual_info->blue_mask);
5228 (void) LogMagickEvent(X11Event,GetMagickModule(),
5229 " significant bits in color: %d bits",
5230 windows->visual_info->bits_per_rgb);
5233 Allocate class and manager hints.
5235 windows->class_hints=XAllocClassHint();
5236 windows->manager_hints=XAllocWMHints();
5237 if ((windows->class_hints == (XClassHint *) NULL) ||
5238 (windows->manager_hints == (XWMHints *) NULL))
5239 ThrowXWindowFatalException(ResourceLimitFatalError,
5240 "MemoryAllocationFailed","...");
5242 Determine group leader if we have one.
5244 root_window=XRootWindow(display,windows->visual_info->screen);
5245 windows->group_leader.id=(Window) NULL;
5246 if (resource_info->window_group != (char *) NULL)
5248 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5249 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5250 strtol((char *) resource_info->window_group,(char **) NULL,0));
5251 if (windows->group_leader.id == (Window) NULL)
5252 windows->group_leader.id=
5253 XWindowByName(display,root_window,resource_info->window_group);
5259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5263 % X M a k e C u r s o r %
5267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5269 % XMakeCursor() creates a crosshairs X11 cursor.
5271 % The format of the XMakeCursor method is:
5273 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5274 % char *background_color,char *foreground_color)
5276 % A description of each parameter follows:
5278 % o display: Specifies a connection to an X server; returned from
5281 % o window: Specifies the ID of the window for which the cursor is
5284 % o colormap: Specifies the ID of the colormap from which the background
5285 % and foreground color will be retrieved.
5287 % o background_color: Specifies the color to use for the cursor background.
5289 % o foreground_color: Specifies the color to use for the cursor foreground.
5292 MagickExport Cursor XMakeCursor(Display *display,Window window,
5293 Colormap colormap,char *background_color,char *foreground_color)
5295 #define scope_height 17
5296 #define scope_x_hot 8
5297 #define scope_y_hot 8
5298 #define scope_width 17
5300 static const unsigned char
5303 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5304 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5305 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5306 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5307 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5311 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5312 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5313 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5314 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5315 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5329 assert(display != (Display *) NULL);
5330 assert(window != (Window) NULL);
5331 assert(colormap != (Colormap) NULL);
5332 assert(background_color != (char *) NULL);
5333 assert(foreground_color != (char *) NULL);
5334 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5335 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5337 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5338 scope_width,scope_height);
5339 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5341 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5342 return((Cursor) NULL);
5344 (void) XParseColor(display,colormap,background_color,&background);
5345 (void) XParseColor(display,colormap,foreground_color,&foreground);
5346 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5347 scope_x_hot,scope_y_hot);
5348 (void) XFreePixmap(display,source);
5349 (void) XFreePixmap(display,mask);
5354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5358 % X M a k e I m a g e %
5362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5364 % XMakeImage() creates an X11 image. If the image size differs from the X11
5365 % image size, the image is first resized.
5367 % The format of the XMakeImage method is:
5369 % MagickBooleanType XMakeImage(Display *display,
5370 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5371 % unsigned int width,unsigned int height)
5373 % A description of each parameter follows:
5375 % o display: Specifies a connection to an X server; returned from
5378 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5380 % o window: Specifies a pointer to a XWindowInfo structure.
5382 % o image: the image.
5384 % o width: Specifies the width in pixels of the rectangular area to
5387 % o height: Specifies the height in pixels of the rectangular area to
5391 MagickExport MagickBooleanType XMakeImage(Display *display,
5392 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5393 unsigned int width,unsigned int height)
5395 #define CheckOverflowException(length,width,height) \
5396 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5409 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5410 assert(display != (Display *) NULL);
5411 assert(resource_info != (XResourceInfo *) NULL);
5412 assert(window != (XWindowInfo *) NULL);
5414 assert(height != 0);
5415 if ((window->width == 0) || (window->height == 0))
5416 return(MagickFalse);
5418 Apply user transforms to the image.
5420 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5421 (void) XFlush(display);
5422 depth=(int) window->depth;
5423 if (window->destroy)
5424 window->image=DestroyImage(window->image);
5425 window->image=image;
5426 window->destroy=MagickFalse;
5427 if (window->image != (Image *) NULL)
5429 if (window->crop_geometry != (char *) NULL)
5440 window->image->page.x=0;
5441 window->image->page.y=0;
5442 (void) ParsePageGeometry(window->image,window->crop_geometry,
5443 &crop_info,&image->exception);
5444 crop_image=CropImage(window->image,&crop_info,&image->exception);
5445 if (crop_image != (Image *) NULL)
5447 if (window->image != image)
5448 window->image=DestroyImage(window->image);
5449 window->image=crop_image;
5450 window->destroy=MagickTrue;
5453 if ((width != (unsigned int) window->image->columns) ||
5454 (height != (unsigned int) window->image->rows))
5462 resize_image=NewImageList();
5463 if (window->pixel_info->colors != 0)
5464 resize_image=SampleImage(window->image,width,height,
5467 resize_image=ThumbnailImage(window->image,width,height,
5469 if (resize_image != (Image *) NULL)
5471 if (window->image != image)
5472 window->image=DestroyImage(window->image);
5473 window->image=resize_image;
5474 window->destroy=MagickTrue;
5477 width=(unsigned int) window->image->columns;
5478 assert((size_t) width == window->image->columns);
5479 height=(unsigned int) window->image->rows;
5480 assert((size_t) height == window->image->rows);
5485 ximage=(XImage *) NULL;
5486 format=(depth == 1) ? XYBitmap : ZPixmap;
5487 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5488 if (window->shared_memory != MagickFalse)
5493 segment_info=(XShmSegmentInfo *) window->segment_info;
5494 segment_info[1].shmid=(-1);
5495 segment_info[1].shmaddr=(char *) NULL;
5496 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5497 (char *) NULL,&segment_info[1],width,height);
5498 if (ximage == (XImage *) NULL)
5499 window->shared_memory=MagickFalse;
5500 length=(size_t) ximage->bytes_per_line*ximage->height;
5501 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5502 window->shared_memory=MagickFalse;
5503 if (window->shared_memory != MagickFalse)
5504 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5505 if (window->shared_memory != MagickFalse)
5506 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5507 if (segment_info[1].shmid < 0)
5508 window->shared_memory=MagickFalse;
5509 if (window->shared_memory != MagickFalse)
5510 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5513 if (ximage != (XImage *) NULL)
5514 XDestroyImage(ximage);
5515 ximage=(XImage *) NULL;
5516 if (segment_info[1].shmaddr)
5518 (void) shmdt(segment_info[1].shmaddr);
5519 segment_info[1].shmaddr=(char *) NULL;
5521 if (segment_info[1].shmid >= 0)
5523 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5524 segment_info[1].shmid=(-1);
5530 Allocate X image pixel data.
5532 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5533 if (window->shared_memory)
5541 (void) XSync(display,MagickFalse);
5542 xerror_alert=MagickFalse;
5543 segment_info=(XShmSegmentInfo *) window->segment_info;
5544 ximage->data=segment_info[1].shmaddr;
5545 segment_info[1].readOnly=MagickFalse;
5546 status=XShmAttach(display,&segment_info[1]);
5547 if (status != False)
5548 (void) XSync(display,MagickFalse);
5549 if ((status == False) || (xerror_alert != MagickFalse))
5551 window->shared_memory=MagickFalse;
5552 if (status != False)
5553 XShmDetach(display,&segment_info[1]);
5554 if (ximage != (XImage *) NULL)
5557 XDestroyImage(ximage);
5558 ximage=(XImage *) NULL;
5560 if (segment_info[1].shmid >= 0)
5562 if (segment_info[1].shmaddr != NULL)
5563 (void) shmdt(segment_info[1].shmaddr);
5564 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5565 segment_info[1].shmid=(-1);
5566 segment_info[1].shmaddr=(char *) NULL;
5571 if (window->shared_memory == MagickFalse)
5572 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5573 (char *) NULL,width,height,XBitmapPad(display),0);
5574 if (ximage == (XImage *) NULL)
5577 Unable to create X image.
5579 (void) XCheckDefineCursor(display,window->id,window->cursor);
5580 return(MagickFalse);
5582 length=(size_t) ximage->bytes_per_line*ximage->height;
5583 if (IsEventLogging())
5585 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5586 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5587 ximage->width,ximage->height);
5588 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5590 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5591 ximage->byte_order);
5592 (void) LogMagickEvent(X11Event,GetMagickModule(),
5593 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5594 ximage->bitmap_bit_order,ximage->bitmap_pad);
5595 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5597 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5598 ximage->bytes_per_line);
5599 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5600 ximage->bits_per_pixel);
5601 (void) LogMagickEvent(X11Event,GetMagickModule(),
5602 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5603 ximage->green_mask,ximage->blue_mask);
5605 if (window->shared_memory == MagickFalse)
5607 if (ximage->format != XYBitmap)
5608 ximage->data=(char *) AcquireQuantumMemory((size_t)
5609 ximage->bytes_per_line,(size_t) ximage->height);
5611 ximage->data=(char *) AcquireQuantumMemory((size_t)
5612 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5614 if (ximage->data == (char *) NULL)
5617 Unable to allocate pixel data.
5619 XDestroyImage(ximage);
5620 ximage=(XImage *) NULL;
5621 (void) XCheckDefineCursor(display,window->id,window->cursor);
5622 return(MagickFalse);
5624 if (window->ximage != (XImage *) NULL)
5627 Destroy previous X image.
5629 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5630 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5631 if (window->segment_info != (XShmSegmentInfo *) NULL)
5636 segment_info=(XShmSegmentInfo *) window->segment_info;
5637 if (segment_info[0].shmid >= 0)
5639 (void) XSync(display,MagickFalse);
5640 (void) XShmDetach(display,&segment_info[0]);
5641 (void) XSync(display,MagickFalse);
5642 if (segment_info[0].shmaddr != (char *) NULL)
5643 (void) shmdt(segment_info[0].shmaddr);
5644 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5645 segment_info[0].shmid=(-1);
5646 segment_info[0].shmaddr=(char *) NULL;
5647 window->ximage->data=(char *) NULL;
5651 if (window->ximage->data != (char *) NULL)
5652 free(window->ximage->data);
5653 window->ximage->data=(char *) NULL;
5654 XDestroyImage(window->ximage);
5655 window->ximage=(XImage *) NULL;
5657 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5658 if (window->segment_info != (XShmSegmentInfo *) NULL)
5663 segment_info=(XShmSegmentInfo *) window->segment_info;
5664 segment_info[0]=segment_info[1];
5667 window->ximage=ximage;
5668 matte_image=(XImage *) NULL;
5669 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5670 if ((window->image->matte != MagickFalse) &&
5671 ((ssize_t) width <= XDisplayWidth(display,window->screen)) &&
5672 ((ssize_t) height <= XDisplayHeight(display,window->screen)))
5677 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5678 (char *) NULL,width,height,XBitmapPad(display),0);
5679 if (IsEventLogging())
5681 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5682 (void) LogMagickEvent(X11Event,GetMagickModule(),
5683 " width, height: %dx%d",matte_image->width,matte_image->height);
5685 if (matte_image != (XImage *) NULL)
5688 Allocate matte image pixel data.
5690 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5691 matte_image->bytes_per_line*matte_image->depth,
5692 (size_t) matte_image->height);
5693 if (matte_image->data == (char *) NULL)
5695 XDestroyImage(matte_image);
5696 matte_image=(XImage *) NULL;
5700 if (window->matte_image != (XImage *) NULL)
5705 if (window->matte_image->data != (char *) NULL)
5706 free(window->matte_image->data);
5707 window->matte_image->data=(char *) NULL;
5708 XDestroyImage(window->matte_image);
5709 window->matte_image=(XImage *) NULL;
5711 window->matte_image=matte_image;
5712 if (window->matte_pixmap != (Pixmap) NULL)
5714 (void) XFreePixmap(display,window->matte_pixmap);
5715 window->matte_pixmap=(Pixmap) NULL;
5716 #if defined(MAGICKCORE_HAVE_SHAPE)
5717 if (window->shape != MagickFalse)
5718 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5721 window->stasis=MagickFalse;
5723 Convert pixels to X image data.
5725 if (window->image != (Image *) NULL)
5727 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5728 (ximage->bitmap_bit_order == LSBFirst)))
5729 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5732 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5735 if (window->matte_image != (XImage *) NULL)
5738 Create matte pixmap.
5740 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5741 if (window->matte_pixmap != (Pixmap) NULL)
5750 Copy matte image to matte pixmap.
5752 context_values.background=1;
5753 context_values.foreground=0;
5754 graphics_context=XCreateGC(display,window->matte_pixmap,
5755 (size_t) (GCBackground | GCForeground),&context_values);
5756 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5757 window->matte_image,0,0,0,0,width,height);
5758 (void) XFreeGC(display,graphics_context);
5759 #if defined(MAGICKCORE_HAVE_SHAPE)
5760 if (window->shape != MagickFalse)
5761 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5762 window->matte_pixmap,ShapeSet);
5766 (void) XMakePixmap(display,resource_info,window);
5770 (void) XCheckDefineCursor(display,window->id,window->cursor);
5775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5779 + X M a k e I m a g e L S B F i r s t %
5783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5785 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5786 % pixels are copied in least-significant bit and byte first order. The
5787 % server's scanline pad is respected. Rather than using one or two general
5788 % cases, many special cases are found here to help speed up the image
5791 % The format of the XMakeImageLSBFirst method is:
5793 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5795 % A description of each parameter follows:
5797 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5799 % o window: Specifies a pointer to a XWindowInfo structure.
5801 % o image: the image.
5803 % o ximage: Specifies a pointer to a XImage structure; returned from
5806 % o matte_image: Specifies a pointer to a XImage structure; returned from
5810 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5811 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5819 register const IndexPacket
5822 register const PixelPacket
5828 register unsigned char
5845 assert(resource_info != (XResourceInfo *) NULL);
5846 assert(window != (XWindowInfo *) NULL);
5847 assert(image != (Image *) NULL);
5848 if (image->debug != MagickFalse)
5849 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5851 if ((window->immutable == MagickFalse) &&
5852 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5855 size[MaxTextExtent];
5863 image_info=AcquireImageInfo();
5864 (void) CopyMagickString(image_info->filename,
5865 resource_info->image_info->texture != (char *) NULL ?
5866 resource_info->image_info->texture : "pattern:checkerboard",
5868 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",(unsigned long)
5869 image->columns,(unsigned long) image->rows);
5870 image_info->size=ConstantString(size);
5871 pattern=ReadImage(image_info,&image->exception);
5872 image_info=DestroyImageInfo(image_info);
5873 if (pattern != (Image *) NULL)
5875 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5876 if (canvas != (Image *) NULL)
5877 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5878 pattern=DestroyImage(pattern);
5881 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5882 ximage->bits_per_pixel) >> 3));
5883 map_info=window->map_info;
5884 pixels=window->pixel_info->pixels;
5885 q=(unsigned char *) ximage->data;
5887 if (ximage->format == XYBitmap)
5889 register unsigned short
5897 Convert canvas to big-endian bitmap.
5899 background=(unsigned char)
5900 (XPixelIntensity(&window->pixel_info->foreground_color) <
5901 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5902 foreground=(unsigned char)
5903 (XPixelIntensity(&window->pixel_info->background_color) <
5904 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5905 polarity=(unsigned short) ((PixelIntensityToQuantum(
5906 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5907 if (canvas->colors == 2)
5908 polarity=PixelIntensity(&canvas->colormap[0]) <
5909 PixelIntensity(&canvas->colormap[1]);
5910 for (y=0; y < (int) canvas->rows; y++)
5912 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5913 if (p == (const PixelPacket *) NULL)
5915 indexes=GetVirtualIndexQueue(canvas);
5918 for (x=0; x < (int) canvas->columns; x++)
5921 if (indexes[x] == (IndexPacket) polarity)
5939 if (window->pixel_info->colors != 0)
5940 switch (ximage->bits_per_pixel)
5944 register unsigned int
5948 Convert to 2 bit color-mapped X canvas.
5950 for (y=0; y < (int) canvas->rows; y++)
5952 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5953 if (p == (const PixelPacket *) NULL)
5955 indexes=GetVirtualIndexQueue(canvas);
5957 for (x=0; x < (int) canvas->columns; x++)
5959 pixel=pixels[(ssize_t) indexes[x]] & 0x0f;
5964 *q=(unsigned char) pixel;
5970 *q|=(unsigned char) (pixel << 2);
5976 *q|=(unsigned char) (pixel << 4);
5982 *q|=(unsigned char) (pixel << 6);
5995 register unsigned int
5999 Convert to 4 bit color-mapped X canvas.
6001 for (y=0; y < (int) canvas->rows; y++)
6003 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6004 if (p == (const PixelPacket *) NULL)
6006 indexes=GetVirtualIndexQueue(canvas);
6008 for (x=0; x < (int) canvas->columns; x++)
6010 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6015 *q=(unsigned char) pixel;
6021 *q|=(unsigned char) (pixel << 4);
6036 Convert to 8 bit color-mapped X canvas.
6038 if (resource_info->color_recovery &&
6039 resource_info->quantize_info->dither)
6041 XDitherImage(canvas,ximage);
6044 for (y=0; y < (int) canvas->rows; y++)
6046 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6047 if (p == (const PixelPacket *) NULL)
6049 indexes=GetVirtualIndexQueue(canvas);
6050 for (x=0; x < (int) canvas->columns; x++)
6052 pixel=pixels[(ssize_t) indexes[x]];
6053 *q++=(unsigned char) pixel;
6064 register unsigned int
6068 channel[sizeof(size_t)];
6071 Convert to multi-byte color-mapped X canvas.
6073 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6074 for (y=0; y < (int) canvas->rows; y++)
6076 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6077 if (p == (const PixelPacket *) NULL)
6079 indexes=GetVirtualIndexQueue(canvas);
6080 for (x=0; x < (int) canvas->columns; x++)
6082 pixel=pixels[(ssize_t) indexes[x]];
6083 for (k=0; k < (int) bytes_per_pixel; k++)
6085 channel[k]=(unsigned char) pixel;
6088 for (k=0; k < (int) bytes_per_pixel; k++)
6097 switch (ximage->bits_per_pixel)
6101 register unsigned int
6105 Convert to contiguous 2 bit continuous-tone X canvas.
6107 for (y=0; y < (int) canvas->rows; y++)
6110 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6111 if (p == (const PixelPacket *) NULL)
6113 for (x=0; x < (int) canvas->columns; x++)
6115 pixel=XGammaPixel(map_info,p);
6121 *q=(unsigned char) pixel;
6127 *q|=(unsigned char) (pixel << 2);
6133 *q|=(unsigned char) (pixel << 4);
6139 *q|=(unsigned char) (pixel << 6);
6153 register unsigned int
6157 Convert to contiguous 4 bit continuous-tone X canvas.
6159 for (y=0; y < (int) canvas->rows; y++)
6161 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6162 if (p == (const PixelPacket *) NULL)
6165 for (x=0; x < (int) canvas->columns; x++)
6167 pixel=XGammaPixel(map_info,p);
6173 *q=(unsigned char) pixel;
6179 *q|=(unsigned char) (pixel << 4);
6195 Convert to contiguous 8 bit continuous-tone X canvas.
6197 if (resource_info->color_recovery &&
6198 resource_info->quantize_info->dither)
6200 XDitherImage(canvas,ximage);
6203 for (y=0; y < (int) canvas->rows; y++)
6205 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6206 if (p == (const PixelPacket *) NULL)
6208 for (x=0; x < (int) canvas->columns; x++)
6210 pixel=XGammaPixel(map_info,p);
6211 *q++=(unsigned char) pixel;
6220 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6221 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6222 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6223 (map_info->blue_mult == 1))
6226 Convert to 32 bit continuous-tone X canvas.
6228 for (y=0; y < (int) canvas->rows; y++)
6230 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6231 &canvas->exception);
6232 if (p == (const PixelPacket *) NULL)
6234 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6235 (blue_gamma != 1.0))
6238 Gamma correct canvas.
6240 for (x=(int) canvas->columns-1; x >= 0; x--)
6242 *q++=ScaleQuantumToChar(XBlueGamma(
6243 GetBluePixelComponent(p)));
6244 *q++=ScaleQuantumToChar(XGreenGamma(
6245 GetGreenPixelComponent(p)));
6246 *q++=ScaleQuantumToChar(XRedGamma(
6247 GetRedPixelComponent(p)));
6253 for (x=(int) canvas->columns-1; x >= 0; x--)
6255 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6256 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6257 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6264 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6265 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6266 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6267 (map_info->blue_mult == 65536L))
6270 Convert to 32 bit continuous-tone X canvas.
6272 for (y=0; y < (int) canvas->rows; y++)
6274 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6275 &canvas->exception);
6276 if (p == (const PixelPacket *) NULL)
6278 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6279 (blue_gamma != 1.0))
6282 Gamma correct canvas.
6284 for (x=(int) canvas->columns-1; x >= 0; x--)
6286 *q++=ScaleQuantumToChar(XRedGamma(
6287 GetRedPixelComponent(p)));
6288 *q++=ScaleQuantumToChar(XGreenGamma(
6289 GetGreenPixelComponent(p)));
6290 *q++=ScaleQuantumToChar(XBlueGamma(
6291 GetBluePixelComponent(p)));
6297 for (x=(int) canvas->columns-1; x >= 0; x--)
6299 *q++=ScaleQuantumToChar((Quantum)
6300 GetRedPixelComponent(p));
6301 *q++=ScaleQuantumToChar((Quantum)
6302 GetGreenPixelComponent(p));
6303 *q++=ScaleQuantumToChar((Quantum)
6304 GetBluePixelComponent(p));
6315 register unsigned int
6319 channel[sizeof(size_t)];
6322 Convert to multi-byte continuous-tone X canvas.
6324 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6325 for (y=0; y < (int) canvas->rows; y++)
6327 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6328 &canvas->exception);
6329 if (p == (PixelPacket *) NULL)
6331 for (x=0; x < (ssize_t) canvas->columns; x++)
6333 pixel=XGammaPixel(map_info,p);
6334 for (k=0; k < (int) bytes_per_pixel; k++)
6336 channel[k]=(unsigned char) pixel;
6339 for (k=0; k < (int) bytes_per_pixel; k++)
6349 if (matte_image != (XImage *) NULL)
6352 Initialize matte canvas.
6354 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6355 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6356 q=(unsigned char *) matte_image->data;
6357 for (y=0; y < (int) canvas->rows; y++)
6359 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6360 if (p == (const PixelPacket *) NULL)
6364 for (x=(int) canvas->columns-1; x >= 0; x--)
6367 if (p->opacity > (ssize_t) (QuantumRange/2))
6383 if (canvas != image)
6384 canvas=DestroyImage(canvas);
6388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6392 + X M a k e I m a g e M S B F i r s t %
6396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6398 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6399 % image pixels are copied in most-significant bit and byte first order. The
6400 % server's scanline pad is also respected. Rather than using one or two
6401 % general cases, many special cases are found here to help speed up the image
6404 % The format of the XMakeImageMSBFirst method is:
6406 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6408 % A description of each parameter follows:
6410 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6412 % o window: Specifies a pointer to a XWindowInfo structure.
6414 % o image: the image.
6416 % o ximage: Specifies a pointer to a XImage structure; returned from
6419 % o matte_image: Specifies a pointer to a XImage structure; returned from
6423 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6424 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6435 register const IndexPacket
6438 register const PixelPacket
6441 register unsigned char
6458 assert(resource_info != (XResourceInfo *) NULL);
6459 assert(window != (XWindowInfo *) NULL);
6460 assert(image != (Image *) NULL);
6461 if (image->debug != MagickFalse)
6462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6464 if ((window->immutable != MagickFalse) &&
6465 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6468 size[MaxTextExtent];
6476 image_info=AcquireImageInfo();
6477 (void) CopyMagickString(image_info->filename,
6478 resource_info->image_info->texture != (char *) NULL ?
6479 resource_info->image_info->texture : "pattern:checkerboard",
6481 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",(unsigned long)
6482 image->columns,(unsigned long) image->rows);
6483 image_info->size=ConstantString(size);
6484 pattern=ReadImage(image_info,&image->exception);
6485 image_info=DestroyImageInfo(image_info);
6486 if (pattern != (Image *) NULL)
6488 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6489 if (canvas != (Image *) NULL)
6490 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6491 pattern=DestroyImage(pattern);
6494 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6495 ((ximage->width*ximage->bits_per_pixel) >> 3));
6496 map_info=window->map_info;
6497 pixels=window->pixel_info->pixels;
6498 q=(unsigned char *) ximage->data;
6500 if (ximage->format == XYBitmap)
6502 register unsigned short
6510 Convert canvas to big-endian bitmap.
6512 background=(unsigned char)
6513 (XPixelIntensity(&window->pixel_info->foreground_color) <
6514 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6515 foreground=(unsigned char)
6516 (XPixelIntensity(&window->pixel_info->background_color) <
6517 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6518 polarity=(unsigned short) ((PixelIntensityToQuantum(
6519 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6520 if (canvas->colors == 2)
6521 polarity=PixelIntensity(&canvas->colormap[0]) <
6522 PixelIntensity(&canvas->colormap[1]);
6523 for (y=0; y < (int) canvas->rows; y++)
6525 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6526 if (p == (const PixelPacket *) NULL)
6528 indexes=GetVirtualIndexQueue(canvas);
6531 for (x=(int) canvas->columns-1; x >= 0; x--)
6534 if (indexes[x] == (IndexPacket) polarity)
6552 if (window->pixel_info->colors != 0)
6553 switch (ximage->bits_per_pixel)
6557 register unsigned int
6561 Convert to 2 bit color-mapped X canvas.
6563 for (y=0; y < (int) canvas->rows; y++)
6565 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6566 if (p == (const PixelPacket *) NULL)
6568 indexes=GetVirtualIndexQueue(canvas);
6570 for (x=0; x < (int) canvas->columns; x++)
6572 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6577 *q=(unsigned char) (pixel << 6);
6583 *q|=(unsigned char) (pixel << 4);
6589 *q|=(unsigned char) (pixel << 2);
6595 *q|=(unsigned char) pixel;
6608 register unsigned int
6612 Convert to 4 bit color-mapped X canvas.
6614 for (y=0; y < (int) canvas->rows; y++)
6616 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6617 if (p == (const PixelPacket *) NULL)
6619 indexes=GetVirtualIndexQueue(canvas);
6621 for (x=0; x < (int) canvas->columns; x++)
6623 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6628 *q=(unsigned char) (pixel << 4);
6634 *q|=(unsigned char) pixel;
6649 Convert to 8 bit color-mapped X canvas.
6651 if (resource_info->color_recovery &&
6652 resource_info->quantize_info->dither)
6654 XDitherImage(canvas,ximage);
6657 for (y=0; y < (int) canvas->rows; y++)
6659 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6660 if (p == (const PixelPacket *) NULL)
6662 indexes=GetVirtualIndexQueue(canvas);
6663 for (x=0; x < (int) canvas->columns; x++)
6665 pixel=pixels[(ssize_t) indexes[x]];
6666 *q++=(unsigned char) pixel;
6677 register unsigned int
6681 channel[sizeof(size_t)];
6684 Convert to 8 bit color-mapped X canvas.
6686 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6687 for (y=0; y < (int) canvas->rows; y++)
6689 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6690 if (p == (const PixelPacket *) NULL)
6692 indexes=GetVirtualIndexQueue(canvas);
6693 for (x=0; x < (int) canvas->columns; x++)
6695 pixel=pixels[(ssize_t) indexes[x]];
6696 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6698 channel[k]=(unsigned char) pixel;
6701 for (k=0; k < (int) bytes_per_pixel; k++)
6710 switch (ximage->bits_per_pixel)
6714 register unsigned int
6718 Convert to 4 bit continuous-tone X canvas.
6720 for (y=0; y < (int) canvas->rows; y++)
6722 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6723 if (p == (const PixelPacket *) NULL)
6726 for (x=(int) canvas->columns-1; x >= 0; x--)
6728 pixel=XGammaPixel(map_info,p);
6734 *q=(unsigned char) (pixel << 6);
6740 *q|=(unsigned char) (pixel << 4);
6746 *q|=(unsigned char) (pixel << 2);
6752 *q|=(unsigned char) pixel;
6766 register unsigned int
6770 Convert to 4 bit continuous-tone X canvas.
6772 for (y=0; y < (int) canvas->rows; y++)
6774 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6775 if (p == (const PixelPacket *) NULL)
6778 for (x=(int) canvas->columns-1; x >= 0; x--)
6780 pixel=XGammaPixel(map_info,p);
6786 *q=(unsigned char) (pixel << 4);
6792 *q|=(unsigned char) pixel;
6808 Convert to 8 bit continuous-tone X canvas.
6810 if (resource_info->color_recovery &&
6811 resource_info->quantize_info->dither)
6813 XDitherImage(canvas,ximage);
6816 for (y=0; y < (int) canvas->rows; y++)
6818 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6819 if (p == (const PixelPacket *) NULL)
6821 for (x=(int) canvas->columns-1; x >= 0; x--)
6823 pixel=XGammaPixel(map_info,p);
6824 *q++=(unsigned char) pixel;
6833 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6834 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6835 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6836 (map_info->blue_mult == 1))
6839 Convert to 32 bit continuous-tone X canvas.
6841 for (y=0; y < (int) canvas->rows; y++)
6843 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6844 &canvas->exception);
6845 if (p == (const PixelPacket *) NULL)
6847 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6848 (blue_gamma != 1.0))
6851 Gamma correct canvas.
6853 for (x=(int) canvas->columns-1; x >= 0; x--)
6856 *q++=ScaleQuantumToChar(XRedGamma(
6857 GetRedPixelComponent(p)));
6858 *q++=ScaleQuantumToChar(XGreenGamma(
6859 GetGreenPixelComponent(p)));
6860 *q++=ScaleQuantumToChar(XBlueGamma(
6861 GetBluePixelComponent(p)));
6866 for (x=(int) canvas->columns-1; x >= 0; x--)
6869 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6870 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6871 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6877 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6878 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6879 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6880 (map_info->blue_mult == 65536L))
6883 Convert to 32 bit continuous-tone X canvas.
6885 for (y=0; y < (int) canvas->rows; y++)
6887 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6888 &canvas->exception);
6889 if (p == (const PixelPacket *) NULL)
6891 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6892 (blue_gamma != 1.0))
6895 Gamma correct canvas.
6897 for (x=(int) canvas->columns-1; x >= 0; x--)
6900 *q++=ScaleQuantumToChar(XBlueGamma(
6901 GetBluePixelComponent(p)));
6902 *q++=ScaleQuantumToChar(XGreenGamma(
6903 GetGreenPixelComponent(p)));
6904 *q++=ScaleQuantumToChar(XRedGamma(
6905 GetRedPixelComponent(p)));
6910 for (x=(int) canvas->columns-1; x >= 0; x--)
6913 *q++=ScaleQuantumToChar((Quantum)
6914 GetBluePixelComponent(p));
6915 *q++=ScaleQuantumToChar((Quantum)
6916 GetGreenPixelComponent(p));
6917 *q++=ScaleQuantumToChar((Quantum)
6918 GetRedPixelComponent(p));
6928 register unsigned int
6932 channel[sizeof(size_t)];
6935 Convert to multi-byte continuous-tone X canvas.
6937 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6938 for (y=0; y < (int) canvas->rows; y++)
6940 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6941 &canvas->exception);
6942 if (p == (const PixelPacket *) NULL)
6944 for (x=(int) canvas->columns-1; x >= 0; x--)
6946 pixel=XGammaPixel(map_info,p);
6947 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6949 channel[k]=(unsigned char) pixel;
6952 for (k=0; k < (int) bytes_per_pixel; k++)
6962 if (matte_image != (XImage *) NULL)
6965 Initialize matte canvas.
6967 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6968 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6969 q=(unsigned char *) matte_image->data;
6970 for (y=0; y < (int) canvas->rows; y++)
6972 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6973 if (p == (const PixelPacket *) NULL)
6977 for (x=(int) canvas->columns-1; x >= 0; x--)
6980 if (p->opacity > (ssize_t) (QuantumRange/2))
6996 if (canvas != image)
6997 canvas=DestroyImage(canvas);
7001 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7005 % X M a k e M a g n i f y I m a g e %
7009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7011 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7013 % The format of the XMakeMagnifyImage method is:
7015 % void XMakeMagnifyImage(display,windows)
7017 % A description of each parameter follows:
7019 % o display: Specifies a connection to an X server; returned from
7022 % o windows: Specifies a pointer to a XWindows structure.
7025 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7028 tuple[MaxTextExtent];
7045 register unsigned char
7050 previous_magnify = 0;
7068 Check boundary conditions.
7070 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7071 assert(display != (Display *) NULL);
7072 assert(windows != (XWindows *) NULL);
7074 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7076 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7078 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7080 while (magnify > windows->magnify.width)
7082 while (magnify > windows->magnify.height)
7084 if (magnify != previous_magnify)
7093 New magnify factor: update magnify window name.
7096 while ((1 << i) <= (int) magnify)
7098 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7099 "Magnify %luX",(unsigned long) i);
7100 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7101 if (status != False)
7103 XSetWMName(display,windows->magnify.id,&window_name);
7104 XSetWMIconName(display,windows->magnify.id,&window_name);
7105 (void) XFree((void *) window_name.value);
7108 previous_magnify=magnify;
7109 ximage=windows->image.ximage;
7110 width=(unsigned int) windows->magnify.ximage->width;
7111 height=(unsigned int) windows->magnify.ximage->height;
7112 if ((windows->magnify.x < 0) ||
7113 (windows->magnify.x >= windows->image.ximage->width))
7114 windows->magnify.x=windows->image.ximage->width >> 1;
7115 x=windows->magnify.x-((width/magnify) >> 1);
7119 if (x > (int) (ximage->width-(width/magnify)))
7120 x=ximage->width-width/magnify;
7121 if ((windows->magnify.y < 0) ||
7122 (windows->magnify.y >= windows->image.ximage->height))
7123 windows->magnify.y=windows->image.ximage->height >> 1;
7124 y=windows->magnify.y-((height/magnify) >> 1);
7128 if (y > (int) (ximage->height-(height/magnify)))
7129 y=ximage->height-height/magnify;
7130 q=(unsigned char *) windows->magnify.ximage->data;
7131 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7132 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7133 if (ximage->bits_per_pixel < 8)
7135 register unsigned char
7142 register unsigned int
7148 pixel_info=windows->magnify.pixel_info;
7149 switch (ximage->bitmap_bit_order)
7154 Magnify little-endian bitmap.
7158 if (ximage->format == XYBitmap)
7160 background=(unsigned char)
7161 (XPixelIntensity(&pixel_info->foreground_color) <
7162 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7163 foreground=(unsigned char)
7164 (XPixelIntensity(&pixel_info->background_color) <
7165 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7166 if (windows->magnify.depth > 1)
7167 Swap(background,foreground);
7169 for (i=0; i < (ssize_t) height; i+=magnify)
7172 Propogate pixel magnify rows.
7174 for (j=0; j < magnify; j++)
7176 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7177 ((x*ximage->bits_per_pixel) >> 3);
7178 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7181 for (k=0; k < width; k+=magnify)
7184 Propogate pixel magnify columns.
7186 for (l=0; l < magnify; l++)
7189 Propogate each bit plane.
7191 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7194 if (*p & (0x01 << (p_bit+plane)))
7207 p_bit+=ximage->bits_per_pixel;
7214 *q=byte >> (8-q_bit);
7226 Magnify big-endian bitmap.
7230 if (ximage->format == XYBitmap)
7232 background=(unsigned char)
7233 (XPixelIntensity(&pixel_info->foreground_color) <
7234 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7235 foreground=(unsigned char)
7236 (XPixelIntensity(&pixel_info->background_color) <
7237 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7238 if (windows->magnify.depth > 1)
7239 Swap(background,foreground);
7241 for (i=0; i < (ssize_t) height; i+=magnify)
7244 Propogate pixel magnify rows.
7246 for (j=0; j < magnify; j++)
7248 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7249 ((x*ximage->bits_per_pixel) >> 3);
7250 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7253 for (k=0; k < width; k+=magnify)
7256 Propogate pixel magnify columns.
7258 for (l=0; l < magnify; l++)
7261 Propogate each bit plane.
7263 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7266 if (*p & (0x80 >> (p_bit+plane)))
7279 p_bit+=ximage->bits_per_pixel;
7286 *q=byte << (8-q_bit);
7297 switch (ximage->bits_per_pixel)
7303 Magnify 8 bit X image.
7305 for (i=0; i < (ssize_t) height; i+=magnify)
7308 Propogate pixel magnify rows.
7310 for (j=0; j < magnify; j++)
7312 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7313 ((x*ximage->bits_per_pixel) >> 3);
7314 for (k=0; k < width; k+=magnify)
7317 Propogate pixel magnify columns.
7319 for (l=0; l < magnify; l++)
7331 register unsigned int
7336 Magnify multi-byte X image.
7338 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7339 for (i=0; i < (ssize_t) height; i+=magnify)
7342 Propogate pixel magnify rows.
7344 for (j=0; j < magnify; j++)
7346 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7347 ((x*ximage->bits_per_pixel) >> 3);
7348 for (k=0; k < width; k+=magnify)
7351 Propogate pixel magnify columns.
7353 for (l=0; l < magnify; l++)
7354 for (m=0; m < bytes_per_pixel; m++)
7366 Copy X image to magnify pixmap.
7368 x=windows->magnify.x-((width/magnify) >> 1);
7370 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7372 if (x > (int) (ximage->width-(width/magnify)))
7373 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7376 y=windows->magnify.y-((height/magnify) >> 1);
7378 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7380 if (y > (int) (ximage->height-(height/magnify)))
7381 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7384 if ((x != 0) || (y != 0))
7385 (void) XFillRectangle(display,windows->magnify.pixmap,
7386 windows->magnify.annotate_context,0,0,width,height);
7387 (void) XPutImage(display,windows->magnify.pixmap,
7388 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7390 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7391 (magnify <= (height >> 1))))
7397 Highlight center pixel.
7399 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7400 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7401 highlight_info.width=magnify;
7402 highlight_info.height=magnify;
7403 (void) XDrawRectangle(display,windows->magnify.pixmap,
7404 windows->magnify.highlight_context,(int) highlight_info.x,
7405 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7406 (unsigned int) highlight_info.height-1);
7408 (void) XDrawRectangle(display,windows->magnify.pixmap,
7409 windows->magnify.annotate_context,(int) highlight_info.x+1,
7410 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7411 (unsigned int) highlight_info.height-3);
7414 Show center pixel color.
7416 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7417 windows->magnify.y,&pixel,&windows->image.image->exception);
7418 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7419 windows->magnify.x,windows->magnify.y);
7420 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7421 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7422 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7423 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7424 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7425 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7426 if (pixel.colorspace == CMYKColorspace)
7428 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7429 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7431 if (pixel.matte != MagickFalse)
7433 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7434 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7436 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7437 height=(unsigned int) windows->magnify.font_info->ascent+
7438 windows->magnify.font_info->descent;
7439 x=windows->magnify.font_info->max_bounds.width >> 1;
7440 y=windows->magnify.font_info->ascent+(height >> 2);
7441 (void) XDrawImageString(display,windows->magnify.pixmap,
7442 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7443 GetColorTuple(&pixel,MagickTrue,tuple);
7445 (void) XDrawImageString(display,windows->magnify.pixmap,
7446 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7447 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7448 &windows->image.image->exception);
7450 (void) XDrawImageString(display,windows->magnify.pixmap,
7451 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7453 Refresh magnify window.
7455 magnify_window=windows->magnify;
7458 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7466 % X M a k e P i x m a p %
7470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7472 % XMakePixmap() creates an X11 pixmap.
7474 % The format of the XMakePixmap method is:
7476 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7477 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7478 % XPixelInfo *pixel)
7480 % A description of each parameter follows:
7482 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7484 % o display: Specifies a connection to an X server; returned from
7487 % o window: Specifies a pointer to a XWindowInfo structure.
7490 static MagickBooleanType XMakePixmap(Display *display,
7491 const XResourceInfo *resource_info,XWindowInfo *window)
7497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7498 assert(display != (Display *) NULL);
7499 assert(resource_info != (XResourceInfo *) NULL);
7500 assert(window != (XWindowInfo *) NULL);
7501 if (window->pixmap != (Pixmap) NULL)
7504 Destroy previous X pixmap.
7506 (void) XFreePixmap(display,window->pixmap);
7507 window->pixmap=(Pixmap) NULL;
7509 if (window->use_pixmap == MagickFalse)
7510 return(MagickFalse);
7511 if (window->ximage == (XImage *) NULL)
7512 return(MagickFalse);
7514 Display busy cursor.
7516 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7517 (void) XFlush(display);
7521 width=(unsigned int) window->ximage->width;
7522 height=(unsigned int) window->ximage->height;
7523 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7524 if (window->pixmap == (Pixmap) NULL)
7527 Unable to allocate pixmap.
7529 (void) XCheckDefineCursor(display,window->id,window->cursor);
7530 return(MagickFalse);
7533 Copy X image to pixmap.
7535 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7536 if (window->shared_memory)
7537 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7538 window->ximage,0,0,0,0,width,height,MagickTrue);
7540 if (window->shared_memory == MagickFalse)
7541 (void) XPutImage(display,window->pixmap,window->annotate_context,
7542 window->ximage,0,0,0,0,width,height);
7543 if (IsEventLogging())
7545 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7546 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7552 (void) XCheckDefineCursor(display,window->id,window->cursor);
7557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7561 % X M a k e S t a n d a r d C o l o r m a p %
7565 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7567 % XMakeStandardColormap() creates an X11 Standard Colormap.
7569 % The format of the XMakeStandardColormap method is:
7571 % XMakeStandardColormap(display,visual_info,resource_info,image,
7574 % A description of each parameter follows:
7576 % o display: Specifies a connection to an X server; returned from
7579 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7580 % returned from XGetVisualInfo.
7582 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7584 % o image: the image.
7586 % o map_info: If a Standard Colormap type is specified, this structure is
7587 % initialized with info from the Standard Colormap.
7589 % o pixel: Specifies a pointer to a XPixelInfo structure.
7593 #if defined(__cplusplus) || defined(c_plusplus)
7597 static inline MagickRealType DiversityPixelIntensity(
7598 const DiversityPacket *pixel)
7603 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7607 static int IntensityCompare(const void *x,const void *y)
7616 color_1=(DiversityPacket *) x;
7617 color_2=(DiversityPacket *) y;
7618 diversity=(int) (DiversityPixelIntensity(color_2)-
7619 DiversityPixelIntensity(color_1));
7623 static int PopularityCompare(const void *x,const void *y)
7629 color_1=(DiversityPacket *) x;
7630 color_2=(DiversityPacket *) y;
7631 return((int) color_2->count-(int) color_1->count);
7634 #if defined(__cplusplus) || defined(c_plusplus)
7638 static inline Quantum ScaleXToQuantum(const size_t x,
7641 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7644 MagickExport void XMakeStandardColormap(Display *display,
7645 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7646 XStandardColormap *map_info,XPixelInfo *pixel)
7654 register IndexPacket
7675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7676 assert(display != (Display *) NULL);
7677 assert(visual_info != (XVisualInfo *) NULL);
7678 assert(map_info != (XStandardColormap *) NULL);
7679 assert(resource_info != (XResourceInfo *) NULL);
7680 assert(pixel != (XPixelInfo *) NULL);
7681 exception=(&image->exception);
7682 if (resource_info->map_type != (char *) NULL)
7685 Standard Colormap is already defined (i.e. xstdcmap).
7687 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7689 number_colors=(unsigned int) (map_info->base_pixel+
7690 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7691 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7692 if ((image->matte == MagickFalse) &&
7693 (resource_info->color_recovery == MagickFalse) &&
7694 resource_info->quantize_info->dither &&
7695 (number_colors < MaxColormapSize))
7700 register PixelPacket
7704 Improve image appearance with error diffusion.
7706 affinity_image=AcquireImage((ImageInfo *) NULL);
7707 if (affinity_image == (Image *) NULL)
7708 ThrowXWindowFatalException(ResourceLimitFatalError,
7709 "UnableToDitherImage",image->filename);
7710 affinity_image->columns=number_colors;
7711 affinity_image->rows=1;
7713 Initialize colormap image.
7715 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7717 if (q != (PixelPacket *) NULL)
7719 for (i=0; i < (ssize_t) number_colors; i++)
7722 if (map_info->red_max != 0)
7723 q->red=ScaleXToQuantum((size_t) (i/
7724 map_info->red_mult),map_info->red_max);
7725 q->green=(Quantum) 0;
7726 if (map_info->green_max != 0)
7727 q->green=ScaleXToQuantum((size_t) ((i/
7728 map_info->green_mult) % (map_info->green_max+1)),
7729 map_info->green_max);
7730 q->blue=(Quantum) 0;
7731 if (map_info->blue_max != 0)
7732 q->blue=ScaleXToQuantum((size_t) (i %
7733 map_info->green_mult),map_info->blue_max);
7734 q->opacity=(Quantum) TransparentOpacity;
7737 (void) SyncAuthenticPixels(affinity_image,exception);
7738 (void) RemapImage(resource_info->quantize_info,image,
7741 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7743 (void) SetImageStorageClass(image,DirectClass);
7744 affinity_image=DestroyImage(affinity_image);
7746 if (IsEventLogging())
7748 (void) LogMagickEvent(X11Event,GetMagickModule(),
7749 "Standard Colormap:");
7750 (void) LogMagickEvent(X11Event,GetMagickModule(),
7751 " colormap id: 0x%lx",map_info->colormap);
7752 (void) LogMagickEvent(X11Event,GetMagickModule(),
7753 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7754 map_info->green_max,map_info->blue_max);
7755 (void) LogMagickEvent(X11Event,GetMagickModule(),
7756 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7757 map_info->green_mult,map_info->blue_mult);
7761 if ((visual_info->klass != DirectColor) &&
7762 (visual_info->klass != TrueColor))
7763 if ((image->storage_class == DirectClass) ||
7764 ((int) image->colors > visual_info->colormap_size))
7770 Image has more colors than the visual supports.
7772 quantize_info=(*resource_info->quantize_info);
7773 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7774 (void) QuantizeImage(&quantize_info,image);
7777 Free previous and create new colormap.
7779 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7780 colormap=XDefaultColormap(display,visual_info->screen);
7781 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7782 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7783 visual_info->visual,visual_info->klass == DirectColor ?
7784 AllocAll : AllocNone);
7785 if (colormap == (Colormap) NULL)
7786 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7789 Initialize the map and pixel info structures.
7791 XGetMapInfo(visual_info,colormap,map_info);
7792 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7794 Allocating colors in server colormap is based on visual class.
7796 switch (visual_info->klass)
7802 Define Standard Colormap for StaticGray or StaticColor visual.
7804 number_colors=image->colors;
7805 colors=(XColor *) AcquireQuantumMemory((size_t)
7806 visual_info->colormap_size,sizeof(*colors));
7807 if (colors == (XColor *) NULL)
7808 ThrowXWindowFatalException(ResourceLimitFatalError,
7809 "UnableToCreateColormap",image->filename);
7811 color.flags=(char) (DoRed | DoGreen | DoBlue);
7812 for (i=0; i < (ssize_t) image->colors; i++)
7814 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7815 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7816 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7817 if (visual_info->klass != StaticColor)
7819 gray_value=(unsigned short) XPixelIntensity(&color);
7820 color.red=gray_value;
7821 color.green=gray_value;
7822 color.blue=gray_value;
7824 status=XAllocColor(display,colormap,&color);
7825 if (status == False)
7827 colormap=XCopyColormapAndFree(display,colormap);
7828 (void) XAllocColor(display,colormap,&color);
7830 pixel->pixels[i]=color.pixel;
7842 Define Standard Colormap for GrayScale or PseudoColor visual.
7844 number_colors=image->colors;
7845 colors=(XColor *) AcquireQuantumMemory((size_t)
7846 visual_info->colormap_size,sizeof(*colors));
7847 if (colors == (XColor *) NULL)
7848 ThrowXWindowFatalException(ResourceLimitFatalError,
7849 "UnableToCreateColormap",image->filename);
7851 Preallocate our GUI colors.
7853 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7854 (void) XAllocColor(display,colormap,&pixel->background_color);
7855 (void) XAllocColor(display,colormap,&pixel->border_color);
7856 (void) XAllocColor(display,colormap,&pixel->matte_color);
7857 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7858 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7859 (void) XAllocColor(display,colormap,&pixel->depth_color);
7860 (void) XAllocColor(display,colormap,&pixel->trough_color);
7861 for (i=0; i < MaxNumberPens; i++)
7862 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7864 Determine if image colors will "fit" into X server colormap.
7866 colormap_type=resource_info->colormap;
7867 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7868 NULL,0,pixel->pixels,(unsigned int) image->colors);
7869 if (status != False)
7870 colormap_type=PrivateColormap;
7871 if (colormap_type == SharedColormap)
7889 Define Standard colormap for shared GrayScale or PseudoColor visual.
7891 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7892 sizeof(*diversity));
7893 if (diversity == (DiversityPacket *) NULL)
7894 ThrowXWindowFatalException(ResourceLimitFatalError,
7895 "UnableToCreateColormap",image->filename);
7896 for (i=0; i < (ssize_t) image->colors; i++)
7898 diversity[i].red=image->colormap[i].red;
7899 diversity[i].green=image->colormap[i].green;
7900 diversity[i].blue=image->colormap[i].blue;
7901 diversity[i].index=(unsigned short) i;
7902 diversity[i].count=0;
7904 for (y=0; y < (int) image->rows; y++)
7909 register PixelPacket
7912 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7913 if (q == (PixelPacket *) NULL)
7915 indexes=GetAuthenticIndexQueue(image);
7916 for (x=(ssize_t) image->columns-1; x >= 0; x--)
7917 diversity[(ssize_t) indexes[x]].count++;
7920 Sort colors by decreasing intensity.
7922 qsort((void *) diversity,image->colors,sizeof(*diversity),
7924 for (i=0; i < (ssize_t) image->colors; )
7926 diversity[i].count<<=4; /* increase this colors popularity */
7927 i+=MagickMax((ssize_t) (image->colors >> 4),2);
7929 diversity[image->colors-1].count<<=4;
7930 qsort((void *) diversity,image->colors,sizeof(*diversity),
7936 color.flags=(char) (DoRed | DoGreen | DoBlue);
7937 for (i=0; i < (ssize_t) image->colors; i++)
7939 index=diversity[i].index;
7941 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7943 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7945 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7946 if (visual_info->klass != PseudoColor)
7948 gray_value=(unsigned short) XPixelIntensity(&color);
7949 color.red=gray_value;
7950 color.green=gray_value;
7951 color.blue=gray_value;
7953 status=XAllocColor(display,colormap,&color);
7954 if (status == False)
7956 pixel->pixels[index]=color.pixel;
7960 Read X server colormap.
7962 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7963 visual_info->colormap_size,sizeof(*server_colors));
7964 if (server_colors == (XColor *) NULL)
7965 ThrowXWindowFatalException(ResourceLimitFatalError,
7966 "UnableToCreateColormap",image->filename);
7967 for (x=visual_info->colormap_size-1; x >= 0; x--)
7968 server_colors[x].pixel=(size_t) x;
7969 (void) XQueryColors(display,colormap,server_colors,
7970 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7972 Select remaining colors from X server colormap.
7974 for (; i < (ssize_t) image->colors; i++)
7976 index=diversity[i].index;
7978 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7980 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7982 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7983 if (visual_info->klass != PseudoColor)
7985 gray_value=(unsigned short) XPixelIntensity(&color);
7986 color.red=gray_value;
7987 color.green=gray_value;
7988 color.blue=gray_value;
7990 XBestPixel(display,colormap,server_colors,(unsigned int)
7991 visual_info->colormap_size,&color);
7992 pixel->pixels[index]=color.pixel;
7995 if ((int) image->colors < visual_info->colormap_size)
7998 Fill up colors array-- more choices for pen colors.
8000 retain_colors=MagickMin((unsigned int)
8001 (visual_info->colormap_size-image->colors),256);
8002 for (i=0; i < (ssize_t) retain_colors; i++)
8003 *p++=server_colors[i];
8004 number_colors+=retain_colors;
8006 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8007 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8011 Define Standard colormap for private GrayScale or PseudoColor visual.
8013 if (status == False)
8016 Not enough colormap entries in the colormap-- Create a new colormap.
8018 colormap=XCreateColormap(display,
8019 XRootWindow(display,visual_info->screen),visual_info->visual,
8021 if (colormap == (Colormap) NULL)
8022 ThrowXWindowFatalException(ResourceLimitFatalError,
8023 "UnableToCreateColormap",image->filename);
8024 map_info->colormap=colormap;
8025 if ((int) image->colors < visual_info->colormap_size)
8028 Retain colors from the default colormap to help lessens the
8029 effects of colormap flashing.
8031 retain_colors=MagickMin((unsigned int)
8032 (visual_info->colormap_size-image->colors),256);
8033 p=colors+image->colors;
8034 for (i=0; i < (ssize_t) retain_colors; i++)
8036 p->pixel=(size_t) i;
8039 (void) XQueryColors(display,
8040 XDefaultColormap(display,visual_info->screen),
8041 colors+image->colors,(int) retain_colors);
8043 Transfer colors from default to private colormap.
8045 (void) XAllocColorCells(display,colormap,MagickFalse,
8046 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8048 p=colors+image->colors;
8049 for (i=0; i < (ssize_t) retain_colors; i++)
8051 p->pixel=pixel->pixels[i];
8054 (void) XStoreColors(display,colormap,colors+image->colors,
8055 (int) retain_colors);
8056 number_colors+=retain_colors;
8058 (void) XAllocColorCells(display,colormap,MagickFalse,
8059 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8063 Store the image colormap.
8066 color.flags=(char) (DoRed | DoGreen | DoBlue);
8067 for (i=0; i < (ssize_t) image->colors; i++)
8069 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8070 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8071 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8072 if (visual_info->klass != PseudoColor)
8074 gray_value=(unsigned short) XPixelIntensity(&color);
8075 color.red=gray_value;
8076 color.green=gray_value;
8077 color.blue=gray_value;
8079 color.pixel=pixel->pixels[i];
8082 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8093 Define Standard Colormap for TrueColor or DirectColor visual.
8095 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8096 (map_info->green_max*map_info->green_mult)+
8097 (map_info->blue_max*map_info->blue_mult)+1);
8098 linear_colormap=(number_colors > 4096) ||
8099 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8100 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8101 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8102 MagickTrue : MagickFalse;
8103 if (linear_colormap != MagickFalse)
8104 number_colors=(size_t) visual_info->colormap_size;
8106 Allocate color array.
8108 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8109 if (colors == (XColor *) NULL)
8110 ThrowXWindowFatalException(ResourceLimitFatalError,
8111 "UnableToCreateColormap",image->filename);
8113 Initialize linear color ramp.
8116 color.flags=(char) (DoRed | DoGreen | DoBlue);
8117 if (linear_colormap != MagickFalse)
8118 for (i=0; i < (ssize_t) number_colors; i++)
8120 color.blue=(unsigned short) 0;
8121 if (map_info->blue_max != 0)
8122 color.blue=(unsigned short) ((size_t)
8123 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8124 color.green=color.blue;
8125 color.red=color.blue;
8126 color.pixel=XStandardPixel(map_info,&color);
8130 for (i=0; i < (ssize_t) number_colors; i++)
8132 color.red=(unsigned short) 0;
8133 if (map_info->red_max != 0)
8134 color.red=(unsigned short) ((size_t)
8135 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8136 color.green=(unsigned int) 0;
8137 if (map_info->green_max != 0)
8138 color.green=(unsigned short) ((size_t)
8139 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8140 map_info->green_max));
8141 color.blue=(unsigned short) 0;
8142 if (map_info->blue_max != 0)
8143 color.blue=(unsigned short) ((size_t)
8144 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8145 color.pixel=XStandardPixel(map_info,&color);
8148 if ((visual_info->klass == DirectColor) &&
8149 (colormap != XDefaultColormap(display,visual_info->screen)))
8150 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8152 for (i=0; i < (ssize_t) number_colors; i++)
8153 (void) XAllocColor(display,colormap,&colors[i]);
8157 if ((visual_info->klass != DirectColor) &&
8158 (visual_info->klass != TrueColor))
8161 Set foreground, background, border, etc. pixels.
8163 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8164 &pixel->foreground_color);
8165 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8166 &pixel->background_color);
8167 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8170 Foreground and background colors must differ.
8172 pixel->background_color.red=(~pixel->foreground_color.red);
8173 pixel->background_color.green=
8174 (~pixel->foreground_color.green);
8175 pixel->background_color.blue=
8176 (~pixel->foreground_color.blue);
8177 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8178 &pixel->background_color);
8180 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8181 &pixel->border_color);
8182 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8183 &pixel->matte_color);
8184 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8185 &pixel->highlight_color);
8186 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8187 &pixel->shadow_color);
8188 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8189 &pixel->depth_color);
8190 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8191 &pixel->trough_color);
8192 for (i=0; i < MaxNumberPens; i++)
8194 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8195 &pixel->pen_colors[i]);
8196 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8198 pixel->colors=image->colors+MaxNumberPens;
8200 colors=(XColor *) RelinquishMagickMemory(colors);
8201 if (IsEventLogging())
8203 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8204 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8205 map_info->colormap);
8206 (void) LogMagickEvent(X11Event,GetMagickModule(),
8207 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8208 map_info->green_max,map_info->blue_max);
8209 (void) LogMagickEvent(X11Event,GetMagickModule(),
8210 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8211 map_info->green_mult,map_info->blue_mult);
8216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8220 % X M a k e W i n d o w %
8224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8226 % XMakeWindow() creates an X11 window.
8228 % The format of the XMakeWindow method is:
8230 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8231 % XClassHint *class_hint,XWMHints *manager_hints,
8232 % XWindowInfo *window_info)
8234 % A description of each parameter follows:
8236 % o display: Specifies a connection to an X server; returned from
8239 % o parent: Specifies the parent window_info.
8241 % o argv: Specifies the application's argument list.
8243 % o argc: Specifies the number of arguments.
8245 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8247 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8249 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8252 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8253 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8254 XWindowInfo *window_info)
8256 #define MinWindowSize 64
8264 static XTextProperty
8275 Set window info hints.
8277 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8278 assert(display != (Display *) NULL);
8279 assert(window_info != (XWindowInfo *) NULL);
8280 size_hints=XAllocSizeHints();
8281 if (size_hints == (XSizeHints *) NULL)
8282 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8283 size_hints->flags=(ssize_t) window_info->flags;
8284 size_hints->x=window_info->x;
8285 size_hints->y=window_info->y;
8286 size_hints->width=(int) window_info->width;
8287 size_hints->height=(int) window_info->height;
8288 if (window_info->immutable != MagickFalse)
8291 Window size cannot be changed.
8293 size_hints->min_width=size_hints->width;
8294 size_hints->min_height=size_hints->height;
8295 size_hints->max_width=size_hints->width;
8296 size_hints->max_height=size_hints->height;
8297 size_hints->flags|=PMinSize;
8298 size_hints->flags|=PMaxSize;
8303 Window size can be changed.
8305 size_hints->min_width=(int) window_info->min_width;
8306 size_hints->min_height=(int) window_info->min_height;
8307 size_hints->flags|=PResizeInc;
8308 size_hints->width_inc=(int) window_info->width_inc;
8309 size_hints->height_inc=(int) window_info->height_inc;
8310 #if !defined(PRE_R4_ICCCM)
8311 size_hints->flags|=PBaseSize;
8312 size_hints->base_width=size_hints->width_inc;
8313 size_hints->base_height=size_hints->height_inc;
8316 gravity=NorthWestGravity;
8317 if (window_info->geometry != (char *) NULL)
8320 default_geometry[MaxTextExtent],
8321 geometry[MaxTextExtent];
8330 User specified geometry.
8332 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8333 size_hints->width,size_hints->height);
8334 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8336 while (strlen(p) != 0)
8338 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8341 (void) CopyMagickString(p,p+1,MaxTextExtent);
8343 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8344 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8345 &size_hints->width,&size_hints->height,&gravity);
8346 if ((flags & WidthValue) && (flags & HeightValue))
8347 size_hints->flags|=USSize;
8348 if ((flags & XValue) && (flags & YValue))
8350 size_hints->flags|=USPosition;
8351 window_info->x=size_hints->x;
8352 window_info->y=size_hints->y;
8355 #if !defined(PRE_R4_ICCCM)
8356 size_hints->win_gravity=gravity;
8357 size_hints->flags|=PWinGravity;
8359 if (window_info->id == (Window) NULL)
8360 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8361 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8362 window_info->border_width,(int) window_info->depth,InputOutput,
8363 window_info->visual,window_info->mask,&window_info->attributes);
8376 Window already exists; change relevant attributes.
8378 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8379 &window_info->attributes);
8380 mask=ConfigureNotify;
8381 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8382 window_changes.x=window_info->x;
8383 window_changes.y=window_info->y;
8384 window_changes.width=(int) window_info->width;
8385 window_changes.height=(int) window_info->height;
8386 mask=(MagickStatusType) (CWWidth | CWHeight);
8387 if (window_info->flags & USPosition)
8389 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8390 mask,&window_changes);
8392 if (window_info->id == (Window) NULL)
8393 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8395 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8396 if (status == False)
8397 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8399 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8400 if (status == False)
8401 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8402 window_info->icon_name);
8403 if (window_info->icon_geometry != (char *) NULL)
8411 User specified icon geometry.
8413 size_hints->flags|=USPosition;
8414 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8415 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8416 &manager_hints->icon_y,&width,&height,&gravity);
8417 if ((flags & XValue) && (flags & YValue))
8418 manager_hints->flags|=IconPositionHint;
8420 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8421 size_hints,manager_hints,class_hint);
8422 if (window_name.value != (void *) NULL)
8424 (void) XFree((void *) window_name.value);
8425 window_name.value=(unsigned char *) NULL;
8426 window_name.nitems=0;
8428 if (icon_name.value != (void *) NULL)
8430 (void) XFree((void *) icon_name.value);
8431 icon_name.value=(unsigned char *) NULL;
8434 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8435 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8436 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8437 (void) XFree((void *) size_hints);
8438 if (window_info->shape != MagickFalse)
8440 #if defined(MAGICKCORE_HAVE_SHAPE)
8446 Can we apply a non-rectangular shaping mask?
8450 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8451 window_info->shape=MagickFalse;
8453 window_info->shape=MagickFalse;
8456 if (window_info->shared_memory)
8458 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8460 Can we use shared memory with this window?
8462 if (XShmQueryExtension(display) == 0)
8463 window_info->shared_memory=MagickFalse;
8465 window_info->shared_memory=MagickFalse;
8468 window_info->image=NewImageList();
8469 window_info->destroy=MagickFalse;
8473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8477 % X M a g i c k P r o g r e s s M o n i t o r %
8481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8483 % XMagickProgressMonitor() displays the progress a task is making in
8484 % completing a task.
8486 % The format of the XMagickProgressMonitor method is:
8488 % void XMagickProgressMonitor(const char *task,
8489 % const MagickOffsetType quantum,const MagickSizeType span,
8490 % void *client_data)
8492 % A description of each parameter follows:
8494 % o task: Identifies the task in progress.
8496 % o quantum: Specifies the quantum position within the span which represents
8497 % how much progress has been made in completing a task.
8499 % o span: Specifies the span relative to completing a task.
8501 % o client_data: Pointer to any client data.
8505 static const char *GetLocaleMonitorMessage(const char *text)
8508 message[MaxTextExtent],
8517 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8519 if (p != (char *) NULL)
8521 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8522 locale_message=GetLocaleMessage(message);
8523 if (locale_message == message)
8525 return(locale_message);
8528 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8529 const MagickOffsetType quantum,const MagickSizeType span,
8530 void *magick_unused(client_data))
8535 windows=XSetWindows((XWindows *) ~0);
8536 if (windows == (XWindows *) NULL)
8538 if (windows->info.mapped != MagickFalse)
8539 XProgressMonitorWidget(windows->display,windows,
8540 GetLocaleMonitorMessage(tag),quantum,span);
8545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8549 % X Q u e r y C o l o r D a t a b a s e %
8553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8555 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8558 % The format of the XQueryColorDatabase method is:
8560 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8562 % A description of each parameter follows:
8564 % o target: Specifies the color to lookup in the X color database.
8566 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8567 % color is returned as this value.
8570 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8577 *display = (Display *) NULL;
8586 Initialize color return value.
8588 assert(color != (XColor *) NULL);
8592 color->flags=(char) (DoRed | DoGreen | DoBlue);
8593 if ((target == (char *) NULL) || (*target == '\0'))
8594 target="#ffffffffffff";
8596 Let the X server define the color for us.
8598 if (display == (Display *) NULL)
8599 display=XOpenDisplay((char *) NULL);
8600 if (display == (Display *) NULL)
8602 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8603 return(MagickFalse);
8605 colormap=XDefaultColormap(display,XDefaultScreen(display));
8606 status=XParseColor(display,colormap,(char *) target,&xcolor);
8607 if (status == False)
8608 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8611 color->red=xcolor.red;
8612 color->green=xcolor.green;
8613 color->blue=xcolor.blue;
8614 color->flags=xcolor.flags;
8616 return(status != False ? MagickTrue : MagickFalse);
8620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8624 % X Q u e r y P o s i t i o n %
8628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8630 % XQueryPosition() gets the pointer coordinates relative to a window.
8632 % The format of the XQueryPosition method is:
8634 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8636 % A description of each parameter follows:
8638 % o display: Specifies a connection to an X server; returned from
8641 % o window: Specifies a pointer to a Window.
8643 % o x: Return the x coordinate of the pointer relative to the origin of the
8646 % o y: Return the y coordinate of the pointer relative to the origin of the
8650 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8663 assert(display != (Display *) NULL);
8664 assert(window != (Window) NULL);
8665 assert(x != (int *) NULL);
8666 assert(y != (int *) NULL);
8667 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8676 % X R e f r e s h W i n d o w %
8680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8682 % XRefreshWindow() refreshes an image in a X window.
8684 % The format of the XRefreshWindow method is:
8686 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8687 % const XEvent *event)
8689 % A description of each parameter follows:
8691 % o display: Specifies a connection to an X server; returned from
8694 % o window: Specifies a pointer to a XWindowInfo structure.
8696 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8697 % the entire image is refreshed.
8700 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8701 const XEvent *event)
8711 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8712 assert(display != (Display *) NULL);
8713 assert(window != (XWindowInfo *) NULL);
8714 if (window->ximage == (XImage *) NULL)
8716 if (event != (XEvent *) NULL)
8719 Determine geometry from expose event.
8723 width=(unsigned int) event->xexpose.width;
8724 height=(unsigned int) event->xexpose.height;
8732 Refresh entire window; discard outstanding expose events.
8736 width=window->width;
8737 height=window->height;
8738 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8739 if (window->matte_pixmap != (Pixmap) NULL)
8741 #if defined(MAGICKCORE_HAVE_SHAPE)
8742 if (window->shape != MagickFalse)
8743 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8744 window->matte_pixmap,ShapeSet);
8749 Check boundary conditions.
8751 if ((window->ximage->width-(x+window->x)) < (int) width)
8752 width=(unsigned int) (window->ximage->width-(x+window->x));
8753 if ((window->ximage->height-(y+window->y)) < (int) height)
8754 height=(unsigned int) (window->ximage->height-(y+window->y));
8758 if (window->matte_pixmap != (Pixmap) NULL)
8759 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8760 if (window->pixmap != (Pixmap) NULL)
8762 if (window->depth > 1)
8763 (void) XCopyArea(display,window->pixmap,window->id,
8764 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8766 (void) XCopyPlane(display,window->pixmap,window->id,
8767 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8772 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8773 if (window->shared_memory)
8774 (void) XShmPutImage(display,window->id,window->annotate_context,
8775 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8777 if (window->shared_memory == MagickFalse)
8778 (void) XPutImage(display,window->id,window->annotate_context,
8779 window->ximage,x+window->x,y+window->y,x,y,width,height);
8781 if (window->matte_pixmap != (Pixmap) NULL)
8782 (void) XSetClipMask(display,window->annotate_context,None);
8783 (void) XFlush(display);
8787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8791 % X R e m o t e C o m m a n d %
8795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8797 % XRemoteCommand() forces a remote display(1) to display the specified
8800 % The format of the XRemoteCommand method is:
8802 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8803 % const char *filename)
8805 % A description of each parameter follows:
8807 % o display: Specifies a connection to an X server; returned from
8810 % o window: Specifies the name or id of an X window.
8812 % o filename: the name of the image filename to display.
8815 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8816 const char *window,const char *filename)
8825 assert(filename != (char *) NULL);
8826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8827 if (display == (Display *) NULL)
8828 display=XOpenDisplay((char *) NULL);
8829 if (display == (Display *) NULL)
8831 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8832 return(MagickFalse);
8834 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8835 remote_window=(Window) NULL;
8836 root_window=XRootWindow(display,XDefaultScreen(display));
8837 if (window != (char *) NULL)
8840 Search window hierarchy and identify any clients by name or ID.
8842 if (isdigit((unsigned char) *window) != 0)
8843 remote_window=XWindowByID(display,root_window,(Window)
8844 strtol((char *) window,(char **) NULL,0));
8845 if (remote_window == (Window) NULL)
8846 remote_window=XWindowByName(display,root_window,window);
8848 if (remote_window == (Window) NULL)
8849 remote_window=XWindowByProperty(display,root_window,remote_atom);
8850 if (remote_window == (Window) NULL)
8852 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8854 return(MagickFalse);
8857 Send remote command.
8859 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8860 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8861 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8862 (void) XSync(display,MagickFalse);
8867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8871 % X R e t a i n W i n d o w C o l o r s %
8875 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8877 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8878 % the colors associated with an image displayed on the window.
8880 % The format of the XRetainWindowColors method is:
8882 % void XRetainWindowColors(Display *display,const Window window)
8884 % A description of each parameter follows:
8886 % o display: Specifies a connection to an X server; returned from
8889 % o window: Specifies a pointer to a XWindowInfo structure.
8892 MagickExport void XRetainWindowColors(Display *display,const Window window)
8901 Put property on the window.
8903 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8904 assert(display != (Display *) NULL);
8905 assert(window != (Window) NULL);
8906 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8907 if (property == (Atom) NULL)
8909 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8913 pixmap=XCreatePixmap(display,window,1,1,1);
8914 if (pixmap == (Pixmap) NULL)
8916 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8919 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8920 (unsigned char *) &pixmap,1);
8921 (void) XSetCloseDownMode(display,RetainPermanent);
8925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8929 % X S e l e c t W i n d o w %
8933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8935 % XSelectWindow() allows a user to select a window using the mouse. If the
8936 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8937 % is returned in the crop_info structure.
8939 % The format of the XSelectWindow function is:
8941 % target_window=XSelectWindow(display,crop_info)
8943 % A description of each parameter follows:
8945 % o window: XSelectWindow returns the window id.
8947 % o display: Specifies a pointer to the Display structure; returned from
8950 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8951 % contains the extents of any cropping rectangle.
8954 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8956 #define MinimumCropArea (unsigned int) 9
8983 Initialize graphic context.
8985 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8986 assert(display != (Display *) NULL);
8987 assert(crop_info != (RectangleInfo *) NULL);
8988 root_window=XRootWindow(display,XDefaultScreen(display));
8989 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8990 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8991 context_values.function=GXinvert;
8992 context_values.plane_mask=
8993 context_values.background ^ context_values.foreground;
8994 context_values.subwindow_mode=IncludeInferiors;
8995 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
8996 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8997 if (annotate_context == (GC) NULL)
8998 return(MagickFalse);
9000 Grab the pointer using target cursor.
9002 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9003 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9004 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9005 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9006 GrabModeAsync,root_window,target_cursor,CurrentTime);
9007 if (status != GrabSuccess)
9009 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9010 return((Window) NULL);
9016 crop_info->height=0;
9018 target_window=(Window) NULL;
9023 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9024 (void) XDrawRectangle(display,root_window,annotate_context,
9025 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9026 (unsigned int) crop_info->height-1);
9028 Allow another event.
9030 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9031 (void) XWindowEvent(display,root_window,ButtonPressMask |
9032 ButtonReleaseMask | ButtonMotionMask,&event);
9033 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9034 (void) XDrawRectangle(display,root_window,annotate_context,
9035 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9036 (unsigned int) crop_info->height-1);
9041 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9042 event.xbutton.x,event.xbutton.y);
9043 if (target_window == (Window) NULL)
9044 target_window=root_window;
9045 x_offset=event.xbutton.x_root;
9046 y_offset=event.xbutton.y_root;
9047 crop_info->x=x_offset;
9048 crop_info->y=y_offset;
9050 crop_info->height=0;
9062 Discard pending button motion events.
9064 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9065 crop_info->x=event.xmotion.x;
9066 crop_info->y=event.xmotion.y;
9068 Check boundary conditions.
9070 if ((int) crop_info->x < x_offset)
9071 crop_info->width=(unsigned int) (x_offset-crop_info->x);
9074 crop_info->width=(unsigned int) (crop_info->x-x_offset);
9075 crop_info->x=x_offset;
9077 if ((int) crop_info->y < y_offset)
9078 crop_info->height=(unsigned int) (y_offset-crop_info->y);
9081 crop_info->height=(unsigned int) (crop_info->y-y_offset);
9082 crop_info->y=y_offset;
9088 } while ((target_window == (Window) NULL) || (presses > 0));
9089 (void) XUngrabPointer(display,CurrentTime);
9090 (void) XFreeCursor(display,target_cursor);
9091 (void) XFreeGC(display,annotate_context);
9092 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9095 crop_info->height=0;
9097 if ((crop_info->width != 0) && (crop_info->height != 0))
9098 target_window=root_window;
9099 return(target_window);
9103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9107 % X S e t C u r s o r S t a t e %
9111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9113 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9114 % reset to their default.
9116 % The format of the XXSetCursorState method is:
9118 % XSetCursorState(display,windows,const MagickStatusType state)
9120 % A description of each parameter follows:
9122 % o display: Specifies a connection to an X server; returned from
9125 % o windows: Specifies a pointer to a XWindows structure.
9127 % o state: An unsigned integer greater than 0 sets the cursor state
9128 % to busy, otherwise the cursor are reset to their default.
9131 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9132 const MagickStatusType state)
9134 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9135 assert(display != (Display *) NULL);
9136 assert(windows != (XWindows *) NULL);
9139 (void) XCheckDefineCursor(display,windows->image.id,
9140 windows->image.busy_cursor);
9141 (void) XCheckDefineCursor(display,windows->pan.id,
9142 windows->pan.busy_cursor);
9143 (void) XCheckDefineCursor(display,windows->magnify.id,
9144 windows->magnify.busy_cursor);
9145 (void) XCheckDefineCursor(display,windows->command.id,
9146 windows->command.busy_cursor);
9150 (void) XCheckDefineCursor(display,windows->image.id,
9151 windows->image.cursor);
9152 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9153 (void) XCheckDefineCursor(display,windows->magnify.id,
9154 windows->magnify.cursor);
9155 (void) XCheckDefineCursor(display,windows->command.id,
9156 windows->command.cursor);
9157 (void) XCheckDefineCursor(display,windows->command.id,
9158 windows->widget.cursor);
9159 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9161 windows->info.mapped=MagickFalse;
9165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9169 % X S e t W i n d o w s %
9173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9175 % XSetWindows() sets the X windows structure if the windows info is specified.
9176 % Otherwise the current windows structure is returned.
9178 % The format of the XSetWindows method is:
9180 % XWindows *XSetWindows(XWindows *windows_info)
9182 % A description of each parameter follows:
9184 % o windows_info: Initialize the Windows structure with this information.
9187 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9190 *windows = (XWindows *) NULL;
9192 if (windows_info != (XWindows *) ~0)
9194 windows=(XWindows *) RelinquishMagickMemory(windows);
9195 windows=windows_info;
9200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9204 % X U s e r P r e f e r e n c e s %
9208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9210 % XUserPreferences() saves the preferences in a configuration file in the
9211 % users' home directory.
9213 % The format of the XUserPreferences method is:
9215 % void XUserPreferences(XResourceInfo *resource_info)
9217 % A description of each parameter follows:
9219 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9222 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9224 #if defined(X11_PREFERENCES_PATH)
9226 cache[MaxTextExtent],
9227 filename[MaxTextExtent],
9228 specifier[MaxTextExtent];
9235 preferences_database;
9238 Save user preferences to the client configuration file.
9240 assert(resource_info != (XResourceInfo *) NULL);
9241 client_name=GetClientName();
9242 preferences_database=XrmGetStringDatabase("");
9243 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9244 value=resource_info->backdrop ? "True" : "False";
9245 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9246 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9247 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9248 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9249 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9251 value=resource_info->confirm_exit ? "True" : "False";
9252 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9253 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9255 value=resource_info->confirm_edit ? "True" : "False";
9256 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9257 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9259 value=resource_info->display_warnings ? "True" : "False";
9260 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9261 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9262 value=resource_info->quantize_info->dither ? "True" : "False";
9263 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9264 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9266 value=resource_info->gamma_correct ? "True" : "False";
9267 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9268 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9269 (void) FormatMagickString(cache,MaxTextExtent,"%lu",(unsigned long)
9270 resource_info->undo_cache);
9271 XrmPutStringResource(&preferences_database,specifier,cache);
9272 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9273 value=resource_info->use_pixmap ? "True" : "False";
9274 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9275 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9276 X11_PREFERENCES_PATH,client_name);
9277 ExpandFilename(filename);
9278 XrmPutFileDatabase(preferences_database,filename);
9283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9287 % X V i s u a l C l a s s N a m e %
9291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9293 % XVisualClassName() returns the visual class name as a character string.
9295 % The format of the XVisualClassName method is:
9297 % char *XVisualClassName(const int visual_class)
9299 % A description of each parameter follows:
9301 % o visual_type: XVisualClassName returns the visual class as a character
9304 % o class: Specifies the visual class.
9307 static const char *XVisualClassName(const int visual_class)
9309 switch (visual_class)
9311 case StaticGray: return("StaticGray");
9312 case GrayScale: return("GrayScale");
9313 case StaticColor: return("StaticColor");
9314 case PseudoColor: return("PseudoColor");
9315 case TrueColor: return("TrueColor");
9316 case DirectColor: return("DirectColor");
9318 return("unknown visual class");
9322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9332 % XWarning() displays a warning reason in a Notice widget.
9334 % The format of the XWarning method is:
9336 % void XWarning(const unsigned int warning,const char *reason,
9337 % const char *description)
9339 % A description of each parameter follows:
9341 % o warning: Specifies the numeric warning category.
9343 % o reason: Specifies the reason to display before terminating the
9346 % o description: Specifies any description to the reason.
9349 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9350 const char *reason,const char *description)
9353 text[MaxTextExtent];
9358 if (reason == (char *) NULL)
9360 (void) CopyMagickString(text,reason,MaxTextExtent);
9361 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9362 windows=XSetWindows((XWindows *) ~0);
9363 XNoticeWidget(windows->display,windows,text,(char *) description);
9367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9371 % X W i n d o w B y I D %
9375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9377 % XWindowByID() locates a child window with a given ID. If not window with
9378 % the given name is found, 0 is returned. Only the window specified and its
9379 % subwindows are searched.
9381 % The format of the XWindowByID function is:
9383 % child=XWindowByID(display,window,id)
9385 % A description of each parameter follows:
9387 % o child: XWindowByID returns the window with the specified
9388 % id. If no windows are found, XWindowByID returns 0.
9390 % o display: Specifies a pointer to the Display structure; returned from
9393 % o id: Specifies the id of the window to locate.
9396 MagickExport Window XWindowByID(Display *display,const Window root_window,
9416 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9417 assert(display != (Display *) NULL);
9418 assert(root_window != (Window) NULL);
9420 return(XSelectWindow(display,&rectangle_info));
9421 if (root_window == id)
9423 status=XQueryTree(display,root_window,&child,&child,&children,
9425 if (status == False)
9426 return((Window) NULL);
9427 window=(Window) NULL;
9428 for (i=0; i < (int) number_children; i++)
9431 Search each child and their children.
9433 window=XWindowByID(display,children[i],id);
9434 if (window != (Window) NULL)
9437 if (children != (Window *) NULL)
9438 (void) XFree((void *) children);
9443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9447 % X W i n d o w B y N a m e %
9451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9453 % XWindowByName() locates a window with a given name on a display. If no
9454 % window with the given name is found, 0 is returned. If more than one window
9455 % has the given name, the first one is returned. Only root and its children
9458 % The format of the XWindowByName function is:
9460 % window=XWindowByName(display,root_window,name)
9462 % A description of each parameter follows:
9464 % o window: XWindowByName returns the window id.
9466 % o display: Specifies a pointer to the Display structure; returned from
9469 % o root_window: Specifies the id of the root window.
9471 % o name: Specifies the name of the window to locate.
9474 MagickExport Window XWindowByName(Display *display,const Window root_window,
9494 assert(display != (Display *) NULL);
9495 assert(root_window != (Window) NULL);
9496 assert(name != (char *) NULL);
9497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9498 if (XGetWMName(display,root_window,&window_name) != 0)
9499 if (LocaleCompare((char *) window_name.value,name) == 0)
9500 return(root_window);
9501 status=XQueryTree(display,root_window,&child,&child,&children,
9503 if (status == False)
9504 return((Window) NULL);
9505 window=(Window) NULL;
9506 for (i=0; i < (int) number_children; i++)
9509 Search each child and their children.
9511 window=XWindowByName(display,children[i],name);
9512 if (window != (Window) NULL)
9515 if (children != (Window *) NULL)
9516 (void) XFree((void *) children);
9521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9525 % X W i n d o w B y P r o p e r y %
9529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9531 % XWindowByProperty() locates a child window with a given property. If not
9532 % window with the given name is found, 0 is returned. If more than one window
9533 % has the given property, the first one is returned. Only the window
9534 % specified and its subwindows are searched.
9536 % The format of the XWindowByProperty function is:
9538 % child=XWindowByProperty(display,window,property)
9540 % A description of each parameter follows:
9542 % o child: XWindowByProperty returns the window id with the specified
9543 % property. If no windows are found, XWindowByProperty returns 0.
9545 % o display: Specifies a pointer to the Display structure; returned from
9548 % o property: Specifies the property of the window to locate.
9551 MagickExport Window XWindowByProperty(Display *display,const Window window,
9552 const Atom property)
9580 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9581 assert(display != (Display *) NULL);
9582 assert(window != (Window) NULL);
9583 assert(property != (Atom) NULL);
9584 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9585 if (status == False)
9586 return((Window) NULL);
9588 child=(Window) NULL;
9589 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9591 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9592 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9594 (void) XFree((void *) data);
9595 if ((status == Success) && (type != (Atom) NULL))
9598 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9599 child=XWindowByProperty(display,children[i],property);
9600 if (children != (Window *) NULL)
9601 (void) XFree((void *) children);
9607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9611 % X I m p o r t I m a g e %
9615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9617 % XImportImage() reads an image from an X window.
9619 % The format of the XImportImage method is:
9621 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9623 % A description of each parameter follows:
9625 % o image_info: the image info..
9627 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9630 MagickExport Image *XImportImage(const ImageInfo *image_info,
9631 XImportInfo *ximage_info)
9633 assert(image_info != (const ImageInfo *) NULL);
9634 assert(image_info->signature == MagickSignature);
9635 if (image_info->debug != MagickFalse)
9636 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9637 image_info->filename);
9638 assert(ximage_info != (XImportInfo *) NULL);
9639 return((Image *) NULL);
9644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9648 + X C o m p o n e n t G e n e s i s %
9652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9654 % XComponentGenesis() instantiates the X component.
9656 % The format of the XComponentGenesis method is:
9658 % MagickBooleanType XComponentGenesis(void)
9661 MagickExport MagickBooleanType XComponentGenesis(void)
9667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9671 % X G e t I m p o r t I n f o %
9675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9677 % XGetImportInfo() initializes the XImportInfo structure.
9679 % The format of the XGetImportInfo method is:
9681 % void XGetImportInfo(XImportInfo *ximage_info)
9683 % A description of each parameter follows:
9685 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9688 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9690 assert(ximage_info != (XImportInfo *) NULL);
9691 ximage_info->frame=MagickFalse;
9692 ximage_info->borders=MagickFalse;
9693 ximage_info->screen=MagickFalse;
9694 ximage_info->descend=MagickTrue;
9695 ximage_info->silent=MagickFalse;