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 MagickDelay(milliseconds);
1787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1791 % X D e s t r o y R e s o u r c e I n f o %
1795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1797 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1800 % The format of the XDestroyResourceInfo method is:
1802 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1804 % A description of each parameter follows:
1806 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1809 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1811 if (resource_info->image_geometry != (char *) NULL)
1812 resource_info->image_geometry=(char *)
1813 RelinquishMagickMemory(resource_info->image_geometry);
1814 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1815 resource_info->quantize_info=DestroyQuantizeInfo(
1816 resource_info->quantize_info);
1817 if (resource_info->client_name != (char *) NULL)
1818 resource_info->client_name=(char *)
1819 RelinquishMagickMemory(resource_info->client_name);
1820 if (resource_info->name != (char *) NULL)
1821 resource_info->name=DestroyString(resource_info->name);
1822 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1830 % X D e s t r o y W i n d o w C o l o r s %
1834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1836 % XDestroyWindowColors() frees X11 color resources previously saved on a
1837 % window by XRetainWindowColors or programs like xsetroot.
1839 % The format of the XDestroyWindowColors method is:
1841 % void XDestroyWindowColors(Display *display,Window window)
1843 % A description of each parameter follows:
1845 % o display: Specifies a connection to an X server; returned from
1848 % o window: Specifies a pointer to a Window structure.
1851 MagickExport void XDestroyWindowColors(Display *display,Window window)
1871 If there are previous resources on the root window, destroy them.
1873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1874 assert(display != (Display *) NULL);
1875 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1876 if (property == (Atom) NULL)
1878 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1882 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1883 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1884 if (status != Success)
1886 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1888 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1889 (void) XDeleteProperty(display,window,property);
1892 (void) XFree((void *) data);
1896 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1900 % X D i s p l a y I m a g e I n f o %
1904 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1906 % XDisplayImageInfo() displays information about an X image.
1908 % The format of the XDisplayImageInfo method is:
1910 % void XDisplayImageInfo(Display *display,
1911 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1914 % A description of each parameter follows:
1916 % o display: Specifies a connection to an X server; returned from
1919 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1921 % o windows: Specifies a pointer to a XWindows structure.
1923 % o undo_image: the undo image.
1925 % o image: the image.
1928 MagickExport void XDisplayImageInfo(Display *display,
1929 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1933 filename[MaxTextExtent],
1956 Write info about the X server to a file.
1958 assert(display != (Display *) NULL);
1959 assert(resource_info != (XResourceInfo *) NULL);
1960 assert(windows != (XWindows *) NULL);
1961 assert(image != (Image *) NULL);
1963 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1965 unique_file=AcquireUniqueFileResource(filename);
1966 if (unique_file != -1)
1967 file=fdopen(unique_file,"w");
1968 if ((unique_file == -1) || (file == (FILE *) NULL))
1970 XNoticeWidget(display,windows,"Unable to display image info",filename);
1973 if (resource_info->gamma_correct != MagickFalse)
1974 if (resource_info->display_gamma != (char *) NULL)
1975 (void) fprintf(file,"Display\n gamma: %s\n\n",
1976 resource_info->display_gamma);
1978 Write info about the X image to a file.
1980 (void) fprintf(file,"X\n visual: %s\n",
1981 XVisualClassName((int) windows->image.storage_class));
1982 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
1983 if (windows->visual_info->colormap_size != 0)
1984 (void) fprintf(file," colormap size: %d\n",
1985 windows->visual_info->colormap_size);
1986 if (resource_info->colormap== SharedColormap)
1987 (void) fprintf(file," colormap type: Shared\n");
1989 (void) fprintf(file," colormap type: Private\n");
1990 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
1991 windows->image.ximage->height);
1992 if (windows->image.crop_geometry != (char *) NULL)
1993 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
1994 if (windows->image.pixmap == (Pixmap) NULL)
1995 (void) fprintf(file," type: X Image\n");
1997 (void) fprintf(file," type: Pixmap\n");
1998 if (windows->image.shape != MagickFalse)
1999 (void) fprintf(file," non-rectangular shape: True\n");
2001 (void) fprintf(file," non-rectangular shape: False\n");
2002 if (windows->image.shared_memory != MagickFalse)
2003 (void) fprintf(file," shared memory: True\n");
2005 (void) fprintf(file," shared memory: False\n");
2006 (void) fprintf(file,"\n");
2007 if (resource_info->font != (char *) NULL)
2008 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2009 if (resource_info->text_font != (char *) NULL)
2010 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2012 Write info about the undo cache to a file.
2015 for (levels=0; undo_image != (Image *) NULL; levels++)
2017 number_pixels=undo_image->list->columns*undo_image->list->rows;
2018 bytes+=number_pixels*sizeof(PixelPacket);
2019 undo_image=GetPreviousImageInList(undo_image);
2021 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2022 (void) fprintf(file," bytes: %.20gmb\n",(double) ((bytes+(1 << 19)) >> 20));
2023 (void) fprintf(file," limit: %.20gmb\n\n",(double)
2024 resource_info->undo_cache);
2026 Write info about the image to a file.
2028 (void) IdentifyImage(image,file,MagickTrue);
2029 (void) fclose(file);
2030 text=FileToString(filename,~0,&image->exception);
2031 (void) RelinquishUniqueFileResource(filename);
2032 if (text == (char *) NULL)
2034 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2035 "UnableToDisplayImageInfo");
2038 textlist=StringToList(text);
2039 if (textlist != (char **) NULL)
2042 title[MaxTextExtent];
2045 Display information about the image in the Text View widget.
2047 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2048 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2050 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2051 (char const **) textlist);
2052 for (i=0; textlist[i] != (char *) NULL; i++)
2053 textlist[i]=DestroyString(textlist[i]);
2054 textlist=(char **) RelinquishMagickMemory(textlist);
2056 text=DestroyString(text);
2060 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2064 + X D i t h e r I m a g e %
2068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2070 % XDitherImage() dithers the reference image as required by the HP Color
2071 % Recovery algorithm. The color values are quantized to 3 bits of red and
2072 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2073 % standard colormap.
2075 % The format of the XDitherImage method is:
2077 % void XDitherImage(Image *image,XImage *ximage)
2079 % A description of each parameter follows:
2081 % o image: the image.
2083 % o ximage: Specifies a pointer to a XImage structure; returned from
2087 static void XDitherImage(Image *image,XImage *ximage)
2089 static const short int
2092 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2093 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2095 dither_green[2][16]=
2097 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2098 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2102 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2103 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2118 register const PixelPacket
2138 Allocate and initialize dither maps.
2140 for (i=0; i < 2; i++)
2141 for (j=0; j < 16; j++)
2143 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2145 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2146 sizeof(*green_map));
2147 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2149 if ((red_map[i][j] == (unsigned char *) NULL) ||
2150 (green_map[i][j] == (unsigned char *) NULL) ||
2151 (blue_map[i][j] == (unsigned char *) NULL))
2153 ThrowXWindowFatalException(ResourceLimitError,
2154 "MemoryAllocationFailed",image->filename);
2159 Initialize dither tables.
2161 for (i=0; i < 2; i++)
2162 for (j=0; j < 16; j++)
2163 for (x=0; x < 256; x++)
2168 value+=dither_red[i][j];
2169 red_map[i][j][x]=(unsigned char)
2170 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2174 value+=dither_green[i][j];
2175 green_map[i][j][x]=(unsigned char)
2176 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2180 value+=((size_t) dither_blue[i][j] << 1);
2181 blue_map[i][j][x]=(unsigned char)
2182 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2187 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2188 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2192 for (y=0; y < (int) image->rows; y++)
2194 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2195 if (p == (const PixelPacket *) NULL)
2197 for (x=0; x < (int) image->columns; x++)
2199 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2200 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2201 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2202 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2203 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2204 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2205 pixel=(size_t) (((size_t) color.red & 0xe0) |
2206 (((size_t) color.green & 0xe0) >> 3) |
2207 (((size_t) color.blue & 0xc0) >> 6));
2220 Free allocated memory.
2222 for (i=0; i < 2; i++)
2223 for (j=0; j < 16; j++)
2225 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2226 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2227 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2236 % X D r a w I m a g e %
2240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2242 % XDrawImage() draws a line on the image.
2244 % The format of the XDrawImage method is:
2246 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2248 % A description of each parameter follows:
2250 % o display: Specifies a connection to an X server; returned from
2253 % o pixel: Specifies a pointer to a XPixelInfo structure.
2255 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2257 % o image: the image.
2260 MagickExport MagickBooleanType XDrawImage(Display *display,
2261 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2297 Initialize drawd image.
2299 assert(display != (Display *) NULL);
2300 assert(pixel != (XPixelInfo *) NULL);
2301 assert(draw_info != (XDrawInfo *) NULL);
2302 assert(image != (Image *) NULL);
2303 if (image->debug != MagickFalse)
2304 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2306 Initialize drawd pixmap.
2308 root_window=XRootWindow(display,XDefaultScreen(display));
2309 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2310 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2311 draw_info->height,depth);
2312 if (draw_pixmap == (Pixmap) NULL)
2313 return(MagickFalse);
2315 Initialize graphics info.
2317 context_values.background=(size_t) (~0);
2318 context_values.foreground=0;
2319 context_values.line_width=(int) draw_info->line_width;
2320 draw_context=XCreateGC(display,root_window,(size_t)
2321 (GCBackground | GCForeground | GCLineWidth),&context_values);
2322 if (draw_context == (GC) NULL)
2323 return(MagickFalse);
2327 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2330 Draw line to pixmap.
2332 (void) XSetBackground(display,draw_context,0);
2333 (void) XSetForeground(display,draw_context,(size_t) (~0));
2334 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2335 (void) XSetStipple(display,draw_context,draw_info->stipple);
2336 switch (draw_info->element)
2341 (void) XDrawLines(display,draw_pixmap,draw_context,
2342 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2348 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2349 draw_info->line_info.y1,draw_info->line_info.x2,
2350 draw_info->line_info.y2);
2353 case RectangleElement:
2355 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2356 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2357 (unsigned int) draw_info->rectangle_info.width,
2358 (unsigned int) draw_info->rectangle_info.height);
2361 case FillRectangleElement:
2363 (void) XFillRectangle(display,draw_pixmap,draw_context,
2364 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2365 (unsigned int) draw_info->rectangle_info.width,
2366 (unsigned int) draw_info->rectangle_info.height);
2370 case EllipseElement:
2372 (void) XDrawArc(display,draw_pixmap,draw_context,
2373 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2374 (unsigned int) draw_info->rectangle_info.width,
2375 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2378 case FillCircleElement:
2379 case FillEllipseElement:
2381 (void) XFillArc(display,draw_pixmap,draw_context,
2382 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2383 (unsigned int) draw_info->rectangle_info.width,
2384 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2387 case PolygonElement:
2392 coordinate_info=draw_info->coordinate_info;
2393 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2394 (int) draw_info->number_coordinates,CoordModeOrigin);
2395 (void) XDrawLine(display,draw_pixmap,draw_context,
2396 coordinate_info[draw_info->number_coordinates-1].x,
2397 coordinate_info[draw_info->number_coordinates-1].y,
2398 coordinate_info[0].x,coordinate_info[0].y);
2401 case FillPolygonElement:
2403 (void) XFillPolygon(display,draw_pixmap,draw_context,
2404 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2409 (void) XFreeGC(display,draw_context);
2413 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2414 draw_info->height,AllPlanes,ZPixmap);
2415 if (draw_ximage == (XImage *) NULL)
2416 return(MagickFalse);
2417 (void) XFreePixmap(display,draw_pixmap);
2419 Initialize draw image.
2421 draw_image=AcquireImage((ImageInfo *) NULL);
2422 if (draw_image == (Image *) NULL)
2423 return(MagickFalse);
2424 draw_image->columns=draw_info->width;
2425 draw_image->rows=draw_info->height;
2427 Transfer drawn X image to image.
2429 width=(unsigned int) image->columns;
2430 height=(unsigned int) image->rows;
2433 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2434 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2436 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2437 return(MagickFalse);
2438 draw_image->matte=MagickTrue;
2439 exception=(&image->exception);
2440 for (y=0; y < (int) draw_image->rows; y++)
2445 register PixelPacket
2448 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2449 if (q == (PixelPacket *) NULL)
2451 for (x=0; x < (ssize_t) draw_image->columns; x++)
2453 if (XGetPixel(draw_ximage,x,y) == 0)
2456 Set this pixel to the background color.
2458 *q=draw_image->background_color;
2459 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2460 TransparentOpacity : OpaqueOpacity);
2465 Set this pixel to the pen color.
2467 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2468 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2469 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2470 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2471 OpaqueOpacity : TransparentOpacity);
2475 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2478 XDestroyImage(draw_ximage);
2480 Determine draw geometry.
2482 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2483 if ((width != (unsigned int) draw_image->columns) ||
2484 (height != (unsigned int) draw_image->rows))
2487 image_geometry[MaxTextExtent];
2492 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2494 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2496 if (draw_info->degrees != 0.0)
2510 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2511 if (rotate_image == (Image *) NULL)
2512 return(MagickFalse);
2513 draw_image=DestroyImage(draw_image);
2514 draw_image=rotate_image;
2516 Annotation is relative to the degree of rotation.
2518 normalized_degrees=draw_info->degrees;
2519 while (normalized_degrees < -45.0)
2520 normalized_degrees+=360.0;
2521 for (rotations=0; normalized_degrees > 45.0; rotations++)
2522 normalized_degrees-=90.0;
2523 switch (rotations % 4)
2533 x=x-(int) draw_image->columns/2;
2534 y=y+(int) draw_image->columns/2;
2542 x=x-(int) draw_image->columns;
2550 x=x-(int) draw_image->columns/2;
2551 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2557 Composite text onto the image.
2559 for (y=0; y < (int) draw_image->rows; y++)
2564 register PixelPacket
2567 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2568 if (q == (PixelPacket *) NULL)
2570 for (x=0; x < (ssize_t) draw_image->columns; x++)
2572 if (q->opacity != (Quantum) TransparentOpacity)
2573 SetOpacityPixelComponent(q,OpaqueOpacity);
2576 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2579 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2580 if (draw_info->stencil == TransparentStencil)
2581 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2585 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2588 draw_image=DestroyImage(draw_image);
2593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2603 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2604 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2605 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2608 % The format of the XError function is:
2610 % XError(display,error)
2612 % A description of each parameter follows:
2614 % o display: Specifies a pointer to the Display structure; returned from
2617 % o error: Specifies the error event.
2621 #if defined(__cplusplus) || defined(c_plusplus)
2625 MagickExport int XError(Display *display,XErrorEvent *error)
2627 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2628 assert(display != (Display *) NULL);
2629 assert(error != (XErrorEvent *) NULL);
2630 xerror_alert=MagickTrue;
2631 switch (error->request_code)
2635 if ((int) error->error_code == BadDrawable)
2636 return(MagickFalse);
2639 case X_GetWindowAttributes:
2642 if ((int) error->error_code == BadWindow)
2643 return(MagickFalse);
2648 if ((int) error->error_code == BadValue)
2649 return(MagickFalse);
2656 #if defined(__cplusplus) || defined(c_plusplus)
2661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2665 % X F r e e R e s o u r c e s %
2669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2671 % XFreeResources() frees X11 resources.
2673 % The format of the XFreeResources method is:
2675 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2676 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2677 % XResourceInfo *resource_info,XWindowInfo *window_info)
2678 % resource_info,window_info)
2680 % A description of each parameter follows:
2682 % o display: Specifies a connection to an X server; returned from
2685 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2686 % returned from XGetVisualInfo.
2688 % o map_info: If map_type is specified, this structure is initialized
2689 % with info from the Standard Colormap.
2691 % o pixel: Specifies a pointer to a XPixelInfo structure.
2693 % o font_info: Specifies a pointer to a XFontStruct structure.
2695 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2697 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2700 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2701 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2702 XResourceInfo *resource_info,XWindowInfo *window_info)
2704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2705 assert(display != (Display *) NULL);
2706 assert(resource_info != (XResourceInfo *) NULL);
2707 if (window_info != (XWindowInfo *) NULL)
2712 if (window_info->ximage != (XImage *) NULL)
2713 XDestroyImage(window_info->ximage);
2714 if (window_info->id != (Window) NULL)
2717 Free destroy window and free cursors.
2719 if (window_info->id != XRootWindow(display,visual_info->screen))
2720 (void) XDestroyWindow(display,window_info->id);
2721 if (window_info->annotate_context != (GC) NULL)
2722 (void) XFreeGC(display,window_info->annotate_context);
2723 if (window_info->highlight_context != (GC) NULL)
2724 (void) XFreeGC(display,window_info->highlight_context);
2725 if (window_info->widget_context != (GC) NULL)
2726 (void) XFreeGC(display,window_info->widget_context);
2727 if (window_info->cursor != (Cursor) NULL)
2728 (void) XFreeCursor(display,window_info->cursor);
2729 window_info->cursor=(Cursor) NULL;
2730 if (window_info->busy_cursor != (Cursor) NULL)
2731 (void) XFreeCursor(display,window_info->busy_cursor);
2732 window_info->busy_cursor=(Cursor) NULL;
2738 if (font_info != (XFontStruct *) NULL)
2739 (void) XFreeFont(display,font_info);
2740 if (map_info != (XStandardColormap *) NULL)
2743 Free X Standard Colormap.
2745 if (resource_info->map_type == (char *) NULL)
2746 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2747 (void) XFree((void *) map_info);
2752 if (visual_info != (XVisualInfo *) NULL)
2753 (void) XFree((void *) visual_info);
2754 if (resource_info->close_server != MagickFalse)
2755 (void) XCloseDisplay(display);
2759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2763 % X F r e e S t a n d a r d C o l o r m a p %
2767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2769 % XFreeStandardColormap() frees an X11 colormap.
2771 % The format of the XFreeStandardColormap method is:
2773 % void XFreeStandardColormap(Display *display,
2774 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2775 % XPixelInfo *pixel)
2777 % A description of each parameter follows:
2779 % o display: Specifies a connection to an X server; returned from
2782 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2783 % returned from XGetVisualInfo.
2785 % o map_info: If map_type is specified, this structure is initialized
2786 % with info from the Standard Colormap.
2788 % o pixel: Specifies a pointer to a XPixelInfo structure.
2791 MagickExport void XFreeStandardColormap(Display *display,
2792 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2797 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2798 assert(display != (Display *) NULL);
2799 assert(visual_info != (XVisualInfo *) NULL);
2800 assert(map_info != (XStandardColormap *) NULL);
2801 (void) XFlush(display);
2802 if (map_info->colormap != (Colormap) NULL)
2804 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2805 (void) XFreeColormap(display,map_info->colormap);
2807 if (pixel != (XPixelInfo *) NULL)
2808 if ((visual_info->klass != TrueColor) &&
2809 (visual_info->klass != DirectColor))
2810 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2811 (int) pixel->colors,0);
2813 map_info->colormap=(Colormap) NULL;
2814 if (pixel != (XPixelInfo *) NULL)
2816 if (pixel->pixels != (unsigned long *) NULL)
2817 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2818 pixel->pixels=(unsigned long *) NULL;
2823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2827 % X G e t A n n o t a t e I n f o %
2831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2833 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2835 % The format of the XGetAnnotateInfo method is:
2837 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2839 % A description of each parameter follows:
2841 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2844 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2847 Initialize annotate structure.
2849 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2850 assert(annotate_info != (XAnnotateInfo *) NULL);
2853 annotate_info->width=0;
2854 annotate_info->height=0;
2855 annotate_info->stencil=ForegroundStencil;
2856 annotate_info->degrees=0.0;
2857 annotate_info->font_info=(XFontStruct *) NULL;
2858 annotate_info->text=(char *) NULL;
2859 *annotate_info->geometry='\0';
2860 annotate_info->previous=(XAnnotateInfo *) NULL;
2861 annotate_info->next=(XAnnotateInfo *) NULL;
2862 (void) XSupportsLocale();
2863 (void) XSetLocaleModifiers("");
2867 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2871 % X G e t M a p I n f o %
2875 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2877 % XGetMapInfo() initializes the XStandardColormap structure.
2879 % The format of the XStandardColormap method is:
2881 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2882 % XStandardColormap *map_info)
2884 % A description of each parameter follows:
2886 % o colormap: Specifies the ID of the X server colormap.
2888 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2889 % returned from XGetVisualInfo.
2891 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2894 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2895 const Colormap colormap,XStandardColormap *map_info)
2898 Initialize map info.
2900 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2901 assert(visual_info != (XVisualInfo *) NULL);
2902 assert(map_info != (XStandardColormap *) NULL);
2903 map_info->colormap=colormap;
2904 map_info->red_max=visual_info->red_mask;
2905 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2906 if (map_info->red_max != 0)
2907 while ((map_info->red_max & 0x01) == 0)
2909 map_info->red_max>>=1;
2910 map_info->red_mult<<=1;
2912 map_info->green_max=visual_info->green_mask;
2913 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2914 if (map_info->green_max != 0)
2915 while ((map_info->green_max & 0x01) == 0)
2917 map_info->green_max>>=1;
2918 map_info->green_mult<<=1;
2920 map_info->blue_max=visual_info->blue_mask;
2921 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2922 if (map_info->blue_max != 0)
2923 while ((map_info->blue_max & 0x01) == 0)
2925 map_info->blue_max>>=1;
2926 map_info->blue_mult<<=1;
2928 map_info->base_pixel=0;
2932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2936 % X G e t P i x e l I n f o %
2940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2942 % XGetPixelPacket() initializes the PixelPacket structure.
2944 % The format of the XGetPixelPacket method is:
2946 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2947 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2948 % Image *image,XPixelInfo *pixel)
2951 % A description of each parameter follows:
2953 % o display: Specifies a connection to an X server; returned from
2956 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2957 % returned from XGetVisualInfo.
2959 % o map_info: If map_type is specified, this structure is initialized
2960 % with info from the Standard Colormap.
2962 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2964 % o image: the image.
2966 % o pixel: Specifies a pointer to a XPixelInfo structure.
2969 MagickExport void XGetPixelPacket(Display *display,
2970 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2971 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
2974 *PenColors[MaxNumberPens]=
2976 "#000000000000", /* black */
2977 "#00000000ffff", /* blue */
2978 "#0000ffffffff", /* cyan */
2979 "#0000ffff0000", /* green */
2980 "#bdbdbdbdbdbd", /* gray */
2981 "#ffff00000000", /* red */
2982 "#ffff0000ffff", /* magenta */
2983 "#ffffffff0000", /* yellow */
2984 "#ffffffffffff", /* white */
2985 "#bdbdbdbdbdbd", /* gray */
2986 "#bdbdbdbdbdbd" /* gray */
3002 Initialize pixel info.
3004 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3005 assert(display != (Display *) NULL);
3006 assert(visual_info != (XVisualInfo *) NULL);
3007 assert(map_info != (XStandardColormap *) NULL);
3008 assert(resource_info != (XResourceInfo *) NULL);
3009 assert(pixel != (XPixelInfo *) NULL);
3011 if (image != (Image *) NULL)
3012 if (image->storage_class == PseudoClass)
3013 pixel->colors=image->colors;
3014 packets=(unsigned int)
3015 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3016 if (pixel->pixels != (unsigned long *) NULL)
3017 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3018 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3019 sizeof(pixel->pixels));
3020 if (pixel->pixels == (unsigned long *) NULL)
3021 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3024 Set foreground color.
3026 colormap=map_info->colormap;
3027 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3028 &pixel->foreground_color);
3029 status=XParseColor(display,colormap,resource_info->foreground_color,
3030 &pixel->foreground_color);
3031 if (status == False)
3032 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3033 resource_info->foreground_color);
3034 pixel->foreground_color.pixel=
3035 XStandardPixel(map_info,&pixel->foreground_color);
3036 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3038 Set background color.
3040 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3041 status=XParseColor(display,colormap,resource_info->background_color,
3042 &pixel->background_color);
3043 if (status == False)
3044 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3045 resource_info->background_color);
3046 pixel->background_color.pixel=
3047 XStandardPixel(map_info,&pixel->background_color);
3048 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3052 (void) XParseColor(display,colormap,(char *) BorderColor,
3053 &pixel->border_color);
3054 status=XParseColor(display,colormap,resource_info->border_color,
3055 &pixel->border_color);
3056 if (status == False)
3057 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3058 resource_info->border_color);
3059 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3060 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3064 pixel->matte_color=pixel->background_color;
3065 if (resource_info->matte_color != (char *) NULL)
3068 Matte color is specified as a X resource or command line argument.
3070 status=XParseColor(display,colormap,resource_info->matte_color,
3071 &pixel->matte_color);
3072 if (status == False)
3073 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3074 resource_info->matte_color);
3075 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3076 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3079 Set highlight color.
3081 pixel->highlight_color.red=(unsigned short) ((
3082 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3083 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3084 pixel->highlight_color.green=(unsigned short) ((
3085 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3086 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3087 pixel->highlight_color.blue=(unsigned short) ((
3088 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3089 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3090 pixel->highlight_color.pixel=
3091 XStandardPixel(map_info,&pixel->highlight_color);
3092 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3096 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3097 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3098 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3099 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3100 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3101 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3102 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3103 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3107 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3108 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3109 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3110 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3111 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3112 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3113 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3114 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3118 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3119 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3120 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3121 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3122 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3123 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3124 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3125 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3129 for (i=0; i < MaxNumberPens; i++)
3131 (void) XParseColor(display,colormap,(char *) PenColors[i],
3132 &pixel->pen_colors[i]);
3133 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3134 &pixel->pen_colors[i]);
3135 if (status == False)
3136 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3137 resource_info->pen_colors[i]);
3138 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3139 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3141 pixel->box_color=pixel->background_color;
3142 pixel->pen_color=pixel->foreground_color;
3145 if (image != (Image *) NULL)
3147 if ((resource_info->gamma_correct != MagickFalse) &&
3148 (image->gamma != 0.0))
3157 Initialize map relative to display and image gamma.
3159 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3160 red_gamma=geometry_info.rho;
3161 green_gamma=geometry_info.sigma;
3162 if ((flags & SigmaValue) == 0)
3163 green_gamma=red_gamma;
3164 blue_gamma=geometry_info.xi;
3165 if ((flags & XiValue) == 0)
3166 blue_gamma=red_gamma;
3167 red_gamma*=image->gamma;
3168 green_gamma*=image->gamma;
3169 blue_gamma*=image->gamma;
3171 if (image->storage_class == PseudoClass)
3174 Initialize pixel array for images of type PseudoClass.
3176 for (i=0; i < (ssize_t) image->colors; i++)
3178 XGammaPixel(map_info,image->colormap+i);
3179 for (i=0; i < MaxNumberPens; i++)
3180 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3181 pixel->colors+=MaxNumberPens;
3187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3191 % X G e t R e s o u r c e C l a s s %
3195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3197 % XGetResourceClass() queries the X server for the specified resource name or
3198 % class. If the resource name or class is not defined in the database, the
3199 % supplied default value is returned.
3201 % The format of the XGetResourceClass method is:
3203 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3204 % const char *keyword,char *resource_default)
3206 % A description of each parameter follows:
3208 % o database: Specifies a resource database; returned from
3209 % XrmGetStringDatabase.
3211 % o client_name: Specifies the application name used to retrieve resource
3212 % info from the X server database.
3214 % o keyword: Specifies the keyword of the value being retrieved.
3216 % o resource_default: Specifies the default value to return if the query
3217 % fails to find the specified keyword/class.
3220 MagickExport char *XGetResourceClass(XrmDatabase database,
3221 const char *client_name,const char *keyword,char *resource_default)
3224 resource_class[MaxTextExtent],
3225 resource_name[MaxTextExtent];
3236 if (database == (XrmDatabase) NULL)
3237 return(resource_default);
3238 *resource_name='\0';
3239 *resource_class='\0';
3240 if (keyword != (char *) NULL)
3247 Initialize resource keyword and class.
3249 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3250 client_name,keyword);
3251 c=(int) (*client_name);
3252 if ((c >= XK_a) && (c <= XK_z))
3255 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3256 c-=(XK_agrave-XK_Agrave);
3258 if ((c >= XK_oslash) && (c <= XK_thorn))
3259 c-=(XK_oslash-XK_Ooblique);
3261 if ((k >= XK_a) && (k <= XK_z))
3264 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3265 k-=(XK_agrave-XK_Agrave);
3267 if ((k >= XK_oslash) && (k <= XK_thorn))
3268 k-=(XK_oslash-XK_Ooblique);
3269 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3270 client_name+1,k,keyword+1);
3272 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3274 if (status == False)
3275 return(resource_default);
3276 return(resource_value.addr);
3280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3284 % X G e t R e s o u r c e D a t a b a s e %
3288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3290 % XGetResourceDatabase() creates a new resource database and initializes it.
3292 % The format of the XGetResourceDatabase method is:
3294 % XrmDatabase XGetResourceDatabase(Display *display,
3295 % const char *client_name)
3297 % A description of each parameter follows:
3299 % o database: XGetResourceDatabase() returns the database after it is
3302 % o display: Specifies a connection to an X server; returned from
3305 % o client_name: Specifies the application name used to retrieve resource
3306 % info from the X server database.
3309 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3310 const char *client_name)
3313 filename[MaxTextExtent];
3325 if (display == (Display *) NULL)
3326 return((XrmDatabase) NULL);
3327 assert(client_name != (char *) NULL);
3329 Initialize resource database.
3332 (void) XGetDefault(display,(char *) client_name,"dummy");
3333 resource_database=XrmGetDatabase(display);
3335 Combine application database.
3337 if (client_name != (char *) NULL)
3340 Get basename of client.
3342 p=client_name+(strlen(client_name)-1);
3343 while ((p > client_name) && (*p != '/'))
3348 c=(int) (*client_name);
3349 if ((c >= XK_a) && (c <= XK_z))
3352 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3353 c-=(XK_agrave-XK_Agrave);
3355 if ((c >= XK_oslash) && (c <= XK_thorn))
3356 c-=(XK_oslash-XK_Ooblique);
3357 #if defined(X11_APPLICATION_PATH)
3358 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3359 X11_APPLICATION_PATH,c,client_name+1);
3360 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3362 if (XResourceManagerString(display) != (char *) NULL)
3365 Combine server database.
3367 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3368 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3371 Merge user preferences database.
3373 #if defined(X11_PREFERENCES_PATH)
3374 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3375 X11_PREFERENCES_PATH,client_name);
3376 ExpandFilename(filename);
3377 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3379 return(resource_database);
3383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3387 % X G e t R e s o u r c e I n f o %
3391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3393 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3395 % The format of the XGetResourceInfo method is:
3397 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3398 % const char *client_name,XResourceInfo *resource_info)
3400 % A description of each parameter follows:
3402 % o image_info: the image info.
3404 % o database: Specifies a resource database; returned from
3405 % XrmGetStringDatabase.
3407 % o client_name: Specifies the application name used to retrieve
3408 % resource info from the X server database.
3410 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3413 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3414 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3421 Initialize resource info fields.
3423 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3424 assert(resource_info != (XResourceInfo *) NULL);
3425 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3426 resource_info->resource_database=database;
3427 resource_info->image_info=(ImageInfo *) image_info;
3428 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3429 XMagickProgressMonitor,(void *) NULL);
3430 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3431 resource_info->close_server=MagickTrue;
3432 resource_info->client_name=AcquireString(client_name);
3433 resource_value=XGetResourceClass(database,client_name,"backdrop",
3435 resource_info->backdrop=IsMagickTrue(resource_value);
3436 resource_info->background_color=XGetResourceInstance(database,client_name,
3437 "background",(char *) "#d6d6d6d6d6d6");
3438 resource_info->border_color=XGetResourceInstance(database,client_name,
3439 "borderColor",BorderColor);
3440 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3442 resource_info->border_width=(unsigned int) StringToUnsignedLong(resource_value);
3443 resource_value=XGetResourceClass(database,client_name,"colormap",
3445 resource_info->colormap=UndefinedColormap;
3446 if (LocaleCompare("private",resource_value) == 0)
3447 resource_info->colormap=PrivateColormap;
3448 if (LocaleCompare("shared",resource_value) == 0)
3449 resource_info->colormap=SharedColormap;
3450 if (resource_info->colormap == UndefinedColormap)
3451 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3453 resource_value=XGetResourceClass(database,client_name,
3454 "colorRecovery",(char *) "False");
3455 resource_info->color_recovery=IsMagickTrue(resource_value);
3456 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3458 resource_info->confirm_exit=IsMagickTrue(resource_value);
3459 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3461 resource_info->confirm_edit=IsMagickTrue(resource_value);
3462 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3463 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3464 resource_info->display_gamma=XGetResourceClass(database,client_name,
3465 "displayGamma",(char *) "2.2");
3466 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3468 resource_info->display_warnings=IsMagickTrue(resource_value);
3469 resource_info->font=XGetResourceClass(database,client_name,"font",
3471 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3472 resource_info->font);
3473 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3475 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3476 (char *) "variable");
3477 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3479 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3481 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3482 (char *) "7x13bold");
3483 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3484 (char *) "8x13bold");
3485 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3486 (char *) "9x15bold");
3487 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3489 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3491 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3493 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3495 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3496 "foreground",ForegroundColor);
3497 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3499 resource_info->gamma_correct=IsMagickTrue(resource_value);
3500 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3501 client_name,"geometry",(char *) NULL));
3502 resource_value=XGetResourceClass(database,client_name,"gravity",
3504 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3505 MagickFalse,resource_value);
3506 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3507 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3508 "iconGeometry",(char *) NULL);
3509 resource_value=XGetResourceClass(database,client_name,"iconic",
3511 resource_info->iconic=IsMagickTrue(resource_value);
3512 resource_value=XGetResourceClass(database,client_name,"immutable",
3513 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3515 resource_info->immutable=IsMagickTrue(resource_value);
3516 resource_value=XGetResourceClass(database,client_name,"magnify",
3518 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3519 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3521 resource_info->matte_color=XGetResourceInstance(database,client_name,
3522 "mattecolor",(char *) NULL);
3523 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3524 "name",(char *) NULL));
3525 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3527 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3529 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3531 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3533 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3535 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3537 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3538 (char *) "magenta");
3539 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3541 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3543 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3545 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3547 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3548 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3549 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3550 resource_info->quantum=StringToLong(resource_value);
3551 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3552 "font",(char *) "fixed");
3553 resource_info->text_font=XGetResourceClass(database,client_name,
3554 "textFontList",resource_info->text_font);
3555 resource_info->title=XGetResourceClass(database,client_name,"title",
3557 resource_value=XGetResourceClass(database,client_name,"undoCache",
3559 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3560 resource_value=XGetResourceClass(database,client_name,"update",
3562 resource_info->update=IsMagickTrue(resource_value);
3563 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3565 resource_info->use_pixmap=IsMagickTrue(resource_value);
3566 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3568 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3569 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3571 resource_info->window_group=XGetResourceClass(database,client_name,
3572 "windowGroup",(char *) NULL);
3573 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3575 resource_info->write_filename=XGetResourceClass(database,client_name,
3576 "writeFilename",(char *) NULL);
3580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3584 % X G e t R e s o u r c e I n s t a n c e %
3588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3590 % XGetResourceInstance() queries the X server for the specified resource name.
3591 % If the resource name is not defined in the database, the supplied default
3592 % value is returned.
3594 % The format of the XGetResourceInstance method is:
3596 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3597 % const char *keyword,const char *resource_default)
3599 % A description of each parameter follows:
3601 % o database: Specifies a resource database; returned from
3602 % XrmGetStringDatabase.
3604 % o client_name: Specifies the application name used to retrieve
3605 % resource info from the X server database.
3607 % o keyword: Specifies the keyword of the value being retrieved.
3609 % o resource_default: Specifies the default value to return if the query
3610 % fails to find the specified keyword/class.
3613 MagickExport char *XGetResourceInstance(XrmDatabase database,
3614 const char *client_name,const char *keyword,const char *resource_default)
3618 resource_name[MaxTextExtent];
3626 if (database == (XrmDatabase) NULL)
3627 return((char *) resource_default);
3628 *resource_name='\0';
3629 if (keyword != (char *) NULL)
3630 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3632 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3634 if (status == False)
3635 return((char *) resource_default);
3636 return(resource_value.addr);
3640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3644 % X G e t S c r e e n D e n s i t y %
3648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3650 % XGetScreenDensity() returns the density of the X server screen in
3653 % The format of the XGetScreenDensity method is:
3655 % char *XGetScreenDensity(Display *display)
3657 % A description of each parameter follows:
3659 % o density: XGetScreenDensity() returns the density of the X screen in
3662 % o display: Specifies a connection to an X server; returned from
3666 MagickExport char *XGetScreenDensity(Display *display)
3669 density[MaxTextExtent];
3676 Set density as determined by screen size.
3678 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3679 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3680 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3681 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3682 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,
3684 return(GetPageGeometry(density));
3688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3692 + X G e t S u b w i n d o w %
3696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3698 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3699 % pointer and a button press.
3701 % The format of the XGetSubwindow method is:
3703 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3705 % A description of each parameter follows:
3707 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3708 % otherwise the subwindow is returned.
3710 % o display: Specifies a connection to an X server; returned from
3713 % o window: Specifies a pointer to a Window.
3715 % o x: the x coordinate of the pointer relative to the origin of the
3718 % o y: the y coordinate of the pointer relative to the origin of the
3722 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3735 assert(display != (Display *) NULL);
3736 source_window=XRootWindow(display,XDefaultScreen(display));
3737 if (window == (Window) NULL)
3738 return(source_window);
3739 target_window=window;
3742 status=XTranslateCoordinates(display,source_window,window,x,y,
3743 &x_offset,&y_offset,&target_window);
3746 if (target_window == (Window) NULL)
3748 source_window=window;
3749 window=target_window;
3753 if (target_window == (Window) NULL)
3754 target_window=window;
3755 return(target_window);
3759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3763 % X G e t W i n d o w C o l o r %
3767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3769 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3772 % The format of the XGetWindowColor method is:
3774 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3777 % A description of each parameter follows:
3779 % o display: Specifies a connection to an X server; returned from
3782 % o windows: Specifies a pointer to a XWindows structure.
3784 % o name: the name of the color if found in the X Color Database is
3785 % returned in this character string.
3788 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3789 XWindows *windows,char *name)
3820 Choose a pixel from the X server.
3822 assert(display != (Display *) NULL);
3823 assert(name != (char *) NULL);
3824 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3826 target_window=XSelectWindow(display,&crop_info);
3827 if (target_window == (Window) NULL)
3828 return(MagickFalse);
3829 root_window=XRootWindow(display,XDefaultScreen(display));
3830 client_window=target_window;
3831 if (target_window != root_window)
3839 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3840 if (status != False)
3842 client_window=XClientWindow(display,target_window);
3843 target_window=client_window;
3847 Verify window is viewable.
3849 status=XGetWindowAttributes(display,target_window,&window_attributes);
3850 if ((status == False) || (window_attributes.map_state != IsViewable))
3851 return(MagickFalse);
3855 (void) XTranslateCoordinates(display,root_window,target_window,
3856 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3857 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3858 if (ximage == (XImage *) NULL)
3859 return(MagickFalse);
3860 color.pixel=XGetPixel(ximage,0,0);
3861 XDestroyImage(ximage);
3863 Match color against the color database.
3865 (void) XQueryColor(display,window_attributes.colormap,&color);
3866 pixel.red=ScaleShortToQuantum(color.red);
3867 pixel.green=ScaleShortToQuantum(color.green);
3868 pixel.blue=ScaleShortToQuantum(color.blue);
3869 pixel.opacity=OpaqueOpacity;
3870 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3871 &windows->image.image->exception);
3876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3880 + X G e t W i n d o w I m a g e %
3884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3886 % XGetWindowImage() reads an image from the target X window and returns it.
3887 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3888 % target image with each child image in an optimized fashion. Any child
3889 % window that have the same visual, colormap, and are contained by its parent
3892 % The format of the XGetWindowImage method is:
3894 % Image *XGetWindowImage(Display *display,const Window window,
3895 % const unsigned int borders,const unsigned int level)
3897 % A description of each parameter follows:
3899 % o display: Specifies a connection to an X server; returned from
3902 % o window: Specifies the window to obtain the image from.
3904 % o borders: Specifies whether borders pixels are to be saved with
3907 % o level: Specifies an unsigned integer representing the level of
3908 % decent in the window hierarchy. This value must be zero or one on
3909 % the initial call to XGetWindowImage. A value of zero returns after
3910 % one call. A value of one causes the function to descend the window
3911 % hierarchy and overlay the target image with each subwindow image.
3914 static Image *XGetWindowImage(Display *display,const Window window,
3915 const unsigned int borders,const unsigned int level)
3917 typedef struct _ColormapInfo
3925 struct _ColormapInfo
3929 typedef struct _WindowInfo
3961 register IndexPacket
3968 *colormap_info = (ColormapInfo *) NULL;
3988 Verify window is viewable.
3990 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3991 assert(display != (Display *) NULL);
3992 status=XGetWindowAttributes(display,window,&window_attributes);
3993 if ((status == False) || (window_attributes.map_state != IsViewable))
3994 return((Image *) NULL);
3996 Cropping rectangle is relative to root window.
3998 root_window=XRootWindow(display,XDefaultScreen(display));
3999 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4001 crop_info.x=(ssize_t) x_offset;
4002 crop_info.y=(ssize_t) y_offset;
4003 crop_info.width=(size_t) window_attributes.width;
4004 crop_info.height=(size_t) window_attributes.height;
4005 if (borders != MagickFalse)
4008 Include border in image.
4010 crop_info.x-=(ssize_t) window_attributes.border_width;
4011 crop_info.y-=(ssize_t) window_attributes.border_width;
4012 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4013 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4016 Crop to root window.
4018 if (crop_info.x < 0)
4020 crop_info.width+=crop_info.x;
4023 if (crop_info.y < 0)
4025 crop_info.height+=crop_info.y;
4028 display_width=XDisplayWidth(display,XDefaultScreen(display));
4029 if ((int) (crop_info.x+crop_info.width) > display_width)
4030 crop_info.width=(size_t) (display_width-crop_info.x);
4031 display_height=XDisplayHeight(display,XDefaultScreen(display));
4032 if ((int) (crop_info.y+crop_info.height) > display_height)
4033 crop_info.height=(size_t) (display_height-crop_info.y);
4035 Initialize window info attributes.
4037 if (number_windows >= max_windows)
4040 Allocate or resize window info buffer.
4043 if (window_info == (WindowInfo *) NULL)
4044 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4045 sizeof(*window_info));
4047 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4048 max_windows,sizeof(*window_info));
4050 if (window_info == (WindowInfo *) NULL)
4052 ThrowXWindowFatalException(ResourceLimitError,
4053 "MemoryAllocationFailed","...");
4054 return((Image *) NULL);
4056 id=number_windows++;
4057 window_info[id].window=window;
4058 window_info[id].visual=window_attributes.visual;
4059 window_info[id].colormap=window_attributes.colormap;
4060 window_info[id].bounds.x1=(short) crop_info.x;
4061 window_info[id].bounds.y1=(short) crop_info.y;
4062 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4063 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4064 crop_info.x-=x_offset;
4065 crop_info.y-=y_offset;
4066 window_info[id].crop_info=crop_info;
4076 Descend the window hierarchy.
4078 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4079 &children,&number_children);
4080 for (i=0; i < id; i++)
4081 if ((window_info[i].window == window_info[id].parent) &&
4082 (window_info[i].visual == window_info[id].visual) &&
4083 (window_info[i].colormap == window_info[id].colormap))
4085 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4086 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4087 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4088 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4091 Eliminate windows not circumscribed by their parent.
4097 if ((status == True) && (number_children != 0))
4099 for (i=0; i < (int) number_children; i++)
4100 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4101 (void) XFree((void *) children);
4126 register PixelPacket
4142 Get X image for each window in the list.
4144 image=NewImageList();
4145 for (id=0; id < number_windows; id++)
4148 Does target window intersect top level window?
4151 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4152 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4153 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4154 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4155 MagickTrue : MagickFalse;
4157 Is target window contained by another window with the same colormap?
4159 for (j=0; j < id; j++)
4160 if ((window_info[id].visual == window_info[j].visual) &&
4161 (window_info[id].colormap == window_info[j].colormap))
4163 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4164 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4165 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4166 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4170 if ((window_info[id].visual != window_info[j].visual) ||
4171 (window_info[id].colormap != window_info[j].colormap))
4173 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4174 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4175 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4176 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4179 if (import == MagickFalse)
4184 ximage=XGetImage(display,window_info[id].window,(int)
4185 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4186 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4187 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4188 if (ximage == (XImage *) NULL)
4191 Initialize window colormap.
4194 colors=(XColor *) NULL;
4195 if (window_info[id].colormap != (Colormap) NULL)
4201 Search colormap list for window colormap.
4203 number_colors=(unsigned int) window_info[id].visual->map_entries;
4204 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4205 if (p->colormap == window_info[id].colormap)
4207 if (p == (ColormapInfo *) NULL)
4210 Get the window colormap.
4212 colors=(XColor *) AcquireQuantumMemory(number_colors,
4214 if (colors == (XColor *) NULL)
4216 XDestroyImage(ximage);
4217 return((Image *) NULL);
4219 if ((window_info[id].visual->klass != DirectColor) &&
4220 (window_info[id].visual->klass != TrueColor))
4221 for (i=0; i < (int) number_colors; i++)
4223 colors[i].pixel=(size_t) i;
4237 DirectColor or TrueColor visual.
4242 red_bit=window_info[id].visual->red_mask &
4243 (~(window_info[id].visual->red_mask)+1);
4244 green_bit=window_info[id].visual->green_mask &
4245 (~(window_info[id].visual->green_mask)+1);
4246 blue_bit=window_info[id].visual->blue_mask &
4247 (~(window_info[id].visual->blue_mask)+1);
4248 for (i=0; i < (int) number_colors; i++)
4250 colors[i].pixel=(unsigned long) (red | green | blue);
4253 if (red > window_info[id].visual->red_mask)
4256 if (green > window_info[id].visual->green_mask)
4259 if (blue > window_info[id].visual->blue_mask)
4263 (void) XQueryColors(display,window_info[id].colormap,colors,
4264 (int) number_colors);
4266 Append colormap to colormap list.
4268 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4269 if (p == (ColormapInfo *) NULL)
4270 return((Image *) NULL);
4271 p->colormap=window_info[id].colormap;
4273 p->next=colormap_info;
4279 Allocate image structure.
4281 composite_image=AcquireImage((ImageInfo *) NULL);
4282 if (composite_image == (Image *) NULL)
4284 XDestroyImage(ximage);
4285 return((Image *) NULL);
4288 Convert X image to MIFF format.
4290 if ((window_info[id].visual->klass != TrueColor) &&
4291 (window_info[id].visual->klass != DirectColor))
4292 composite_image->storage_class=PseudoClass;
4293 composite_image->columns=(size_t) ximage->width;
4294 composite_image->rows=(size_t) ximage->height;
4295 exception=(&composite_image->exception);
4296 switch (composite_image->storage_class)
4314 Determine shift and mask for red, green, and blue.
4316 red_mask=window_info[id].visual->red_mask;
4318 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4323 green_mask=window_info[id].visual->green_mask;
4325 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4330 blue_mask=window_info[id].visual->blue_mask;
4332 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4338 Convert X image to DirectClass packets.
4340 if ((number_colors != 0) &&
4341 (window_info[id].visual->klass == DirectColor))
4342 for (y=0; y < (int) composite_image->rows; y++)
4344 q=QueueAuthenticPixels(composite_image,0,y,
4345 composite_image->columns,1,exception);
4346 if (q == (PixelPacket *) NULL)
4348 for (x=0; x < (int) composite_image->columns; x++)
4350 pixel=XGetPixel(ximage,x,y);
4351 index=(pixel >> red_shift) & red_mask;
4352 q->red=ScaleShortToQuantum(colors[index].red);
4353 index=(pixel >> green_shift) & green_mask;
4354 q->green=ScaleShortToQuantum(colors[index].green);
4355 index=(pixel >> blue_shift) & blue_mask;
4356 q->blue=ScaleShortToQuantum(colors[index].blue);
4359 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4363 for (y=0; y < (int) composite_image->rows; y++)
4365 q=QueueAuthenticPixels(composite_image,0,y,
4366 composite_image->columns,1,exception);
4367 if (q == (PixelPacket *) NULL)
4369 for (x=0; x < (int) composite_image->columns; x++)
4371 pixel=XGetPixel(ximage,x,y);
4372 color=(pixel >> red_shift) & red_mask;
4373 color=(65535UL*color)/red_mask;
4374 q->red=ScaleShortToQuantum((unsigned short) color);
4375 color=(pixel >> green_shift) & green_mask;
4376 color=(65535UL*color)/green_mask;
4377 q->green=ScaleShortToQuantum((unsigned short) color);
4378 color=(pixel >> blue_shift) & blue_mask;
4379 color=(65535UL*color)/blue_mask;
4380 q->blue=ScaleShortToQuantum((unsigned short) color);
4383 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4393 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4395 XDestroyImage(ximage);
4396 composite_image=DestroyImage(composite_image);
4397 return((Image *) NULL);
4399 for (i=0; i < (int) composite_image->colors; i++)
4401 composite_image->colormap[colors[i].pixel].red=
4402 ScaleShortToQuantum(colors[i].red);
4403 composite_image->colormap[colors[i].pixel].green=
4404 ScaleShortToQuantum(colors[i].green);
4405 composite_image->colormap[colors[i].pixel].blue=
4406 ScaleShortToQuantum(colors[i].blue);
4409 Convert X image to PseudoClass packets.
4411 for (y=0; y < (int) composite_image->rows; y++)
4413 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4414 if (q == (PixelPacket *) NULL)
4416 indexes=GetAuthenticIndexQueue(composite_image);
4417 for (x=0; x < (int) composite_image->columns; x++)
4419 index=(IndexPacket) XGetPixel(ximage,x,y);
4421 *q++=composite_image->colormap[(ssize_t) index];
4423 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4429 XDestroyImage(ximage);
4430 if (image == (Image *) NULL)
4432 image=composite_image;
4436 Composite any children in back-to-front order.
4438 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4439 &x_offset,&y_offset,&child);
4440 x_offset-=(int) crop_info.x;
4443 y_offset-=(int) crop_info.y;
4446 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4450 Relinquish resources.
4452 while (colormap_info != (ColormapInfo *) NULL)
4454 next=colormap_info->next;
4455 colormap_info->colors=(XColor *)
4456 RelinquishMagickMemory(colormap_info->colors);
4457 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4461 Relinquish resources and restore initial state.
4463 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4466 colormap_info=(ColormapInfo *) NULL;
4469 return((Image *) NULL);
4473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4477 % X G e t W i n d o w I n f o %
4481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4483 % XGetWindowInfo() initializes the XWindowInfo structure.
4485 % The format of the XGetWindowInfo method is:
4487 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4488 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4489 % XResourceInfo *resource_info,XWindowInfo *window)
4490 % resource_info,window)
4492 % A description of each parameter follows:
4494 % o display: Specifies a connection to an X server; returned from
4497 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4498 % returned from XGetVisualInfo.
4500 % o map_info: If map_type is specified, this structure is initialized
4501 % with info from the Standard Colormap.
4503 % o pixel: Specifies a pointer to a XPixelInfo structure.
4505 % o font_info: Specifies a pointer to a XFontStruct structure.
4507 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4510 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4511 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4512 XResourceInfo *resource_info,XWindowInfo *window)
4515 Initialize window info.
4517 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4518 assert(display != (Display *) NULL);
4519 assert(visual_info != (XVisualInfo *) NULL);
4520 assert(map_info != (XStandardColormap *) NULL);
4521 assert(pixel != (XPixelInfo *) NULL);
4522 assert(resource_info != (XResourceInfo *) NULL);
4523 assert(window != (XWindowInfo *) NULL);
4524 if (window->id != (Window) NULL)
4526 if (window->cursor != (Cursor) NULL)
4527 (void) XFreeCursor(display,window->cursor);
4528 if (window->busy_cursor != (Cursor) NULL)
4529 (void) XFreeCursor(display,window->busy_cursor);
4530 if (window->highlight_stipple != (Pixmap) NULL)
4531 (void) XFreePixmap(display,window->highlight_stipple);
4532 if (window->shadow_stipple != (Pixmap) NULL)
4533 (void) XFreePixmap(display,window->shadow_stipple);
4534 if (window->name == (char *) NULL)
4535 window->name=AcquireString("");
4536 if (window->icon_name == (char *) NULL)
4537 window->icon_name=AcquireString("");
4542 Initialize these attributes just once.
4544 window->id=(Window) NULL;
4545 if (window->name == (char *) NULL)
4546 window->name=AcquireString("");
4547 if (window->icon_name == (char *) NULL)
4548 window->icon_name=AcquireString("");
4549 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4550 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4551 window->ximage=(XImage *) NULL;
4552 window->matte_image=(XImage *) NULL;
4553 window->pixmap=(Pixmap) NULL;
4554 window->matte_pixmap=(Pixmap) NULL;
4555 window->mapped=MagickFalse;
4556 window->stasis=MagickFalse;
4557 window->shared_memory=MagickTrue;
4558 window->segment_info=(void *) NULL;
4559 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4564 if (window->segment_info == (void *) NULL)
4565 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4566 segment_info=(XShmSegmentInfo *) window->segment_info;
4567 segment_info[0].shmid=(-1);
4568 segment_info[0].shmaddr=(char *) NULL;
4569 segment_info[1].shmid=(-1);
4570 segment_info[1].shmaddr=(char *) NULL;
4575 Initialize these attributes every time function is called.
4577 window->screen=visual_info->screen;
4578 window->root=XRootWindow(display,visual_info->screen);
4579 window->visual=visual_info->visual;
4580 window->storage_class=(unsigned int) visual_info->klass;
4581 window->depth=(unsigned int) visual_info->depth;
4582 window->visual_info=visual_info;
4583 window->map_info=map_info;
4584 window->pixel_info=pixel;
4585 window->font_info=font_info;
4586 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4587 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4588 window->geometry=(char *) NULL;
4589 window->icon_geometry=(char *) NULL;
4590 if (resource_info->icon_geometry != (char *) NULL)
4591 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4592 window->crop_geometry=(char *) NULL;
4593 window->flags=(size_t) PSize;
4596 window->min_width=1;
4597 window->min_height=1;
4598 window->width_inc=1;
4599 window->height_inc=1;
4600 window->border_width=resource_info->border_width;
4601 window->annotate_context=pixel->annotate_context;
4602 window->highlight_context=pixel->highlight_context;
4603 window->widget_context=pixel->widget_context;
4604 window->shadow_stipple=(Pixmap) NULL;
4605 window->highlight_stipple=(Pixmap) NULL;
4606 window->use_pixmap=MagickTrue;
4607 window->immutable=MagickFalse;
4608 window->shape=MagickFalse;
4610 window->mask=(size_t) (CWBackingStore | CWBackPixel | CWBackPixmap |
4611 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4612 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4613 window->attributes.background_pixel=pixel->background_color.pixel;
4614 window->attributes.background_pixmap=(Pixmap) NULL;
4615 window->attributes.bit_gravity=ForgetGravity;
4616 window->attributes.backing_store=WhenMapped;
4617 window->attributes.save_under=MagickTrue;
4618 window->attributes.border_pixel=pixel->border_color.pixel;
4619 window->attributes.colormap=map_info->colormap;
4620 window->attributes.cursor=window->cursor;
4621 window->attributes.do_not_propagate_mask=NoEventMask;
4622 window->attributes.event_mask=NoEventMask;
4623 window->attributes.override_redirect=MagickFalse;
4624 window->attributes.win_gravity=NorthWestGravity;
4625 window->orphan=MagickFalse;
4629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4633 % X H i g h l i g h t E l l i p s e %
4637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4639 % XHighlightEllipse() puts a border on the X server around a region defined by
4642 % The format of the XHighlightEllipse method is:
4644 % void XHighlightEllipse(Display *display,Window window,
4645 % GC annotate_context,const RectangleInfo *highlight_info)
4647 % A description of each parameter follows:
4649 % o display: Specifies a connection to an X server; returned from
4652 % o window: Specifies a pointer to a Window structure.
4654 % o annotate_context: Specifies a pointer to a GC structure.
4656 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4657 % contains the extents of any highlighting rectangle.
4660 MagickExport void XHighlightEllipse(Display *display,Window window,
4661 GC annotate_context,const RectangleInfo *highlight_info)
4663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4664 assert(display != (Display *) NULL);
4665 assert(window != (Window) NULL);
4666 assert(annotate_context != (GC) NULL);
4667 assert(highlight_info != (RectangleInfo *) NULL);
4668 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4670 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4671 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4672 (unsigned int) highlight_info->height-1,0,360*64);
4673 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4674 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4675 (unsigned int) highlight_info->height-3,0,360*64);
4679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4683 % X H i g h l i g h t L i n e %
4687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4689 % XHighlightLine() puts a border on the X server around a region defined by
4692 % The format of the XHighlightLine method is:
4694 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4695 % const XSegment *highlight_info)
4697 % A description of each parameter follows:
4699 % o display: Specifies a connection to an X server; returned from
4702 % o window: Specifies a pointer to a Window structure.
4704 % o annotate_context: Specifies a pointer to a GC structure.
4706 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4707 % contains the extents of any highlighting rectangle.
4710 MagickExport void XHighlightLine(Display *display,Window window,
4711 GC annotate_context,const XSegment *highlight_info)
4713 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4714 assert(display != (Display *) NULL);
4715 assert(window != (Window) NULL);
4716 assert(annotate_context != (GC) NULL);
4717 assert(highlight_info != (XSegment *) NULL);
4718 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4719 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4727 % X H i g h l i g h t R e c t a n g l e %
4731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4733 % XHighlightRectangle() puts a border on the X server around a region defined
4734 % by highlight_info.
4736 % The format of the XHighlightRectangle method is:
4738 % void XHighlightRectangle(Display *display,Window window,
4739 % GC annotate_context,const RectangleInfo *highlight_info)
4741 % A description of each parameter follows:
4743 % o display: Specifies a connection to an X server; returned from
4746 % o window: Specifies a pointer to a Window structure.
4748 % o annotate_context: Specifies a pointer to a GC structure.
4750 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4751 % contains the extents of any highlighting rectangle.
4754 MagickExport void XHighlightRectangle(Display *display,Window window,
4755 GC annotate_context,const RectangleInfo *highlight_info)
4757 assert(display != (Display *) NULL);
4758 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4759 assert(window != (Window) NULL);
4760 assert(annotate_context != (GC) NULL);
4761 assert(highlight_info != (RectangleInfo *) NULL);
4762 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4764 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4765 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4766 (unsigned int) highlight_info->height-1);
4767 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4768 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4769 (unsigned int) highlight_info->height-3);
4773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4777 % X I m p o r t I m a g e %
4781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4783 % XImportImage() reads an image from an X window.
4785 % The format of the XImportImage method is:
4787 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4789 % A description of each parameter follows:
4791 % o image_info: the image info.
4793 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4796 MagickExport Image *XImportImage(const ImageInfo *image_info,
4797 XImportInfo *ximage_info)
4830 Open X server connection.
4832 assert(image_info != (const ImageInfo *) NULL);
4833 assert(image_info->signature == MagickSignature);
4834 if (image_info->debug != MagickFalse)
4835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4836 image_info->filename);
4837 assert(ximage_info != (XImportInfo *) NULL);
4838 display=XOpenDisplay(image_info->server_name);
4839 if (display == (Display *) NULL)
4841 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4842 XDisplayName(image_info->server_name));
4843 return((Image *) NULL);
4846 Set our forgiving exception handler.
4848 (void) XSetErrorHandler(XError);
4850 Select target window.
4856 root=XRootWindow(display,XDefaultScreen(display));
4857 target=(Window) NULL;
4858 if ((image_info->filename != (char *) NULL) &&
4859 (*image_info->filename != '\0'))
4861 if (LocaleCompare(image_info->filename,"root") == 0)
4866 Select window by ID or name.
4868 if (isdigit((unsigned char) *image_info->filename) != 0)
4869 target=XWindowByID(display,root,(Window)
4870 strtol(image_info->filename,(char **) NULL,0));
4871 if (target == (Window) NULL)
4872 target=XWindowByName(display,root,image_info->filename);
4873 if (target == (Window) NULL)
4874 ThrowXWindowFatalException(XServerError,
4875 "NoWindowWithSpecifiedIDExists",image_info->filename);
4879 If target window is not defined, interactively select one.
4881 prior_target=target;
4882 if (target == (Window) NULL)
4883 target=XSelectWindow(display,&crop_info);
4884 if (target == (Window) NULL)
4885 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4886 image_info->filename);
4887 client=target; /* obsolete */
4893 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4894 if (status != False)
4902 Find window manager frame.
4904 status=XQueryTree(display,target,&root,&parent,&children,&d);
4905 if ((status != False) && (children != (Window *) NULL))
4906 (void) XFree((char *) children);
4907 if ((status == False) || (parent == (Window) NULL) ||
4915 client=XClientWindow(display,target);
4916 if (ximage_info->frame == MagickFalse)
4918 if ((ximage_info->frame == MagickFalse) &&
4919 (prior_target != MagickFalse))
4920 target=prior_target;
4921 XDelay(display,SuspendTime << 4);
4924 if (ximage_info->screen)
4936 Obtain window image directly from screen.
4938 status=XGetWindowAttributes(display,target,&window_attributes);
4939 if (status == False)
4941 ThrowXWindowFatalException(XServerError,
4942 "UnableToReadXWindowAttributes",image_info->filename);
4943 (void) XCloseDisplay(display);
4944 return((Image *) NULL);
4946 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4949 crop_info.width=(size_t) window_attributes.width;
4950 crop_info.height=(size_t) window_attributes.height;
4951 if (ximage_info->borders != 0)
4954 Include border in image.
4956 crop_info.x-=window_attributes.border_width;
4957 crop_info.y-=window_attributes.border_width;
4958 crop_info.width+=window_attributes.border_width << 1;
4959 crop_info.height+=window_attributes.border_width << 1;
4964 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4967 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4968 if ((status == True) && (number_windows > 0))
4970 ximage_info->descend=MagickTrue;
4971 (void) XFree ((char *) children);
4973 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
4974 if (number_colormaps > 0)
4976 if (number_colormaps > 1)
4977 ximage_info->descend=MagickTrue;
4978 (void) XFree((char *) colormaps);
4981 Alert the user not to alter the screen.
4983 if (ximage_info->silent == MagickFalse)
4984 (void) XBell(display,0);
4986 Get image by window id.
4988 (void) XGrabServer(display);
4989 image=XGetWindowImage(display,target,ximage_info->borders,
4990 ximage_info->descend ? 1U : 0U);
4991 (void) XUngrabServer(display);
4992 if (image == (Image *) NULL)
4993 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4994 image_info->filename)
4997 (void) CopyMagickString(image->filename,image_info->filename,
4999 if ((crop_info.width != 0) && (crop_info.height != 0))
5006 Crop image as defined by the cropping rectangle.
5008 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5009 if (clone_image != (Image *) NULL)
5011 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5012 if (crop_image != (Image *) NULL)
5014 image=DestroyImage(image);
5019 status=XGetWMName(display,target,&window_name);
5022 if ((image_info->filename != (char *) NULL) &&
5023 (*image_info->filename == '\0'))
5024 (void) CopyMagickString(image->filename,(char *) window_name.value,
5025 (size_t) window_name.nitems+1);
5026 (void) XFree((void *) window_name.value);
5029 if (ximage_info->silent == MagickFalse)
5032 Alert the user we're done.
5034 (void) XBell(display,0);
5035 (void) XBell(display,0);
5037 (void) XCloseDisplay(display);
5042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5046 % X I n i t i a l i z e W i n d o w s %
5050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5052 % XInitializeWindows() initializes the XWindows structure.
5054 % The format of the XInitializeWindows method is:
5056 % XWindows *XInitializeWindows(Display *display,
5057 % XResourceInfo *resource_info)
5059 % A description of each parameter follows:
5061 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5063 % o display: Specifies a connection to an X server; returned from
5066 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5069 MagickExport XWindows *XInitializeWindows(Display *display,
5070 XResourceInfo *resource_info)
5079 Allocate windows structure.
5081 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5082 if (windows == (XWindows *) NULL)
5084 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5086 return((XWindows *) NULL);
5088 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5089 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5090 sizeof(*windows->pixel_info));
5091 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5092 sizeof(*windows->icon_pixel));
5093 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5094 sizeof(*windows->icon_resources));
5095 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5096 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5097 (windows->icon_resources == (XResourceInfo *) NULL))
5099 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5101 return((XWindows *) NULL);
5104 Initialize windows structure.
5106 windows->display=display;
5107 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5108 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5109 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5110 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5111 windows->im_remote_command=
5112 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5113 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5114 windows->im_update_colormap=
5115 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5116 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5117 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5118 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5119 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5120 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5121 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5122 (void) XSynchronize(display,IsWindows95());
5124 if (IsEventLogging())
5126 (void) XSynchronize(display,MagickTrue);
5127 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5128 GetMagickVersion((size_t *) NULL));
5129 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5130 (void) LogMagickEvent(X11Event,GetMagickModule(),
5131 " Window Manager: 0x%lx",windows->wm_protocols);
5132 (void) LogMagickEvent(X11Event,GetMagickModule(),
5133 " delete window: 0x%lx",windows->wm_delete_window);
5134 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5135 windows->wm_take_focus);
5136 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5137 windows->im_protocols);
5138 (void) LogMagickEvent(X11Event,GetMagickModule(),
5139 " remote command: 0x%lx",windows->im_remote_command);
5140 (void) LogMagickEvent(X11Event,GetMagickModule(),
5141 " update widget: 0x%lx",windows->im_update_widget);
5142 (void) LogMagickEvent(X11Event,GetMagickModule(),
5143 " update colormap: 0x%lx",windows->im_update_colormap);
5144 (void) LogMagickEvent(X11Event,GetMagickModule(),
5145 " former image: 0x%lx",windows->im_former_image);
5146 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5147 windows->im_next_image);
5148 (void) LogMagickEvent(X11Event,GetMagickModule(),
5149 " retain colors: 0x%lx",windows->im_retain_colors);
5150 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5152 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5153 windows->dnd_protocols);
5156 Allocate standard colormap.
5158 windows->map_info=XAllocStandardColormap();
5159 windows->icon_map=XAllocStandardColormap();
5160 if ((windows->map_info == (XStandardColormap *) NULL) ||
5161 (windows->icon_map == (XStandardColormap *) NULL))
5162 ThrowXWindowFatalException(ResourceLimitFatalError,
5163 "MemoryAllocationFailed","...");
5164 windows->map_info->colormap=(Colormap) NULL;
5165 windows->icon_map->colormap=(Colormap) NULL;
5166 windows->pixel_info->pixels=(unsigned long *) NULL;
5167 windows->pixel_info->annotate_context=(GC) NULL;
5168 windows->pixel_info->highlight_context=(GC) NULL;
5169 windows->pixel_info->widget_context=(GC) NULL;
5170 windows->font_info=(XFontStruct *) NULL;
5171 windows->icon_pixel->annotate_context=(GC) NULL;
5172 windows->icon_pixel->pixels=(unsigned long *) NULL;
5176 *windows->icon_resources=(*resource_info);
5177 windows->icon_resources->visual_type=(char *) "default";
5178 windows->icon_resources->colormap=SharedColormap;
5179 windows->visual_info=
5180 XBestVisualInfo(display,windows->map_info,resource_info);
5181 windows->icon_visual=
5182 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5183 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5184 (windows->icon_visual == (XVisualInfo *) NULL))
5185 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5186 resource_info->visual_type);
5187 if (IsEventLogging())
5189 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5190 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5191 windows->visual_info->visualid);
5192 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5193 XVisualClassName(windows->visual_info->klass));
5194 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5195 windows->visual_info->depth);
5196 (void) LogMagickEvent(X11Event,GetMagickModule(),
5197 " size of colormap: %d entries",windows->visual_info->colormap_size);
5198 (void) LogMagickEvent(X11Event,GetMagickModule(),
5199 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5200 windows->visual_info->red_mask,windows->visual_info->green_mask,
5201 windows->visual_info->blue_mask);
5202 (void) LogMagickEvent(X11Event,GetMagickModule(),
5203 " significant bits in color: %d bits",
5204 windows->visual_info->bits_per_rgb);
5207 Allocate class and manager hints.
5209 windows->class_hints=XAllocClassHint();
5210 windows->manager_hints=XAllocWMHints();
5211 if ((windows->class_hints == (XClassHint *) NULL) ||
5212 (windows->manager_hints == (XWMHints *) NULL))
5213 ThrowXWindowFatalException(ResourceLimitFatalError,
5214 "MemoryAllocationFailed","...");
5216 Determine group leader if we have one.
5218 root_window=XRootWindow(display,windows->visual_info->screen);
5219 windows->group_leader.id=(Window) NULL;
5220 if (resource_info->window_group != (char *) NULL)
5222 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5223 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5224 strtol((char *) resource_info->window_group,(char **) NULL,0));
5225 if (windows->group_leader.id == (Window) NULL)
5226 windows->group_leader.id=
5227 XWindowByName(display,root_window,resource_info->window_group);
5233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5237 % X M a k e C u r s o r %
5241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5243 % XMakeCursor() creates a crosshairs X11 cursor.
5245 % The format of the XMakeCursor method is:
5247 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5248 % char *background_color,char *foreground_color)
5250 % A description of each parameter follows:
5252 % o display: Specifies a connection to an X server; returned from
5255 % o window: Specifies the ID of the window for which the cursor is
5258 % o colormap: Specifies the ID of the colormap from which the background
5259 % and foreground color will be retrieved.
5261 % o background_color: Specifies the color to use for the cursor background.
5263 % o foreground_color: Specifies the color to use for the cursor foreground.
5266 MagickExport Cursor XMakeCursor(Display *display,Window window,
5267 Colormap colormap,char *background_color,char *foreground_color)
5269 #define scope_height 17
5270 #define scope_x_hot 8
5271 #define scope_y_hot 8
5272 #define scope_width 17
5274 static const unsigned char
5277 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5278 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5279 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5280 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5281 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5285 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5286 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5287 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5288 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5289 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5303 assert(display != (Display *) NULL);
5304 assert(window != (Window) NULL);
5305 assert(colormap != (Colormap) NULL);
5306 assert(background_color != (char *) NULL);
5307 assert(foreground_color != (char *) NULL);
5308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5309 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5311 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5312 scope_width,scope_height);
5313 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5315 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5316 return((Cursor) NULL);
5318 (void) XParseColor(display,colormap,background_color,&background);
5319 (void) XParseColor(display,colormap,foreground_color,&foreground);
5320 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5321 scope_x_hot,scope_y_hot);
5322 (void) XFreePixmap(display,source);
5323 (void) XFreePixmap(display,mask);
5328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5332 % X M a k e I m a g e %
5336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5338 % XMakeImage() creates an X11 image. If the image size differs from the X11
5339 % image size, the image is first resized.
5341 % The format of the XMakeImage method is:
5343 % MagickBooleanType XMakeImage(Display *display,
5344 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5345 % unsigned int width,unsigned int height)
5347 % A description of each parameter follows:
5349 % o display: Specifies a connection to an X server; returned from
5352 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5354 % o window: Specifies a pointer to a XWindowInfo structure.
5356 % o image: the image.
5358 % o width: Specifies the width in pixels of the rectangular area to
5361 % o height: Specifies the height in pixels of the rectangular area to
5365 MagickExport MagickBooleanType XMakeImage(Display *display,
5366 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5367 unsigned int width,unsigned int height)
5369 #define CheckOverflowException(length,width,height) \
5370 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5383 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5384 assert(display != (Display *) NULL);
5385 assert(resource_info != (XResourceInfo *) NULL);
5386 assert(window != (XWindowInfo *) NULL);
5388 assert(height != 0);
5389 if ((window->width == 0) || (window->height == 0))
5390 return(MagickFalse);
5392 Apply user transforms to the image.
5394 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5395 (void) XFlush(display);
5396 depth=(int) window->depth;
5397 if (window->destroy)
5398 window->image=DestroyImage(window->image);
5399 window->image=image;
5400 window->destroy=MagickFalse;
5401 if (window->image != (Image *) NULL)
5403 if (window->crop_geometry != (char *) NULL)
5414 window->image->page.x=0;
5415 window->image->page.y=0;
5416 (void) ParsePageGeometry(window->image,window->crop_geometry,
5417 &crop_info,&image->exception);
5418 crop_image=CropImage(window->image,&crop_info,&image->exception);
5419 if (crop_image != (Image *) NULL)
5421 if (window->image != image)
5422 window->image=DestroyImage(window->image);
5423 window->image=crop_image;
5424 window->destroy=MagickTrue;
5427 if ((width != (unsigned int) window->image->columns) ||
5428 (height != (unsigned int) window->image->rows))
5436 resize_image=NewImageList();
5437 if (window->pixel_info->colors != 0)
5438 resize_image=SampleImage(window->image,width,height,
5441 resize_image=ThumbnailImage(window->image,width,height,
5443 if (resize_image != (Image *) NULL)
5445 if (window->image != image)
5446 window->image=DestroyImage(window->image);
5447 window->image=resize_image;
5448 window->destroy=MagickTrue;
5451 width=(unsigned int) window->image->columns;
5452 assert((size_t) width == window->image->columns);
5453 height=(unsigned int) window->image->rows;
5454 assert((size_t) height == window->image->rows);
5459 ximage=(XImage *) NULL;
5460 format=(depth == 1) ? XYBitmap : ZPixmap;
5461 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5462 if (window->shared_memory != MagickFalse)
5467 segment_info=(XShmSegmentInfo *) window->segment_info;
5468 segment_info[1].shmid=(-1);
5469 segment_info[1].shmaddr=(char *) NULL;
5470 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5471 (char *) NULL,&segment_info[1],width,height);
5472 if (ximage == (XImage *) NULL)
5473 window->shared_memory=MagickFalse;
5474 length=(size_t) ximage->bytes_per_line*ximage->height;
5475 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5476 window->shared_memory=MagickFalse;
5477 if (window->shared_memory != MagickFalse)
5478 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5479 if (window->shared_memory != MagickFalse)
5480 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5481 if (segment_info[1].shmid < 0)
5482 window->shared_memory=MagickFalse;
5483 if (window->shared_memory != MagickFalse)
5484 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5487 if (ximage != (XImage *) NULL)
5488 XDestroyImage(ximage);
5489 ximage=(XImage *) NULL;
5490 if (segment_info[1].shmaddr)
5492 (void) shmdt(segment_info[1].shmaddr);
5493 segment_info[1].shmaddr=(char *) NULL;
5495 if (segment_info[1].shmid >= 0)
5497 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5498 segment_info[1].shmid=(-1);
5504 Allocate X image pixel data.
5506 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5507 if (window->shared_memory)
5515 (void) XSync(display,MagickFalse);
5516 xerror_alert=MagickFalse;
5517 segment_info=(XShmSegmentInfo *) window->segment_info;
5518 ximage->data=segment_info[1].shmaddr;
5519 segment_info[1].readOnly=MagickFalse;
5520 status=XShmAttach(display,&segment_info[1]);
5521 if (status != False)
5522 (void) XSync(display,MagickFalse);
5523 if ((status == False) || (xerror_alert != MagickFalse))
5525 window->shared_memory=MagickFalse;
5526 if (status != False)
5527 XShmDetach(display,&segment_info[1]);
5528 if (ximage != (XImage *) NULL)
5531 XDestroyImage(ximage);
5532 ximage=(XImage *) NULL;
5534 if (segment_info[1].shmid >= 0)
5536 if (segment_info[1].shmaddr != NULL)
5537 (void) shmdt(segment_info[1].shmaddr);
5538 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5539 segment_info[1].shmid=(-1);
5540 segment_info[1].shmaddr=(char *) NULL;
5545 if (window->shared_memory == MagickFalse)
5546 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5547 (char *) NULL,width,height,XBitmapPad(display),0);
5548 if (ximage == (XImage *) NULL)
5551 Unable to create X image.
5553 (void) XCheckDefineCursor(display,window->id,window->cursor);
5554 return(MagickFalse);
5556 length=(size_t) ximage->bytes_per_line*ximage->height;
5557 if (IsEventLogging())
5559 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5560 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5561 ximage->width,ximage->height);
5562 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5564 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5565 ximage->byte_order);
5566 (void) LogMagickEvent(X11Event,GetMagickModule(),
5567 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5568 ximage->bitmap_bit_order,ximage->bitmap_pad);
5569 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5571 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5572 ximage->bytes_per_line);
5573 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5574 ximage->bits_per_pixel);
5575 (void) LogMagickEvent(X11Event,GetMagickModule(),
5576 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5577 ximage->green_mask,ximage->blue_mask);
5579 if (window->shared_memory == MagickFalse)
5581 if (ximage->format != XYBitmap)
5582 ximage->data=(char *) AcquireQuantumMemory((size_t)
5583 ximage->bytes_per_line,(size_t) ximage->height);
5585 ximage->data=(char *) AcquireQuantumMemory((size_t)
5586 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5588 if (ximage->data == (char *) NULL)
5591 Unable to allocate pixel data.
5593 XDestroyImage(ximage);
5594 ximage=(XImage *) NULL;
5595 (void) XCheckDefineCursor(display,window->id,window->cursor);
5596 return(MagickFalse);
5598 if (window->ximage != (XImage *) NULL)
5601 Destroy previous X image.
5603 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5604 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5605 if (window->segment_info != (XShmSegmentInfo *) NULL)
5610 segment_info=(XShmSegmentInfo *) window->segment_info;
5611 if (segment_info[0].shmid >= 0)
5613 (void) XSync(display,MagickFalse);
5614 (void) XShmDetach(display,&segment_info[0]);
5615 (void) XSync(display,MagickFalse);
5616 if (segment_info[0].shmaddr != (char *) NULL)
5617 (void) shmdt(segment_info[0].shmaddr);
5618 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5619 segment_info[0].shmid=(-1);
5620 segment_info[0].shmaddr=(char *) NULL;
5621 window->ximage->data=(char *) NULL;
5625 if (window->ximage->data != (char *) NULL)
5626 free(window->ximage->data);
5627 window->ximage->data=(char *) NULL;
5628 XDestroyImage(window->ximage);
5629 window->ximage=(XImage *) NULL;
5631 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5632 if (window->segment_info != (XShmSegmentInfo *) NULL)
5637 segment_info=(XShmSegmentInfo *) window->segment_info;
5638 segment_info[0]=segment_info[1];
5641 window->ximage=ximage;
5642 matte_image=(XImage *) NULL;
5643 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5644 if ((window->image->matte != MagickFalse) &&
5645 ((ssize_t) width <= XDisplayWidth(display,window->screen)) &&
5646 ((ssize_t) height <= XDisplayHeight(display,window->screen)))
5651 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5652 (char *) NULL,width,height,XBitmapPad(display),0);
5653 if (IsEventLogging())
5655 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5656 (void) LogMagickEvent(X11Event,GetMagickModule(),
5657 " width, height: %dx%d",matte_image->width,matte_image->height);
5659 if (matte_image != (XImage *) NULL)
5662 Allocate matte image pixel data.
5664 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5665 matte_image->bytes_per_line*matte_image->depth,
5666 (size_t) matte_image->height);
5667 if (matte_image->data == (char *) NULL)
5669 XDestroyImage(matte_image);
5670 matte_image=(XImage *) NULL;
5674 if (window->matte_image != (XImage *) NULL)
5679 if (window->matte_image->data != (char *) NULL)
5680 free(window->matte_image->data);
5681 window->matte_image->data=(char *) NULL;
5682 XDestroyImage(window->matte_image);
5683 window->matte_image=(XImage *) NULL;
5685 window->matte_image=matte_image;
5686 if (window->matte_pixmap != (Pixmap) NULL)
5688 (void) XFreePixmap(display,window->matte_pixmap);
5689 window->matte_pixmap=(Pixmap) NULL;
5690 #if defined(MAGICKCORE_HAVE_SHAPE)
5691 if (window->shape != MagickFalse)
5692 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5695 window->stasis=MagickFalse;
5697 Convert pixels to X image data.
5699 if (window->image != (Image *) NULL)
5701 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5702 (ximage->bitmap_bit_order == LSBFirst)))
5703 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5706 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5709 if (window->matte_image != (XImage *) NULL)
5712 Create matte pixmap.
5714 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5715 if (window->matte_pixmap != (Pixmap) NULL)
5724 Copy matte image to matte pixmap.
5726 context_values.background=1;
5727 context_values.foreground=0;
5728 graphics_context=XCreateGC(display,window->matte_pixmap,
5729 (size_t) (GCBackground | GCForeground),&context_values);
5730 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5731 window->matte_image,0,0,0,0,width,height);
5732 (void) XFreeGC(display,graphics_context);
5733 #if defined(MAGICKCORE_HAVE_SHAPE)
5734 if (window->shape != MagickFalse)
5735 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5736 window->matte_pixmap,ShapeSet);
5740 (void) XMakePixmap(display,resource_info,window);
5744 (void) XCheckDefineCursor(display,window->id,window->cursor);
5749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5753 + X M a k e I m a g e L S B F i r s t %
5757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5759 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5760 % pixels are copied in least-significant bit and byte first order. The
5761 % server's scanline pad is respected. Rather than using one or two general
5762 % cases, many special cases are found here to help speed up the image
5765 % The format of the XMakeImageLSBFirst method is:
5767 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5769 % A description of each parameter follows:
5771 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5773 % o window: Specifies a pointer to a XWindowInfo structure.
5775 % o image: the image.
5777 % o ximage: Specifies a pointer to a XImage structure; returned from
5780 % o matte_image: Specifies a pointer to a XImage structure; returned from
5784 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5785 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5793 register const IndexPacket
5796 register const PixelPacket
5802 register unsigned char
5819 assert(resource_info != (XResourceInfo *) NULL);
5820 assert(window != (XWindowInfo *) NULL);
5821 assert(image != (Image *) NULL);
5822 if (image->debug != MagickFalse)
5823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5825 if ((window->immutable == MagickFalse) &&
5826 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5829 size[MaxTextExtent];
5837 image_info=AcquireImageInfo();
5838 (void) CopyMagickString(image_info->filename,
5839 resource_info->image_info->texture != (char *) NULL ?
5840 resource_info->image_info->texture : "pattern:checkerboard",
5842 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
5843 image->columns,(double) image->rows);
5844 image_info->size=ConstantString(size);
5845 pattern=ReadImage(image_info,&image->exception);
5846 image_info=DestroyImageInfo(image_info);
5847 if (pattern != (Image *) NULL)
5849 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5850 if (canvas != (Image *) NULL)
5851 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5852 pattern=DestroyImage(pattern);
5855 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5856 ximage->bits_per_pixel) >> 3));
5857 map_info=window->map_info;
5858 pixels=window->pixel_info->pixels;
5859 q=(unsigned char *) ximage->data;
5861 if (ximage->format == XYBitmap)
5863 register unsigned short
5871 Convert canvas to big-endian bitmap.
5873 background=(unsigned char)
5874 (XPixelIntensity(&window->pixel_info->foreground_color) <
5875 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5876 foreground=(unsigned char)
5877 (XPixelIntensity(&window->pixel_info->background_color) <
5878 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5879 polarity=(unsigned short) ((PixelIntensityToQuantum(
5880 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5881 if (canvas->colors == 2)
5882 polarity=PixelIntensity(&canvas->colormap[0]) <
5883 PixelIntensity(&canvas->colormap[1]);
5884 for (y=0; y < (int) canvas->rows; y++)
5886 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5887 if (p == (const PixelPacket *) NULL)
5889 indexes=GetVirtualIndexQueue(canvas);
5892 for (x=0; x < (int) canvas->columns; x++)
5895 if (indexes[x] == (IndexPacket) polarity)
5913 if (window->pixel_info->colors != 0)
5914 switch (ximage->bits_per_pixel)
5918 register unsigned int
5922 Convert to 2 bit color-mapped X canvas.
5924 for (y=0; y < (int) canvas->rows; y++)
5926 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5927 if (p == (const PixelPacket *) NULL)
5929 indexes=GetVirtualIndexQueue(canvas);
5931 for (x=0; x < (int) canvas->columns; x++)
5933 pixel=pixels[(ssize_t) indexes[x]] & 0x0f;
5938 *q=(unsigned char) pixel;
5944 *q|=(unsigned char) (pixel << 2);
5950 *q|=(unsigned char) (pixel << 4);
5956 *q|=(unsigned char) (pixel << 6);
5969 register unsigned int
5973 Convert to 4 bit color-mapped X canvas.
5975 for (y=0; y < (int) canvas->rows; y++)
5977 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5978 if (p == (const PixelPacket *) NULL)
5980 indexes=GetVirtualIndexQueue(canvas);
5982 for (x=0; x < (int) canvas->columns; x++)
5984 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
5989 *q=(unsigned char) pixel;
5995 *q|=(unsigned char) (pixel << 4);
6010 Convert to 8 bit color-mapped X canvas.
6012 if (resource_info->color_recovery &&
6013 resource_info->quantize_info->dither)
6015 XDitherImage(canvas,ximage);
6018 for (y=0; y < (int) canvas->rows; y++)
6020 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6021 if (p == (const PixelPacket *) NULL)
6023 indexes=GetVirtualIndexQueue(canvas);
6024 for (x=0; x < (int) canvas->columns; x++)
6026 pixel=pixels[(ssize_t) indexes[x]];
6027 *q++=(unsigned char) pixel;
6038 register unsigned int
6042 channel[sizeof(size_t)];
6045 Convert to multi-byte color-mapped X canvas.
6047 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6048 for (y=0; y < (int) canvas->rows; y++)
6050 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6051 if (p == (const PixelPacket *) NULL)
6053 indexes=GetVirtualIndexQueue(canvas);
6054 for (x=0; x < (int) canvas->columns; x++)
6056 pixel=pixels[(ssize_t) indexes[x]];
6057 for (k=0; k < (int) bytes_per_pixel; k++)
6059 channel[k]=(unsigned char) pixel;
6062 for (k=0; k < (int) bytes_per_pixel; k++)
6071 switch (ximage->bits_per_pixel)
6075 register unsigned int
6079 Convert to contiguous 2 bit continuous-tone X canvas.
6081 for (y=0; y < (int) canvas->rows; y++)
6084 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6085 if (p == (const PixelPacket *) NULL)
6087 for (x=0; x < (int) canvas->columns; x++)
6089 pixel=XGammaPixel(map_info,p);
6095 *q=(unsigned char) pixel;
6101 *q|=(unsigned char) (pixel << 2);
6107 *q|=(unsigned char) (pixel << 4);
6113 *q|=(unsigned char) (pixel << 6);
6127 register unsigned int
6131 Convert to contiguous 4 bit continuous-tone X canvas.
6133 for (y=0; y < (int) canvas->rows; y++)
6135 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6136 if (p == (const PixelPacket *) NULL)
6139 for (x=0; x < (int) canvas->columns; x++)
6141 pixel=XGammaPixel(map_info,p);
6147 *q=(unsigned char) pixel;
6153 *q|=(unsigned char) (pixel << 4);
6169 Convert to contiguous 8 bit continuous-tone X canvas.
6171 if (resource_info->color_recovery &&
6172 resource_info->quantize_info->dither)
6174 XDitherImage(canvas,ximage);
6177 for (y=0; y < (int) canvas->rows; y++)
6179 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6180 if (p == (const PixelPacket *) NULL)
6182 for (x=0; x < (int) canvas->columns; x++)
6184 pixel=XGammaPixel(map_info,p);
6185 *q++=(unsigned char) pixel;
6194 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6195 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6196 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6197 (map_info->blue_mult == 1))
6200 Convert to 32 bit continuous-tone X canvas.
6202 for (y=0; y < (int) canvas->rows; y++)
6204 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6205 &canvas->exception);
6206 if (p == (const PixelPacket *) NULL)
6208 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6209 (blue_gamma != 1.0))
6212 Gamma correct canvas.
6214 for (x=(int) canvas->columns-1; x >= 0; x--)
6216 *q++=ScaleQuantumToChar(XBlueGamma(
6217 GetBluePixelComponent(p)));
6218 *q++=ScaleQuantumToChar(XGreenGamma(
6219 GetGreenPixelComponent(p)));
6220 *q++=ScaleQuantumToChar(XRedGamma(
6221 GetRedPixelComponent(p)));
6227 for (x=(int) canvas->columns-1; x >= 0; x--)
6229 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6230 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6231 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6238 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6239 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6240 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6241 (map_info->blue_mult == 65536L))
6244 Convert to 32 bit continuous-tone X canvas.
6246 for (y=0; y < (int) canvas->rows; y++)
6248 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6249 &canvas->exception);
6250 if (p == (const PixelPacket *) NULL)
6252 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6253 (blue_gamma != 1.0))
6256 Gamma correct canvas.
6258 for (x=(int) canvas->columns-1; x >= 0; x--)
6260 *q++=ScaleQuantumToChar(XRedGamma(
6261 GetRedPixelComponent(p)));
6262 *q++=ScaleQuantumToChar(XGreenGamma(
6263 GetGreenPixelComponent(p)));
6264 *q++=ScaleQuantumToChar(XBlueGamma(
6265 GetBluePixelComponent(p)));
6271 for (x=(int) canvas->columns-1; x >= 0; x--)
6273 *q++=ScaleQuantumToChar((Quantum)
6274 GetRedPixelComponent(p));
6275 *q++=ScaleQuantumToChar((Quantum)
6276 GetGreenPixelComponent(p));
6277 *q++=ScaleQuantumToChar((Quantum)
6278 GetBluePixelComponent(p));
6289 register unsigned int
6293 channel[sizeof(size_t)];
6296 Convert to multi-byte continuous-tone X canvas.
6298 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6299 for (y=0; y < (int) canvas->rows; y++)
6301 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6302 &canvas->exception);
6303 if (p == (PixelPacket *) NULL)
6305 for (x=0; x < (ssize_t) canvas->columns; x++)
6307 pixel=XGammaPixel(map_info,p);
6308 for (k=0; k < (int) bytes_per_pixel; k++)
6310 channel[k]=(unsigned char) pixel;
6313 for (k=0; k < (int) bytes_per_pixel; k++)
6323 if (matte_image != (XImage *) NULL)
6326 Initialize matte canvas.
6328 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6329 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6330 q=(unsigned char *) matte_image->data;
6331 for (y=0; y < (int) canvas->rows; y++)
6333 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6334 if (p == (const PixelPacket *) NULL)
6338 for (x=(int) canvas->columns-1; x >= 0; x--)
6341 if (p->opacity > (ssize_t) (QuantumRange/2))
6357 if (canvas != image)
6358 canvas=DestroyImage(canvas);
6362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6366 + X M a k e I m a g e M S B F i r s t %
6370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6372 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6373 % image pixels are copied in most-significant bit and byte first order. The
6374 % server's scanline pad is also respected. Rather than using one or two
6375 % general cases, many special cases are found here to help speed up the image
6378 % The format of the XMakeImageMSBFirst method is:
6380 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6382 % A description of each parameter follows:
6384 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6386 % o window: Specifies a pointer to a XWindowInfo structure.
6388 % o image: the image.
6390 % o ximage: Specifies a pointer to a XImage structure; returned from
6393 % o matte_image: Specifies a pointer to a XImage structure; returned from
6397 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6398 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6409 register const IndexPacket
6412 register const PixelPacket
6415 register unsigned char
6432 assert(resource_info != (XResourceInfo *) NULL);
6433 assert(window != (XWindowInfo *) NULL);
6434 assert(image != (Image *) NULL);
6435 if (image->debug != MagickFalse)
6436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6438 if ((window->immutable != MagickFalse) &&
6439 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6442 size[MaxTextExtent];
6450 image_info=AcquireImageInfo();
6451 (void) CopyMagickString(image_info->filename,
6452 resource_info->image_info->texture != (char *) NULL ?
6453 resource_info->image_info->texture : "pattern:checkerboard",
6455 (void) FormatMagickString(size,MaxTextExtent,"%.20gx%.20g",(double)
6456 image->columns,(double) image->rows);
6457 image_info->size=ConstantString(size);
6458 pattern=ReadImage(image_info,&image->exception);
6459 image_info=DestroyImageInfo(image_info);
6460 if (pattern != (Image *) NULL)
6462 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6463 if (canvas != (Image *) NULL)
6464 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6465 pattern=DestroyImage(pattern);
6468 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6469 ((ximage->width*ximage->bits_per_pixel) >> 3));
6470 map_info=window->map_info;
6471 pixels=window->pixel_info->pixels;
6472 q=(unsigned char *) ximage->data;
6474 if (ximage->format == XYBitmap)
6476 register unsigned short
6484 Convert canvas to big-endian bitmap.
6486 background=(unsigned char)
6487 (XPixelIntensity(&window->pixel_info->foreground_color) <
6488 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6489 foreground=(unsigned char)
6490 (XPixelIntensity(&window->pixel_info->background_color) <
6491 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6492 polarity=(unsigned short) ((PixelIntensityToQuantum(
6493 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6494 if (canvas->colors == 2)
6495 polarity=PixelIntensity(&canvas->colormap[0]) <
6496 PixelIntensity(&canvas->colormap[1]);
6497 for (y=0; y < (int) canvas->rows; y++)
6499 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6500 if (p == (const PixelPacket *) NULL)
6502 indexes=GetVirtualIndexQueue(canvas);
6505 for (x=(int) canvas->columns-1; x >= 0; x--)
6508 if (indexes[x] == (IndexPacket) polarity)
6526 if (window->pixel_info->colors != 0)
6527 switch (ximage->bits_per_pixel)
6531 register unsigned int
6535 Convert to 2 bit color-mapped X canvas.
6537 for (y=0; y < (int) canvas->rows; y++)
6539 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6540 if (p == (const PixelPacket *) NULL)
6542 indexes=GetVirtualIndexQueue(canvas);
6544 for (x=0; x < (int) canvas->columns; x++)
6546 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6551 *q=(unsigned char) (pixel << 6);
6557 *q|=(unsigned char) (pixel << 4);
6563 *q|=(unsigned char) (pixel << 2);
6569 *q|=(unsigned char) pixel;
6582 register unsigned int
6586 Convert to 4 bit color-mapped X canvas.
6588 for (y=0; y < (int) canvas->rows; y++)
6590 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6591 if (p == (const PixelPacket *) NULL)
6593 indexes=GetVirtualIndexQueue(canvas);
6595 for (x=0; x < (int) canvas->columns; x++)
6597 pixel=pixels[(ssize_t) indexes[x]] & 0xf;
6602 *q=(unsigned char) (pixel << 4);
6608 *q|=(unsigned char) pixel;
6623 Convert to 8 bit color-mapped X canvas.
6625 if (resource_info->color_recovery &&
6626 resource_info->quantize_info->dither)
6628 XDitherImage(canvas,ximage);
6631 for (y=0; y < (int) canvas->rows; y++)
6633 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6634 if (p == (const PixelPacket *) NULL)
6636 indexes=GetVirtualIndexQueue(canvas);
6637 for (x=0; x < (int) canvas->columns; x++)
6639 pixel=pixels[(ssize_t) indexes[x]];
6640 *q++=(unsigned char) pixel;
6651 register unsigned int
6655 channel[sizeof(size_t)];
6658 Convert to 8 bit color-mapped X canvas.
6660 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6661 for (y=0; y < (int) canvas->rows; y++)
6663 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6664 if (p == (const PixelPacket *) NULL)
6666 indexes=GetVirtualIndexQueue(canvas);
6667 for (x=0; x < (int) canvas->columns; x++)
6669 pixel=pixels[(ssize_t) indexes[x]];
6670 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6672 channel[k]=(unsigned char) pixel;
6675 for (k=0; k < (int) bytes_per_pixel; k++)
6684 switch (ximage->bits_per_pixel)
6688 register unsigned int
6692 Convert to 4 bit continuous-tone X canvas.
6694 for (y=0; y < (int) canvas->rows; y++)
6696 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6697 if (p == (const PixelPacket *) NULL)
6700 for (x=(int) canvas->columns-1; x >= 0; x--)
6702 pixel=XGammaPixel(map_info,p);
6708 *q=(unsigned char) (pixel << 6);
6714 *q|=(unsigned char) (pixel << 4);
6720 *q|=(unsigned char) (pixel << 2);
6726 *q|=(unsigned char) pixel;
6740 register unsigned int
6744 Convert to 4 bit continuous-tone X canvas.
6746 for (y=0; y < (int) canvas->rows; y++)
6748 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6749 if (p == (const PixelPacket *) NULL)
6752 for (x=(int) canvas->columns-1; x >= 0; x--)
6754 pixel=XGammaPixel(map_info,p);
6760 *q=(unsigned char) (pixel << 4);
6766 *q|=(unsigned char) pixel;
6782 Convert to 8 bit continuous-tone X canvas.
6784 if (resource_info->color_recovery &&
6785 resource_info->quantize_info->dither)
6787 XDitherImage(canvas,ximage);
6790 for (y=0; y < (int) canvas->rows; y++)
6792 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6793 if (p == (const PixelPacket *) NULL)
6795 for (x=(int) canvas->columns-1; x >= 0; x--)
6797 pixel=XGammaPixel(map_info,p);
6798 *q++=(unsigned char) pixel;
6807 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6808 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6809 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6810 (map_info->blue_mult == 1))
6813 Convert to 32 bit continuous-tone X canvas.
6815 for (y=0; y < (int) canvas->rows; y++)
6817 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6818 &canvas->exception);
6819 if (p == (const PixelPacket *) NULL)
6821 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6822 (blue_gamma != 1.0))
6825 Gamma correct canvas.
6827 for (x=(int) canvas->columns-1; x >= 0; x--)
6830 *q++=ScaleQuantumToChar(XRedGamma(
6831 GetRedPixelComponent(p)));
6832 *q++=ScaleQuantumToChar(XGreenGamma(
6833 GetGreenPixelComponent(p)));
6834 *q++=ScaleQuantumToChar(XBlueGamma(
6835 GetBluePixelComponent(p)));
6840 for (x=(int) canvas->columns-1; x >= 0; x--)
6843 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6844 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6845 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6851 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6852 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6853 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6854 (map_info->blue_mult == 65536L))
6857 Convert to 32 bit continuous-tone X canvas.
6859 for (y=0; y < (int) canvas->rows; y++)
6861 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6862 &canvas->exception);
6863 if (p == (const PixelPacket *) NULL)
6865 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6866 (blue_gamma != 1.0))
6869 Gamma correct canvas.
6871 for (x=(int) canvas->columns-1; x >= 0; x--)
6874 *q++=ScaleQuantumToChar(XBlueGamma(
6875 GetBluePixelComponent(p)));
6876 *q++=ScaleQuantumToChar(XGreenGamma(
6877 GetGreenPixelComponent(p)));
6878 *q++=ScaleQuantumToChar(XRedGamma(
6879 GetRedPixelComponent(p)));
6884 for (x=(int) canvas->columns-1; x >= 0; x--)
6887 *q++=ScaleQuantumToChar((Quantum)
6888 GetBluePixelComponent(p));
6889 *q++=ScaleQuantumToChar((Quantum)
6890 GetGreenPixelComponent(p));
6891 *q++=ScaleQuantumToChar((Quantum)
6892 GetRedPixelComponent(p));
6902 register unsigned int
6906 channel[sizeof(size_t)];
6909 Convert to multi-byte continuous-tone X canvas.
6911 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6912 for (y=0; y < (int) canvas->rows; y++)
6914 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6915 &canvas->exception);
6916 if (p == (const PixelPacket *) NULL)
6918 for (x=(int) canvas->columns-1; x >= 0; x--)
6920 pixel=XGammaPixel(map_info,p);
6921 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6923 channel[k]=(unsigned char) pixel;
6926 for (k=0; k < (int) bytes_per_pixel; k++)
6936 if (matte_image != (XImage *) NULL)
6939 Initialize matte canvas.
6941 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6942 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6943 q=(unsigned char *) matte_image->data;
6944 for (y=0; y < (int) canvas->rows; y++)
6946 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6947 if (p == (const PixelPacket *) NULL)
6951 for (x=(int) canvas->columns-1; x >= 0; x--)
6954 if (p->opacity > (ssize_t) (QuantumRange/2))
6970 if (canvas != image)
6971 canvas=DestroyImage(canvas);
6975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6979 % X M a k e M a g n i f y I m a g e %
6983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6985 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
6987 % The format of the XMakeMagnifyImage method is:
6989 % void XMakeMagnifyImage(display,windows)
6991 % A description of each parameter follows:
6993 % o display: Specifies a connection to an X server; returned from
6996 % o windows: Specifies a pointer to a XWindows structure.
6999 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7002 tuple[MaxTextExtent];
7019 register unsigned char
7024 previous_magnify = 0;
7042 Check boundary conditions.
7044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7045 assert(display != (Display *) NULL);
7046 assert(windows != (XWindows *) NULL);
7048 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7050 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7052 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7054 while (magnify > windows->magnify.width)
7056 while (magnify > windows->magnify.height)
7058 if (magnify != previous_magnify)
7067 New magnify factor: update magnify window name.
7070 while ((1 << i) <= (int) magnify)
7072 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7073 "Magnify %.20gX",(double) i);
7074 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7075 if (status != False)
7077 XSetWMName(display,windows->magnify.id,&window_name);
7078 XSetWMIconName(display,windows->magnify.id,&window_name);
7079 (void) XFree((void *) window_name.value);
7082 previous_magnify=magnify;
7083 ximage=windows->image.ximage;
7084 width=(unsigned int) windows->magnify.ximage->width;
7085 height=(unsigned int) windows->magnify.ximage->height;
7086 if ((windows->magnify.x < 0) ||
7087 (windows->magnify.x >= windows->image.ximage->width))
7088 windows->magnify.x=windows->image.ximage->width >> 1;
7089 x=windows->magnify.x-((width/magnify) >> 1);
7093 if (x > (int) (ximage->width-(width/magnify)))
7094 x=ximage->width-width/magnify;
7095 if ((windows->magnify.y < 0) ||
7096 (windows->magnify.y >= windows->image.ximage->height))
7097 windows->magnify.y=windows->image.ximage->height >> 1;
7098 y=windows->magnify.y-((height/magnify) >> 1);
7102 if (y > (int) (ximage->height-(height/magnify)))
7103 y=ximage->height-height/magnify;
7104 q=(unsigned char *) windows->magnify.ximage->data;
7105 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7106 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7107 if (ximage->bits_per_pixel < 8)
7109 register unsigned char
7116 register unsigned int
7122 pixel_info=windows->magnify.pixel_info;
7123 switch (ximage->bitmap_bit_order)
7128 Magnify little-endian bitmap.
7132 if (ximage->format == XYBitmap)
7134 background=(unsigned char)
7135 (XPixelIntensity(&pixel_info->foreground_color) <
7136 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7137 foreground=(unsigned char)
7138 (XPixelIntensity(&pixel_info->background_color) <
7139 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7140 if (windows->magnify.depth > 1)
7141 Swap(background,foreground);
7143 for (i=0; i < (ssize_t) height; i+=magnify)
7146 Propogate pixel magnify rows.
7148 for (j=0; j < magnify; j++)
7150 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7151 ((x*ximage->bits_per_pixel) >> 3);
7152 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7155 for (k=0; k < width; k+=magnify)
7158 Propogate pixel magnify columns.
7160 for (l=0; l < magnify; l++)
7163 Propogate each bit plane.
7165 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7168 if (*p & (0x01 << (p_bit+plane)))
7181 p_bit+=ximage->bits_per_pixel;
7188 *q=byte >> (8-q_bit);
7200 Magnify big-endian bitmap.
7204 if (ximage->format == XYBitmap)
7206 background=(unsigned char)
7207 (XPixelIntensity(&pixel_info->foreground_color) <
7208 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7209 foreground=(unsigned char)
7210 (XPixelIntensity(&pixel_info->background_color) <
7211 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7212 if (windows->magnify.depth > 1)
7213 Swap(background,foreground);
7215 for (i=0; i < (ssize_t) height; i+=magnify)
7218 Propogate pixel magnify rows.
7220 for (j=0; j < magnify; j++)
7222 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7223 ((x*ximage->bits_per_pixel) >> 3);
7224 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7227 for (k=0; k < width; k+=magnify)
7230 Propogate pixel magnify columns.
7232 for (l=0; l < magnify; l++)
7235 Propogate each bit plane.
7237 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7240 if (*p & (0x80 >> (p_bit+plane)))
7253 p_bit+=ximage->bits_per_pixel;
7260 *q=byte << (8-q_bit);
7271 switch (ximage->bits_per_pixel)
7277 Magnify 8 bit X image.
7279 for (i=0; i < (ssize_t) height; i+=magnify)
7282 Propogate pixel magnify rows.
7284 for (j=0; j < magnify; j++)
7286 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7287 ((x*ximage->bits_per_pixel) >> 3);
7288 for (k=0; k < width; k+=magnify)
7291 Propogate pixel magnify columns.
7293 for (l=0; l < magnify; l++)
7305 register unsigned int
7310 Magnify multi-byte X image.
7312 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7313 for (i=0; i < (ssize_t) height; i+=magnify)
7316 Propogate pixel magnify rows.
7318 for (j=0; j < magnify; j++)
7320 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7321 ((x*ximage->bits_per_pixel) >> 3);
7322 for (k=0; k < width; k+=magnify)
7325 Propogate pixel magnify columns.
7327 for (l=0; l < magnify; l++)
7328 for (m=0; m < bytes_per_pixel; m++)
7340 Copy X image to magnify pixmap.
7342 x=windows->magnify.x-((width/magnify) >> 1);
7344 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7346 if (x > (int) (ximage->width-(width/magnify)))
7347 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7350 y=windows->magnify.y-((height/magnify) >> 1);
7352 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7354 if (y > (int) (ximage->height-(height/magnify)))
7355 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7358 if ((x != 0) || (y != 0))
7359 (void) XFillRectangle(display,windows->magnify.pixmap,
7360 windows->magnify.annotate_context,0,0,width,height);
7361 (void) XPutImage(display,windows->magnify.pixmap,
7362 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7364 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7365 (magnify <= (height >> 1))))
7371 Highlight center pixel.
7373 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7374 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7375 highlight_info.width=magnify;
7376 highlight_info.height=magnify;
7377 (void) XDrawRectangle(display,windows->magnify.pixmap,
7378 windows->magnify.highlight_context,(int) highlight_info.x,
7379 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7380 (unsigned int) highlight_info.height-1);
7382 (void) XDrawRectangle(display,windows->magnify.pixmap,
7383 windows->magnify.annotate_context,(int) highlight_info.x+1,
7384 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7385 (unsigned int) highlight_info.height-3);
7388 Show center pixel color.
7390 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7391 windows->magnify.y,&pixel,&windows->image.image->exception);
7392 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7393 windows->magnify.x,windows->magnify.y);
7394 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7395 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7396 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7397 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7398 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7399 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7400 if (pixel.colorspace == CMYKColorspace)
7402 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7403 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7405 if (pixel.matte != MagickFalse)
7407 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7408 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7410 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7411 height=(unsigned int) windows->magnify.font_info->ascent+
7412 windows->magnify.font_info->descent;
7413 x=windows->magnify.font_info->max_bounds.width >> 1;
7414 y=windows->magnify.font_info->ascent+(height >> 2);
7415 (void) XDrawImageString(display,windows->magnify.pixmap,
7416 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7417 GetColorTuple(&pixel,MagickTrue,tuple);
7419 (void) XDrawImageString(display,windows->magnify.pixmap,
7420 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7421 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7422 &windows->image.image->exception);
7424 (void) XDrawImageString(display,windows->magnify.pixmap,
7425 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7427 Refresh magnify window.
7429 magnify_window=windows->magnify;
7432 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7440 % X M a k e P i x m a p %
7444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7446 % XMakePixmap() creates an X11 pixmap.
7448 % The format of the XMakePixmap method is:
7450 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7451 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7452 % XPixelInfo *pixel)
7454 % A description of each parameter follows:
7456 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7458 % o display: Specifies a connection to an X server; returned from
7461 % o window: Specifies a pointer to a XWindowInfo structure.
7464 static MagickBooleanType XMakePixmap(Display *display,
7465 const XResourceInfo *resource_info,XWindowInfo *window)
7471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7472 assert(display != (Display *) NULL);
7473 assert(resource_info != (XResourceInfo *) NULL);
7474 assert(window != (XWindowInfo *) NULL);
7475 if (window->pixmap != (Pixmap) NULL)
7478 Destroy previous X pixmap.
7480 (void) XFreePixmap(display,window->pixmap);
7481 window->pixmap=(Pixmap) NULL;
7483 if (window->use_pixmap == MagickFalse)
7484 return(MagickFalse);
7485 if (window->ximage == (XImage *) NULL)
7486 return(MagickFalse);
7488 Display busy cursor.
7490 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7491 (void) XFlush(display);
7495 width=(unsigned int) window->ximage->width;
7496 height=(unsigned int) window->ximage->height;
7497 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7498 if (window->pixmap == (Pixmap) NULL)
7501 Unable to allocate pixmap.
7503 (void) XCheckDefineCursor(display,window->id,window->cursor);
7504 return(MagickFalse);
7507 Copy X image to pixmap.
7509 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7510 if (window->shared_memory)
7511 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7512 window->ximage,0,0,0,0,width,height,MagickTrue);
7514 if (window->shared_memory == MagickFalse)
7515 (void) XPutImage(display,window->pixmap,window->annotate_context,
7516 window->ximage,0,0,0,0,width,height);
7517 if (IsEventLogging())
7519 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7520 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7526 (void) XCheckDefineCursor(display,window->id,window->cursor);
7531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7535 % X M a k e S t a n d a r d C o l o r m a p %
7539 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7541 % XMakeStandardColormap() creates an X11 Standard Colormap.
7543 % The format of the XMakeStandardColormap method is:
7545 % XMakeStandardColormap(display,visual_info,resource_info,image,
7548 % A description of each parameter follows:
7550 % o display: Specifies a connection to an X server; returned from
7553 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7554 % returned from XGetVisualInfo.
7556 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7558 % o image: the image.
7560 % o map_info: If a Standard Colormap type is specified, this structure is
7561 % initialized with info from the Standard Colormap.
7563 % o pixel: Specifies a pointer to a XPixelInfo structure.
7567 #if defined(__cplusplus) || defined(c_plusplus)
7571 static inline MagickRealType DiversityPixelIntensity(
7572 const DiversityPacket *pixel)
7577 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7581 static int IntensityCompare(const void *x,const void *y)
7590 color_1=(DiversityPacket *) x;
7591 color_2=(DiversityPacket *) y;
7592 diversity=(int) (DiversityPixelIntensity(color_2)-
7593 DiversityPixelIntensity(color_1));
7597 static int PopularityCompare(const void *x,const void *y)
7603 color_1=(DiversityPacket *) x;
7604 color_2=(DiversityPacket *) y;
7605 return((int) color_2->count-(int) color_1->count);
7608 #if defined(__cplusplus) || defined(c_plusplus)
7612 static inline Quantum ScaleXToQuantum(const size_t x,
7615 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7618 MagickExport void XMakeStandardColormap(Display *display,
7619 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7620 XStandardColormap *map_info,XPixelInfo *pixel)
7628 register IndexPacket
7649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7650 assert(display != (Display *) NULL);
7651 assert(visual_info != (XVisualInfo *) NULL);
7652 assert(map_info != (XStandardColormap *) NULL);
7653 assert(resource_info != (XResourceInfo *) NULL);
7654 assert(pixel != (XPixelInfo *) NULL);
7655 exception=(&image->exception);
7656 if (resource_info->map_type != (char *) NULL)
7659 Standard Colormap is already defined (i.e. xstdcmap).
7661 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7663 number_colors=(unsigned int) (map_info->base_pixel+
7664 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7665 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7666 if ((image->matte == MagickFalse) &&
7667 (resource_info->color_recovery == MagickFalse) &&
7668 resource_info->quantize_info->dither &&
7669 (number_colors < MaxColormapSize))
7674 register PixelPacket
7678 Improve image appearance with error diffusion.
7680 affinity_image=AcquireImage((ImageInfo *) NULL);
7681 if (affinity_image == (Image *) NULL)
7682 ThrowXWindowFatalException(ResourceLimitFatalError,
7683 "UnableToDitherImage",image->filename);
7684 affinity_image->columns=number_colors;
7685 affinity_image->rows=1;
7687 Initialize colormap image.
7689 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7691 if (q != (PixelPacket *) NULL)
7693 for (i=0; i < (ssize_t) number_colors; i++)
7696 if (map_info->red_max != 0)
7697 q->red=ScaleXToQuantum((size_t) (i/
7698 map_info->red_mult),map_info->red_max);
7699 q->green=(Quantum) 0;
7700 if (map_info->green_max != 0)
7701 q->green=ScaleXToQuantum((size_t) ((i/
7702 map_info->green_mult) % (map_info->green_max+1)),
7703 map_info->green_max);
7704 q->blue=(Quantum) 0;
7705 if (map_info->blue_max != 0)
7706 q->blue=ScaleXToQuantum((size_t) (i %
7707 map_info->green_mult),map_info->blue_max);
7708 q->opacity=(Quantum) TransparentOpacity;
7711 (void) SyncAuthenticPixels(affinity_image,exception);
7712 (void) RemapImage(resource_info->quantize_info,image,
7715 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7717 (void) SetImageStorageClass(image,DirectClass);
7718 affinity_image=DestroyImage(affinity_image);
7720 if (IsEventLogging())
7722 (void) LogMagickEvent(X11Event,GetMagickModule(),
7723 "Standard Colormap:");
7724 (void) LogMagickEvent(X11Event,GetMagickModule(),
7725 " colormap id: 0x%lx",map_info->colormap);
7726 (void) LogMagickEvent(X11Event,GetMagickModule(),
7727 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7728 map_info->green_max,map_info->blue_max);
7729 (void) LogMagickEvent(X11Event,GetMagickModule(),
7730 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7731 map_info->green_mult,map_info->blue_mult);
7735 if ((visual_info->klass != DirectColor) &&
7736 (visual_info->klass != TrueColor))
7737 if ((image->storage_class == DirectClass) ||
7738 ((int) image->colors > visual_info->colormap_size))
7744 Image has more colors than the visual supports.
7746 quantize_info=(*resource_info->quantize_info);
7747 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7748 (void) QuantizeImage(&quantize_info,image);
7751 Free previous and create new colormap.
7753 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7754 colormap=XDefaultColormap(display,visual_info->screen);
7755 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7756 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7757 visual_info->visual,visual_info->klass == DirectColor ?
7758 AllocAll : AllocNone);
7759 if (colormap == (Colormap) NULL)
7760 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7763 Initialize the map and pixel info structures.
7765 XGetMapInfo(visual_info,colormap,map_info);
7766 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7768 Allocating colors in server colormap is based on visual class.
7770 switch (visual_info->klass)
7776 Define Standard Colormap for StaticGray or StaticColor visual.
7778 number_colors=image->colors;
7779 colors=(XColor *) AcquireQuantumMemory((size_t)
7780 visual_info->colormap_size,sizeof(*colors));
7781 if (colors == (XColor *) NULL)
7782 ThrowXWindowFatalException(ResourceLimitFatalError,
7783 "UnableToCreateColormap",image->filename);
7785 color.flags=(char) (DoRed | DoGreen | DoBlue);
7786 for (i=0; i < (ssize_t) image->colors; i++)
7788 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7789 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7790 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7791 if (visual_info->klass != StaticColor)
7793 gray_value=(unsigned short) XPixelIntensity(&color);
7794 color.red=gray_value;
7795 color.green=gray_value;
7796 color.blue=gray_value;
7798 status=XAllocColor(display,colormap,&color);
7799 if (status == False)
7801 colormap=XCopyColormapAndFree(display,colormap);
7802 (void) XAllocColor(display,colormap,&color);
7804 pixel->pixels[i]=color.pixel;
7816 Define Standard Colormap for GrayScale or PseudoColor visual.
7818 number_colors=image->colors;
7819 colors=(XColor *) AcquireQuantumMemory((size_t)
7820 visual_info->colormap_size,sizeof(*colors));
7821 if (colors == (XColor *) NULL)
7822 ThrowXWindowFatalException(ResourceLimitFatalError,
7823 "UnableToCreateColormap",image->filename);
7825 Preallocate our GUI colors.
7827 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7828 (void) XAllocColor(display,colormap,&pixel->background_color);
7829 (void) XAllocColor(display,colormap,&pixel->border_color);
7830 (void) XAllocColor(display,colormap,&pixel->matte_color);
7831 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7832 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7833 (void) XAllocColor(display,colormap,&pixel->depth_color);
7834 (void) XAllocColor(display,colormap,&pixel->trough_color);
7835 for (i=0; i < MaxNumberPens; i++)
7836 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7838 Determine if image colors will "fit" into X server colormap.
7840 colormap_type=resource_info->colormap;
7841 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7842 NULL,0,pixel->pixels,(unsigned int) image->colors);
7843 if (status != False)
7844 colormap_type=PrivateColormap;
7845 if (colormap_type == SharedColormap)
7863 Define Standard colormap for shared GrayScale or PseudoColor visual.
7865 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7866 sizeof(*diversity));
7867 if (diversity == (DiversityPacket *) NULL)
7868 ThrowXWindowFatalException(ResourceLimitFatalError,
7869 "UnableToCreateColormap",image->filename);
7870 for (i=0; i < (ssize_t) image->colors; i++)
7872 diversity[i].red=image->colormap[i].red;
7873 diversity[i].green=image->colormap[i].green;
7874 diversity[i].blue=image->colormap[i].blue;
7875 diversity[i].index=(unsigned short) i;
7876 diversity[i].count=0;
7878 for (y=0; y < (int) image->rows; y++)
7883 register PixelPacket
7886 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7887 if (q == (PixelPacket *) NULL)
7889 indexes=GetAuthenticIndexQueue(image);
7890 for (x=(ssize_t) image->columns-1; x >= 0; x--)
7891 diversity[(ssize_t) indexes[x]].count++;
7894 Sort colors by decreasing intensity.
7896 qsort((void *) diversity,image->colors,sizeof(*diversity),
7898 for (i=0; i < (ssize_t) image->colors; )
7900 diversity[i].count<<=4; /* increase this colors popularity */
7901 i+=MagickMax((int) (image->colors >> 4),2);
7903 diversity[image->colors-1].count<<=4;
7904 qsort((void *) diversity,image->colors,sizeof(*diversity),
7910 color.flags=(char) (DoRed | DoGreen | DoBlue);
7911 for (i=0; i < (ssize_t) image->colors; i++)
7913 index=diversity[i].index;
7915 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7917 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7919 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7920 if (visual_info->klass != PseudoColor)
7922 gray_value=(unsigned short) XPixelIntensity(&color);
7923 color.red=gray_value;
7924 color.green=gray_value;
7925 color.blue=gray_value;
7927 status=XAllocColor(display,colormap,&color);
7928 if (status == False)
7930 pixel->pixels[index]=color.pixel;
7934 Read X server colormap.
7936 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7937 visual_info->colormap_size,sizeof(*server_colors));
7938 if (server_colors == (XColor *) NULL)
7939 ThrowXWindowFatalException(ResourceLimitFatalError,
7940 "UnableToCreateColormap",image->filename);
7941 for (x=visual_info->colormap_size-1; x >= 0; x--)
7942 server_colors[x].pixel=(size_t) x;
7943 (void) XQueryColors(display,colormap,server_colors,
7944 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7946 Select remaining colors from X server colormap.
7948 for (; i < (ssize_t) image->colors; i++)
7950 index=diversity[i].index;
7952 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7954 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7956 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7957 if (visual_info->klass != PseudoColor)
7959 gray_value=(unsigned short) XPixelIntensity(&color);
7960 color.red=gray_value;
7961 color.green=gray_value;
7962 color.blue=gray_value;
7964 XBestPixel(display,colormap,server_colors,(unsigned int)
7965 visual_info->colormap_size,&color);
7966 pixel->pixels[index]=color.pixel;
7969 if ((int) image->colors < visual_info->colormap_size)
7972 Fill up colors array-- more choices for pen colors.
7974 retain_colors=MagickMin((unsigned int)
7975 (visual_info->colormap_size-image->colors),256);
7976 for (i=0; i < (ssize_t) retain_colors; i++)
7977 *p++=server_colors[i];
7978 number_colors+=retain_colors;
7980 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
7981 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
7985 Define Standard colormap for private GrayScale or PseudoColor visual.
7987 if (status == False)
7990 Not enough colormap entries in the colormap-- Create a new colormap.
7992 colormap=XCreateColormap(display,
7993 XRootWindow(display,visual_info->screen),visual_info->visual,
7995 if (colormap == (Colormap) NULL)
7996 ThrowXWindowFatalException(ResourceLimitFatalError,
7997 "UnableToCreateColormap",image->filename);
7998 map_info->colormap=colormap;
7999 if ((int) image->colors < visual_info->colormap_size)
8002 Retain colors from the default colormap to help lessens the
8003 effects of colormap flashing.
8005 retain_colors=MagickMin((unsigned int)
8006 (visual_info->colormap_size-image->colors),256);
8007 p=colors+image->colors;
8008 for (i=0; i < (ssize_t) retain_colors; i++)
8013 (void) XQueryColors(display,
8014 XDefaultColormap(display,visual_info->screen),
8015 colors+image->colors,(int) retain_colors);
8017 Transfer colors from default to private colormap.
8019 (void) XAllocColorCells(display,colormap,MagickFalse,
8020 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8022 p=colors+image->colors;
8023 for (i=0; i < (ssize_t) retain_colors; i++)
8025 p->pixel=pixel->pixels[i];
8028 (void) XStoreColors(display,colormap,colors+image->colors,
8029 (int) retain_colors);
8030 number_colors+=retain_colors;
8032 (void) XAllocColorCells(display,colormap,MagickFalse,
8033 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8037 Store the image colormap.
8040 color.flags=(char) (DoRed | DoGreen | DoBlue);
8041 for (i=0; i < (ssize_t) image->colors; i++)
8043 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8044 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8045 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8046 if (visual_info->klass != PseudoColor)
8048 gray_value=(unsigned short) XPixelIntensity(&color);
8049 color.red=gray_value;
8050 color.green=gray_value;
8051 color.blue=gray_value;
8053 color.pixel=pixel->pixels[i];
8056 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8067 Define Standard Colormap for TrueColor or DirectColor visual.
8069 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8070 (map_info->green_max*map_info->green_mult)+
8071 (map_info->blue_max*map_info->blue_mult)+1);
8072 linear_colormap=(number_colors > 4096) ||
8073 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8074 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8075 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8076 MagickTrue : MagickFalse;
8077 if (linear_colormap != MagickFalse)
8078 number_colors=(size_t) visual_info->colormap_size;
8080 Allocate color array.
8082 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8083 if (colors == (XColor *) NULL)
8084 ThrowXWindowFatalException(ResourceLimitFatalError,
8085 "UnableToCreateColormap",image->filename);
8087 Initialize linear color ramp.
8090 color.flags=(char) (DoRed | DoGreen | DoBlue);
8091 if (linear_colormap != MagickFalse)
8092 for (i=0; i < (ssize_t) number_colors; i++)
8094 color.blue=(unsigned short) 0;
8095 if (map_info->blue_max != 0)
8096 color.blue=(unsigned short) ((size_t)
8097 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8098 color.green=color.blue;
8099 color.red=color.blue;
8100 color.pixel=XStandardPixel(map_info,&color);
8104 for (i=0; i < (ssize_t) number_colors; i++)
8106 color.red=(unsigned short) 0;
8107 if (map_info->red_max != 0)
8108 color.red=(unsigned short) ((size_t)
8109 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8110 color.green=(unsigned int) 0;
8111 if (map_info->green_max != 0)
8112 color.green=(unsigned short) ((size_t)
8113 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8114 map_info->green_max));
8115 color.blue=(unsigned short) 0;
8116 if (map_info->blue_max != 0)
8117 color.blue=(unsigned short) ((size_t)
8118 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8119 color.pixel=XStandardPixel(map_info,&color);
8122 if ((visual_info->klass == DirectColor) &&
8123 (colormap != XDefaultColormap(display,visual_info->screen)))
8124 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8126 for (i=0; i < (ssize_t) number_colors; i++)
8127 (void) XAllocColor(display,colormap,&colors[i]);
8131 if ((visual_info->klass != DirectColor) &&
8132 (visual_info->klass != TrueColor))
8135 Set foreground, background, border, etc. pixels.
8137 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8138 &pixel->foreground_color);
8139 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8140 &pixel->background_color);
8141 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8144 Foreground and background colors must differ.
8146 pixel->background_color.red=(~pixel->foreground_color.red);
8147 pixel->background_color.green=
8148 (~pixel->foreground_color.green);
8149 pixel->background_color.blue=
8150 (~pixel->foreground_color.blue);
8151 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8152 &pixel->background_color);
8154 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8155 &pixel->border_color);
8156 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8157 &pixel->matte_color);
8158 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8159 &pixel->highlight_color);
8160 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8161 &pixel->shadow_color);
8162 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8163 &pixel->depth_color);
8164 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8165 &pixel->trough_color);
8166 for (i=0; i < MaxNumberPens; i++)
8168 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8169 &pixel->pen_colors[i]);
8170 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8172 pixel->colors=image->colors+MaxNumberPens;
8174 colors=(XColor *) RelinquishMagickMemory(colors);
8175 if (IsEventLogging())
8177 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8178 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8179 map_info->colormap);
8180 (void) LogMagickEvent(X11Event,GetMagickModule(),
8181 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8182 map_info->green_max,map_info->blue_max);
8183 (void) LogMagickEvent(X11Event,GetMagickModule(),
8184 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8185 map_info->green_mult,map_info->blue_mult);
8190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8194 % X M a k e W i n d o w %
8198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8200 % XMakeWindow() creates an X11 window.
8202 % The format of the XMakeWindow method is:
8204 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8205 % XClassHint *class_hint,XWMHints *manager_hints,
8206 % XWindowInfo *window_info)
8208 % A description of each parameter follows:
8210 % o display: Specifies a connection to an X server; returned from
8213 % o parent: Specifies the parent window_info.
8215 % o argv: Specifies the application's argument list.
8217 % o argc: Specifies the number of arguments.
8219 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8221 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8223 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8226 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8227 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8228 XWindowInfo *window_info)
8230 #define MinWindowSize 64
8238 static XTextProperty
8249 Set window info hints.
8251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8252 assert(display != (Display *) NULL);
8253 assert(window_info != (XWindowInfo *) NULL);
8254 size_hints=XAllocSizeHints();
8255 if (size_hints == (XSizeHints *) NULL)
8256 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8257 size_hints->flags=(int) window_info->flags;
8258 size_hints->x=window_info->x;
8259 size_hints->y=window_info->y;
8260 size_hints->width=(int) window_info->width;
8261 size_hints->height=(int) window_info->height;
8262 if (window_info->immutable != MagickFalse)
8265 Window size cannot be changed.
8267 size_hints->min_width=size_hints->width;
8268 size_hints->min_height=size_hints->height;
8269 size_hints->max_width=size_hints->width;
8270 size_hints->max_height=size_hints->height;
8271 size_hints->flags|=PMinSize;
8272 size_hints->flags|=PMaxSize;
8277 Window size can be changed.
8279 size_hints->min_width=(int) window_info->min_width;
8280 size_hints->min_height=(int) window_info->min_height;
8281 size_hints->flags|=PResizeInc;
8282 size_hints->width_inc=(int) window_info->width_inc;
8283 size_hints->height_inc=(int) window_info->height_inc;
8284 #if !defined(PRE_R4_ICCCM)
8285 size_hints->flags|=PBaseSize;
8286 size_hints->base_width=size_hints->width_inc;
8287 size_hints->base_height=size_hints->height_inc;
8290 gravity=NorthWestGravity;
8291 if (window_info->geometry != (char *) NULL)
8294 default_geometry[MaxTextExtent],
8295 geometry[MaxTextExtent];
8304 User specified geometry.
8306 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8307 size_hints->width,size_hints->height);
8308 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8310 while (strlen(p) != 0)
8312 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8315 (void) CopyMagickString(p,p+1,MaxTextExtent);
8317 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8318 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8319 &size_hints->width,&size_hints->height,&gravity);
8320 if ((flags & WidthValue) && (flags & HeightValue))
8321 size_hints->flags|=USSize;
8322 if ((flags & XValue) && (flags & YValue))
8324 size_hints->flags|=USPosition;
8325 window_info->x=size_hints->x;
8326 window_info->y=size_hints->y;
8329 #if !defined(PRE_R4_ICCCM)
8330 size_hints->win_gravity=gravity;
8331 size_hints->flags|=PWinGravity;
8333 if (window_info->id == (Window) NULL)
8334 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8335 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8336 window_info->border_width,(int) window_info->depth,InputOutput,
8337 window_info->visual,window_info->mask,&window_info->attributes);
8350 Window already exists; change relevant attributes.
8352 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8353 &window_info->attributes);
8354 mask=ConfigureNotify;
8355 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8356 window_changes.x=window_info->x;
8357 window_changes.y=window_info->y;
8358 window_changes.width=(int) window_info->width;
8359 window_changes.height=(int) window_info->height;
8360 mask=(MagickStatusType) (CWWidth | CWHeight);
8361 if (window_info->flags & USPosition)
8363 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8364 mask,&window_changes);
8366 if (window_info->id == (Window) NULL)
8367 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8369 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8370 if (status == False)
8371 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8373 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8374 if (status == False)
8375 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8376 window_info->icon_name);
8377 if (window_info->icon_geometry != (char *) NULL)
8385 User specified icon geometry.
8387 size_hints->flags|=USPosition;
8388 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8389 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8390 &manager_hints->icon_y,&width,&height,&gravity);
8391 if ((flags & XValue) && (flags & YValue))
8392 manager_hints->flags|=IconPositionHint;
8394 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8395 size_hints,manager_hints,class_hint);
8396 if (window_name.value != (void *) NULL)
8398 (void) XFree((void *) window_name.value);
8399 window_name.value=(unsigned char *) NULL;
8400 window_name.nitems=0;
8402 if (icon_name.value != (void *) NULL)
8404 (void) XFree((void *) icon_name.value);
8405 icon_name.value=(unsigned char *) NULL;
8408 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8409 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8410 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8411 (void) XFree((void *) size_hints);
8412 if (window_info->shape != MagickFalse)
8414 #if defined(MAGICKCORE_HAVE_SHAPE)
8420 Can we apply a non-rectangular shaping mask?
8424 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8425 window_info->shape=MagickFalse;
8427 window_info->shape=MagickFalse;
8430 if (window_info->shared_memory)
8432 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8434 Can we use shared memory with this window?
8436 if (XShmQueryExtension(display) == 0)
8437 window_info->shared_memory=MagickFalse;
8439 window_info->shared_memory=MagickFalse;
8442 window_info->image=NewImageList();
8443 window_info->destroy=MagickFalse;
8447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8451 % X M a g i c k P r o g r e s s M o n i t o r %
8455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8457 % XMagickProgressMonitor() displays the progress a task is making in
8458 % completing a task.
8460 % The format of the XMagickProgressMonitor method is:
8462 % void XMagickProgressMonitor(const char *task,
8463 % const MagickOffsetType quantum,const MagickSizeType span,
8464 % void *client_data)
8466 % A description of each parameter follows:
8468 % o task: Identifies the task in progress.
8470 % o quantum: Specifies the quantum position within the span which represents
8471 % how much progress has been made in completing a task.
8473 % o span: Specifies the span relative to completing a task.
8475 % o client_data: Pointer to any client data.
8479 static const char *GetLocaleMonitorMessage(const char *text)
8482 message[MaxTextExtent],
8491 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8493 if (p != (char *) NULL)
8495 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8496 locale_message=GetLocaleMessage(message);
8497 if (locale_message == message)
8499 return(locale_message);
8502 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8503 const MagickOffsetType quantum,const MagickSizeType span,
8504 void *magick_unused(client_data))
8509 windows=XSetWindows((XWindows *) ~0);
8510 if (windows == (XWindows *) NULL)
8512 if (windows->info.mapped != MagickFalse)
8513 XProgressMonitorWidget(windows->display,windows,
8514 GetLocaleMonitorMessage(tag),quantum,span);
8519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8523 % X Q u e r y C o l o r D a t a b a s e %
8527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8529 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8532 % The format of the XQueryColorDatabase method is:
8534 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8536 % A description of each parameter follows:
8538 % o target: Specifies the color to lookup in the X color database.
8540 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8541 % color is returned as this value.
8544 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8551 *display = (Display *) NULL;
8560 Initialize color return value.
8562 assert(color != (XColor *) NULL);
8566 color->flags=(char) (DoRed | DoGreen | DoBlue);
8567 if ((target == (char *) NULL) || (*target == '\0'))
8568 target="#ffffffffffff";
8570 Let the X server define the color for us.
8572 if (display == (Display *) NULL)
8573 display=XOpenDisplay((char *) NULL);
8574 if (display == (Display *) NULL)
8576 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8577 return(MagickFalse);
8579 colormap=XDefaultColormap(display,XDefaultScreen(display));
8580 status=XParseColor(display,colormap,(char *) target,&xcolor);
8581 if (status == False)
8582 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8585 color->red=xcolor.red;
8586 color->green=xcolor.green;
8587 color->blue=xcolor.blue;
8588 color->flags=xcolor.flags;
8590 return(status != False ? MagickTrue : MagickFalse);
8594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8598 % X Q u e r y P o s i t i o n %
8602 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8604 % XQueryPosition() gets the pointer coordinates relative to a window.
8606 % The format of the XQueryPosition method is:
8608 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8610 % A description of each parameter follows:
8612 % o display: Specifies a connection to an X server; returned from
8615 % o window: Specifies a pointer to a Window.
8617 % o x: Return the x coordinate of the pointer relative to the origin of the
8620 % o y: Return the y coordinate of the pointer relative to the origin of the
8624 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8636 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8637 assert(display != (Display *) NULL);
8638 assert(window != (Window) NULL);
8639 assert(x != (int *) NULL);
8640 assert(y != (int *) NULL);
8641 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8650 % X R e f r e s h W i n d o w %
8654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8656 % XRefreshWindow() refreshes an image in a X window.
8658 % The format of the XRefreshWindow method is:
8660 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8661 % const XEvent *event)
8663 % A description of each parameter follows:
8665 % o display: Specifies a connection to an X server; returned from
8668 % o window: Specifies a pointer to a XWindowInfo structure.
8670 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8671 % the entire image is refreshed.
8674 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8675 const XEvent *event)
8685 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8686 assert(display != (Display *) NULL);
8687 assert(window != (XWindowInfo *) NULL);
8688 if (window->ximage == (XImage *) NULL)
8690 if (event != (XEvent *) NULL)
8693 Determine geometry from expose event.
8697 width=(unsigned int) event->xexpose.width;
8698 height=(unsigned int) event->xexpose.height;
8706 Refresh entire window; discard outstanding expose events.
8710 width=window->width;
8711 height=window->height;
8712 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8713 if (window->matte_pixmap != (Pixmap) NULL)
8715 #if defined(MAGICKCORE_HAVE_SHAPE)
8716 if (window->shape != MagickFalse)
8717 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8718 window->matte_pixmap,ShapeSet);
8723 Check boundary conditions.
8725 if ((window->ximage->width-(x+window->x)) < (int) width)
8726 width=(unsigned int) (window->ximage->width-(x+window->x));
8727 if ((window->ximage->height-(y+window->y)) < (int) height)
8728 height=(unsigned int) (window->ximage->height-(y+window->y));
8732 if (window->matte_pixmap != (Pixmap) NULL)
8733 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8734 if (window->pixmap != (Pixmap) NULL)
8736 if (window->depth > 1)
8737 (void) XCopyArea(display,window->pixmap,window->id,
8738 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8740 (void) XCopyPlane(display,window->pixmap,window->id,
8741 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8746 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8747 if (window->shared_memory)
8748 (void) XShmPutImage(display,window->id,window->annotate_context,
8749 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8751 if (window->shared_memory == MagickFalse)
8752 (void) XPutImage(display,window->id,window->annotate_context,
8753 window->ximage,x+window->x,y+window->y,x,y,width,height);
8755 if (window->matte_pixmap != (Pixmap) NULL)
8756 (void) XSetClipMask(display,window->annotate_context,None);
8757 (void) XFlush(display);
8761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8765 % X R e m o t e C o m m a n d %
8769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8771 % XRemoteCommand() forces a remote display(1) to display the specified
8774 % The format of the XRemoteCommand method is:
8776 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8777 % const char *filename)
8779 % A description of each parameter follows:
8781 % o display: Specifies a connection to an X server; returned from
8784 % o window: Specifies the name or id of an X window.
8786 % o filename: the name of the image filename to display.
8789 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8790 const char *window,const char *filename)
8799 assert(filename != (char *) NULL);
8800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8801 if (display == (Display *) NULL)
8802 display=XOpenDisplay((char *) NULL);
8803 if (display == (Display *) NULL)
8805 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8806 return(MagickFalse);
8808 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8809 remote_window=(Window) NULL;
8810 root_window=XRootWindow(display,XDefaultScreen(display));
8811 if (window != (char *) NULL)
8814 Search window hierarchy and identify any clients by name or ID.
8816 if (isdigit((unsigned char) *window) != 0)
8817 remote_window=XWindowByID(display,root_window,(Window)
8818 strtol((char *) window,(char **) NULL,0));
8819 if (remote_window == (Window) NULL)
8820 remote_window=XWindowByName(display,root_window,window);
8822 if (remote_window == (Window) NULL)
8823 remote_window=XWindowByProperty(display,root_window,remote_atom);
8824 if (remote_window == (Window) NULL)
8826 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8828 return(MagickFalse);
8831 Send remote command.
8833 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8834 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8835 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8836 (void) XSync(display,MagickFalse);
8841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8845 % X R e t a i n W i n d o w C o l o r s %
8849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8851 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8852 % the colors associated with an image displayed on the window.
8854 % The format of the XRetainWindowColors method is:
8856 % void XRetainWindowColors(Display *display,const Window window)
8858 % A description of each parameter follows:
8860 % o display: Specifies a connection to an X server; returned from
8863 % o window: Specifies a pointer to a XWindowInfo structure.
8866 MagickExport void XRetainWindowColors(Display *display,const Window window)
8875 Put property on the window.
8877 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8878 assert(display != (Display *) NULL);
8879 assert(window != (Window) NULL);
8880 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8881 if (property == (Atom) NULL)
8883 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8887 pixmap=XCreatePixmap(display,window,1,1,1);
8888 if (pixmap == (Pixmap) NULL)
8890 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8893 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8894 (unsigned char *) &pixmap,1);
8895 (void) XSetCloseDownMode(display,RetainPermanent);
8899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8903 % X S e l e c t W i n d o w %
8907 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8909 % XSelectWindow() allows a user to select a window using the mouse. If the
8910 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8911 % is returned in the crop_info structure.
8913 % The format of the XSelectWindow function is:
8915 % target_window=XSelectWindow(display,crop_info)
8917 % A description of each parameter follows:
8919 % o window: XSelectWindow returns the window id.
8921 % o display: Specifies a pointer to the Display structure; returned from
8924 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8925 % contains the extents of any cropping rectangle.
8928 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8930 #define MinimumCropArea (unsigned int) 9
8957 Initialize graphic context.
8959 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8960 assert(display != (Display *) NULL);
8961 assert(crop_info != (RectangleInfo *) NULL);
8962 root_window=XRootWindow(display,XDefaultScreen(display));
8963 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8964 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8965 context_values.function=GXinvert;
8966 context_values.plane_mask=
8967 context_values.background ^ context_values.foreground;
8968 context_values.subwindow_mode=IncludeInferiors;
8969 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
8970 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8971 if (annotate_context == (GC) NULL)
8972 return(MagickFalse);
8974 Grab the pointer using target cursor.
8976 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
8977 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
8978 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
8979 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
8980 GrabModeAsync,root_window,target_cursor,CurrentTime);
8981 if (status != GrabSuccess)
8983 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
8984 return((Window) NULL);
8990 crop_info->height=0;
8992 target_window=(Window) NULL;
8997 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
8998 (void) XDrawRectangle(display,root_window,annotate_context,
8999 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9000 (unsigned int) crop_info->height-1);
9002 Allow another event.
9004 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9005 (void) XWindowEvent(display,root_window,ButtonPressMask |
9006 ButtonReleaseMask | ButtonMotionMask,&event);
9007 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9008 (void) XDrawRectangle(display,root_window,annotate_context,
9009 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9010 (unsigned int) crop_info->height-1);
9015 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9016 event.xbutton.x,event.xbutton.y);
9017 if (target_window == (Window) NULL)
9018 target_window=root_window;
9019 x_offset=event.xbutton.x_root;
9020 y_offset=event.xbutton.y_root;
9021 crop_info->x=(ssize_t) x_offset;
9022 crop_info->y=(ssize_t) y_offset;
9024 crop_info->height=0;
9036 Discard pending button motion events.
9038 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9039 crop_info->x=(ssize_t) event.xmotion.x;
9040 crop_info->y=(ssize_t) event.xmotion.y;
9042 Check boundary conditions.
9044 if ((int) crop_info->x < x_offset)
9045 crop_info->width=(size_t) (x_offset-crop_info->x);
9048 crop_info->width=(size_t) (crop_info->x-x_offset);
9049 crop_info->x=(ssize_t) x_offset;
9051 if ((int) crop_info->y < y_offset)
9052 crop_info->height=(size_t) (y_offset-crop_info->y);
9055 crop_info->height=(size_t) (crop_info->y-y_offset);
9056 crop_info->y=(ssize_t) y_offset;
9062 } while ((target_window == (Window) NULL) || (presses > 0));
9063 (void) XUngrabPointer(display,CurrentTime);
9064 (void) XFreeCursor(display,target_cursor);
9065 (void) XFreeGC(display,annotate_context);
9066 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9069 crop_info->height=0;
9071 if ((crop_info->width != 0) && (crop_info->height != 0))
9072 target_window=root_window;
9073 return(target_window);
9077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9081 % X S e t C u r s o r S t a t e %
9085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9087 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9088 % reset to their default.
9090 % The format of the XXSetCursorState method is:
9092 % XSetCursorState(display,windows,const MagickStatusType state)
9094 % A description of each parameter follows:
9096 % o display: Specifies a connection to an X server; returned from
9099 % o windows: Specifies a pointer to a XWindows structure.
9101 % o state: An unsigned integer greater than 0 sets the cursor state
9102 % to busy, otherwise the cursor are reset to their default.
9105 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9106 const MagickStatusType state)
9108 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9109 assert(display != (Display *) NULL);
9110 assert(windows != (XWindows *) NULL);
9113 (void) XCheckDefineCursor(display,windows->image.id,
9114 windows->image.busy_cursor);
9115 (void) XCheckDefineCursor(display,windows->pan.id,
9116 windows->pan.busy_cursor);
9117 (void) XCheckDefineCursor(display,windows->magnify.id,
9118 windows->magnify.busy_cursor);
9119 (void) XCheckDefineCursor(display,windows->command.id,
9120 windows->command.busy_cursor);
9124 (void) XCheckDefineCursor(display,windows->image.id,
9125 windows->image.cursor);
9126 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9127 (void) XCheckDefineCursor(display,windows->magnify.id,
9128 windows->magnify.cursor);
9129 (void) XCheckDefineCursor(display,windows->command.id,
9130 windows->command.cursor);
9131 (void) XCheckDefineCursor(display,windows->command.id,
9132 windows->widget.cursor);
9133 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9135 windows->info.mapped=MagickFalse;
9139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9143 % X S e t W i n d o w s %
9147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9149 % XSetWindows() sets the X windows structure if the windows info is specified.
9150 % Otherwise the current windows structure is returned.
9152 % The format of the XSetWindows method is:
9154 % XWindows *XSetWindows(XWindows *windows_info)
9156 % A description of each parameter follows:
9158 % o windows_info: Initialize the Windows structure with this information.
9161 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9164 *windows = (XWindows *) NULL;
9166 if (windows_info != (XWindows *) ~0)
9168 windows=(XWindows *) RelinquishMagickMemory(windows);
9169 windows=windows_info;
9174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9178 % X U s e r P r e f e r e n c e s %
9182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9184 % XUserPreferences() saves the preferences in a configuration file in the
9185 % users' home directory.
9187 % The format of the XUserPreferences method is:
9189 % void XUserPreferences(XResourceInfo *resource_info)
9191 % A description of each parameter follows:
9193 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9196 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9198 #if defined(X11_PREFERENCES_PATH)
9200 cache[MaxTextExtent],
9201 filename[MaxTextExtent],
9202 specifier[MaxTextExtent];
9209 preferences_database;
9212 Save user preferences to the client configuration file.
9214 assert(resource_info != (XResourceInfo *) NULL);
9215 client_name=GetClientName();
9216 preferences_database=XrmGetStringDatabase("");
9217 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9218 value=resource_info->backdrop ? "True" : "False";
9219 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9220 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9221 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9222 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9223 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9225 value=resource_info->confirm_exit ? "True" : "False";
9226 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9227 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9229 value=resource_info->confirm_edit ? "True" : "False";
9230 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9231 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9233 value=resource_info->display_warnings ? "True" : "False";
9234 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9235 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9236 value=resource_info->quantize_info->dither ? "True" : "False";
9237 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9238 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9240 value=resource_info->gamma_correct ? "True" : "False";
9241 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9242 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9243 (void) FormatMagickString(cache,MaxTextExtent,"%.20g",(double)
9244 resource_info->undo_cache);
9245 XrmPutStringResource(&preferences_database,specifier,cache);
9246 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9247 value=resource_info->use_pixmap ? "True" : "False";
9248 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9249 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9250 X11_PREFERENCES_PATH,client_name);
9251 ExpandFilename(filename);
9252 XrmPutFileDatabase(preferences_database,filename);
9257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9261 % X V i s u a l C l a s s N a m e %
9265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9267 % XVisualClassName() returns the visual class name as a character string.
9269 % The format of the XVisualClassName method is:
9271 % char *XVisualClassName(const int visual_class)
9273 % A description of each parameter follows:
9275 % o visual_type: XVisualClassName returns the visual class as a character
9278 % o class: Specifies the visual class.
9281 static const char *XVisualClassName(const int visual_class)
9283 switch (visual_class)
9285 case StaticGray: return("StaticGray");
9286 case GrayScale: return("GrayScale");
9287 case StaticColor: return("StaticColor");
9288 case PseudoColor: return("PseudoColor");
9289 case TrueColor: return("TrueColor");
9290 case DirectColor: return("DirectColor");
9292 return("unknown visual class");
9296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9306 % XWarning() displays a warning reason in a Notice widget.
9308 % The format of the XWarning method is:
9310 % void XWarning(const unsigned int warning,const char *reason,
9311 % const char *description)
9313 % A description of each parameter follows:
9315 % o warning: Specifies the numeric warning category.
9317 % o reason: Specifies the reason to display before terminating the
9320 % o description: Specifies any description to the reason.
9323 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9324 const char *reason,const char *description)
9327 text[MaxTextExtent];
9332 if (reason == (char *) NULL)
9334 (void) CopyMagickString(text,reason,MaxTextExtent);
9335 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9336 windows=XSetWindows((XWindows *) ~0);
9337 XNoticeWidget(windows->display,windows,text,(char *) description);
9341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9345 % X W i n d o w B y I D %
9349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9351 % XWindowByID() locates a child window with a given ID. If not window with
9352 % the given name is found, 0 is returned. Only the window specified and its
9353 % subwindows are searched.
9355 % The format of the XWindowByID function is:
9357 % child=XWindowByID(display,window,id)
9359 % A description of each parameter follows:
9361 % o child: XWindowByID returns the window with the specified
9362 % id. If no windows are found, XWindowByID returns 0.
9364 % o display: Specifies a pointer to the Display structure; returned from
9367 % o id: Specifies the id of the window to locate.
9370 MagickExport Window XWindowByID(Display *display,const Window root_window,
9390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9391 assert(display != (Display *) NULL);
9392 assert(root_window != (Window) NULL);
9394 return(XSelectWindow(display,&rectangle_info));
9395 if (root_window == id)
9396 return(root_window);
9397 status=XQueryTree(display,root_window,&child,&child,&children,
9399 if (status == False)
9400 return((Window) NULL);
9401 window=(Window) NULL;
9402 for (i=0; i < (int) number_children; i++)
9405 Search each child and their children.
9407 window=XWindowByID(display,children[i],id);
9408 if (window != (Window) NULL)
9411 if (children != (Window *) NULL)
9412 (void) XFree((void *) children);
9417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9421 % X W i n d o w B y N a m e %
9425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9427 % XWindowByName() locates a window with a given name on a display. If no
9428 % window with the given name is found, 0 is returned. If more than one window
9429 % has the given name, the first one is returned. Only root and its children
9432 % The format of the XWindowByName function is:
9434 % window=XWindowByName(display,root_window,name)
9436 % A description of each parameter follows:
9438 % o window: XWindowByName returns the window id.
9440 % o display: Specifies a pointer to the Display structure; returned from
9443 % o root_window: Specifies the id of the root window.
9445 % o name: Specifies the name of the window to locate.
9448 MagickExport Window XWindowByName(Display *display,const Window root_window,
9468 assert(display != (Display *) NULL);
9469 assert(root_window != (Window) NULL);
9470 assert(name != (char *) NULL);
9471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9472 if (XGetWMName(display,root_window,&window_name) != 0)
9473 if (LocaleCompare((char *) window_name.value,name) == 0)
9474 return(root_window);
9475 status=XQueryTree(display,root_window,&child,&child,&children,
9477 if (status == False)
9478 return((Window) NULL);
9479 window=(Window) NULL;
9480 for (i=0; i < (int) number_children; i++)
9483 Search each child and their children.
9485 window=XWindowByName(display,children[i],name);
9486 if (window != (Window) NULL)
9489 if (children != (Window *) NULL)
9490 (void) XFree((void *) children);
9495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9499 % X W i n d o w B y P r o p e r y %
9503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9505 % XWindowByProperty() locates a child window with a given property. If not
9506 % window with the given name is found, 0 is returned. If more than one window
9507 % has the given property, the first one is returned. Only the window
9508 % specified and its subwindows are searched.
9510 % The format of the XWindowByProperty function is:
9512 % child=XWindowByProperty(display,window,property)
9514 % A description of each parameter follows:
9516 % o child: XWindowByProperty returns the window id with the specified
9517 % property. If no windows are found, XWindowByProperty returns 0.
9519 % o display: Specifies a pointer to the Display structure; returned from
9522 % o property: Specifies the property of the window to locate.
9525 MagickExport Window XWindowByProperty(Display *display,const Window window,
9526 const Atom property)
9554 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9555 assert(display != (Display *) NULL);
9556 assert(window != (Window) NULL);
9557 assert(property != (Atom) NULL);
9558 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9559 if (status == False)
9560 return((Window) NULL);
9562 child=(Window) NULL;
9563 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9565 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9566 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9568 (void) XFree((void *) data);
9569 if ((status == Success) && (type != (Atom) NULL))
9572 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9573 child=XWindowByProperty(display,children[i],property);
9574 if (children != (Window *) NULL)
9575 (void) XFree((void *) children);
9581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9585 % X I m p o r t I m a g e %
9589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9591 % XImportImage() reads an image from an X window.
9593 % The format of the XImportImage method is:
9595 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9597 % A description of each parameter follows:
9599 % o image_info: the image info..
9601 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9604 MagickExport Image *XImportImage(const ImageInfo *image_info,
9605 XImportInfo *ximage_info)
9607 assert(image_info != (const ImageInfo *) NULL);
9608 assert(image_info->signature == MagickSignature);
9609 if (image_info->debug != MagickFalse)
9610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9611 image_info->filename);
9612 assert(ximage_info != (XImportInfo *) NULL);
9613 return((Image *) NULL);
9618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9622 + X C o m p o n e n t G e n e s i s %
9626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9628 % XComponentGenesis() instantiates the X component.
9630 % The format of the XComponentGenesis method is:
9632 % MagickBooleanType XComponentGenesis(void)
9635 MagickExport MagickBooleanType XComponentGenesis(void)
9641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9645 % X G e t I m p o r t I n f o %
9649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9651 % XGetImportInfo() initializes the XImportInfo structure.
9653 % The format of the XGetImportInfo method is:
9655 % void XGetImportInfo(XImportInfo *ximage_info)
9657 % A description of each parameter follows:
9659 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9662 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9664 assert(ximage_info != (XImportInfo *) NULL);
9665 ximage_info->frame=MagickFalse;
9666 ximage_info->borders=MagickFalse;
9667 ximage_info->screen=MagickFalse;
9668 ximage_info->descend=MagickTrue;
9669 ximage_info->silent=MagickFalse;