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)
1171 Restrict visual search by screen number.
1173 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1174 assert(display != (Display *) NULL);
1175 assert(map_info != (XStandardColormap *) NULL);
1176 assert(resource_info != (XResourceInfo *) NULL);
1177 map_type=resource_info->map_type;
1178 visual_type=resource_info->visual_type;
1179 visual_mask=VisualScreenMask;
1180 visual_template.screen=XDefaultScreen(display);
1181 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1183 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1184 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1185 visual_mask|=VisualDepthMask;
1186 if (visual_type != (char *) NULL)
1189 Restrict visual search by class or visual id.
1191 if (LocaleCompare("staticgray",visual_type) == 0)
1193 visual_mask|=VisualClassMask;
1194 visual_template.klass=StaticGray;
1197 if (LocaleCompare("grayscale",visual_type) == 0)
1199 visual_mask|=VisualClassMask;
1200 visual_template.klass=GrayScale;
1203 if (LocaleCompare("staticcolor",visual_type) == 0)
1205 visual_mask|=VisualClassMask;
1206 visual_template.klass=StaticColor;
1209 if (LocaleCompare("pseudocolor",visual_type) == 0)
1211 visual_mask|=VisualClassMask;
1212 visual_template.klass=PseudoColor;
1215 if (LocaleCompare("truecolor",visual_type) == 0)
1217 visual_mask|=VisualClassMask;
1218 visual_template.klass=TrueColor;
1221 if (LocaleCompare("directcolor",visual_type) == 0)
1223 visual_mask|=VisualClassMask;
1224 visual_template.klass=DirectColor;
1227 if (LocaleCompare("default",visual_type) == 0)
1229 visual_mask|=VisualIDMask;
1230 visual_template.visualid=XVisualIDFromVisual(
1231 XDefaultVisual(display,XDefaultScreen(display)));
1234 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1236 visual_mask|=VisualIDMask;
1237 visual_template.visualid=
1238 strtol(visual_type,(char **) NULL,0);
1241 ThrowXWindowFatalException(XServerError,
1242 "UnrecognizedVisualSpecifier",visual_type);
1245 Get all visuals that meet our criteria so far.
1248 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1250 visual_mask=VisualScreenMask | VisualIDMask;
1251 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1254 Failed to get visual; try using the default visual.
1256 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1258 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1259 XDefaultScreen(display)));
1260 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1262 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1263 return((XVisualInfo *) NULL);
1264 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1265 XVisualClassName(visual_list->klass));
1267 resource_info->color_recovery=MagickFalse;
1268 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1274 map_name[MaxTextExtent];
1290 Choose a visual associated with a standard colormap.
1292 root_window=XRootWindow(display,XDefaultScreen(display));
1294 if (LocaleCompare(map_type,"list") != 0)
1297 User specified Standard Colormap.
1299 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1300 "RGB_%s_MAP",map_type);
1301 LocaleUpper(map_name);
1302 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1303 if (map_property != (Atom) NULL)
1304 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1310 *colormap[MaxStandardColormaps]=
1312 "_HP_RGB_SMOOTH_MAP_LIST",
1322 Choose a standard colormap from a list.
1324 for (i=0; i < MaxStandardColormaps; i++)
1326 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1327 if (map_property == (Atom) NULL)
1329 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1331 if (status != False)
1334 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1336 if (status == False)
1338 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1340 return((XVisualInfo *) NULL);
1343 Search all Standard Colormaps and visuals for ids that match.
1345 *map_info=map_list[0];
1346 #if !defined(PRE_R4_ICCCM)
1347 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1348 for (i=0; i < number_maps; i++)
1349 for (j=0; j < number_visuals; j++)
1350 if (map_list[i].visualid ==
1351 XVisualIDFromVisual(visual_list[j].visual))
1353 *map_info=map_list[i];
1354 visual_template.visualid=XVisualIDFromVisual(
1355 visual_list[j].visual);
1358 if (map_info->visualid != visual_template.visualid)
1360 ThrowXWindowFatalException(XServerError,
1361 "UnableToMatchVisualToStandardColormap",map_type);
1362 return((XVisualInfo *) NULL);
1365 if (map_info->colormap == (Colormap) NULL)
1367 ThrowXWindowFatalException(XServerError,
1368 "StandardColormapIsNotInitialized",map_type);
1369 return((XVisualInfo *) NULL);
1371 (void) XFree((void *) map_list);
1375 static const unsigned int
1390 Pick one visual that displays the most simultaneous colors.
1392 visual_info=visual_list;
1394 for (i=1; i < number_visuals; i++)
1397 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1400 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1401 if (rank[p->klass] > rank[visual_info->klass])
1404 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1406 (void) XFree((void *) visual_list);
1408 Retrieve only one visual by its screen & id number.
1410 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1412 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1413 return((XVisualInfo *) NULL);
1414 return(visual_info);
1418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1422 % X C h e c k D e f i n e C u r s o r %
1426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1428 % XCheckDefineCursor() prevents cursor changes on the root window.
1430 % The format of the XXCheckDefineCursor method is:
1432 % XCheckDefineCursor(display,window,cursor)
1434 % A description of each parameter follows:
1436 % o display: Specifies a connection to an X server; returned from
1439 % o window: the window.
1441 % o cursor: the cursor.
1444 MagickExport int XCheckDefineCursor(Display *display,Window window,
1447 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1448 assert(display != (Display *) NULL);
1449 if (window == XRootWindow(display,XDefaultScreen(display)))
1451 return(XDefineCursor(display,window,cursor));
1455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1459 % X C h e c k R e f r e s h W i n d o w s %
1463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1465 % XCheckRefreshWindows() checks the X server for exposure events for a
1466 % particular window and updates the areassociated with the exposure event.
1468 % The format of the XCheckRefreshWindows method is:
1470 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1472 % A description of each parameter follows:
1474 % o display: Specifies a connection to an X server; returned from
1477 % o windows: Specifies a pointer to a XWindows structure.
1480 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1488 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1489 assert(display != (Display *) NULL);
1490 assert(windows != (XWindows *) NULL);
1491 XDelay(display,SuspendTime);
1492 id=windows->command.id;
1493 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1494 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1495 id=windows->image.id;
1496 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1497 XRefreshWindow(display,&windows->image,&event);
1498 XDelay(display,SuspendTime << 1);
1499 id=windows->command.id;
1500 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1501 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1502 id=windows->image.id;
1503 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1504 XRefreshWindow(display,&windows->image,&event);
1508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1512 % X C l i e n t M e s s a g e %
1516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1519 % initialized with a particular protocol type and atom.
1521 % The format of the XClientMessage function is:
1523 % XClientMessage(display,window,protocol,reason,timestamp)
1525 % A description of each parameter follows:
1527 % o display: Specifies a pointer to the Display structure; returned from
1530 % o window: Specifies a pointer to a Window structure.
1532 % o protocol: Specifies an atom value.
1534 % o reason: Specifies an atom value which is the reason to send.
1536 % o timestamp: Specifies a value of type Time.
1539 MagickExport void XClientMessage(Display *display,const Window window,
1540 const Atom protocol,const Atom reason,const Time timestamp)
1545 assert(display != (Display *) NULL);
1546 client_event.type=ClientMessage;
1547 client_event.window=window;
1548 client_event.message_type=protocol;
1549 client_event.format=32;
1550 client_event.data.l[0]=(ssize_t) reason;
1551 client_event.data.l[1]=(ssize_t) timestamp;
1552 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560 + X C l i e n t W i n d o w %
1564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566 % XClientWindow() finds a window, at or below the specified window, which has
1567 % a WM_STATE property. If such a window is found, it is returned, otherwise
1568 % the argument window is returned.
1570 % The format of the XClientWindow function is:
1572 % client_window=XClientWindow(display,target_window)
1574 % A description of each parameter follows:
1576 % o client_window: XClientWindow returns a window, at or below the specified
1577 % window, which has a WM_STATE property otherwise the argument
1578 % target_window is returned.
1580 % o display: Specifies a pointer to the Display structure; returned from
1583 % o target_window: Specifies the window to find a WM_STATE property.
1586 static Window XClientWindow(Display *display,Window target_window)
1608 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1609 assert(display != (Display *) NULL);
1610 state=XInternAtom(display,"WM_STATE",MagickTrue);
1611 if (state == (Atom) NULL)
1612 return(target_window);
1614 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1615 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1616 if ((status == Success) && (type != (Atom) NULL))
1617 return(target_window);
1618 client_window=XWindowByProperty(display,target_window,state);
1619 if (client_window == (Window) NULL)
1620 return(target_window);
1621 return(client_window);
1625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1629 + X C o m p o n e n t T e r m i n u s %
1633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1635 % XComponentTerminus() destroys the module component.
1637 % The format of the XComponentTerminus method is:
1639 % XComponentTerminus(void)
1642 MagickExport void XComponentTerminus(void)
1644 DestroyXResources();
1648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1652 % X C o n f i g u r e I m a g e C o l o r m a p %
1656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1658 % XConfigureImageColormap() creates a new X colormap.
1660 % The format of the XConfigureImageColormap method is:
1662 % void XConfigureImageColormap(Display *display,
1663 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1665 % A description of each parameter follows:
1667 % o display: Specifies a connection to an X server; returned from
1670 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1672 % o windows: Specifies a pointer to a XWindows structure.
1674 % o image: the image.
1677 MagickExport void XConfigureImageColormap(Display *display,
1678 XResourceInfo *resource_info,XWindows *windows,Image *image)
1684 Make standard colormap.
1686 XSetCursorState(display,windows,MagickTrue);
1687 XCheckRefreshWindows(display,windows);
1688 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1689 windows->map_info,windows->pixel_info);
1690 colormap=windows->map_info->colormap;
1691 (void) XSetWindowColormap(display,windows->image.id,colormap);
1692 (void) XSetWindowColormap(display,windows->command.id,colormap);
1693 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1694 if (windows->magnify.mapped != MagickFalse)
1695 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1696 if (windows->pan.mapped != MagickFalse)
1697 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1698 XSetCursorState(display,windows,MagickFalse);
1699 XClientMessage(display,windows->image.id,windows->im_protocols,
1700 windows->im_update_colormap,CurrentTime);
1704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1708 % X C o n s t r a i n W i n d o w P o s i t i o n %
1712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1714 % XConstrainWindowPosition() assures a window is positioned within the X
1715 % server boundaries.
1717 % The format of the XConstrainWindowPosition method is:
1719 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1721 % A description of each parameter follows:
1723 % o display: Specifies a pointer to the Display structure; returned from
1726 % o window_info: Specifies a pointer to a XWindowInfo structure.
1729 MagickExport void XConstrainWindowPosition(Display *display,
1730 XWindowInfo *window_info)
1735 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1736 assert(display != (Display *) NULL);
1737 assert(window_info != (XWindowInfo *) NULL);
1738 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1739 if (window_info->x < 0)
1742 if (window_info->x > (int) limit)
1743 window_info->x=(int) limit;
1744 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1745 if (window_info->y < 0)
1748 if (window_info->y > limit)
1749 window_info->y=limit;
1753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763 % XDelay() suspends program execution for the number of milliseconds
1766 % The format of the Delay method is:
1768 % void XDelay(Display *display,const size_t milliseconds)
1770 % A description of each parameter follows:
1772 % o display: Specifies a pointer to the Display structure; returned from
1775 % o milliseconds: Specifies the number of milliseconds to delay before
1779 MagickExport void XDelay(Display *display,const size_t milliseconds)
1781 assert(display != (Display *) NULL);
1782 (void) XFlush(display);
1783 if (milliseconds == 0)
1785 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1786 Sleep((long) milliseconds);
1792 timer=milliseconds/1000.0;
1795 #elif defined(MAGICKCORE_HAVE_USLEEP)
1796 usleep(1000*milliseconds);
1797 #elif defined(MAGICKCORE_HAVE_SELECT)
1802 timer.tv_sec=(ssize_t) milliseconds/1000;
1803 timer.tv_usec=(ssize_t) (milliseconds % 1000)*1000;
1804 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1806 #elif defined(MAGICKCORE_HAVE_POLL)
1807 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1808 #elif defined(__BEOS__)
1809 snooze(1000*milliseconds);
1811 # error "Time delay method not defined."
1816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1820 % X D e s t r o y R e s o u r c e I n f o %
1824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1826 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1829 % The format of the XDestroyResourceInfo method is:
1831 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1833 % A description of each parameter follows:
1835 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1838 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1840 if (resource_info->image_geometry != (char *) NULL)
1841 resource_info->image_geometry=(char *)
1842 RelinquishMagickMemory(resource_info->image_geometry);
1843 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1844 resource_info->quantize_info=DestroyQuantizeInfo(
1845 resource_info->quantize_info);
1846 if (resource_info->client_name != (char *) NULL)
1847 resource_info->client_name=(char *)
1848 RelinquishMagickMemory(resource_info->client_name);
1849 if (resource_info->name != (char *) NULL)
1850 resource_info->name=DestroyString(resource_info->name);
1851 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1859 % X D e s t r o y W i n d o w C o l o r s %
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1865 % XDestroyWindowColors() frees X11 color resources previously saved on a
1866 % window by XRetainWindowColors or programs like xsetroot.
1868 % The format of the XDestroyWindowColors method is:
1870 % void XDestroyWindowColors(Display *display,Window window)
1872 % A description of each parameter follows:
1874 % o display: Specifies a connection to an X server; returned from
1877 % o window: Specifies a pointer to a Window structure.
1880 MagickExport void XDestroyWindowColors(Display *display,Window window)
1900 If there are previous resources on the root window, destroy them.
1902 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1903 assert(display != (Display *) NULL);
1904 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1905 if (property == (Atom) NULL)
1907 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1911 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1912 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1913 if (status != Success)
1915 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1917 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1918 (void) XDeleteProperty(display,window,property);
1921 (void) XFree((void *) data);
1925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1929 % X D i s p l a y I m a g e I n f o %
1933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935 % XDisplayImageInfo() displays information about an X image.
1937 % The format of the XDisplayImageInfo method is:
1939 % void XDisplayImageInfo(Display *display,
1940 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1943 % A description of each parameter follows:
1945 % o display: Specifies a connection to an X server; returned from
1948 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1950 % o windows: Specifies a pointer to a XWindows structure.
1952 % o undo_image: the undo image.
1954 % o image: the image.
1957 MagickExport void XDisplayImageInfo(Display *display,
1958 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1962 filename[MaxTextExtent],
1985 Write info about the X server to a file.
1987 assert(display != (Display *) NULL);
1988 assert(resource_info != (XResourceInfo *) NULL);
1989 assert(windows != (XWindows *) NULL);
1990 assert(image != (Image *) NULL);
1992 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1994 unique_file=AcquireUniqueFileResource(filename);
1995 if (unique_file != -1)
1996 file=fdopen(unique_file,"w");
1997 if ((unique_file == -1) || (file == (FILE *) NULL))
1999 XNoticeWidget(display,windows,"Unable to display image info",filename);
2002 if (resource_info->gamma_correct != MagickFalse)
2003 if (resource_info->display_gamma != (char *) NULL)
2004 (void) fprintf(file,"Display\n gamma: %s\n\n",
2005 resource_info->display_gamma);
2007 Write info about the X image to a file.
2009 (void) fprintf(file,"X\n visual: %s\n",
2010 XVisualClassName((int) windows->image.storage_class));
2011 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
2012 if (windows->visual_info->colormap_size != 0)
2013 (void) fprintf(file," colormap size: %d\n",
2014 windows->visual_info->colormap_size);
2015 if (resource_info->colormap== SharedColormap)
2016 (void) fprintf(file," colormap type: Shared\n");
2018 (void) fprintf(file," colormap type: Private\n");
2019 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
2020 windows->image.ximage->height);
2021 if (windows->image.crop_geometry != (char *) NULL)
2022 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
2023 if (windows->image.pixmap == (Pixmap) NULL)
2024 (void) fprintf(file," type: X Image\n");
2026 (void) fprintf(file," type: Pixmap\n");
2027 if (windows->image.shape != MagickFalse)
2028 (void) fprintf(file," non-rectangular shape: True\n");
2030 (void) fprintf(file," non-rectangular shape: False\n");
2031 if (windows->image.shared_memory != MagickFalse)
2032 (void) fprintf(file," shared memory: True\n");
2034 (void) fprintf(file," shared memory: False\n");
2035 (void) fprintf(file,"\n");
2036 if (resource_info->font != (char *) NULL)
2037 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2038 if (resource_info->text_font != (char *) NULL)
2039 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2041 Write info about the undo cache to a file.
2044 for (levels=0; undo_image != (Image *) NULL; levels++)
2046 number_pixels=undo_image->list->columns*undo_image->list->rows;
2047 bytes+=number_pixels*sizeof(PixelPacket);
2048 undo_image=GetPreviousImageInList(undo_image);
2050 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2051 (void) fprintf(file," bytes: %.20gmb\n",(double) ((bytes+(1 << 19)) >> 20));
2052 (void) fprintf(file," limit: %.20gmb\n\n",(double)
2053 resource_info->undo_cache);
2055 Write info about the image to a file.
2057 (void) IdentifyImage(image,file,MagickTrue);
2058 (void) fclose(file);
2059 text=FileToString(filename,~0,&image->exception);
2060 (void) RelinquishUniqueFileResource(filename);
2061 if (text == (char *) NULL)
2063 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2064 "UnableToDisplayImageInfo");
2067 textlist=StringToList(text);
2068 if (textlist != (char **) NULL)
2071 title[MaxTextExtent];
2074 Display information about the image in the Text View widget.
2076 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2077 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2079 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2080 (char const **) textlist);
2081 for (i=0; textlist[i] != (char *) NULL; i++)
2082 textlist[i]=DestroyString(textlist[i]);
2083 textlist=(char **) RelinquishMagickMemory(textlist);
2085 text=DestroyString(text);
2089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2093 + X D i t h e r I m a g e %
2097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2099 % XDitherImage() dithers the reference image as required by the HP Color
2100 % Recovery algorithm. The color values are quantized to 3 bits of red and
2101 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2102 % standard colormap.
2104 % The format of the XDitherImage method is:
2106 % void XDitherImage(Image *image,XImage *ximage)
2108 % A description of each parameter follows:
2110 % o image: the image.
2112 % o ximage: Specifies a pointer to a XImage structure; returned from
2116 static void XDitherImage(Image *image,XImage *ximage)
2118 static const short int
2121 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2122 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2124 dither_green[2][16]=
2126 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2127 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2131 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2132 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2147 register const PixelPacket
2167 Allocate and initialize dither maps.
2169 for (i=0; i < 2; i++)
2170 for (j=0; j < 16; j++)
2172 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2174 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2175 sizeof(*green_map));
2176 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2178 if ((red_map[i][j] == (unsigned char *) NULL) ||
2179 (green_map[i][j] == (unsigned char *) NULL) ||
2180 (blue_map[i][j] == (unsigned char *) NULL))
2182 ThrowXWindowFatalException(ResourceLimitError,
2183 "MemoryAllocationFailed",image->filename);
2188 Initialize dither tables.
2190 for (i=0; i < 2; i++)
2191 for (j=0; j < 16; j++)
2192 for (x=0; x < 256; x++)
2197 value+=dither_red[i][j];
2198 red_map[i][j][x]=(unsigned char)
2199 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2203 value+=dither_green[i][j];
2204 green_map[i][j][x]=(unsigned char)
2205 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2209 value+=((size_t) dither_blue[i][j] << 1);
2210 blue_map[i][j][x]=(unsigned char)
2211 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2216 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2217 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2221 for (y=0; y < (int) image->rows; y++)
2223 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2224 if (p == (const PixelPacket *) NULL)
2226 for (x=0; x < (int) image->columns; x++)
2228 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2229 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2230 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2231 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2232 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2233 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2234 pixel=(size_t) (((size_t) color.red & 0xe0) |
2235 (((size_t) color.green & 0xe0) >> 3) |
2236 (((size_t) color.blue & 0xc0) >> 6));
2249 Free allocated memory.
2251 for (i=0; i < 2; i++)
2252 for (j=0; j < 16; j++)
2254 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2255 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2256 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2265 % X D r a w I m a g e %
2269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2271 % XDrawImage() draws a line on the image.
2273 % The format of the XDrawImage method is:
2275 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2277 % A description of each parameter follows:
2279 % o display: Specifies a connection to an X server; returned from
2282 % o pixel: Specifies a pointer to a XPixelInfo structure.
2284 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2286 % o image: the image.
2289 MagickExport MagickBooleanType XDrawImage(Display *display,
2290 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2326 Initialize drawd image.
2328 assert(display != (Display *) NULL);
2329 assert(pixel != (XPixelInfo *) NULL);
2330 assert(draw_info != (XDrawInfo *) NULL);
2331 assert(image != (Image *) NULL);
2332 if (image->debug != MagickFalse)
2333 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2335 Initialize drawd pixmap.
2337 root_window=XRootWindow(display,XDefaultScreen(display));
2338 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2339 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2340 draw_info->height,depth);
2341 if (draw_pixmap == (Pixmap) NULL)
2342 return(MagickFalse);
2344 Initialize graphics info.
2346 context_values.background=(size_t) (~0);
2347 context_values.foreground=0;
2348 context_values.line_width=(int) draw_info->line_width;
2349 draw_context=XCreateGC(display,root_window,(size_t)
2350 (GCBackground | GCForeground | GCLineWidth),&context_values);
2351 if (draw_context == (GC) NULL)
2352 return(MagickFalse);
2356 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2359 Draw line to pixmap.
2361 (void) XSetBackground(display,draw_context,0);
2362 (void) XSetForeground(display,draw_context,(size_t) (~0));
2363 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2364 (void) XSetStipple(display,draw_context,draw_info->stipple);
2365 switch (draw_info->element)
2370 (void) XDrawLines(display,draw_pixmap,draw_context,
2371 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2377 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2378 draw_info->line_info.y1,draw_info->line_info.x2,
2379 draw_info->line_info.y2);
2382 case RectangleElement:
2384 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2385 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2386 (unsigned int) draw_info->rectangle_info.width,
2387 (unsigned int) draw_info->rectangle_info.height);
2390 case FillRectangleElement:
2392 (void) XFillRectangle(display,draw_pixmap,draw_context,
2393 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2394 (unsigned int) draw_info->rectangle_info.width,
2395 (unsigned int) draw_info->rectangle_info.height);
2399 case EllipseElement:
2401 (void) XDrawArc(display,draw_pixmap,draw_context,
2402 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2403 (unsigned int) draw_info->rectangle_info.width,
2404 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2407 case FillCircleElement:
2408 case FillEllipseElement:
2410 (void) XFillArc(display,draw_pixmap,draw_context,
2411 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2412 (unsigned int) draw_info->rectangle_info.width,
2413 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2416 case PolygonElement:
2421 coordinate_info=draw_info->coordinate_info;
2422 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2423 (int) draw_info->number_coordinates,CoordModeOrigin);
2424 (void) XDrawLine(display,draw_pixmap,draw_context,
2425 coordinate_info[draw_info->number_coordinates-1].x,
2426 coordinate_info[draw_info->number_coordinates-1].y,
2427 coordinate_info[0].x,coordinate_info[0].y);
2430 case FillPolygonElement:
2432 (void) XFillPolygon(display,draw_pixmap,draw_context,
2433 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2438 (void) XFreeGC(display,draw_context);
2442 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2443 draw_info->height,AllPlanes,ZPixmap);
2444 if (draw_ximage == (XImage *) NULL)
2445 return(MagickFalse);
2446 (void) XFreePixmap(display,draw_pixmap);
2448 Initialize draw image.
2450 draw_image=AcquireImage((ImageInfo *) NULL);
2451 if (draw_image == (Image *) NULL)
2452 return(MagickFalse);
2453 draw_image->columns=draw_info->width;
2454 draw_image->rows=draw_info->height;
2456 Transfer drawn X image to image.
2458 width=(unsigned int) image->columns;
2459 height=(unsigned int) image->rows;
2462 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2463 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2465 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2466 return(MagickFalse);
2467 draw_image->matte=MagickTrue;
2468 exception=(&image->exception);
2469 for (y=0; y < (int) draw_image->rows; y++)
2474 register PixelPacket
2477 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2478 if (q == (PixelPacket *) NULL)
2480 for (x=0; x < (ssize_t) draw_image->columns; x++)
2482 if (XGetPixel(draw_ximage,x,y) == 0)
2485 Set this pixel to the background color.
2487 *q=draw_image->background_color;
2488 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2489 TransparentOpacity : OpaqueOpacity);
2494 Set this pixel to the pen color.
2496 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2497 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2498 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2499 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2500 OpaqueOpacity : TransparentOpacity);
2504 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2507 XDestroyImage(draw_ximage);
2509 Determine draw geometry.
2511 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2512 if ((width != (unsigned int) draw_image->columns) ||
2513 (height != (unsigned int) draw_image->rows))
2516 image_geometry[MaxTextExtent];
2521 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2523 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2525 if (draw_info->degrees != 0.0)
2539 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2540 if (rotate_image == (Image *) NULL)
2541 return(MagickFalse);
2542 draw_image=DestroyImage(draw_image);
2543 draw_image=rotate_image;
2545 Annotation is relative to the degree of rotation.
2547 normalized_degrees=draw_info->degrees;
2548 while (normalized_degrees < -45.0)
2549 normalized_degrees+=360.0;
2550 for (rotations=0; normalized_degrees > 45.0; rotations++)
2551 normalized_degrees-=90.0;
2552 switch (rotations % 4)
2562 x=x-(int) draw_image->columns/2;
2563 y=y+(int) draw_image->columns/2;
2571 x=x-(int) draw_image->columns;
2579 x=x-(int) draw_image->columns/2;
2580 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2586 Composite text onto the image.
2588 for (y=0; y < (int) draw_image->rows; y++)
2593 register PixelPacket
2596 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2597 if (q == (PixelPacket *) NULL)
2599 for (x=0; x < (ssize_t) draw_image->columns; x++)
2601 if (q->opacity != (Quantum) TransparentOpacity)
2602 SetOpacityPixelComponent(q,OpaqueOpacity);
2605 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2608 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2609 if (draw_info->stencil == TransparentStencil)
2610 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2614 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2617 draw_image=DestroyImage(draw_image);
2622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2632 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2633 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2634 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2637 % The format of the XError function is:
2639 % XError(display,error)
2641 % A description of each parameter follows:
2643 % o display: Specifies a pointer to the Display structure; returned from
2646 % o error: Specifies the error event.
2650 #if defined(__cplusplus) || defined(c_plusplus)
2654 MagickExport int XError(Display *display,XErrorEvent *error)
2656 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2657 assert(display != (Display *) NULL);
2658 assert(error != (XErrorEvent *) NULL);
2659 xerror_alert=MagickTrue;
2660 switch (error->request_code)
2664 if ((int) error->error_code == BadDrawable)
2665 return(MagickFalse);
2668 case X_GetWindowAttributes:
2671 if ((int) error->error_code == BadWindow)
2672 return(MagickFalse);
2677 if ((int) error->error_code == BadValue)
2678 return(MagickFalse);
2685 #if defined(__cplusplus) || defined(c_plusplus)
2690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2694 % X F r e e R e s o u r c e s %
2698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2700 % XFreeResources() frees X11 resources.
2702 % The format of the XFreeResources method is:
2704 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2705 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2706 % XResourceInfo *resource_info,XWindowInfo *window_info)
2707 % resource_info,window_info)
2709 % A description of each parameter follows:
2711 % o display: Specifies a connection to an X server; returned from
2714 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2715 % returned from XGetVisualInfo.
2717 % o map_info: If map_type is specified, this structure is initialized
2718 % with info from the Standard Colormap.
2720 % o pixel: Specifies a pointer to a XPixelInfo structure.
2722 % o font_info: Specifies a pointer to a XFontStruct structure.
2724 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2726 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2729 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2730 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2731 XResourceInfo *resource_info,XWindowInfo *window_info)
2733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2734 assert(display != (Display *) NULL);
2735 assert(resource_info != (XResourceInfo *) NULL);
2736 if (window_info != (XWindowInfo *) NULL)
2741 if (window_info->ximage != (XImage *) NULL)
2742 XDestroyImage(window_info->ximage);
2743 if (window_info->id != (Window) NULL)
2746 Free destroy window and free cursors.
2748 if (window_info->id != XRootWindow(display,visual_info->screen))
2749 (void) XDestroyWindow(display,window_info->id);
2750 if (window_info->annotate_context != (GC) NULL)
2751 (void) XFreeGC(display,window_info->annotate_context);
2752 if (window_info->highlight_context != (GC) NULL)
2753 (void) XFreeGC(display,window_info->highlight_context);
2754 if (window_info->widget_context != (GC) NULL)
2755 (void) XFreeGC(display,window_info->widget_context);
2756 if (window_info->cursor != (Cursor) NULL)
2757 (void) XFreeCursor(display,window_info->cursor);
2758 window_info->cursor=(Cursor) NULL;
2759 if (window_info->busy_cursor != (Cursor) NULL)
2760 (void) XFreeCursor(display,window_info->busy_cursor);
2761 window_info->busy_cursor=(Cursor) NULL;
2767 if (font_info != (XFontStruct *) NULL)
2768 (void) XFreeFont(display,font_info);
2769 if (map_info != (XStandardColormap *) NULL)
2772 Free X Standard Colormap.
2774 if (resource_info->map_type == (char *) NULL)
2775 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2776 (void) XFree((void *) map_info);
2781 if (visual_info != (XVisualInfo *) NULL)
2782 (void) XFree((void *) visual_info);
2783 if (resource_info->close_server != MagickFalse)
2784 (void) XCloseDisplay(display);
2788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2792 % X F r e e S t a n d a r d C o l o r m a p %
2796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2798 % XFreeStandardColormap() frees an X11 colormap.
2800 % The format of the XFreeStandardColormap method is:
2802 % void XFreeStandardColormap(Display *display,
2803 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2804 % XPixelInfo *pixel)
2806 % A description of each parameter follows:
2808 % o display: Specifies a connection to an X server; returned from
2811 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2812 % returned from XGetVisualInfo.
2814 % o map_info: If map_type is specified, this structure is initialized
2815 % with info from the Standard Colormap.
2817 % o pixel: Specifies a pointer to a XPixelInfo structure.
2820 MagickExport void XFreeStandardColormap(Display *display,
2821 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2827 assert(display != (Display *) NULL);
2828 assert(visual_info != (XVisualInfo *) NULL);
2829 assert(map_info != (XStandardColormap *) NULL);
2830 (void) XFlush(display);
2831 if (map_info->colormap != (Colormap) NULL)
2833 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2834 (void) XFreeColormap(display,map_info->colormap);
2836 if (pixel != (XPixelInfo *) NULL)
2837 if ((visual_info->klass != TrueColor) &&
2838 (visual_info->klass != DirectColor))
2839 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2840 (int) pixel->colors,0);
2842 map_info->colormap=(Colormap) NULL;
2843 if (pixel != (XPixelInfo *) NULL)
2845 if (pixel->pixels != (unsigned long *) NULL)
2846 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2847 pixel->pixels=(unsigned long *) NULL;
2852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2856 % X G e t A n n o t a t e I n f o %
2860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2862 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2864 % The format of the XGetAnnotateInfo method is:
2866 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2868 % A description of each parameter follows:
2870 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2873 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2876 Initialize annotate structure.
2878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2879 assert(annotate_info != (XAnnotateInfo *) NULL);
2882 annotate_info->width=0;
2883 annotate_info->height=0;
2884 annotate_info->stencil=ForegroundStencil;
2885 annotate_info->degrees=0.0;
2886 annotate_info->font_info=(XFontStruct *) NULL;
2887 annotate_info->text=(char *) NULL;
2888 *annotate_info->geometry='\0';
2889 annotate_info->previous=(XAnnotateInfo *) NULL;
2890 annotate_info->next=(XAnnotateInfo *) NULL;
2891 (void) XSupportsLocale();
2892 (void) XSetLocaleModifiers("");
2896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2900 % X G e t M a p I n f o %
2904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2906 % XGetMapInfo() initializes the XStandardColormap structure.
2908 % The format of the XStandardColormap method is:
2910 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2911 % XStandardColormap *map_info)
2913 % A description of each parameter follows:
2915 % o colormap: Specifies the ID of the X server colormap.
2917 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2918 % returned from XGetVisualInfo.
2920 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2923 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2924 const Colormap colormap,XStandardColormap *map_info)
2927 Initialize map info.
2929 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2930 assert(visual_info != (XVisualInfo *) NULL);
2931 assert(map_info != (XStandardColormap *) NULL);
2932 map_info->colormap=colormap;
2933 map_info->red_max=visual_info->red_mask;
2934 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2935 if (map_info->red_max != 0)
2936 while ((map_info->red_max & 0x01) == 0)
2938 map_info->red_max>>=1;
2939 map_info->red_mult<<=1;
2941 map_info->green_max=visual_info->green_mask;
2942 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2943 if (map_info->green_max != 0)
2944 while ((map_info->green_max & 0x01) == 0)
2946 map_info->green_max>>=1;
2947 map_info->green_mult<<=1;
2949 map_info->blue_max=visual_info->blue_mask;
2950 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2951 if (map_info->blue_max != 0)
2952 while ((map_info->blue_max & 0x01) == 0)
2954 map_info->blue_max>>=1;
2955 map_info->blue_mult<<=1;
2957 map_info->base_pixel=0;
2961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2965 % X G e t P i x e l I n f o %
2969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2971 % XGetPixelPacket() initializes the PixelPacket structure.
2973 % The format of the XGetPixelPacket method is:
2975 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2976 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2977 % Image *image,XPixelInfo *pixel)
2980 % A description of each parameter follows:
2982 % o display: Specifies a connection to an X server; returned from
2985 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2986 % returned from XGetVisualInfo.
2988 % o map_info: If map_type is specified, this structure is initialized
2989 % with info from the Standard Colormap.
2991 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2993 % o image: the image.
2995 % o pixel: Specifies a pointer to a XPixelInfo structure.
2998 MagickExport void XGetPixelPacket(Display *display,
2999 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3000 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3003 *PenColors[MaxNumberPens]=
3005 "#000000000000", /* black */
3006 "#00000000ffff", /* blue */
3007 "#0000ffffffff", /* cyan */
3008 "#0000ffff0000", /* green */
3009 "#bdbdbdbdbdbd", /* gray */
3010 "#ffff00000000", /* red */
3011 "#ffff0000ffff", /* magenta */
3012 "#ffffffff0000", /* yellow */
3013 "#ffffffffffff", /* white */
3014 "#bdbdbdbdbdbd", /* gray */
3015 "#bdbdbdbdbdbd" /* gray */
3031 Initialize pixel info.
3033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3034 assert(display != (Display *) NULL);
3035 assert(visual_info != (XVisualInfo *) NULL);
3036 assert(map_info != (XStandardColormap *) NULL);
3037 assert(resource_info != (XResourceInfo *) NULL);
3038 assert(pixel != (XPixelInfo *) NULL);
3040 if (image != (Image *) NULL)
3041 if (image->storage_class == PseudoClass)
3042 pixel->colors=image->colors;
3043 packets=(unsigned int)
3044 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3045 if (pixel->pixels != (unsigned long *) NULL)
3046 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3047 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3048 sizeof(pixel->pixels));
3049 if (pixel->pixels == (unsigned long *) NULL)
3050 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3053 Set foreground color.
3055 colormap=map_info->colormap;
3056 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3057 &pixel->foreground_color);
3058 status=XParseColor(display,colormap,resource_info->foreground_color,
3059 &pixel->foreground_color);
3060 if (status == False)
3061 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3062 resource_info->foreground_color);
3063 pixel->foreground_color.pixel=
3064 XStandardPixel(map_info,&pixel->foreground_color);
3065 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3067 Set background color.
3069 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3070 status=XParseColor(display,colormap,resource_info->background_color,
3071 &pixel->background_color);
3072 if (status == False)
3073 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3074 resource_info->background_color);
3075 pixel->background_color.pixel=
3076 XStandardPixel(map_info,&pixel->background_color);
3077 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3081 (void) XParseColor(display,colormap,(char *) BorderColor,
3082 &pixel->border_color);
3083 status=XParseColor(display,colormap,resource_info->border_color,
3084 &pixel->border_color);
3085 if (status == False)
3086 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3087 resource_info->border_color);
3088 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3089 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3093 pixel->matte_color=pixel->background_color;
3094 if (resource_info->matte_color != (char *) NULL)
3097 Matte color is specified as a X resource or command line argument.
3099 status=XParseColor(display,colormap,resource_info->matte_color,
3100 &pixel->matte_color);
3101 if (status == False)
3102 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3103 resource_info->matte_color);
3104 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3105 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3108 Set highlight color.
3110 pixel->highlight_color.red=(unsigned short) ((
3111 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3112 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3113 pixel->highlight_color.green=(unsigned short) ((
3114 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3115 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3116 pixel->highlight_color.blue=(unsigned short) ((
3117 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3118 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3119 pixel->highlight_color.pixel=
3120 XStandardPixel(map_info,&pixel->highlight_color);
3121 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3125 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3126 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3127 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3128 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3129 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3130 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3131 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3132 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3136 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3137 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3138 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3139 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3140 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3141 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3142 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3143 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3147 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3148 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3149 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3150 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3151 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3152 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3153 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3154 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3158 for (i=0; i < MaxNumberPens; i++)
3160 (void) XParseColor(display,colormap,(char *) PenColors[i],
3161 &pixel->pen_colors[i]);
3162 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3163 &pixel->pen_colors[i]);
3164 if (status == False)
3165 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3166 resource_info->pen_colors[i]);
3167 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3168 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3170 pixel->box_color=pixel->background_color;
3171 pixel->pen_color=pixel->foreground_color;
3174 if (image != (Image *) NULL)
3176 if ((resource_info->gamma_correct != MagickFalse) &&
3177 (image->gamma != 0.0))
3186 Initialize map relative to display and image gamma.
3188 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3189 red_gamma=geometry_info.rho;
3190 green_gamma=geometry_info.sigma;
3191 if ((flags & SigmaValue) == 0)
3192 green_gamma=red_gamma;
3193 blue_gamma=geometry_info.xi;
3194 if ((flags & XiValue) == 0)
3195 blue_gamma=red_gamma;
3196 red_gamma*=image->gamma;
3197 green_gamma*=image->gamma;
3198 blue_gamma*=image->gamma;
3200 if (image->storage_class == PseudoClass)
3203 Initialize pixel array for images of type PseudoClass.
3205 for (i=0; i < (ssize_t) image->colors; i++)
3207 XGammaPixel(map_info,image->colormap+i);
3208 for (i=0; i < MaxNumberPens; i++)
3209 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3210 pixel->colors+=MaxNumberPens;
3216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3220 % X G e t R e s o u r c e C l a s s %
3224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3226 % XGetResourceClass() queries the X server for the specified resource name or
3227 % class. If the resource name or class is not defined in the database, the
3228 % supplied default value is returned.
3230 % The format of the XGetResourceClass method is:
3232 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3233 % const char *keyword,char *resource_default)
3235 % A description of each parameter follows:
3237 % o database: Specifies a resource database; returned from
3238 % XrmGetStringDatabase.
3240 % o client_name: Specifies the application name used to retrieve resource
3241 % info from the X server database.
3243 % o keyword: Specifies the keyword of the value being retrieved.
3245 % o resource_default: Specifies the default value to return if the query
3246 % fails to find the specified keyword/class.
3249 MagickExport char *XGetResourceClass(XrmDatabase database,
3250 const char *client_name,const char *keyword,char *resource_default)
3253 resource_class[MaxTextExtent],
3254 resource_name[MaxTextExtent];
3265 if (database == (XrmDatabase) NULL)
3266 return(resource_default);
3267 *resource_name='\0';
3268 *resource_class='\0';
3269 if (keyword != (char *) NULL)
3276 Initialize resource keyword and class.
3278 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3279 client_name,keyword);
3280 c=(int) (*client_name);
3281 if ((c >= XK_a) && (c <= XK_z))
3284 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3285 c-=(XK_agrave-XK_Agrave);
3287 if ((c >= XK_oslash) && (c <= XK_thorn))
3288 c-=(XK_oslash-XK_Ooblique);
3290 if ((k >= XK_a) && (k <= XK_z))
3293 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3294 k-=(XK_agrave-XK_Agrave);
3296 if ((k >= XK_oslash) && (k <= XK_thorn))
3297 k-=(XK_oslash-XK_Ooblique);
3298 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3299 client_name+1,k,keyword+1);
3301 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3303 if (status == False)
3304 return(resource_default);
3305 return(resource_value.addr);
3309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3313 % X G e t R e s o u r c e D a t a b a s e %
3317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3319 % XGetResourceDatabase() creates a new resource database and initializes it.
3321 % The format of the XGetResourceDatabase method is:
3323 % XrmDatabase XGetResourceDatabase(Display *display,
3324 % const char *client_name)
3326 % A description of each parameter follows:
3328 % o database: XGetResourceDatabase() returns the database after it is
3331 % o display: Specifies a connection to an X server; returned from
3334 % o client_name: Specifies the application name used to retrieve resource
3335 % info from the X server database.
3338 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3339 const char *client_name)
3342 filename[MaxTextExtent];
3354 if (display == (Display *) NULL)
3355 return((XrmDatabase) NULL);
3356 assert(client_name != (char *) NULL);
3358 Initialize resource database.
3361 (void) XGetDefault(display,(char *) client_name,"dummy");
3362 resource_database=XrmGetDatabase(display);
3364 Combine application database.
3366 if (client_name != (char *) NULL)
3369 Get basename of client.
3371 p=client_name+(strlen(client_name)-1);
3372 while ((p > client_name) && (*p != '/'))
3377 c=(int) (*client_name);
3378 if ((c >= XK_a) && (c <= XK_z))
3381 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3382 c-=(XK_agrave-XK_Agrave);
3384 if ((c >= XK_oslash) && (c <= XK_thorn))
3385 c-=(XK_oslash-XK_Ooblique);
3386 #if defined(X11_APPLICATION_PATH)
3387 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3388 X11_APPLICATION_PATH,c,client_name+1);
3389 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3391 if (XResourceManagerString(display) != (char *) NULL)
3394 Combine server database.
3396 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3397 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3400 Merge user preferences database.
3402 #if defined(X11_PREFERENCES_PATH)
3403 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3404 X11_PREFERENCES_PATH,client_name);
3405 ExpandFilename(filename);
3406 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3408 return(resource_database);
3412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3416 % X G e t R e s o u r c e I n f o %
3420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3422 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3424 % The format of the XGetResourceInfo method is:
3426 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3427 % const char *client_name,XResourceInfo *resource_info)
3429 % A description of each parameter follows:
3431 % o image_info: the image info.
3433 % o database: Specifies a resource database; returned from
3434 % XrmGetStringDatabase.
3436 % o client_name: Specifies the application name used to retrieve
3437 % resource info from the X server database.
3439 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3442 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3443 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3450 Initialize resource info fields.
3452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3453 assert(resource_info != (XResourceInfo *) NULL);
3454 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3455 resource_info->resource_database=database;
3456 resource_info->image_info=(ImageInfo *) image_info;
3457 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3458 XMagickProgressMonitor,(void *) NULL);
3459 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3460 resource_info->close_server=MagickTrue;
3461 resource_info->client_name=AcquireString(client_name);
3462 resource_value=XGetResourceClass(database,client_name,"backdrop",
3464 resource_info->backdrop=IsMagickTrue(resource_value);
3465 resource_info->background_color=XGetResourceInstance(database,client_name,
3466 "background",(char *) "#d6d6d6d6d6d6");
3467 resource_info->border_color=XGetResourceInstance(database,client_name,
3468 "borderColor",BorderColor);
3469 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3471 resource_info->border_width=(unsigned int) StringToUnsignedLong(resource_value);
3472 resource_value=XGetResourceClass(database,client_name,"colormap",
3474 resource_info->colormap=UndefinedColormap;
3475 if (LocaleCompare("private",resource_value) == 0)
3476 resource_info->colormap=PrivateColormap;
3477 if (LocaleCompare("shared",resource_value) == 0)
3478 resource_info->colormap=SharedColormap;
3479 if (resource_info->colormap == UndefinedColormap)
3480 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3482 resource_value=XGetResourceClass(database,client_name,
3483 "colorRecovery",(char *) "False");
3484 resource_info->color_recovery=IsMagickTrue(resource_value);
3485 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3487 resource_info->confirm_exit=IsMagickTrue(resource_value);
3488 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3490 resource_info->confirm_edit=IsMagickTrue(resource_value);
3491 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "0");
3492 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3493 resource_info->display_gamma=XGetResourceClass(database,client_name,
3494 "displayGamma",(char *) "2.2");
3495 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3497 resource_info->display_warnings=IsMagickTrue(resource_value);
3498 resource_info->font=XGetResourceClass(database,client_name,"font",
3500 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3501 resource_info->font);
3502 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3504 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3505 (char *) "variable");
3506 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3508 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3510 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3511 (char *) "7x13bold");
3512 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3513 (char *) "8x13bold");
3514 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3515 (char *) "9x15bold");
3516 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3518 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3520 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3522 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3524 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3525 "foreground",ForegroundColor);
3526 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3528 resource_info->gamma_correct=IsMagickTrue(resource_value);
3529 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3530 client_name,"geometry",(char *) NULL));
3531 resource_value=XGetResourceClass(database,client_name,"gravity",
3533 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3534 MagickFalse,resource_value);
3535 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3536 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3537 "iconGeometry",(char *) NULL);
3538 resource_value=XGetResourceClass(database,client_name,"iconic",
3540 resource_info->iconic=IsMagickTrue(resource_value);
3541 resource_value=XGetResourceClass(database,client_name,"immutable",
3542 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3544 resource_info->immutable=IsMagickTrue(resource_value);
3545 resource_value=XGetResourceClass(database,client_name,"magnify",
3547 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3548 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3550 resource_info->matte_color=XGetResourceInstance(database,client_name,
3551 "mattecolor",(char *) NULL);
3552 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3553 "name",(char *) NULL));
3554 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3556 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3558 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3560 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3562 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3564 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3566 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3567 (char *) "magenta");
3568 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3570 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3572 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3574 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3576 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3577 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3578 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3579 resource_info->quantum=StringToLong(resource_value);
3580 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3581 "font",(char *) "fixed");
3582 resource_info->text_font=XGetResourceClass(database,client_name,
3583 "textFontList",resource_info->text_font);
3584 resource_info->title=XGetResourceClass(database,client_name,"title",
3586 resource_value=XGetResourceClass(database,client_name,"undoCache",
3588 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3589 resource_value=XGetResourceClass(database,client_name,"update",
3591 resource_info->update=IsMagickTrue(resource_value);
3592 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3594 resource_info->use_pixmap=IsMagickTrue(resource_value);
3595 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3597 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3598 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3600 resource_info->window_group=XGetResourceClass(database,client_name,
3601 "windowGroup",(char *) NULL);
3602 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3604 resource_info->write_filename=XGetResourceClass(database,client_name,
3605 "writeFilename",(char *) NULL);
3609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3613 % X G e t R e s o u r c e I n s t a n c e %
3617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3619 % XGetResourceInstance() queries the X server for the specified resource name.
3620 % If the resource name is not defined in the database, the supplied default
3621 % value is returned.
3623 % The format of the XGetResourceInstance method is:
3625 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3626 % const char *keyword,const char *resource_default)
3628 % A description of each parameter follows:
3630 % o database: Specifies a resource database; returned from
3631 % XrmGetStringDatabase.
3633 % o client_name: Specifies the application name used to retrieve
3634 % resource info from the X server database.
3636 % o keyword: Specifies the keyword of the value being retrieved.
3638 % o resource_default: Specifies the default value to return if the query
3639 % fails to find the specified keyword/class.
3642 MagickExport char *XGetResourceInstance(XrmDatabase database,
3643 const char *client_name,const char *keyword,const char *resource_default)
3647 resource_name[MaxTextExtent];
3655 if (database == (XrmDatabase) NULL)
3656 return((char *) resource_default);
3657 *resource_name='\0';
3658 if (keyword != (char *) NULL)
3659 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3661 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3663 if (status == False)
3664 return((char *) resource_default);
3665 return(resource_value.addr);
3669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3673 % X G e t S c r e e n D e n s i t y %
3677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3679 % XGetScreenDensity() returns the density of the X server screen in
3682 % The format of the XGetScreenDensity method is:
3684 % char *XGetScreenDensity(Display *display)
3686 % A description of each parameter follows:
3688 % o density: XGetScreenDensity() returns the density of the X screen in
3691 % o display: Specifies a connection to an X server; returned from
3695 MagickExport char *XGetScreenDensity(Display *display)
3698 density[MaxTextExtent];
3705 Set density as determined by screen size.
3707 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3708 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3709 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3710 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3711 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,
3713 return(GetPageGeometry(density));
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3721 + X G e t S u b w i n d o w %
3725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3727 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3728 % pointer and a button press.
3730 % The format of the XGetSubwindow method is:
3732 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3734 % A description of each parameter follows:
3736 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3737 % otherwise the subwindow is returned.
3739 % o display: Specifies a connection to an X server; returned from
3742 % o window: Specifies a pointer to a Window.
3744 % o x: the x coordinate of the pointer relative to the origin of the
3747 % o y: the y coordinate of the pointer relative to the origin of the
3751 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3764 assert(display != (Display *) NULL);
3765 source_window=XRootWindow(display,XDefaultScreen(display));
3766 if (window == (Window) NULL)
3767 return(source_window);
3768 target_window=window;
3771 status=XTranslateCoordinates(display,source_window,window,x,y,
3772 &x_offset,&y_offset,&target_window);
3775 if (target_window == (Window) NULL)
3777 source_window=window;
3778 window=target_window;
3782 if (target_window == (Window) NULL)
3783 target_window=window;
3784 return(target_window);
3788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3792 % X G e t W i n d o w C o l o r %
3796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3798 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3801 % The format of the XGetWindowColor method is:
3803 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3806 % A description of each parameter follows:
3808 % o display: Specifies a connection to an X server; returned from
3811 % o windows: Specifies a pointer to a XWindows structure.
3813 % o name: the name of the color if found in the X Color Database is
3814 % returned in this character string.
3817 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3818 XWindows *windows,char *name)
3849 Choose a pixel from the X server.
3851 assert(display != (Display *) NULL);
3852 assert(name != (char *) NULL);
3853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3855 target_window=XSelectWindow(display,&crop_info);
3856 if (target_window == (Window) NULL)
3857 return(MagickFalse);
3858 root_window=XRootWindow(display,XDefaultScreen(display));
3859 client_window=target_window;
3860 if (target_window != root_window)
3868 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3869 if (status != False)
3871 client_window=XClientWindow(display,target_window);
3872 target_window=client_window;
3876 Verify window is viewable.
3878 status=XGetWindowAttributes(display,target_window,&window_attributes);
3879 if ((status == False) || (window_attributes.map_state != IsViewable))
3880 return(MagickFalse);
3884 (void) XTranslateCoordinates(display,root_window,target_window,
3885 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3886 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3887 if (ximage == (XImage *) NULL)
3888 return(MagickFalse);
3889 color.pixel=XGetPixel(ximage,0,0);
3890 XDestroyImage(ximage);
3892 Match color against the color database.
3894 (void) XQueryColor(display,window_attributes.colormap,&color);
3895 pixel.red=ScaleShortToQuantum(color.red);
3896 pixel.green=ScaleShortToQuantum(color.green);
3897 pixel.blue=ScaleShortToQuantum(color.blue);
3898 pixel.opacity=OpaqueOpacity;
3899 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3900 &windows->image.image->exception);
3905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3909 + X G e t W i n d o w I m a g e %
3913 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3915 % XGetWindowImage() reads an image from the target X window and returns it.
3916 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3917 % target image with each child image in an optimized fashion. Any child
3918 % window that have the same visual, colormap, and are contained by its parent
3921 % The format of the XGetWindowImage method is:
3923 % Image *XGetWindowImage(Display *display,const Window window,
3924 % const unsigned int borders,const unsigned int level)
3926 % A description of each parameter follows:
3928 % o display: Specifies a connection to an X server; returned from
3931 % o window: Specifies the window to obtain the image from.
3933 % o borders: Specifies whether borders pixels are to be saved with
3936 % o level: Specifies an unsigned integer representing the level of
3937 % decent in the window hierarchy. This value must be zero or one on
3938 % the initial call to XGetWindowImage. A value of zero returns after
3939 % one call. A value of one causes the function to descend the window
3940 % hierarchy and overlay the target image with each subwindow image.
3943 static Image *XGetWindowImage(Display *display,const Window window,
3944 const unsigned int borders,const unsigned int level)
3946 typedef struct _ColormapInfo
3954 struct _ColormapInfo
3958 typedef struct _WindowInfo
3990 register IndexPacket
3997 *colormap_info = (ColormapInfo *) NULL;
4017 Verify window is viewable.
4019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4020 assert(display != (Display *) NULL);
4021 status=XGetWindowAttributes(display,window,&window_attributes);
4022 if ((status == False) || (window_attributes.map_state != IsViewable))
4023 return((Image *) NULL);
4025 Cropping rectangle is relative to root window.
4027 root_window=XRootWindow(display,XDefaultScreen(display));
4028 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4030 crop_info.x=(ssize_t) x_offset;
4031 crop_info.y=(ssize_t) y_offset;
4032 crop_info.width=(size_t) window_attributes.width;
4033 crop_info.height=(size_t) window_attributes.height;
4034 if (borders != MagickFalse)
4037 Include border in image.
4039 crop_info.x-=(ssize_t) window_attributes.border_width;
4040 crop_info.y-=(ssize_t) window_attributes.border_width;
4041 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4042 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4045 Crop to root window.
4047 if (crop_info.x < 0)
4049 crop_info.width+=crop_info.x;
4052 if (crop_info.y < 0)
4054 crop_info.height+=crop_info.y;
4057 display_width=XDisplayWidth(display,XDefaultScreen(display));
4058 if ((int) (crop_info.x+crop_info.width) > display_width)
4059 crop_info.width=(size_t) (display_width-crop_info.x);
4060 display_height=XDisplayHeight(display,XDefaultScreen(display));
4061 if ((int) (crop_info.y+crop_info.height) > display_height)
4062 crop_info.height=(size_t) (display_height-crop_info.y);
4064 Initialize window info attributes.
4066 if (number_windows >= max_windows)
4069 Allocate or resize window info buffer.
4072 if (window_info == (WindowInfo *) NULL)
4073 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4074 sizeof(*window_info));
4076 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4077 max_windows,sizeof(*window_info));
4079 if (window_info == (WindowInfo *) NULL)
4081 ThrowXWindowFatalException(ResourceLimitError,
4082 "MemoryAllocationFailed","...");
4083 return((Image *) NULL);
4085 id=number_windows++;
4086 window_info[id].window=window;
4087 window_info[id].visual=window_attributes.visual;
4088 window_info[id].colormap=window_attributes.colormap;
4089 window_info[id].bounds.x1=(short) crop_info.x;
4090 window_info[id].bounds.y1=(short) crop_info.y;
4091 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4092 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4093 crop_info.x-=x_offset;
4094 crop_info.y-=y_offset;
4095 window_info[id].crop_info=crop_info;
4105 Descend the window hierarchy.
4107 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4108 &children,&number_children);
4109 for (i=0; i < id; i++)
4110 if ((window_info[i].window == window_info[id].parent) &&
4111 (window_info[i].visual == window_info[id].visual) &&
4112 (window_info[i].colormap == window_info[id].colormap))
4114 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4115 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4116 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4117 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4120 Eliminate windows not circumscribed by their parent.
4126 if ((status == True) && (number_children != 0))
4128 for (i=0; i < (int) number_children; i++)
4129 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4130 (void) XFree((void *) children);
4155 register PixelPacket
4171 Get X image for each window in the list.
4173 image=NewImageList();
4174 for (id=0; id < number_windows; id++)
4177 Does target window intersect top level window?
4180 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4181 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4182 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4183 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4184 MagickTrue : MagickFalse;
4186 Is target window contained by another window with the same colormap?
4188 for (j=0; j < id; j++)
4189 if ((window_info[id].visual == window_info[j].visual) &&
4190 (window_info[id].colormap == window_info[j].colormap))
4192 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4193 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4194 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4195 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4199 if ((window_info[id].visual != window_info[j].visual) ||
4200 (window_info[id].colormap != window_info[j].colormap))
4202 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4203 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4204 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4205 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4208 if (import == MagickFalse)
4213 ximage=XGetImage(display,window_info[id].window,(int)
4214 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4215 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4216 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4217 if (ximage == (XImage *) NULL)
4220 Initialize window colormap.
4223 colors=(XColor *) NULL;
4224 if (window_info[id].colormap != (Colormap) NULL)
4230 Search colormap list for window colormap.
4232 number_colors=(unsigned int) window_info[id].visual->map_entries;
4233 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4234 if (p->colormap == window_info[id].colormap)
4236 if (p == (ColormapInfo *) NULL)
4239 Get the window colormap.
4241 colors=(XColor *) AcquireQuantumMemory(number_colors,
4243 if (colors == (XColor *) NULL)
4245 XDestroyImage(ximage);
4246 return((Image *) NULL);
4248 if ((window_info[id].visual->klass != DirectColor) &&
4249 (window_info[id].visual->klass != TrueColor))
4250 for (i=0; i < (int) number_colors; i++)
4252 colors[i].pixel=(size_t) i;
4266 DirectColor or TrueColor visual.
4271 red_bit=window_info[id].visual->red_mask &
4272 (~(window_info[id].visual->red_mask)+1);
4273 green_bit=window_info[id].visual->green_mask &
4274 (~(window_info[id].visual->green_mask)+1);
4275 blue_bit=window_info[id].visual->blue_mask &
4276 (~(window_info[id].visual->blue_mask)+1);
4277 for (i=0; i < (int) number_colors; i++)
4279 colors[i].pixel=(unsigned long) (red | green | blue);
4282 if (red > window_info[id].visual->red_mask)
4285 if (green > window_info[id].visual->green_mask)
4288 if (blue > window_info[id].visual->blue_mask)
4292 (void) XQueryColors(display,window_info[id].colormap,colors,
4293 (int) number_colors);
4295 Append colormap to colormap list.
4297 p=(ColormapInfo *) AcquireAlignedMemory(1,sizeof(*p));
4298 if (p == (ColormapInfo *) NULL)
4299 return((Image *) NULL);
4300 p->colormap=window_info[id].colormap;
4302 p->next=colormap_info;
4308 Allocate image structure.
4310 composite_image=AcquireImage((ImageInfo *) NULL);
4311 if (composite_image == (Image *) NULL)
4313 XDestroyImage(ximage);
4314 return((Image *) NULL);
4317 Convert X image to MIFF format.
4319 if ((window_info[id].visual->klass != TrueColor) &&
4320 (window_info[id].visual->klass != DirectColor))
4321 composite_image->storage_class=PseudoClass;
4322 composite_image->columns=(size_t) ximage->width;
4323 composite_image->rows=(size_t) ximage->height;
4324 exception=(&composite_image->exception);
4325 switch (composite_image->storage_class)
4343 Determine shift and mask for red, green, and blue.
4345 red_mask=window_info[id].visual->red_mask;
4347 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4352 green_mask=window_info[id].visual->green_mask;
4354 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4359 blue_mask=window_info[id].visual->blue_mask;
4361 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4367 Convert X image to DirectClass packets.
4369 if ((number_colors != 0) &&
4370 (window_info[id].visual->klass == DirectColor))
4371 for (y=0; y < (int) composite_image->rows; y++)
4373 q=QueueAuthenticPixels(composite_image,0,y,
4374 composite_image->columns,1,exception);
4375 if (q == (PixelPacket *) NULL)
4377 for (x=0; x < (int) composite_image->columns; x++)
4379 pixel=XGetPixel(ximage,x,y);
4380 index=(pixel >> red_shift) & red_mask;
4381 q->red=ScaleShortToQuantum(colors[index].red);
4382 index=(pixel >> green_shift) & green_mask;
4383 q->green=ScaleShortToQuantum(colors[index].green);
4384 index=(pixel >> blue_shift) & blue_mask;
4385 q->blue=ScaleShortToQuantum(colors[index].blue);
4388 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4392 for (y=0; y < (int) composite_image->rows; y++)
4394 q=QueueAuthenticPixels(composite_image,0,y,
4395 composite_image->columns,1,exception);
4396 if (q == (PixelPacket *) NULL)
4398 for (x=0; x < (int) composite_image->columns; x++)
4400 pixel=XGetPixel(ximage,x,y);
4401 color=(pixel >> red_shift) & red_mask;
4402 color=(65535UL*color)/red_mask;
4403 q->red=ScaleShortToQuantum((unsigned short) color);
4404 color=(pixel >> green_shift) & green_mask;
4405 color=(65535UL*color)/green_mask;
4406 q->green=ScaleShortToQuantum((unsigned short) color);
4407 color=(pixel >> blue_shift) & blue_mask;
4408 color=(65535UL*color)/blue_mask;
4409 q->blue=ScaleShortToQuantum((unsigned short) color);
4412 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4422 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4424 XDestroyImage(ximage);
4425 composite_image=DestroyImage(composite_image);
4426 return((Image *) NULL);
4428 for (i=0; i < (int) composite_image->colors; i++)
4430 composite_image->colormap[colors[i].pixel].red=
4431 ScaleShortToQuantum(colors[i].red);
4432 composite_image->colormap[colors[i].pixel].green=
4433 ScaleShortToQuantum(colors[i].green);
4434 composite_image->colormap[colors[i].pixel].blue=
4435 ScaleShortToQuantum(colors[i].blue);
4438 Convert X image to PseudoClass packets.
4440 for (y=0; y < (int) composite_image->rows; y++)
4442 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4443 if (q == (PixelPacket *) NULL)
4445 indexes=GetAuthenticIndexQueue(composite_image);
4446 for (x=0; x < (int) composite_image->columns; x++)
4448 index=(IndexPacket) XGetPixel(ximage,x,y);
4450 *q++=composite_image->colormap[(ssize_t) index];
4452 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4458 XDestroyImage(ximage);
4459 if (image == (Image *) NULL)
4461 image=composite_image;
4465 Composite any children in back-to-front order.
4467 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4468 &x_offset,&y_offset,&child);
4469 x_offset-=(int) crop_info.x;
4472 y_offset-=(int) crop_info.y;
4475 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4479 Relinquish resources.
4481 while (colormap_info != (ColormapInfo *) NULL)
4483 next=colormap_info->next;
4484 colormap_info->colors=(XColor *)
4485 RelinquishMagickMemory(colormap_info->colors);
4486 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4490 Relinquish resources and restore initial state.
4492 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4495 colormap_info=(ColormapInfo *) NULL;
4498 return((Image *) NULL);
4502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4506 % X G e t W i n d o w I n f o %
4510 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4512 % XGetWindowInfo() initializes the XWindowInfo structure.
4514 % The format of the XGetWindowInfo method is:
4516 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4517 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4518 % XResourceInfo *resource_info,XWindowInfo *window)
4519 % resource_info,window)
4521 % A description of each parameter follows:
4523 % o display: Specifies a connection to an X server; returned from
4526 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4527 % returned from XGetVisualInfo.
4529 % o map_info: If map_type is specified, this structure is initialized
4530 % with info from the Standard Colormap.
4532 % o pixel: Specifies a pointer to a XPixelInfo structure.
4534 % o font_info: Specifies a pointer to a XFontStruct structure.
4536 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4539 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4540 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4541 XResourceInfo *resource_info,XWindowInfo *window)
4544 Initialize window info.
4546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4547 assert(display != (Display *) NULL);
4548 assert(visual_info != (XVisualInfo *) NULL);
4549 assert(map_info != (XStandardColormap *) NULL);
4550 assert(pixel != (XPixelInfo *) NULL);
4551 assert(resource_info != (XResourceInfo *) NULL);
4552 assert(window != (XWindowInfo *) NULL);
4553 if (window->id != (Window) NULL)
4555 if (window->cursor != (Cursor) NULL)
4556 (void) XFreeCursor(display,window->cursor);
4557 if (window->busy_cursor != (Cursor) NULL)
4558 (void) XFreeCursor(display,window->busy_cursor);
4559 if (window->highlight_stipple != (Pixmap) NULL)
4560 (void) XFreePixmap(display,window->highlight_stipple);
4561 if (window->shadow_stipple != (Pixmap) NULL)
4562 (void) XFreePixmap(display,window->shadow_stipple);
4563 if (window->name == (char *) NULL)
4564 window->name=AcquireString("");
4565 if (window->icon_name == (char *) NULL)
4566 window->icon_name=AcquireString("");
4571 Initialize these attributes just once.
4573 window->id=(Window) NULL;
4574 if (window->name == (char *) NULL)
4575 window->name=AcquireString("");
4576 if (window->icon_name == (char *) NULL)
4577 window->icon_name=AcquireString("");
4578 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4579 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4580 window->ximage=(XImage *) NULL;
4581 window->matte_image=(XImage *) NULL;
4582 window->pixmap=(Pixmap) NULL;
4583 window->matte_pixmap=(Pixmap) NULL;
4584 window->mapped=MagickFalse;
4585 window->stasis=MagickFalse;
4586 window->shared_memory=MagickTrue;
4587 window->segment_info=(void *) NULL;
4588 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4593 if (window->segment_info == (void *) NULL)
4594 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4595 segment_info=(XShmSegmentInfo *) window->segment_info;
4596 segment_info[0].shmid=(-1);
4597 segment_info[0].shmaddr=(char *) NULL;
4598 segment_info[1].shmid=(-1);
4599 segment_info[1].shmaddr=(char *) NULL;
4604 Initialize these attributes every time function is called.
4606 window->screen=visual_info->screen;
4607 window->root=XRootWindow(display,visual_info->screen);
4608 window->visual=visual_info->visual;
4609 window->storage_class=(unsigned int) visual_info->klass;
4610 window->depth=(unsigned int) visual_info->depth;
4611 window->visual_info=visual_info;
4612 window->map_info=map_info;
4613 window->pixel_info=pixel;
4614 window->font_info=font_info;
4615 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4616 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4617 window->geometry=(char *) NULL;
4618 window->icon_geometry=(char *) NULL;
4619 if (resource_info->icon_geometry != (char *) NULL)
4620 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4621 window->crop_geometry=(char *) NULL;
4622 window->flags=(size_t) PSize;
4625 window->min_width=1;
4626 window->min_height=1;
4627 window->width_inc=1;
4628 window->height_inc=1;
4629 window->border_width=resource_info->border_width;
4630 window->annotate_context=pixel->annotate_context;
4631 window->highlight_context=pixel->highlight_context;
4632 window->widget_context=pixel->widget_context;
4633 window->shadow_stipple=(Pixmap) NULL;
4634 window->highlight_stipple=(Pixmap) NULL;
4635 window->use_pixmap=MagickTrue;
4636 window->immutable=MagickFalse;
4637 window->shape=MagickFalse;
4639 window->mask=(size_t) (CWBackingStore | CWBackPixel | CWBackPixmap |
4640 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4641 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4642 window->attributes.background_pixel=pixel->background_color.pixel;
4643 window->attributes.background_pixmap=(Pixmap) NULL;
4644 window->attributes.bit_gravity=ForgetGravity;
4645 window->attributes.backing_store=WhenMapped;
4646 window->attributes.save_under=MagickTrue;
4647 window->attributes.border_pixel=pixel->border_color.pixel;
4648 window->attributes.colormap=map_info->colormap;
4649 window->attributes.cursor=window->cursor;
4650 window->attributes.do_not_propagate_mask=NoEventMask;
4651 window->attributes.event_mask=NoEventMask;
4652 window->attributes.override_redirect=MagickFalse;
4653 window->attributes.win_gravity=NorthWestGravity;
4654 window->orphan=MagickFalse;
4658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4662 % X H i g h l i g h t E l l i p s e %
4666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4668 % XHighlightEllipse() puts a border on the X server around a region defined by
4671 % The format of the XHighlightEllipse method is:
4673 % void XHighlightEllipse(Display *display,Window window,
4674 % GC annotate_context,const RectangleInfo *highlight_info)
4676 % A description of each parameter follows:
4678 % o display: Specifies a connection to an X server; returned from
4681 % o window: Specifies a pointer to a Window structure.
4683 % o annotate_context: Specifies a pointer to a GC structure.
4685 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4686 % contains the extents of any highlighting rectangle.
4689 MagickExport void XHighlightEllipse(Display *display,Window window,
4690 GC annotate_context,const RectangleInfo *highlight_info)
4692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4693 assert(display != (Display *) NULL);
4694 assert(window != (Window) NULL);
4695 assert(annotate_context != (GC) NULL);
4696 assert(highlight_info != (RectangleInfo *) NULL);
4697 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4699 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4700 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4701 (unsigned int) highlight_info->height-1,0,360*64);
4702 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4703 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4704 (unsigned int) highlight_info->height-3,0,360*64);
4708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4712 % X H i g h l i g h t L i n e %
4716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4718 % XHighlightLine() puts a border on the X server around a region defined by
4721 % The format of the XHighlightLine method is:
4723 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4724 % const XSegment *highlight_info)
4726 % A description of each parameter follows:
4728 % o display: Specifies a connection to an X server; returned from
4731 % o window: Specifies a pointer to a Window structure.
4733 % o annotate_context: Specifies a pointer to a GC structure.
4735 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4736 % contains the extents of any highlighting rectangle.
4739 MagickExport void XHighlightLine(Display *display,Window window,
4740 GC annotate_context,const XSegment *highlight_info)
4742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4743 assert(display != (Display *) NULL);
4744 assert(window != (Window) NULL);
4745 assert(annotate_context != (GC) NULL);
4746 assert(highlight_info != (XSegment *) NULL);
4747 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4748 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4752 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4756 % X H i g h l i g h t R e c t a n g l e %
4760 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4762 % XHighlightRectangle() puts a border on the X server around a region defined
4763 % by highlight_info.
4765 % The format of the XHighlightRectangle method is:
4767 % void XHighlightRectangle(Display *display,Window window,
4768 % GC annotate_context,const RectangleInfo *highlight_info)
4770 % A description of each parameter follows:
4772 % o display: Specifies a connection to an X server; returned from
4775 % o window: Specifies a pointer to a Window structure.
4777 % o annotate_context: Specifies a pointer to a GC structure.
4779 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4780 % contains the extents of any highlighting rectangle.
4783 MagickExport void XHighlightRectangle(Display *display,Window window,
4784 GC annotate_context,const RectangleInfo *highlight_info)
4786 assert(display != (Display *) NULL);
4787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4788 assert(window != (Window) NULL);
4789 assert(annotate_context != (GC) NULL);
4790 assert(highlight_info != (RectangleInfo *) NULL);
4791 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4793 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4794 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4795 (unsigned int) highlight_info->height-1);
4796 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4797 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4798 (unsigned int) highlight_info->height-3);
4802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4806 % X I m p o r t I m a g e %
4810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4812 % XImportImage() reads an image from an X window.
4814 % The format of the XImportImage method is:
4816 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4818 % A description of each parameter follows:
4820 % o image_info: the image info.
4822 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4825 MagickExport Image *XImportImage(const ImageInfo *image_info,
4826 XImportInfo *ximage_info)
4859 Open X server connection.
4861 assert(image_info != (const ImageInfo *) NULL);
4862 assert(image_info->signature == MagickSignature);
4863 if (image_info->debug != MagickFalse)
4864 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4865 image_info->filename);
4866 assert(ximage_info != (XImportInfo *) NULL);
4867 display=XOpenDisplay(image_info->server_name);
4868 if (display == (Display *) NULL)
4870 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4871 XDisplayName(image_info->server_name));
4872 return((Image *) NULL);
4875 Set our forgiving exception handler.
4877 (void) XSetErrorHandler(XError);
4879 Select target window.
4885 root=XRootWindow(display,XDefaultScreen(display));
4886 target=(Window) NULL;
4887 if ((image_info->filename != (char *) NULL) &&
4888 (*image_info->filename != '\0'))
4890 if (LocaleCompare(image_info->filename,"root") == 0)
4895 Select window by ID or name.
4897 if (isdigit((unsigned char) *image_info->filename) != 0)
4898 target=XWindowByID(display,root,(Window)
4899 strtol(image_info->filename,(char **) NULL,0));
4900 if (target == (Window) NULL)
4901 target=XWindowByName(display,root,image_info->filename);
4902 if (target == (Window) NULL)
4903 ThrowXWindowFatalException(XServerError,
4904 "NoWindowWithSpecifiedIDExists",image_info->filename);
4908 If target window is not defined, interactively select one.
4910 prior_target=target;
4911 if (target == (Window) NULL)
4912 target=XSelectWindow(display,&crop_info);
4913 if (target == (Window) NULL)
4914 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4915 image_info->filename);
4916 client=target; /* obsolete */
4922 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4923 if (status != False)
4931 Find window manager frame.
4933 status=XQueryTree(display,target,&root,&parent,&children,&d);
4934 if ((status != False) && (children != (Window *) NULL))
4935 (void) XFree((char *) children);
4936 if ((status == False) || (parent == (Window) NULL) ||
4944 client=XClientWindow(display,target);
4945 if (ximage_info->frame == MagickFalse)
4947 if ((ximage_info->frame == MagickFalse) &&
4948 (prior_target != MagickFalse))
4949 target=prior_target;
4950 XDelay(display,SuspendTime << 4);
4953 if (ximage_info->screen)
4965 Obtain window image directly from screen.
4967 status=XGetWindowAttributes(display,target,&window_attributes);
4968 if (status == False)
4970 ThrowXWindowFatalException(XServerError,
4971 "UnableToReadXWindowAttributes",image_info->filename);
4972 (void) XCloseDisplay(display);
4973 return((Image *) NULL);
4975 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4978 crop_info.width=(size_t) window_attributes.width;
4979 crop_info.height=(size_t) window_attributes.height;
4980 if (ximage_info->borders != 0)
4983 Include border in image.
4985 crop_info.x-=window_attributes.border_width;
4986 crop_info.y-=window_attributes.border_width;
4987 crop_info.width+=window_attributes.border_width << 1;
4988 crop_info.height+=window_attributes.border_width << 1;
4993 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4996 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4997 if ((status == True) && (number_windows > 0))
4999 ximage_info->descend=MagickTrue;
5000 (void) XFree ((char *) children);
5002 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5003 if (number_colormaps > 0)
5005 if (number_colormaps > 1)
5006 ximage_info->descend=MagickTrue;
5007 (void) XFree((char *) colormaps);
5010 Alert the user not to alter the screen.
5012 if (ximage_info->silent == MagickFalse)
5013 (void) XBell(display,0);
5015 Get image by window id.
5017 (void) XGrabServer(display);
5018 image=XGetWindowImage(display,target,ximage_info->borders,
5019 ximage_info->descend ? 1U : 0U);
5020 (void) XUngrabServer(display);
5021 if (image == (Image *) NULL)
5022 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5023 image_info->filename)
5026 (void) CopyMagickString(image->filename,image_info->filename,
5028 if ((crop_info.width != 0) && (crop_info.height != 0))
5035 Crop image as defined by the cropping rectangle.
5037 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5038 if (clone_image != (Image *) NULL)
5040 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5041 if (crop_image != (Image *) NULL)
5043 image=DestroyImage(image);
5048 status=XGetWMName(display,target,&window_name);
5051 if ((image_info->filename != (char *) NULL) &&
5052 (*image_info->filename == '\0'))
5053 (void) CopyMagickString(image->filename,(char *) window_name.value,
5054 (size_t) window_name.nitems+1);
5055 (void) XFree((void *) window_name.value);
5058 if (ximage_info->silent == MagickFalse)
5061 Alert the user we're done.
5063 (void) XBell(display,0);
5064 (void) XBell(display,0);
5066 (void) XCloseDisplay(display);
5071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5075 % X I n i t i a l i z e W i n d o w s %
5079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5081 % XInitializeWindows() initializes the XWindows structure.
5083 % The format of the XInitializeWindows method is:
5085 % XWindows *XInitializeWindows(Display *display,
5086 % XResourceInfo *resource_info)
5088 % A description of each parameter follows:
5090 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5092 % o display: Specifies a connection to an X server; returned from
5095 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5098 MagickExport XWindows *XInitializeWindows(Display *display,
5099 XResourceInfo *resource_info)
5108 Allocate windows structure.
5110 windows=(XWindows *) AcquireAlignedMemory(1,sizeof(*windows));
5111 if (windows == (XWindows *) NULL)
5113 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5115 return((XWindows *) NULL);
5117 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5118 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5119 sizeof(*windows->pixel_info));
5120 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5121 sizeof(*windows->icon_pixel));
5122 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5123 sizeof(*windows->icon_resources));
5124 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5125 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5126 (windows->icon_resources == (XResourceInfo *) NULL))
5128 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5130 return((XWindows *) NULL);
5133 Initialize windows structure.
5135 windows->display=display;
5136 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5137 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5138 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5139 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5140 windows->im_remote_command=
5141 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5142 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5143 windows->im_update_colormap=
5144 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5145 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5146 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5147 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5148 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5149 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5150 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5151 (void) XSynchronize(display,IsWindows95());
5153 if (IsEventLogging())
5155 (void) XSynchronize(display,MagickTrue);
5156 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5157 GetMagickVersion((size_t *) NULL));
5158 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5159 (void) LogMagickEvent(X11Event,GetMagickModule(),
5160 " Window Manager: 0x%lx",windows->wm_protocols);
5161 (void) LogMagickEvent(X11Event,GetMagickModule(),
5162 " delete window: 0x%lx",windows->wm_delete_window);
5163 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5164 windows->wm_take_focus);
5165 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5166 windows->im_protocols);
5167 (void) LogMagickEvent(X11Event,GetMagickModule(),
5168 " remote command: 0x%lx",windows->im_remote_command);
5169 (void) LogMagickEvent(X11Event,GetMagickModule(),
5170 " update widget: 0x%lx",windows->im_update_widget);
5171 (void) LogMagickEvent(X11Event,GetMagickModule(),
5172 " update colormap: 0x%lx",windows->im_update_colormap);
5173 (void) LogMagickEvent(X11Event,GetMagickModule(),
5174 " former image: 0x%lx",windows->im_former_image);
5175 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5176 windows->im_next_image);
5177 (void) LogMagickEvent(X11Event,GetMagickModule(),
5178 " retain colors: 0x%lx",windows->im_retain_colors);
5179 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5181 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5182 windows->dnd_protocols);
5185 Allocate standard colormap.
5187 windows->map_info=XAllocStandardColormap();
5188 windows->icon_map=XAllocStandardColormap();
5189 if ((windows->map_info == (XStandardColormap *) NULL) ||
5190 (windows->icon_map == (XStandardColormap *) NULL))
5191 ThrowXWindowFatalException(ResourceLimitFatalError,
5192 "MemoryAllocationFailed","...");
5193 windows->map_info->colormap=(Colormap) NULL;
5194 windows->icon_map->colormap=(Colormap) NULL;
5195 windows->pixel_info->pixels=(unsigned long *) NULL;
5196 windows->pixel_info->annotate_context=(GC) NULL;
5197 windows->pixel_info->highlight_context=(GC) NULL;
5198 windows->pixel_info->widget_context=(GC) NULL;
5199 windows->font_info=(XFontStruct *) NULL;
5200 windows->icon_pixel->annotate_context=(GC) NULL;
5201 windows->icon_pixel->pixels=(unsigned long *) NULL;
5205 *windows->icon_resources=(*resource_info);
5206 windows->icon_resources->visual_type=(char *) "default";
5207 windows->icon_resources->colormap=SharedColormap;
5208 windows->visual_info=
5209 XBestVisualInfo(display,windows->map_info,resource_info);
5210 windows->icon_visual=
5211 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5212 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5213 (windows->icon_visual == (XVisualInfo *) NULL))
5214 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5215 resource_info->visual_type);
5216 if (IsEventLogging())
5218 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5219 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5220 windows->visual_info->visualid);
5221 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5222 XVisualClassName(windows->visual_info->klass));
5223 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5224 windows->visual_info->depth);
5225 (void) LogMagickEvent(X11Event,GetMagickModule(),
5226 " size of colormap: %d entries",windows->visual_info->colormap_size);
5227 (void) LogMagickEvent(X11Event,GetMagickModule(),
5228 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5229 windows->visual_info->red_mask,windows->visual_info->green_mask,
5230 windows->visual_info->blue_mask);
5231 (void) LogMagickEvent(X11Event,GetMagickModule(),
5232 " significant bits in color: %d bits",
5233 windows->visual_info->bits_per_rgb);
5236 Allocate class and manager hints.
5238 windows->class_hints=XAllocClassHint();
5239 windows->manager_hints=XAllocWMHints();
5240 if ((windows->class_hints == (XClassHint *) NULL) ||
5241 (windows->manager_hints == (XWMHints *) NULL))
5242 ThrowXWindowFatalException(ResourceLimitFatalError,
5243 "MemoryAllocationFailed","...");
5245 Determine group leader if we have one.
5247 root_window=XRootWindow(display,windows->visual_info->screen);
5248 windows->group_leader.id=(Window) NULL;
5249 if (resource_info->window_group != (char *) NULL)
5251 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5252 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5253 strtol((char *) resource_info->window_group,(char **) NULL,0));
5254 if (windows->group_leader.id == (Window) NULL)
5255 windows->group_leader.id=
5256 XWindowByName(display,root_window,resource_info->window_group);
5262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5266 % X M a k e C u r s o r %
5270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5272 % XMakeCursor() creates a crosshairs X11 cursor.
5274 % The format of the XMakeCursor method is:
5276 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5277 % char *background_color,char *foreground_color)
5279 % A description of each parameter follows:
5281 % o display: Specifies a connection to an X server; returned from
5284 % o window: Specifies the ID of the window for which the cursor is
5287 % o colormap: Specifies the ID of the colormap from which the background
5288 % and foreground color will be retrieved.
5290 % o background_color: Specifies the color to use for the cursor background.
5292 % o foreground_color: Specifies the color to use for the cursor foreground.
5295 MagickExport Cursor XMakeCursor(Display *display,Window window,
5296 Colormap colormap,char *background_color,char *foreground_color)
5298 #define scope_height 17
5299 #define scope_x_hot 8
5300 #define scope_y_hot 8
5301 #define scope_width 17
5303 static const unsigned char
5306 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5307 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5308 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5309 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5310 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5314 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5315 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5316 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5317 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5318 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5332 assert(display != (Display *) NULL);
5333 assert(window != (Window) NULL);
5334 assert(colormap != (Colormap) NULL);
5335 assert(background_color != (char *) NULL);
5336 assert(foreground_color != (char *) NULL);
5337 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5338 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5340 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5341 scope_width,scope_height);
5342 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5344 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5345 return((Cursor) NULL);
5347 (void) XParseColor(display,colormap,background_color,&background);
5348 (void) XParseColor(display,colormap,foreground_color,&foreground);
5349 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5350 scope_x_hot,scope_y_hot);
5351 (void) XFreePixmap(display,source);
5352 (void) XFreePixmap(display,mask);
5357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5361 % X M a k e I m a g e %
5365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5367 % XMakeImage() creates an X11 image. If the image size differs from the X11
5368 % image size, the image is first resized.
5370 % The format of the XMakeImage method is:
5372 % MagickBooleanType XMakeImage(Display *display,
5373 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5374 % unsigned int width,unsigned int height)
5376 % A description of each parameter follows:
5378 % o display: Specifies a connection to an X server; returned from
5381 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5383 % o window: Specifies a pointer to a XWindowInfo structure.
5385 % o image: the image.
5387 % o width: Specifies the width in pixels of the rectangular area to
5390 % o height: Specifies the height in pixels of the rectangular area to
5394 MagickExport MagickBooleanType XMakeImage(Display *display,
5395 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5396 unsigned int width,unsigned int height)
5398 #define CheckOverflowException(length,width,height) \
5399 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5413 assert(display != (Display *) NULL);
5414 assert(resource_info != (XResourceInfo *) NULL);
5415 assert(window != (XWindowInfo *) NULL);
5417 assert(height != 0);
5418 if ((window->width == 0) || (window->height == 0))
5419 return(MagickFalse);
5421 Apply user transforms to the image.
5423 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5424 (void) XFlush(display);
5425 depth=(int) window->depth;
5426 if (window->destroy)
5427 window->image=DestroyImage(window->image);
5428 window->image=image;
5429 window->destroy=MagickFalse;
5430 if (window->image != (Image *) NULL)
5432 if (window->crop_geometry != (char *) NULL)
5443 window->image->page.x=0;
5444 window->image->page.y=0;
5445 (void) ParsePageGeometry(window->image,window->crop_geometry,
5446 &crop_info,&image->exception);
5447 crop_image=CropImage(window->image,&crop_info,&image->exception);
5448 if (crop_image != (Image *) NULL)
5450 if (window->image != image)
5451 window->image=DestroyImage(window->image);
5452 window->image=crop_image;
5453 window->destroy=MagickTrue;
5456 if ((width != (unsigned int) window->image->columns) ||
5457 (height != (unsigned int) window->image->rows))
5465 resize_image=NewImageList();
5466 if (window->pixel_info->colors != 0)
5467 resize_image=SampleImage(window->image,width,height,
5470 resize_image=ThumbnailImage(window->image,width,height,
5472 if (resize_image != (Image *) NULL)
5474 if (window->image != image)
5475 window->image=DestroyImage(window->image);
5476 window->image=resize_image;
5477 window->destroy=MagickTrue;
5480 width=(unsigned int) window->image->columns;
5481 assert((size_t) width == window->image->columns);
5482 height=(unsigned int) window->image->rows;
5483 assert((size_t) height == window->image->rows);
5488 ximage=(XImage *) NULL;
5489 format=(depth == 1) ? XYBitmap : ZPixmap;
5490 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5491 if (window->shared_memory != MagickFalse)
5496 segment_info=(XShmSegmentInfo *) window->segment_info;
5497 segment_info[1].shmid=(-1);
5498 segment_info[1].shmaddr=(char *) NULL;
5499 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5500 (char *) NULL,&segment_info[1],width,height);
5501 if (ximage == (XImage *) NULL)
5502 window->shared_memory=MagickFalse;
5503 length=(size_t) ximage->bytes_per_line*ximage->height;
5504 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5505 window->shared_memory=MagickFalse;
5506 if (window->shared_memory != MagickFalse)
5507 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5508 if (window->shared_memory != MagickFalse)
5509 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5510 if (segment_info[1].shmid < 0)
5511 window->shared_memory=MagickFalse;
5512 if (window->shared_memory != MagickFalse)
5513 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5516 if (ximage != (XImage *) NULL)
5517 XDestroyImage(ximage);
5518 ximage=(XImage *) NULL;
5519 if (segment_info[1].shmaddr)
5521 (void) shmdt(segment_info[1].shmaddr);
5522 segment_info[1].shmaddr=(char *) NULL;
5524 if (segment_info[1].shmid >= 0)
5526 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5527 segment_info[1].shmid=(-1);
5533 Allocate X image pixel data.
5535 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5536 if (window->shared_memory)
5544 (void) XSync(display,MagickFalse);
5545 xerror_alert=MagickFalse;
5546 segment_info=(XShmSegmentInfo *) window->segment_info;
5547 ximage->data=segment_info[1].shmaddr;
5548 segment_info[1].readOnly=MagickFalse;
5549 status=XShmAttach(display,&segment_info[1]);
5550 if (status != False)
5551 (void) XSync(display,MagickFalse);
5552 if ((status == False) || (xerror_alert != MagickFalse))
5554 window->shared_memory=MagickFalse;
5555 if (status != False)
5556 XShmDetach(display,&segment_info[1]);
5557 if (ximage != (XImage *) NULL)
5560 XDestroyImage(ximage);
5561 ximage=(XImage *) NULL;
5563 if (segment_info[1].shmid >= 0)
5565 if (segment_info[1].shmaddr != NULL)
5566 (void) shmdt(segment_info[1].shmaddr);
5567 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5568 segment_info[1].shmid=(-1);
5569 segment_info[1].shmaddr=(char *) NULL;
5574 if (window->shared_memory == MagickFalse)
5575 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5576 (char *) NULL,width,height,XBitmapPad(display),0);
5577 if (ximage == (XImage *) NULL)
5580 Unable to create X image.
5582 (void) XCheckDefineCursor(display,window->id,window->cursor);
5583 return(MagickFalse);
5585 length=(size_t) ximage->bytes_per_line*ximage->height;
5586 if (IsEventLogging())
5588 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5589 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5590 ximage->width,ximage->height);
5591 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5593 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5594 ximage->byte_order);
5595 (void) LogMagickEvent(X11Event,GetMagickModule(),
5596 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5597 ximage->bitmap_bit_order,ximage->bitmap_pad);
5598 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5600 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5601 ximage->bytes_per_line);
5602 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5603 ximage->bits_per_pixel);
5604 (void) LogMagickEvent(X11Event,GetMagickModule(),
5605 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5606 ximage->green_mask,ximage->blue_mask);
5608 if (window->shared_memory == MagickFalse)
5610 if (ximage->format != XYBitmap)
5611 ximage->data=(char *) AcquireQuantumMemory((size_t)
5612 ximage->bytes_per_line,(size_t) ximage->height);
5614 ximage->data=(char *) AcquireQuantumMemory((size_t)
5615 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5617 if (ximage->data == (char *) NULL)
5620 Unable to allocate pixel data.
5622 XDestroyImage(ximage);
5623 ximage=(XImage *) NULL;
5624 (void) XCheckDefineCursor(display,window->id,window->cursor);
5625 return(MagickFalse);
5627 if (window->ximage != (XImage *) NULL)
5630 Destroy previous X image.
5632 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5633 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5634 if (window->segment_info != (XShmSegmentInfo *) NULL)
5639 segment_info=(XShmSegmentInfo *) window->segment_info;
5640 if (segment_info[0].shmid >= 0)
5642 (void) XSync(display,MagickFalse);
5643 (void) XShmDetach(display,&segment_info[0]);
5644 (void) XSync(display,MagickFalse);
5645 if (segment_info[0].shmaddr != (char *) NULL)
5646 (void) shmdt(segment_info[0].shmaddr);
5647 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5648 segment_info[0].shmid=(-1);
5649 segment_info[0].shmaddr=(char *) NULL;
5650 window->ximage->data=(char *) NULL;
5654 if (window->ximage->data != (char *) NULL)
5655 free(window->ximage->data);
5656 window->ximage->data=(char *) NULL;
5657 XDestroyImage(window->ximage);
5658 window->ximage=(XImage *) NULL;
5660 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5661 if (window->segment_info != (XShmSegmentInfo *) NULL)
5666 segment_info=(XShmSegmentInfo *) window->segment_info;
5667 segment_info[0]=segment_info[1];
5670 window->ximage=ximage;
5671 matte_image=(XImage *) NULL;
5672 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5673 if ((window->image->matte != MagickFalse) &&
5674 ((ssize_t) width <= XDisplayWidth(display,window->screen)) &&
5675 ((ssize_t) height <= XDisplayHeight(display,window->screen)))
5680 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5681 (char *) NULL,width,height,XBitmapPad(display),0);
5682 if (IsEventLogging())
5684 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5685 (void) LogMagickEvent(X11Event,GetMagickModule(),
5686 " width, height: %dx%d",matte_image->width,matte_image->height);
5688 if (matte_image != (XImage *) NULL)
5691 Allocate matte image pixel data.
5693 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5694 matte_image->bytes_per_line*matte_image->depth,
5695 (size_t) matte_image->height);
5696 if (matte_image->data == (char *) NULL)
5698 XDestroyImage(matte_image);
5699 matte_image=(XImage *) NULL;
5703 if (window->matte_image != (XImage *) NULL)
5708 if (window->matte_image->data != (char *) NULL)
5709 free(window->matte_image->data);
5710 window->matte_image->data=(char *) NULL;
5711 XDestroyImage(window->matte_image);
5712 window->matte_image=(XImage *) NULL;
5714 window->matte_image=matte_image;
5715 if (window->matte_pixmap != (Pixmap) NULL)
5717 (void) XFreePixmap(display,window->matte_pixmap);
5718 window->matte_pixmap=(Pixmap) NULL;
5719 #if defined(MAGICKCORE_HAVE_SHAPE)
5720 if (window->shape != MagickFalse)
5721 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5724 window->stasis=MagickFalse;
5726 Convert pixels to X image data.
5728 if (window->image != (Image *) NULL)
5730 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5731 (ximage->bitmap_bit_order == LSBFirst)))
5732 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5735 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5738 if (window->matte_image != (XImage *) NULL)
5741 Create matte pixmap.
5743 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5744 if (window->matte_pixmap != (Pixmap) NULL)
5753 Copy matte image to matte pixmap.
5755 context_values.background=1;
5756 context_values.foreground=0;
5757 graphics_context=XCreateGC(display,window->matte_pixmap,
5758 (size_t) (GCBackground | GCForeground),&context_values);
5759 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5760 window->matte_image,0,0,0,0,width,height);
5761 (void) XFreeGC(display,graphics_context);
5762 #if defined(MAGICKCORE_HAVE_SHAPE)
5763 if (window->shape != MagickFalse)
5764 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5765 window->matte_pixmap,ShapeSet);
5769 (void) XMakePixmap(display,resource_info,window);
5773 (void) XCheckDefineCursor(display,window->id,window->cursor);
5778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5782 + X M a k e I m a g e L S B F i r s t %
5786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5788 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5789 % pixels are copied in least-significant bit and byte first order. The
5790 % server's scanline pad is respected. Rather than using one or two general
5791 % cases, many special cases are found here to help speed up the image
5794 % The format of the XMakeImageLSBFirst method is:
5796 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5798 % A description of each parameter follows:
5800 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5802 % o window: Specifies a pointer to a XWindowInfo structure.
5804 % o image: the image.
5806 % o ximage: Specifies a pointer to a XImage structure; returned from
5809 % o matte_image: Specifies a pointer to a XImage structure; returned from
5813 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5814 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5822 register const IndexPacket
5825 register const PixelPacket
5831 register unsigned char
5848 assert(resource_info != (XResourceInfo *) NULL);
5849 assert(window != (XWindowInfo *) NULL);
5850 assert(image != (Image *) NULL);
5851 if (image->debug != MagickFalse)
5852 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5854 if ((window->immutable == MagickFalse) &&
5855 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5858 size[MaxTextExtent];
5866 image_info=AcquireImageInfo();
5867 (void) CopyMagickString(image_info->filename,
5868 resource_info->image_info->texture != (char *) NULL ?
5869 resource_info->image_info->texture : "pattern:checkerboard",
5871 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
5872 image->columns,(double) image->rows);
5873 image_info->size=ConstantString(size);
5874 pattern=ReadImage(image_info,&image->exception);
5875 image_info=DestroyImageInfo(image_info);
5876 if (pattern != (Image *) NULL)
5878 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5879 if (canvas != (Image *) NULL)
5880 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5881 pattern=DestroyImage(pattern);
5884 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5885 ximage->bits_per_pixel) >> 3));
5886 map_info=window->map_info;
5887 pixels=window->pixel_info->pixels;
5888 q=(unsigned char *) ximage->data;
5890 if (ximage->format == XYBitmap)
5892 register unsigned short
5900 Convert canvas to big-endian bitmap.
5902 background=(unsigned char)
5903 (XPixelIntensity(&window->pixel_info->foreground_color) <
5904 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5905 foreground=(unsigned char)
5906 (XPixelIntensity(&window->pixel_info->background_color) <
5907 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5908 polarity=(unsigned short) ((PixelIntensityToQuantum(
5909 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5910 if (canvas->colors == 2)
5911 polarity=PixelIntensity(&canvas->colormap[0]) <
5912 PixelIntensity(&canvas->colormap[1]);
5913 for (y=0; y < (int) canvas->rows; y++)
5915 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5916 if (p == (const PixelPacket *) NULL)
5918 indexes=GetVirtualIndexQueue(canvas);
5921 for (x=0; x < (int) canvas->columns; x++)
5924 if (indexes[x] == (IndexPacket) polarity)
5942 if (window->pixel_info->colors != 0)
5943 switch (ximage->bits_per_pixel)
5947 register unsigned int
5951 Convert to 2 bit color-mapped X canvas.
5953 for (y=0; y < (int) canvas->rows; y++)
5955 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5956 if (p == (const PixelPacket *) NULL)
5958 indexes=GetVirtualIndexQueue(canvas);
5960 for (x=0; x < (int) canvas->columns; x++)
5962 pixel=pixels[(ssize_t) indexes[x]] & 0x0f;
5967 *q=(unsigned char) pixel;
5973 *q|=(unsigned char) (pixel << 2);
5979 *q|=(unsigned char) (pixel << 4);
5985 *q|=(unsigned char) (pixel << 6);
5998 register unsigned int
6002 Convert to 4 bit color-mapped X canvas.
6004 for (y=0; y < (int) canvas->rows; y++)
6006 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6007 if (p == (const PixelPacket *) NULL)
6009 indexes=GetVirtualIndexQueue(canvas);
6011 for (x=0; x < (int) canvas->columns; x++)
6013 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6018 *q=(unsigned char) pixel;
6024 *q|=(unsigned char) (pixel << 4);
6039 Convert to 8 bit color-mapped X canvas.
6041 if (resource_info->color_recovery &&
6042 resource_info->quantize_info->dither)
6044 XDitherImage(canvas,ximage);
6047 for (y=0; y < (int) canvas->rows; y++)
6049 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6050 if (p == (const PixelPacket *) NULL)
6052 indexes=GetVirtualIndexQueue(canvas);
6053 for (x=0; x < (int) canvas->columns; x++)
6055 pixel=pixels[(ssize_t) indexes[x]];
6056 *q++=(unsigned char) pixel;
6067 register unsigned int
6071 channel[sizeof(size_t)];
6074 Convert to multi-byte color-mapped X canvas.
6076 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6077 for (y=0; y < (int) canvas->rows; y++)
6079 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6080 if (p == (const PixelPacket *) NULL)
6082 indexes=GetVirtualIndexQueue(canvas);
6083 for (x=0; x < (int) canvas->columns; x++)
6085 pixel=pixels[(ssize_t) indexes[x]];
6086 for (k=0; k < (int) bytes_per_pixel; k++)
6088 channel[k]=(unsigned char) pixel;
6091 for (k=0; k < (int) bytes_per_pixel; k++)
6100 switch (ximage->bits_per_pixel)
6104 register unsigned int
6108 Convert to contiguous 2 bit continuous-tone X canvas.
6110 for (y=0; y < (int) canvas->rows; y++)
6113 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6114 if (p == (const PixelPacket *) NULL)
6116 for (x=0; x < (int) canvas->columns; x++)
6118 pixel=XGammaPixel(map_info,p);
6124 *q=(unsigned char) pixel;
6130 *q|=(unsigned char) (pixel << 2);
6136 *q|=(unsigned char) (pixel << 4);
6142 *q|=(unsigned char) (pixel << 6);
6156 register unsigned int
6160 Convert to contiguous 4 bit continuous-tone X canvas.
6162 for (y=0; y < (int) canvas->rows; y++)
6164 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6165 if (p == (const PixelPacket *) NULL)
6168 for (x=0; x < (int) canvas->columns; x++)
6170 pixel=XGammaPixel(map_info,p);
6176 *q=(unsigned char) pixel;
6182 *q|=(unsigned char) (pixel << 4);
6198 Convert to contiguous 8 bit continuous-tone X canvas.
6200 if (resource_info->color_recovery &&
6201 resource_info->quantize_info->dither)
6203 XDitherImage(canvas,ximage);
6206 for (y=0; y < (int) canvas->rows; y++)
6208 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6209 if (p == (const PixelPacket *) NULL)
6211 for (x=0; x < (int) canvas->columns; x++)
6213 pixel=XGammaPixel(map_info,p);
6214 *q++=(unsigned char) pixel;
6223 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6224 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6225 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6226 (map_info->blue_mult == 1))
6229 Convert to 32 bit continuous-tone X canvas.
6231 for (y=0; y < (int) canvas->rows; y++)
6233 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6234 &canvas->exception);
6235 if (p == (const PixelPacket *) NULL)
6237 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6238 (blue_gamma != 1.0))
6241 Gamma correct canvas.
6243 for (x=(int) canvas->columns-1; x >= 0; x--)
6245 *q++=ScaleQuantumToChar(XBlueGamma(
6246 GetBluePixelComponent(p)));
6247 *q++=ScaleQuantumToChar(XGreenGamma(
6248 GetGreenPixelComponent(p)));
6249 *q++=ScaleQuantumToChar(XRedGamma(
6250 GetRedPixelComponent(p)));
6256 for (x=(int) canvas->columns-1; x >= 0; x--)
6258 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6259 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6260 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6267 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6268 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6269 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6270 (map_info->blue_mult == 65536L))
6273 Convert to 32 bit continuous-tone X canvas.
6275 for (y=0; y < (int) canvas->rows; y++)
6277 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6278 &canvas->exception);
6279 if (p == (const PixelPacket *) NULL)
6281 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6282 (blue_gamma != 1.0))
6285 Gamma correct canvas.
6287 for (x=(int) canvas->columns-1; x >= 0; x--)
6289 *q++=ScaleQuantumToChar(XRedGamma(
6290 GetRedPixelComponent(p)));
6291 *q++=ScaleQuantumToChar(XGreenGamma(
6292 GetGreenPixelComponent(p)));
6293 *q++=ScaleQuantumToChar(XBlueGamma(
6294 GetBluePixelComponent(p)));
6300 for (x=(int) canvas->columns-1; x >= 0; x--)
6302 *q++=ScaleQuantumToChar((Quantum)
6303 GetRedPixelComponent(p));
6304 *q++=ScaleQuantumToChar((Quantum)
6305 GetGreenPixelComponent(p));
6306 *q++=ScaleQuantumToChar((Quantum)
6307 GetBluePixelComponent(p));
6318 register unsigned int
6322 channel[sizeof(size_t)];
6325 Convert to multi-byte continuous-tone X canvas.
6327 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6328 for (y=0; y < (int) canvas->rows; y++)
6330 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6331 &canvas->exception);
6332 if (p == (PixelPacket *) NULL)
6334 for (x=0; x < (ssize_t) canvas->columns; x++)
6336 pixel=XGammaPixel(map_info,p);
6337 for (k=0; k < (int) bytes_per_pixel; k++)
6339 channel[k]=(unsigned char) pixel;
6342 for (k=0; k < (int) bytes_per_pixel; k++)
6352 if (matte_image != (XImage *) NULL)
6355 Initialize matte canvas.
6357 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6358 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6359 q=(unsigned char *) matte_image->data;
6360 for (y=0; y < (int) canvas->rows; y++)
6362 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6363 if (p == (const PixelPacket *) NULL)
6367 for (x=(int) canvas->columns-1; x >= 0; x--)
6370 if (p->opacity > (ssize_t) (QuantumRange/2))
6386 if (canvas != image)
6387 canvas=DestroyImage(canvas);
6391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6395 + X M a k e I m a g e M S B F i r s t %
6399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6401 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6402 % image pixels are copied in most-significant bit and byte first order. The
6403 % server's scanline pad is also respected. Rather than using one or two
6404 % general cases, many special cases are found here to help speed up the image
6407 % The format of the XMakeImageMSBFirst method is:
6409 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6411 % A description of each parameter follows:
6413 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6415 % o window: Specifies a pointer to a XWindowInfo structure.
6417 % o image: the image.
6419 % o ximage: Specifies a pointer to a XImage structure; returned from
6422 % o matte_image: Specifies a pointer to a XImage structure; returned from
6426 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6427 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6438 register const IndexPacket
6441 register const PixelPacket
6444 register unsigned char
6461 assert(resource_info != (XResourceInfo *) NULL);
6462 assert(window != (XWindowInfo *) NULL);
6463 assert(image != (Image *) NULL);
6464 if (image->debug != MagickFalse)
6465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6467 if ((window->immutable != MagickFalse) &&
6468 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6471 size[MaxTextExtent];
6479 image_info=AcquireImageInfo();
6480 (void) CopyMagickString(image_info->filename,
6481 resource_info->image_info->texture != (char *) NULL ?
6482 resource_info->image_info->texture : "pattern:checkerboard",
6484 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
6485 image->columns,(double) image->rows);
6486 image_info->size=ConstantString(size);
6487 pattern=ReadImage(image_info,&image->exception);
6488 image_info=DestroyImageInfo(image_info);
6489 if (pattern != (Image *) NULL)
6491 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6492 if (canvas != (Image *) NULL)
6493 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6494 pattern=DestroyImage(pattern);
6497 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6498 ((ximage->width*ximage->bits_per_pixel) >> 3));
6499 map_info=window->map_info;
6500 pixels=window->pixel_info->pixels;
6501 q=(unsigned char *) ximage->data;
6503 if (ximage->format == XYBitmap)
6505 register unsigned short
6513 Convert canvas to big-endian bitmap.
6515 background=(unsigned char)
6516 (XPixelIntensity(&window->pixel_info->foreground_color) <
6517 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6518 foreground=(unsigned char)
6519 (XPixelIntensity(&window->pixel_info->background_color) <
6520 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6521 polarity=(unsigned short) ((PixelIntensityToQuantum(
6522 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6523 if (canvas->colors == 2)
6524 polarity=PixelIntensity(&canvas->colormap[0]) <
6525 PixelIntensity(&canvas->colormap[1]);
6526 for (y=0; y < (int) canvas->rows; y++)
6528 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6529 if (p == (const PixelPacket *) NULL)
6531 indexes=GetVirtualIndexQueue(canvas);
6534 for (x=(int) canvas->columns-1; x >= 0; x--)
6537 if (indexes[x] == (IndexPacket) polarity)
6555 if (window->pixel_info->colors != 0)
6556 switch (ximage->bits_per_pixel)
6560 register unsigned int
6564 Convert to 2 bit color-mapped X canvas.
6566 for (y=0; y < (int) canvas->rows; y++)
6568 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6569 if (p == (const PixelPacket *) NULL)
6571 indexes=GetVirtualIndexQueue(canvas);
6573 for (x=0; x < (int) canvas->columns; x++)
6575 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6580 *q=(unsigned char) (pixel << 6);
6586 *q|=(unsigned char) (pixel << 4);
6592 *q|=(unsigned char) (pixel << 2);
6598 *q|=(unsigned char) pixel;
6611 register unsigned int
6615 Convert to 4 bit color-mapped X canvas.
6617 for (y=0; y < (int) canvas->rows; y++)
6619 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6620 if (p == (const PixelPacket *) NULL)
6622 indexes=GetVirtualIndexQueue(canvas);
6624 for (x=0; x < (int) canvas->columns; x++)
6626 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6631 *q=(unsigned char) (pixel << 4);
6637 *q|=(unsigned char) pixel;
6652 Convert to 8 bit color-mapped X canvas.
6654 if (resource_info->color_recovery &&
6655 resource_info->quantize_info->dither)
6657 XDitherImage(canvas,ximage);
6660 for (y=0; y < (int) canvas->rows; y++)
6662 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6663 if (p == (const PixelPacket *) NULL)
6665 indexes=GetVirtualIndexQueue(canvas);
6666 for (x=0; x < (int) canvas->columns; x++)
6668 pixel=pixels[(ssize_t) indexes[x]];
6669 *q++=(unsigned char) pixel;
6680 register unsigned int
6684 channel[sizeof(size_t)];
6687 Convert to 8 bit color-mapped X canvas.
6689 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6690 for (y=0; y < (int) canvas->rows; y++)
6692 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6693 if (p == (const PixelPacket *) NULL)
6695 indexes=GetVirtualIndexQueue(canvas);
6696 for (x=0; x < (int) canvas->columns; x++)
6698 pixel=pixels[(ssize_t) indexes[x]];
6699 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6701 channel[k]=(unsigned char) pixel;
6704 for (k=0; k < (int) bytes_per_pixel; k++)
6713 switch (ximage->bits_per_pixel)
6717 register unsigned int
6721 Convert to 4 bit continuous-tone X canvas.
6723 for (y=0; y < (int) canvas->rows; y++)
6725 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6726 if (p == (const PixelPacket *) NULL)
6729 for (x=(int) canvas->columns-1; x >= 0; x--)
6731 pixel=XGammaPixel(map_info,p);
6737 *q=(unsigned char) (pixel << 6);
6743 *q|=(unsigned char) (pixel << 4);
6749 *q|=(unsigned char) (pixel << 2);
6755 *q|=(unsigned char) pixel;
6769 register unsigned int
6773 Convert to 4 bit continuous-tone X canvas.
6775 for (y=0; y < (int) canvas->rows; y++)
6777 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6778 if (p == (const PixelPacket *) NULL)
6781 for (x=(int) canvas->columns-1; x >= 0; x--)
6783 pixel=XGammaPixel(map_info,p);
6789 *q=(unsigned char) (pixel << 4);
6795 *q|=(unsigned char) pixel;
6811 Convert to 8 bit continuous-tone X canvas.
6813 if (resource_info->color_recovery &&
6814 resource_info->quantize_info->dither)
6816 XDitherImage(canvas,ximage);
6819 for (y=0; y < (int) canvas->rows; y++)
6821 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6822 if (p == (const PixelPacket *) NULL)
6824 for (x=(int) canvas->columns-1; x >= 0; x--)
6826 pixel=XGammaPixel(map_info,p);
6827 *q++=(unsigned char) pixel;
6836 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6837 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6838 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6839 (map_info->blue_mult == 1))
6842 Convert to 32 bit continuous-tone X canvas.
6844 for (y=0; y < (int) canvas->rows; y++)
6846 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6847 &canvas->exception);
6848 if (p == (const PixelPacket *) NULL)
6850 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6851 (blue_gamma != 1.0))
6854 Gamma correct canvas.
6856 for (x=(int) canvas->columns-1; x >= 0; x--)
6859 *q++=ScaleQuantumToChar(XRedGamma(
6860 GetRedPixelComponent(p)));
6861 *q++=ScaleQuantumToChar(XGreenGamma(
6862 GetGreenPixelComponent(p)));
6863 *q++=ScaleQuantumToChar(XBlueGamma(
6864 GetBluePixelComponent(p)));
6869 for (x=(int) canvas->columns-1; x >= 0; x--)
6872 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6873 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6874 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6880 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6881 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6882 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6883 (map_info->blue_mult == 65536L))
6886 Convert to 32 bit continuous-tone X canvas.
6888 for (y=0; y < (int) canvas->rows; y++)
6890 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6891 &canvas->exception);
6892 if (p == (const PixelPacket *) NULL)
6894 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6895 (blue_gamma != 1.0))
6898 Gamma correct canvas.
6900 for (x=(int) canvas->columns-1; x >= 0; x--)
6903 *q++=ScaleQuantumToChar(XBlueGamma(
6904 GetBluePixelComponent(p)));
6905 *q++=ScaleQuantumToChar(XGreenGamma(
6906 GetGreenPixelComponent(p)));
6907 *q++=ScaleQuantumToChar(XRedGamma(
6908 GetRedPixelComponent(p)));
6913 for (x=(int) canvas->columns-1; x >= 0; x--)
6916 *q++=ScaleQuantumToChar((Quantum)
6917 GetBluePixelComponent(p));
6918 *q++=ScaleQuantumToChar((Quantum)
6919 GetGreenPixelComponent(p));
6920 *q++=ScaleQuantumToChar((Quantum)
6921 GetRedPixelComponent(p));
6931 register unsigned int
6935 channel[sizeof(size_t)];
6938 Convert to multi-byte continuous-tone X canvas.
6940 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6941 for (y=0; y < (int) canvas->rows; y++)
6943 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6944 &canvas->exception);
6945 if (p == (const PixelPacket *) NULL)
6947 for (x=(int) canvas->columns-1; x >= 0; x--)
6949 pixel=XGammaPixel(map_info,p);
6950 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6952 channel[k]=(unsigned char) pixel;
6955 for (k=0; k < (int) bytes_per_pixel; k++)
6965 if (matte_image != (XImage *) NULL)
6968 Initialize matte canvas.
6970 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6971 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6972 q=(unsigned char *) matte_image->data;
6973 for (y=0; y < (int) canvas->rows; y++)
6975 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6976 if (p == (const PixelPacket *) NULL)
6980 for (x=(int) canvas->columns-1; x >= 0; x--)
6983 if (p->opacity > (ssize_t) (QuantumRange/2))
6999 if (canvas != image)
7000 canvas=DestroyImage(canvas);
7004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7008 % X M a k e M a g n i f y I m a g e %
7012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7014 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7016 % The format of the XMakeMagnifyImage method is:
7018 % void XMakeMagnifyImage(display,windows)
7020 % A description of each parameter follows:
7022 % o display: Specifies a connection to an X server; returned from
7025 % o windows: Specifies a pointer to a XWindows structure.
7028 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7031 tuple[MaxTextExtent];
7048 register unsigned char
7053 previous_magnify = 0;
7071 Check boundary conditions.
7073 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7074 assert(display != (Display *) NULL);
7075 assert(windows != (XWindows *) NULL);
7077 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7079 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7081 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7083 while (magnify > windows->magnify.width)
7085 while (magnify > windows->magnify.height)
7087 if (magnify != previous_magnify)
7096 New magnify factor: update magnify window name.
7099 while ((1 << i) <= (int) magnify)
7101 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7102 "Magnify %.20gX",(double) i);
7103 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7104 if (status != False)
7106 XSetWMName(display,windows->magnify.id,&window_name);
7107 XSetWMIconName(display,windows->magnify.id,&window_name);
7108 (void) XFree((void *) window_name.value);
7111 previous_magnify=magnify;
7112 ximage=windows->image.ximage;
7113 width=(unsigned int) windows->magnify.ximage->width;
7114 height=(unsigned int) windows->magnify.ximage->height;
7115 if ((windows->magnify.x < 0) ||
7116 (windows->magnify.x >= windows->image.ximage->width))
7117 windows->magnify.x=windows->image.ximage->width >> 1;
7118 x=windows->magnify.x-((width/magnify) >> 1);
7122 if (x > (int) (ximage->width-(width/magnify)))
7123 x=ximage->width-width/magnify;
7124 if ((windows->magnify.y < 0) ||
7125 (windows->magnify.y >= windows->image.ximage->height))
7126 windows->magnify.y=windows->image.ximage->height >> 1;
7127 y=windows->magnify.y-((height/magnify) >> 1);
7131 if (y > (int) (ximage->height-(height/magnify)))
7132 y=ximage->height-height/magnify;
7133 q=(unsigned char *) windows->magnify.ximage->data;
7134 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7135 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7136 if (ximage->bits_per_pixel < 8)
7138 register unsigned char
7145 register unsigned int
7151 pixel_info=windows->magnify.pixel_info;
7152 switch (ximage->bitmap_bit_order)
7157 Magnify little-endian bitmap.
7161 if (ximage->format == XYBitmap)
7163 background=(unsigned char)
7164 (XPixelIntensity(&pixel_info->foreground_color) <
7165 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7166 foreground=(unsigned char)
7167 (XPixelIntensity(&pixel_info->background_color) <
7168 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7169 if (windows->magnify.depth > 1)
7170 Swap(background,foreground);
7172 for (i=0; i < (ssize_t) height; i+=magnify)
7175 Propogate pixel magnify rows.
7177 for (j=0; j < magnify; j++)
7179 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7180 ((x*ximage->bits_per_pixel) >> 3);
7181 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7184 for (k=0; k < width; k+=magnify)
7187 Propogate pixel magnify columns.
7189 for (l=0; l < magnify; l++)
7192 Propogate each bit plane.
7194 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7197 if (*p & (0x01 << (p_bit+plane)))
7210 p_bit+=ximage->bits_per_pixel;
7217 *q=byte >> (8-q_bit);
7229 Magnify big-endian bitmap.
7233 if (ximage->format == XYBitmap)
7235 background=(unsigned char)
7236 (XPixelIntensity(&pixel_info->foreground_color) <
7237 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7238 foreground=(unsigned char)
7239 (XPixelIntensity(&pixel_info->background_color) <
7240 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7241 if (windows->magnify.depth > 1)
7242 Swap(background,foreground);
7244 for (i=0; i < (ssize_t) height; i+=magnify)
7247 Propogate pixel magnify rows.
7249 for (j=0; j < magnify; j++)
7251 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7252 ((x*ximage->bits_per_pixel) >> 3);
7253 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7256 for (k=0; k < width; k+=magnify)
7259 Propogate pixel magnify columns.
7261 for (l=0; l < magnify; l++)
7264 Propogate each bit plane.
7266 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7269 if (*p & (0x80 >> (p_bit+plane)))
7282 p_bit+=ximage->bits_per_pixel;
7289 *q=byte << (8-q_bit);
7300 switch (ximage->bits_per_pixel)
7306 Magnify 8 bit X image.
7308 for (i=0; i < (ssize_t) height; i+=magnify)
7311 Propogate pixel magnify rows.
7313 for (j=0; j < magnify; j++)
7315 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7316 ((x*ximage->bits_per_pixel) >> 3);
7317 for (k=0; k < width; k+=magnify)
7320 Propogate pixel magnify columns.
7322 for (l=0; l < magnify; l++)
7334 register unsigned int
7339 Magnify multi-byte X image.
7341 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7342 for (i=0; i < (ssize_t) height; i+=magnify)
7345 Propogate pixel magnify rows.
7347 for (j=0; j < magnify; j++)
7349 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7350 ((x*ximage->bits_per_pixel) >> 3);
7351 for (k=0; k < width; k+=magnify)
7354 Propogate pixel magnify columns.
7356 for (l=0; l < magnify; l++)
7357 for (m=0; m < bytes_per_pixel; m++)
7369 Copy X image to magnify pixmap.
7371 x=windows->magnify.x-((width/magnify) >> 1);
7373 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7375 if (x > (int) (ximage->width-(width/magnify)))
7376 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7379 y=windows->magnify.y-((height/magnify) >> 1);
7381 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7383 if (y > (int) (ximage->height-(height/magnify)))
7384 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7387 if ((x != 0) || (y != 0))
7388 (void) XFillRectangle(display,windows->magnify.pixmap,
7389 windows->magnify.annotate_context,0,0,width,height);
7390 (void) XPutImage(display,windows->magnify.pixmap,
7391 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7393 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7394 (magnify <= (height >> 1))))
7400 Highlight center pixel.
7402 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7403 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7404 highlight_info.width=magnify;
7405 highlight_info.height=magnify;
7406 (void) XDrawRectangle(display,windows->magnify.pixmap,
7407 windows->magnify.highlight_context,(int) highlight_info.x,
7408 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7409 (unsigned int) highlight_info.height-1);
7411 (void) XDrawRectangle(display,windows->magnify.pixmap,
7412 windows->magnify.annotate_context,(int) highlight_info.x+1,
7413 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7414 (unsigned int) highlight_info.height-3);
7417 Show center pixel color.
7419 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7420 windows->magnify.y,&pixel,&windows->image.image->exception);
7421 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7422 windows->magnify.x,windows->magnify.y);
7423 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7424 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7425 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7426 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7427 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7428 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7429 if (pixel.colorspace == CMYKColorspace)
7431 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7432 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7434 if (pixel.matte != MagickFalse)
7436 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7437 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7439 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7440 height=(unsigned int) windows->magnify.font_info->ascent+
7441 windows->magnify.font_info->descent;
7442 x=windows->magnify.font_info->max_bounds.width >> 1;
7443 y=windows->magnify.font_info->ascent+(height >> 2);
7444 (void) XDrawImageString(display,windows->magnify.pixmap,
7445 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7446 GetColorTuple(&pixel,MagickTrue,tuple);
7448 (void) XDrawImageString(display,windows->magnify.pixmap,
7449 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7450 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7451 &windows->image.image->exception);
7453 (void) XDrawImageString(display,windows->magnify.pixmap,
7454 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7456 Refresh magnify window.
7458 magnify_window=windows->magnify;
7461 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7469 % X M a k e P i x m a p %
7473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7475 % XMakePixmap() creates an X11 pixmap.
7477 % The format of the XMakePixmap method is:
7479 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7480 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7481 % XPixelInfo *pixel)
7483 % A description of each parameter follows:
7485 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7487 % o display: Specifies a connection to an X server; returned from
7490 % o window: Specifies a pointer to a XWindowInfo structure.
7493 static MagickBooleanType XMakePixmap(Display *display,
7494 const XResourceInfo *resource_info,XWindowInfo *window)
7500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7501 assert(display != (Display *) NULL);
7502 assert(resource_info != (XResourceInfo *) NULL);
7503 assert(window != (XWindowInfo *) NULL);
7504 if (window->pixmap != (Pixmap) NULL)
7507 Destroy previous X pixmap.
7509 (void) XFreePixmap(display,window->pixmap);
7510 window->pixmap=(Pixmap) NULL;
7512 if (window->use_pixmap == MagickFalse)
7513 return(MagickFalse);
7514 if (window->ximage == (XImage *) NULL)
7515 return(MagickFalse);
7517 Display busy cursor.
7519 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7520 (void) XFlush(display);
7524 width=(unsigned int) window->ximage->width;
7525 height=(unsigned int) window->ximage->height;
7526 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7527 if (window->pixmap == (Pixmap) NULL)
7530 Unable to allocate pixmap.
7532 (void) XCheckDefineCursor(display,window->id,window->cursor);
7533 return(MagickFalse);
7536 Copy X image to pixmap.
7538 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7539 if (window->shared_memory)
7540 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7541 window->ximage,0,0,0,0,width,height,MagickTrue);
7543 if (window->shared_memory == MagickFalse)
7544 (void) XPutImage(display,window->pixmap,window->annotate_context,
7545 window->ximage,0,0,0,0,width,height);
7546 if (IsEventLogging())
7548 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7549 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7555 (void) XCheckDefineCursor(display,window->id,window->cursor);
7560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7564 % X M a k e S t a n d a r d C o l o r m a p %
7568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7570 % XMakeStandardColormap() creates an X11 Standard Colormap.
7572 % The format of the XMakeStandardColormap method is:
7574 % XMakeStandardColormap(display,visual_info,resource_info,image,
7577 % A description of each parameter follows:
7579 % o display: Specifies a connection to an X server; returned from
7582 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7583 % returned from XGetVisualInfo.
7585 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7587 % o image: the image.
7589 % o map_info: If a Standard Colormap type is specified, this structure is
7590 % initialized with info from the Standard Colormap.
7592 % o pixel: Specifies a pointer to a XPixelInfo structure.
7596 #if defined(__cplusplus) || defined(c_plusplus)
7600 static inline MagickRealType DiversityPixelIntensity(
7601 const DiversityPacket *pixel)
7606 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7610 static int IntensityCompare(const void *x,const void *y)
7619 color_1=(DiversityPacket *) x;
7620 color_2=(DiversityPacket *) y;
7621 diversity=(int) (DiversityPixelIntensity(color_2)-
7622 DiversityPixelIntensity(color_1));
7626 static int PopularityCompare(const void *x,const void *y)
7632 color_1=(DiversityPacket *) x;
7633 color_2=(DiversityPacket *) y;
7634 return((int) color_2->count-(int) color_1->count);
7637 #if defined(__cplusplus) || defined(c_plusplus)
7641 static inline Quantum ScaleXToQuantum(const size_t x,
7644 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7647 MagickExport void XMakeStandardColormap(Display *display,
7648 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7649 XStandardColormap *map_info,XPixelInfo *pixel)
7657 register IndexPacket
7678 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7679 assert(display != (Display *) NULL);
7680 assert(visual_info != (XVisualInfo *) NULL);
7681 assert(map_info != (XStandardColormap *) NULL);
7682 assert(resource_info != (XResourceInfo *) NULL);
7683 assert(pixel != (XPixelInfo *) NULL);
7684 exception=(&image->exception);
7685 if (resource_info->map_type != (char *) NULL)
7688 Standard Colormap is already defined (i.e. xstdcmap).
7690 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7692 number_colors=(unsigned int) (map_info->base_pixel+
7693 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7694 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7695 if ((image->matte == MagickFalse) &&
7696 (resource_info->color_recovery == MagickFalse) &&
7697 resource_info->quantize_info->dither &&
7698 (number_colors < MaxColormapSize))
7703 register PixelPacket
7707 Improve image appearance with error diffusion.
7709 affinity_image=AcquireImage((ImageInfo *) NULL);
7710 if (affinity_image == (Image *) NULL)
7711 ThrowXWindowFatalException(ResourceLimitFatalError,
7712 "UnableToDitherImage",image->filename);
7713 affinity_image->columns=number_colors;
7714 affinity_image->rows=1;
7716 Initialize colormap image.
7718 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7720 if (q != (PixelPacket *) NULL)
7722 for (i=0; i < (ssize_t) number_colors; i++)
7725 if (map_info->red_max != 0)
7726 q->red=ScaleXToQuantum((size_t) (i/
7727 map_info->red_mult),map_info->red_max);
7728 q->green=(Quantum) 0;
7729 if (map_info->green_max != 0)
7730 q->green=ScaleXToQuantum((size_t) ((i/
7731 map_info->green_mult) % (map_info->green_max+1)),
7732 map_info->green_max);
7733 q->blue=(Quantum) 0;
7734 if (map_info->blue_max != 0)
7735 q->blue=ScaleXToQuantum((size_t) (i %
7736 map_info->green_mult),map_info->blue_max);
7737 q->opacity=(Quantum) TransparentOpacity;
7740 (void) SyncAuthenticPixels(affinity_image,exception);
7741 (void) RemapImage(resource_info->quantize_info,image,
7744 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7746 (void) SetImageStorageClass(image,DirectClass);
7747 affinity_image=DestroyImage(affinity_image);
7749 if (IsEventLogging())
7751 (void) LogMagickEvent(X11Event,GetMagickModule(),
7752 "Standard Colormap:");
7753 (void) LogMagickEvent(X11Event,GetMagickModule(),
7754 " colormap id: 0x%lx",map_info->colormap);
7755 (void) LogMagickEvent(X11Event,GetMagickModule(),
7756 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7757 map_info->green_max,map_info->blue_max);
7758 (void) LogMagickEvent(X11Event,GetMagickModule(),
7759 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7760 map_info->green_mult,map_info->blue_mult);
7764 if ((visual_info->klass != DirectColor) &&
7765 (visual_info->klass != TrueColor))
7766 if ((image->storage_class == DirectClass) ||
7767 ((int) image->colors > visual_info->colormap_size))
7773 Image has more colors than the visual supports.
7775 quantize_info=(*resource_info->quantize_info);
7776 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7777 (void) QuantizeImage(&quantize_info,image);
7780 Free previous and create new colormap.
7782 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7783 colormap=XDefaultColormap(display,visual_info->screen);
7784 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7785 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7786 visual_info->visual,visual_info->klass == DirectColor ?
7787 AllocAll : AllocNone);
7788 if (colormap == (Colormap) NULL)
7789 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7792 Initialize the map and pixel info structures.
7794 XGetMapInfo(visual_info,colormap,map_info);
7795 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7797 Allocating colors in server colormap is based on visual class.
7799 switch (visual_info->klass)
7805 Define Standard Colormap for StaticGray or StaticColor visual.
7807 number_colors=image->colors;
7808 colors=(XColor *) AcquireQuantumMemory((size_t)
7809 visual_info->colormap_size,sizeof(*colors));
7810 if (colors == (XColor *) NULL)
7811 ThrowXWindowFatalException(ResourceLimitFatalError,
7812 "UnableToCreateColormap",image->filename);
7814 color.flags=(char) (DoRed | DoGreen | DoBlue);
7815 for (i=0; i < (ssize_t) image->colors; i++)
7817 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7818 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7819 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7820 if (visual_info->klass != StaticColor)
7822 gray_value=(unsigned short) XPixelIntensity(&color);
7823 color.red=gray_value;
7824 color.green=gray_value;
7825 color.blue=gray_value;
7827 status=XAllocColor(display,colormap,&color);
7828 if (status == False)
7830 colormap=XCopyColormapAndFree(display,colormap);
7831 (void) XAllocColor(display,colormap,&color);
7833 pixel->pixels[i]=color.pixel;
7845 Define Standard Colormap for GrayScale or PseudoColor visual.
7847 number_colors=image->colors;
7848 colors=(XColor *) AcquireQuantumMemory((size_t)
7849 visual_info->colormap_size,sizeof(*colors));
7850 if (colors == (XColor *) NULL)
7851 ThrowXWindowFatalException(ResourceLimitFatalError,
7852 "UnableToCreateColormap",image->filename);
7854 Preallocate our GUI colors.
7856 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7857 (void) XAllocColor(display,colormap,&pixel->background_color);
7858 (void) XAllocColor(display,colormap,&pixel->border_color);
7859 (void) XAllocColor(display,colormap,&pixel->matte_color);
7860 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7861 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7862 (void) XAllocColor(display,colormap,&pixel->depth_color);
7863 (void) XAllocColor(display,colormap,&pixel->trough_color);
7864 for (i=0; i < MaxNumberPens; i++)
7865 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7867 Determine if image colors will "fit" into X server colormap.
7869 colormap_type=resource_info->colormap;
7870 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7871 NULL,0,pixel->pixels,(unsigned int) image->colors);
7872 if (status != False)
7873 colormap_type=PrivateColormap;
7874 if (colormap_type == SharedColormap)
7892 Define Standard colormap for shared GrayScale or PseudoColor visual.
7894 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7895 sizeof(*diversity));
7896 if (diversity == (DiversityPacket *) NULL)
7897 ThrowXWindowFatalException(ResourceLimitFatalError,
7898 "UnableToCreateColormap",image->filename);
7899 for (i=0; i < (ssize_t) image->colors; i++)
7901 diversity[i].red=image->colormap[i].red;
7902 diversity[i].green=image->colormap[i].green;
7903 diversity[i].blue=image->colormap[i].blue;
7904 diversity[i].index=(unsigned short) i;
7905 diversity[i].count=0;
7907 for (y=0; y < (int) image->rows; y++)
7912 register PixelPacket
7915 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7916 if (q == (PixelPacket *) NULL)
7918 indexes=GetAuthenticIndexQueue(image);
7919 for (x=(ssize_t) image->columns-1; x >= 0; x--)
7920 diversity[(ssize_t) indexes[x]].count++;
7923 Sort colors by decreasing intensity.
7925 qsort((void *) diversity,image->colors,sizeof(*diversity),
7927 for (i=0; i < (ssize_t) image->colors; )
7929 diversity[i].count<<=4; /* increase this colors popularity */
7930 i+=MagickMax((ssize_t) (image->colors >> 4),2);
7932 diversity[image->colors-1].count<<=4;
7933 qsort((void *) diversity,image->colors,sizeof(*diversity),
7939 color.flags=(char) (DoRed | DoGreen | DoBlue);
7940 for (i=0; i < (ssize_t) image->colors; i++)
7942 index=diversity[i].index;
7944 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7946 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7948 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7949 if (visual_info->klass != PseudoColor)
7951 gray_value=(unsigned short) XPixelIntensity(&color);
7952 color.red=gray_value;
7953 color.green=gray_value;
7954 color.blue=gray_value;
7956 status=XAllocColor(display,colormap,&color);
7957 if (status == False)
7959 pixel->pixels[index]=color.pixel;
7963 Read X server colormap.
7965 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7966 visual_info->colormap_size,sizeof(*server_colors));
7967 if (server_colors == (XColor *) NULL)
7968 ThrowXWindowFatalException(ResourceLimitFatalError,
7969 "UnableToCreateColormap",image->filename);
7970 for (x=visual_info->colormap_size-1; x >= 0; x--)
7971 server_colors[x].pixel=(size_t) x;
7972 (void) XQueryColors(display,colormap,server_colors,
7973 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7975 Select remaining colors from X server colormap.
7977 for (; i < (ssize_t) image->colors; i++)
7979 index=diversity[i].index;
7981 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7983 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7985 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7986 if (visual_info->klass != PseudoColor)
7988 gray_value=(unsigned short) XPixelIntensity(&color);
7989 color.red=gray_value;
7990 color.green=gray_value;
7991 color.blue=gray_value;
7993 XBestPixel(display,colormap,server_colors,(unsigned int)
7994 visual_info->colormap_size,&color);
7995 pixel->pixels[index]=color.pixel;
7998 if ((int) image->colors < visual_info->colormap_size)
8001 Fill up colors array-- more choices for pen colors.
8003 retain_colors=MagickMin((unsigned int)
8004 (visual_info->colormap_size-image->colors),256);
8005 for (i=0; i < (ssize_t) retain_colors; i++)
8006 *p++=server_colors[i];
8007 number_colors+=retain_colors;
8009 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8010 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8014 Define Standard colormap for private GrayScale or PseudoColor visual.
8016 if (status == False)
8019 Not enough colormap entries in the colormap-- Create a new colormap.
8021 colormap=XCreateColormap(display,
8022 XRootWindow(display,visual_info->screen),visual_info->visual,
8024 if (colormap == (Colormap) NULL)
8025 ThrowXWindowFatalException(ResourceLimitFatalError,
8026 "UnableToCreateColormap",image->filename);
8027 map_info->colormap=colormap;
8028 if ((int) image->colors < visual_info->colormap_size)
8031 Retain colors from the default colormap to help lessens the
8032 effects of colormap flashing.
8034 retain_colors=MagickMin((unsigned int)
8035 (visual_info->colormap_size-image->colors),256);
8036 p=colors+image->colors;
8037 for (i=0; i < (ssize_t) retain_colors; i++)
8039 p->pixel=(size_t) i;
8042 (void) XQueryColors(display,
8043 XDefaultColormap(display,visual_info->screen),
8044 colors+image->colors,(int) retain_colors);
8046 Transfer colors from default to private colormap.
8048 (void) XAllocColorCells(display,colormap,MagickFalse,
8049 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8051 p=colors+image->colors;
8052 for (i=0; i < (ssize_t) retain_colors; i++)
8054 p->pixel=pixel->pixels[i];
8057 (void) XStoreColors(display,colormap,colors+image->colors,
8058 (int) retain_colors);
8059 number_colors+=retain_colors;
8061 (void) XAllocColorCells(display,colormap,MagickFalse,
8062 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8066 Store the image colormap.
8069 color.flags=(char) (DoRed | DoGreen | DoBlue);
8070 for (i=0; i < (ssize_t) image->colors; i++)
8072 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8073 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8074 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8075 if (visual_info->klass != PseudoColor)
8077 gray_value=(unsigned short) XPixelIntensity(&color);
8078 color.red=gray_value;
8079 color.green=gray_value;
8080 color.blue=gray_value;
8082 color.pixel=pixel->pixels[i];
8085 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8096 Define Standard Colormap for TrueColor or DirectColor visual.
8098 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8099 (map_info->green_max*map_info->green_mult)+
8100 (map_info->blue_max*map_info->blue_mult)+1);
8101 linear_colormap=(number_colors > 4096) ||
8102 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8103 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8104 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8105 MagickTrue : MagickFalse;
8106 if (linear_colormap != MagickFalse)
8107 number_colors=(size_t) visual_info->colormap_size;
8109 Allocate color array.
8111 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8112 if (colors == (XColor *) NULL)
8113 ThrowXWindowFatalException(ResourceLimitFatalError,
8114 "UnableToCreateColormap",image->filename);
8116 Initialize linear color ramp.
8119 color.flags=(char) (DoRed | DoGreen | DoBlue);
8120 if (linear_colormap != MagickFalse)
8121 for (i=0; i < (ssize_t) number_colors; i++)
8123 color.blue=(unsigned short) 0;
8124 if (map_info->blue_max != 0)
8125 color.blue=(unsigned short) ((size_t)
8126 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8127 color.green=color.blue;
8128 color.red=color.blue;
8129 color.pixel=XStandardPixel(map_info,&color);
8133 for (i=0; i < (ssize_t) number_colors; i++)
8135 color.red=(unsigned short) 0;
8136 if (map_info->red_max != 0)
8137 color.red=(unsigned short) ((size_t)
8138 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8139 color.green=(unsigned int) 0;
8140 if (map_info->green_max != 0)
8141 color.green=(unsigned short) ((size_t)
8142 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8143 map_info->green_max));
8144 color.blue=(unsigned short) 0;
8145 if (map_info->blue_max != 0)
8146 color.blue=(unsigned short) ((size_t)
8147 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8148 color.pixel=XStandardPixel(map_info,&color);
8151 if ((visual_info->klass == DirectColor) &&
8152 (colormap != XDefaultColormap(display,visual_info->screen)))
8153 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8155 for (i=0; i < (ssize_t) number_colors; i++)
8156 (void) XAllocColor(display,colormap,&colors[i]);
8160 if ((visual_info->klass != DirectColor) &&
8161 (visual_info->klass != TrueColor))
8164 Set foreground, background, border, etc. pixels.
8166 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8167 &pixel->foreground_color);
8168 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8169 &pixel->background_color);
8170 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8173 Foreground and background colors must differ.
8175 pixel->background_color.red=(~pixel->foreground_color.red);
8176 pixel->background_color.green=
8177 (~pixel->foreground_color.green);
8178 pixel->background_color.blue=
8179 (~pixel->foreground_color.blue);
8180 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8181 &pixel->background_color);
8183 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8184 &pixel->border_color);
8185 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8186 &pixel->matte_color);
8187 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8188 &pixel->highlight_color);
8189 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8190 &pixel->shadow_color);
8191 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8192 &pixel->depth_color);
8193 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8194 &pixel->trough_color);
8195 for (i=0; i < MaxNumberPens; i++)
8197 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8198 &pixel->pen_colors[i]);
8199 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8201 pixel->colors=image->colors+MaxNumberPens;
8203 colors=(XColor *) RelinquishMagickMemory(colors);
8204 if (IsEventLogging())
8206 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8207 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8208 map_info->colormap);
8209 (void) LogMagickEvent(X11Event,GetMagickModule(),
8210 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8211 map_info->green_max,map_info->blue_max);
8212 (void) LogMagickEvent(X11Event,GetMagickModule(),
8213 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8214 map_info->green_mult,map_info->blue_mult);
8219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8223 % X M a k e W i n d o w %
8227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8229 % XMakeWindow() creates an X11 window.
8231 % The format of the XMakeWindow method is:
8233 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8234 % XClassHint *class_hint,XWMHints *manager_hints,
8235 % XWindowInfo *window_info)
8237 % A description of each parameter follows:
8239 % o display: Specifies a connection to an X server; returned from
8242 % o parent: Specifies the parent window_info.
8244 % o argv: Specifies the application's argument list.
8246 % o argc: Specifies the number of arguments.
8248 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8250 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8252 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8255 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8256 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8257 XWindowInfo *window_info)
8259 #define MinWindowSize 64
8267 static XTextProperty
8278 Set window info hints.
8280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8281 assert(display != (Display *) NULL);
8282 assert(window_info != (XWindowInfo *) NULL);
8283 size_hints=XAllocSizeHints();
8284 if (size_hints == (XSizeHints *) NULL)
8285 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8286 size_hints->flags=(ssize_t) window_info->flags;
8287 size_hints->x=window_info->x;
8288 size_hints->y=window_info->y;
8289 size_hints->width=(int) window_info->width;
8290 size_hints->height=(int) window_info->height;
8291 if (window_info->immutable != MagickFalse)
8294 Window size cannot be changed.
8296 size_hints->min_width=size_hints->width;
8297 size_hints->min_height=size_hints->height;
8298 size_hints->max_width=size_hints->width;
8299 size_hints->max_height=size_hints->height;
8300 size_hints->flags|=PMinSize;
8301 size_hints->flags|=PMaxSize;
8306 Window size can be changed.
8308 size_hints->min_width=(int) window_info->min_width;
8309 size_hints->min_height=(int) window_info->min_height;
8310 size_hints->flags|=PResizeInc;
8311 size_hints->width_inc=(int) window_info->width_inc;
8312 size_hints->height_inc=(int) window_info->height_inc;
8313 #if !defined(PRE_R4_ICCCM)
8314 size_hints->flags|=PBaseSize;
8315 size_hints->base_width=size_hints->width_inc;
8316 size_hints->base_height=size_hints->height_inc;
8319 gravity=NorthWestGravity;
8320 if (window_info->geometry != (char *) NULL)
8323 default_geometry[MaxTextExtent],
8324 geometry[MaxTextExtent];
8333 User specified geometry.
8335 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8336 size_hints->width,size_hints->height);
8337 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8339 while (strlen(p) != 0)
8341 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8344 (void) CopyMagickString(p,p+1,MaxTextExtent);
8346 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8347 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8348 &size_hints->width,&size_hints->height,&gravity);
8349 if ((flags & WidthValue) && (flags & HeightValue))
8350 size_hints->flags|=USSize;
8351 if ((flags & XValue) && (flags & YValue))
8353 size_hints->flags|=USPosition;
8354 window_info->x=size_hints->x;
8355 window_info->y=size_hints->y;
8358 #if !defined(PRE_R4_ICCCM)
8359 size_hints->win_gravity=gravity;
8360 size_hints->flags|=PWinGravity;
8362 if (window_info->id == (Window) NULL)
8363 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8364 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8365 window_info->border_width,(int) window_info->depth,InputOutput,
8366 window_info->visual,window_info->mask,&window_info->attributes);
8379 Window already exists; change relevant attributes.
8381 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8382 &window_info->attributes);
8383 mask=ConfigureNotify;
8384 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8385 window_changes.x=window_info->x;
8386 window_changes.y=window_info->y;
8387 window_changes.width=(int) window_info->width;
8388 window_changes.height=(int) window_info->height;
8389 mask=(MagickStatusType) (CWWidth | CWHeight);
8390 if (window_info->flags & USPosition)
8392 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8393 mask,&window_changes);
8395 if (window_info->id == (Window) NULL)
8396 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8398 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8399 if (status == False)
8400 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8402 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8403 if (status == False)
8404 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8405 window_info->icon_name);
8406 if (window_info->icon_geometry != (char *) NULL)
8414 User specified icon geometry.
8416 size_hints->flags|=USPosition;
8417 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8418 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8419 &manager_hints->icon_y,&width,&height,&gravity);
8420 if ((flags & XValue) && (flags & YValue))
8421 manager_hints->flags|=IconPositionHint;
8423 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8424 size_hints,manager_hints,class_hint);
8425 if (window_name.value != (void *) NULL)
8427 (void) XFree((void *) window_name.value);
8428 window_name.value=(unsigned char *) NULL;
8429 window_name.nitems=0;
8431 if (icon_name.value != (void *) NULL)
8433 (void) XFree((void *) icon_name.value);
8434 icon_name.value=(unsigned char *) NULL;
8437 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8438 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8439 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8440 (void) XFree((void *) size_hints);
8441 if (window_info->shape != MagickFalse)
8443 #if defined(MAGICKCORE_HAVE_SHAPE)
8449 Can we apply a non-rectangular shaping mask?
8453 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8454 window_info->shape=MagickFalse;
8456 window_info->shape=MagickFalse;
8459 if (window_info->shared_memory)
8461 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8463 Can we use shared memory with this window?
8465 if (XShmQueryExtension(display) == 0)
8466 window_info->shared_memory=MagickFalse;
8468 window_info->shared_memory=MagickFalse;
8471 window_info->image=NewImageList();
8472 window_info->destroy=MagickFalse;
8476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8480 % X M a g i c k P r o g r e s s M o n i t o r %
8484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8486 % XMagickProgressMonitor() displays the progress a task is making in
8487 % completing a task.
8489 % The format of the XMagickProgressMonitor method is:
8491 % void XMagickProgressMonitor(const char *task,
8492 % const MagickOffsetType quantum,const MagickSizeType span,
8493 % void *client_data)
8495 % A description of each parameter follows:
8497 % o task: Identifies the task in progress.
8499 % o quantum: Specifies the quantum position within the span which represents
8500 % how much progress has been made in completing a task.
8502 % o span: Specifies the span relative to completing a task.
8504 % o client_data: Pointer to any client data.
8508 static const char *GetLocaleMonitorMessage(const char *text)
8511 message[MaxTextExtent],
8520 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8522 if (p != (char *) NULL)
8524 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8525 locale_message=GetLocaleMessage(message);
8526 if (locale_message == message)
8528 return(locale_message);
8531 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8532 const MagickOffsetType quantum,const MagickSizeType span,
8533 void *magick_unused(client_data))
8538 windows=XSetWindows((XWindows *) ~0);
8539 if (windows == (XWindows *) NULL)
8541 if (windows->info.mapped != MagickFalse)
8542 XProgressMonitorWidget(windows->display,windows,
8543 GetLocaleMonitorMessage(tag),quantum,span);
8548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8552 % X Q u e r y C o l o r D a t a b a s e %
8556 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8558 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8561 % The format of the XQueryColorDatabase method is:
8563 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8565 % A description of each parameter follows:
8567 % o target: Specifies the color to lookup in the X color database.
8569 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8570 % color is returned as this value.
8573 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8580 *display = (Display *) NULL;
8589 Initialize color return value.
8591 assert(color != (XColor *) NULL);
8595 color->flags=(char) (DoRed | DoGreen | DoBlue);
8596 if ((target == (char *) NULL) || (*target == '\0'))
8597 target="#ffffffffffff";
8599 Let the X server define the color for us.
8601 if (display == (Display *) NULL)
8602 display=XOpenDisplay((char *) NULL);
8603 if (display == (Display *) NULL)
8605 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8606 return(MagickFalse);
8608 colormap=XDefaultColormap(display,XDefaultScreen(display));
8609 status=XParseColor(display,colormap,(char *) target,&xcolor);
8610 if (status == False)
8611 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8614 color->red=xcolor.red;
8615 color->green=xcolor.green;
8616 color->blue=xcolor.blue;
8617 color->flags=xcolor.flags;
8619 return(status != False ? MagickTrue : MagickFalse);
8623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8627 % X Q u e r y P o s i t i o n %
8631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8633 % XQueryPosition() gets the pointer coordinates relative to a window.
8635 % The format of the XQueryPosition method is:
8637 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8639 % A description of each parameter follows:
8641 % o display: Specifies a connection to an X server; returned from
8644 % o window: Specifies a pointer to a Window.
8646 % o x: Return the x coordinate of the pointer relative to the origin of the
8649 % o y: Return the y coordinate of the pointer relative to the origin of the
8653 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8665 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8666 assert(display != (Display *) NULL);
8667 assert(window != (Window) NULL);
8668 assert(x != (int *) NULL);
8669 assert(y != (int *) NULL);
8670 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8679 % X R e f r e s h W i n d o w %
8683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8685 % XRefreshWindow() refreshes an image in a X window.
8687 % The format of the XRefreshWindow method is:
8689 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8690 % const XEvent *event)
8692 % A description of each parameter follows:
8694 % o display: Specifies a connection to an X server; returned from
8697 % o window: Specifies a pointer to a XWindowInfo structure.
8699 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8700 % the entire image is refreshed.
8703 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8704 const XEvent *event)
8714 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8715 assert(display != (Display *) NULL);
8716 assert(window != (XWindowInfo *) NULL);
8717 if (window->ximage == (XImage *) NULL)
8719 if (event != (XEvent *) NULL)
8722 Determine geometry from expose event.
8726 width=(unsigned int) event->xexpose.width;
8727 height=(unsigned int) event->xexpose.height;
8735 Refresh entire window; discard outstanding expose events.
8739 width=window->width;
8740 height=window->height;
8741 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8742 if (window->matte_pixmap != (Pixmap) NULL)
8744 #if defined(MAGICKCORE_HAVE_SHAPE)
8745 if (window->shape != MagickFalse)
8746 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8747 window->matte_pixmap,ShapeSet);
8752 Check boundary conditions.
8754 if ((window->ximage->width-(x+window->x)) < (int) width)
8755 width=(unsigned int) (window->ximage->width-(x+window->x));
8756 if ((window->ximage->height-(y+window->y)) < (int) height)
8757 height=(unsigned int) (window->ximage->height-(y+window->y));
8761 if (window->matte_pixmap != (Pixmap) NULL)
8762 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8763 if (window->pixmap != (Pixmap) NULL)
8765 if (window->depth > 1)
8766 (void) XCopyArea(display,window->pixmap,window->id,
8767 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8769 (void) XCopyPlane(display,window->pixmap,window->id,
8770 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8775 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8776 if (window->shared_memory)
8777 (void) XShmPutImage(display,window->id,window->annotate_context,
8778 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8780 if (window->shared_memory == MagickFalse)
8781 (void) XPutImage(display,window->id,window->annotate_context,
8782 window->ximage,x+window->x,y+window->y,x,y,width,height);
8784 if (window->matte_pixmap != (Pixmap) NULL)
8785 (void) XSetClipMask(display,window->annotate_context,None);
8786 (void) XFlush(display);
8790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8794 % X R e m o t e C o m m a n d %
8798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8800 % XRemoteCommand() forces a remote display(1) to display the specified
8803 % The format of the XRemoteCommand method is:
8805 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8806 % const char *filename)
8808 % A description of each parameter follows:
8810 % o display: Specifies a connection to an X server; returned from
8813 % o window: Specifies the name or id of an X window.
8815 % o filename: the name of the image filename to display.
8818 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8819 const char *window,const char *filename)
8828 assert(filename != (char *) NULL);
8829 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8830 if (display == (Display *) NULL)
8831 display=XOpenDisplay((char *) NULL);
8832 if (display == (Display *) NULL)
8834 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8835 return(MagickFalse);
8837 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8838 remote_window=(Window) NULL;
8839 root_window=XRootWindow(display,XDefaultScreen(display));
8840 if (window != (char *) NULL)
8843 Search window hierarchy and identify any clients by name or ID.
8845 if (isdigit((unsigned char) *window) != 0)
8846 remote_window=XWindowByID(display,root_window,(Window)
8847 strtol((char *) window,(char **) NULL,0));
8848 if (remote_window == (Window) NULL)
8849 remote_window=XWindowByName(display,root_window,window);
8851 if (remote_window == (Window) NULL)
8852 remote_window=XWindowByProperty(display,root_window,remote_atom);
8853 if (remote_window == (Window) NULL)
8855 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8857 return(MagickFalse);
8860 Send remote command.
8862 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8863 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8864 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8865 (void) XSync(display,MagickFalse);
8870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8874 % X R e t a i n W i n d o w C o l o r s %
8878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8880 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8881 % the colors associated with an image displayed on the window.
8883 % The format of the XRetainWindowColors method is:
8885 % void XRetainWindowColors(Display *display,const Window window)
8887 % A description of each parameter follows:
8889 % o display: Specifies a connection to an X server; returned from
8892 % o window: Specifies a pointer to a XWindowInfo structure.
8895 MagickExport void XRetainWindowColors(Display *display,const Window window)
8904 Put property on the window.
8906 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8907 assert(display != (Display *) NULL);
8908 assert(window != (Window) NULL);
8909 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8910 if (property == (Atom) NULL)
8912 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8916 pixmap=XCreatePixmap(display,window,1,1,1);
8917 if (pixmap == (Pixmap) NULL)
8919 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8922 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8923 (unsigned char *) &pixmap,1);
8924 (void) XSetCloseDownMode(display,RetainPermanent);
8928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8932 % X S e l e c t W i n d o w %
8936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8938 % XSelectWindow() allows a user to select a window using the mouse. If the
8939 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8940 % is returned in the crop_info structure.
8942 % The format of the XSelectWindow function is:
8944 % target_window=XSelectWindow(display,crop_info)
8946 % A description of each parameter follows:
8948 % o window: XSelectWindow returns the window id.
8950 % o display: Specifies a pointer to the Display structure; returned from
8953 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8954 % contains the extents of any cropping rectangle.
8957 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8959 #define MinimumCropArea (unsigned int) 9
8986 Initialize graphic context.
8988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8989 assert(display != (Display *) NULL);
8990 assert(crop_info != (RectangleInfo *) NULL);
8991 root_window=XRootWindow(display,XDefaultScreen(display));
8992 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8993 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8994 context_values.function=GXinvert;
8995 context_values.plane_mask=
8996 context_values.background ^ context_values.foreground;
8997 context_values.subwindow_mode=IncludeInferiors;
8998 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
8999 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9000 if (annotate_context == (GC) NULL)
9001 return(MagickFalse);
9003 Grab the pointer using target cursor.
9005 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9006 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9007 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9008 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9009 GrabModeAsync,root_window,target_cursor,CurrentTime);
9010 if (status != GrabSuccess)
9012 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9013 return((Window) NULL);
9019 crop_info->height=0;
9021 target_window=(Window) NULL;
9026 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9027 (void) XDrawRectangle(display,root_window,annotate_context,
9028 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9029 (unsigned int) crop_info->height-1);
9031 Allow another event.
9033 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9034 (void) XWindowEvent(display,root_window,ButtonPressMask |
9035 ButtonReleaseMask | ButtonMotionMask,&event);
9036 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9037 (void) XDrawRectangle(display,root_window,annotate_context,
9038 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9039 (unsigned int) crop_info->height-1);
9044 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9045 event.xbutton.x,event.xbutton.y);
9046 if (target_window == (Window) NULL)
9047 target_window=root_window;
9048 x_offset=event.xbutton.x_root;
9049 y_offset=event.xbutton.y_root;
9050 crop_info->x=(ssize_t) x_offset;
9051 crop_info->y=(ssize_t) y_offset;
9053 crop_info->height=0;
9065 Discard pending button motion events.
9067 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9068 crop_info->x=(ssize_t) event.xmotion.x;
9069 crop_info->y=(ssize_t) event.xmotion.y;
9071 Check boundary conditions.
9073 if ((int) crop_info->x < x_offset)
9074 crop_info->width=(size_t) (x_offset-crop_info->x);
9077 crop_info->width=(size_t) (crop_info->x-x_offset);
9078 crop_info->x=(ssize_t) x_offset;
9080 if ((int) crop_info->y < y_offset)
9081 crop_info->height=(size_t) (y_offset-crop_info->y);
9084 crop_info->height=(size_t) (crop_info->y-y_offset);
9085 crop_info->y=(ssize_t) y_offset;
9091 } while ((target_window == (Window) NULL) || (presses > 0));
9092 (void) XUngrabPointer(display,CurrentTime);
9093 (void) XFreeCursor(display,target_cursor);
9094 (void) XFreeGC(display,annotate_context);
9095 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9098 crop_info->height=0;
9100 if ((crop_info->width != 0) && (crop_info->height != 0))
9101 target_window=root_window;
9102 return(target_window);
9106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9110 % X S e t C u r s o r S t a t e %
9114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9116 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9117 % reset to their default.
9119 % The format of the XXSetCursorState method is:
9121 % XSetCursorState(display,windows,const MagickStatusType state)
9123 % A description of each parameter follows:
9125 % o display: Specifies a connection to an X server; returned from
9128 % o windows: Specifies a pointer to a XWindows structure.
9130 % o state: An unsigned integer greater than 0 sets the cursor state
9131 % to busy, otherwise the cursor are reset to their default.
9134 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9135 const MagickStatusType state)
9137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9138 assert(display != (Display *) NULL);
9139 assert(windows != (XWindows *) NULL);
9142 (void) XCheckDefineCursor(display,windows->image.id,
9143 windows->image.busy_cursor);
9144 (void) XCheckDefineCursor(display,windows->pan.id,
9145 windows->pan.busy_cursor);
9146 (void) XCheckDefineCursor(display,windows->magnify.id,
9147 windows->magnify.busy_cursor);
9148 (void) XCheckDefineCursor(display,windows->command.id,
9149 windows->command.busy_cursor);
9153 (void) XCheckDefineCursor(display,windows->image.id,
9154 windows->image.cursor);
9155 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9156 (void) XCheckDefineCursor(display,windows->magnify.id,
9157 windows->magnify.cursor);
9158 (void) XCheckDefineCursor(display,windows->command.id,
9159 windows->command.cursor);
9160 (void) XCheckDefineCursor(display,windows->command.id,
9161 windows->widget.cursor);
9162 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9164 windows->info.mapped=MagickFalse;
9168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9172 % X S e t W i n d o w s %
9176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9178 % XSetWindows() sets the X windows structure if the windows info is specified.
9179 % Otherwise the current windows structure is returned.
9181 % The format of the XSetWindows method is:
9183 % XWindows *XSetWindows(XWindows *windows_info)
9185 % A description of each parameter follows:
9187 % o windows_info: Initialize the Windows structure with this information.
9190 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9193 *windows = (XWindows *) NULL;
9195 if (windows_info != (XWindows *) ~0)
9197 windows=(XWindows *) RelinquishMagickMemory(windows);
9198 windows=windows_info;
9203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9207 % X U s e r P r e f e r e n c e s %
9211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9213 % XUserPreferences() saves the preferences in a configuration file in the
9214 % users' home directory.
9216 % The format of the XUserPreferences method is:
9218 % void XUserPreferences(XResourceInfo *resource_info)
9220 % A description of each parameter follows:
9222 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9225 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9227 #if defined(X11_PREFERENCES_PATH)
9229 cache[MaxTextExtent],
9230 filename[MaxTextExtent],
9231 specifier[MaxTextExtent];
9238 preferences_database;
9241 Save user preferences to the client configuration file.
9243 assert(resource_info != (XResourceInfo *) NULL);
9244 client_name=GetClientName();
9245 preferences_database=XrmGetStringDatabase("");
9246 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9247 value=resource_info->backdrop ? "True" : "False";
9248 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9249 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9250 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9251 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9252 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9254 value=resource_info->confirm_exit ? "True" : "False";
9255 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9256 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9258 value=resource_info->confirm_edit ? "True" : "False";
9259 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9260 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9262 value=resource_info->display_warnings ? "True" : "False";
9263 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9264 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9265 value=resource_info->quantize_info->dither ? "True" : "False";
9266 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9267 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9269 value=resource_info->gamma_correct ? "True" : "False";
9270 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9271 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9272 (void) FormatMagickString(cache,MaxTextExtent,"%.20g",(double)
9273 resource_info->undo_cache);
9274 XrmPutStringResource(&preferences_database,specifier,cache);
9275 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9276 value=resource_info->use_pixmap ? "True" : "False";
9277 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9278 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9279 X11_PREFERENCES_PATH,client_name);
9280 ExpandFilename(filename);
9281 XrmPutFileDatabase(preferences_database,filename);
9286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9290 % X V i s u a l C l a s s N a m e %
9294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9296 % XVisualClassName() returns the visual class name as a character string.
9298 % The format of the XVisualClassName method is:
9300 % char *XVisualClassName(const int visual_class)
9302 % A description of each parameter follows:
9304 % o visual_type: XVisualClassName returns the visual class as a character
9307 % o class: Specifies the visual class.
9310 static const char *XVisualClassName(const int visual_class)
9312 switch (visual_class)
9314 case StaticGray: return("StaticGray");
9315 case GrayScale: return("GrayScale");
9316 case StaticColor: return("StaticColor");
9317 case PseudoColor: return("PseudoColor");
9318 case TrueColor: return("TrueColor");
9319 case DirectColor: return("DirectColor");
9321 return("unknown visual class");
9325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9335 % XWarning() displays a warning reason in a Notice widget.
9337 % The format of the XWarning method is:
9339 % void XWarning(const unsigned int warning,const char *reason,
9340 % const char *description)
9342 % A description of each parameter follows:
9344 % o warning: Specifies the numeric warning category.
9346 % o reason: Specifies the reason to display before terminating the
9349 % o description: Specifies any description to the reason.
9352 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9353 const char *reason,const char *description)
9356 text[MaxTextExtent];
9361 if (reason == (char *) NULL)
9363 (void) CopyMagickString(text,reason,MaxTextExtent);
9364 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9365 windows=XSetWindows((XWindows *) ~0);
9366 XNoticeWidget(windows->display,windows,text,(char *) description);
9370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9374 % X W i n d o w B y I D %
9378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9380 % XWindowByID() locates a child window with a given ID. If not window with
9381 % the given name is found, 0 is returned. Only the window specified and its
9382 % subwindows are searched.
9384 % The format of the XWindowByID function is:
9386 % child=XWindowByID(display,window,id)
9388 % A description of each parameter follows:
9390 % o child: XWindowByID returns the window with the specified
9391 % id. If no windows are found, XWindowByID returns 0.
9393 % o display: Specifies a pointer to the Display structure; returned from
9396 % o id: Specifies the id of the window to locate.
9399 MagickExport Window XWindowByID(Display *display,const Window root_window,
9419 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9420 assert(display != (Display *) NULL);
9421 assert(root_window != (Window) NULL);
9423 return(XSelectWindow(display,&rectangle_info));
9424 if (root_window == id)
9426 status=XQueryTree(display,root_window,&child,&child,&children,
9428 if (status == False)
9429 return((Window) NULL);
9430 window=(Window) NULL;
9431 for (i=0; i < (int) number_children; i++)
9434 Search each child and their children.
9436 window=XWindowByID(display,children[i],id);
9437 if (window != (Window) NULL)
9440 if (children != (Window *) NULL)
9441 (void) XFree((void *) children);
9446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9450 % X W i n d o w B y N a m e %
9454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9456 % XWindowByName() locates a window with a given name on a display. If no
9457 % window with the given name is found, 0 is returned. If more than one window
9458 % has the given name, the first one is returned. Only root and its children
9461 % The format of the XWindowByName function is:
9463 % window=XWindowByName(display,root_window,name)
9465 % A description of each parameter follows:
9467 % o window: XWindowByName returns the window id.
9469 % o display: Specifies a pointer to the Display structure; returned from
9472 % o root_window: Specifies the id of the root window.
9474 % o name: Specifies the name of the window to locate.
9477 MagickExport Window XWindowByName(Display *display,const Window root_window,
9497 assert(display != (Display *) NULL);
9498 assert(root_window != (Window) NULL);
9499 assert(name != (char *) NULL);
9500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9501 if (XGetWMName(display,root_window,&window_name) != 0)
9502 if (LocaleCompare((char *) window_name.value,name) == 0)
9503 return(root_window);
9504 status=XQueryTree(display,root_window,&child,&child,&children,
9506 if (status == False)
9507 return((Window) NULL);
9508 window=(Window) NULL;
9509 for (i=0; i < (int) number_children; i++)
9512 Search each child and their children.
9514 window=XWindowByName(display,children[i],name);
9515 if (window != (Window) NULL)
9518 if (children != (Window *) NULL)
9519 (void) XFree((void *) children);
9524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9528 % X W i n d o w B y P r o p e r y %
9532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9534 % XWindowByProperty() locates a child window with a given property. If not
9535 % window with the given name is found, 0 is returned. If more than one window
9536 % has the given property, the first one is returned. Only the window
9537 % specified and its subwindows are searched.
9539 % The format of the XWindowByProperty function is:
9541 % child=XWindowByProperty(display,window,property)
9543 % A description of each parameter follows:
9545 % o child: XWindowByProperty returns the window id with the specified
9546 % property. If no windows are found, XWindowByProperty returns 0.
9548 % o display: Specifies a pointer to the Display structure; returned from
9551 % o property: Specifies the property of the window to locate.
9554 MagickExport Window XWindowByProperty(Display *display,const Window window,
9555 const Atom property)
9583 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9584 assert(display != (Display *) NULL);
9585 assert(window != (Window) NULL);
9586 assert(property != (Atom) NULL);
9587 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9588 if (status == False)
9589 return((Window) NULL);
9591 child=(Window) NULL;
9592 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9594 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9595 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9597 (void) XFree((void *) data);
9598 if ((status == Success) && (type != (Atom) NULL))
9601 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9602 child=XWindowByProperty(display,children[i],property);
9603 if (children != (Window *) NULL)
9604 (void) XFree((void *) children);
9610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9614 % X I m p o r t I m a g e %
9618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9620 % XImportImage() reads an image from an X window.
9622 % The format of the XImportImage method is:
9624 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9626 % A description of each parameter follows:
9628 % o image_info: the image info..
9630 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9633 MagickExport Image *XImportImage(const ImageInfo *image_info,
9634 XImportInfo *ximage_info)
9636 assert(image_info != (const ImageInfo *) NULL);
9637 assert(image_info->signature == MagickSignature);
9638 if (image_info->debug != MagickFalse)
9639 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9640 image_info->filename);
9641 assert(ximage_info != (XImportInfo *) NULL);
9642 return((Image *) NULL);
9647 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9651 + X C o m p o n e n t G e n e s i s %
9655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9657 % XComponentGenesis() instantiates the X component.
9659 % The format of the XComponentGenesis method is:
9661 % MagickBooleanType XComponentGenesis(void)
9664 MagickExport MagickBooleanType XComponentGenesis(void)
9670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9674 % X G e t I m p o r t I n f o %
9678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9680 % XGetImportInfo() initializes the XImportInfo structure.
9682 % The format of the XGetImportInfo method is:
9684 % void XGetImportInfo(XImportInfo *ximage_info)
9686 % A description of each parameter follows:
9688 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9691 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9693 assert(ximage_info != (XImportInfo *) NULL);
9694 ximage_info->frame=MagickFalse;
9695 ximage_info->borders=MagickFalse;
9696 ximage_info->screen=MagickFalse;
9697 ximage_info->descend=MagickTrue;
9698 ximage_info->silent=MagickFalse;