2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % X X W W IIIII N N DDDD OOO W W %
7 % X X W W I NN N D D O O W W %
8 % X W W I N N N D D O O W W %
9 % X X W W W I N NN D D O O W W W %
10 % X X W W IIIII N N DDDD OOO W W %
13 % MagickCore X11 Utility Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/animate.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/client.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colormap.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/display.h"
53 #include "MagickCore/exception.h"
54 #include "MagickCore/exception-private.h"
55 #include "MagickCore/geometry.h"
56 #include "MagickCore/identify.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/locale_.h"
61 #include "MagickCore/log.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/monitor.h"
65 #include "MagickCore/option.h"
66 #include "MagickCore/pixel-accessor.h"
67 #include "MagickCore/PreRvIcccm.h"
68 #include "MagickCore/quantize.h"
69 #include "MagickCore/quantum.h"
70 #include "MagickCore/quantum-private.h"
71 #include "MagickCore/resource_.h"
72 #include "MagickCore/resize.h"
73 #include "MagickCore/shear.h"
74 #include "MagickCore/statistic.h"
75 #include "MagickCore/string_.h"
76 #include "MagickCore/string-private.h"
77 #include "MagickCore/transform.h"
78 #include "MagickCore/utility.h"
79 #include "MagickCore/widget.h"
80 #include "MagickCore/xwindow.h"
81 #include "MagickCore/xwindow-private.h"
82 #include "MagickCore/version.h"
86 #if defined(MAGICKCORE_X11_DELEGATE)
87 #include <X11/Xproto.h>
88 #include <X11/Xlocale.h>
89 #if defined(MAGICK_HAVE_POLL)
90 # include <sys/poll.h>
92 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
93 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
94 # include <machine/param.h>
98 #include <X11/extensions/XShm.h>
100 #if defined(MAGICKCORE_HAVE_SHAPE)
101 #include <X11/extensions/shape.h>
107 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
108 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
110 #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
111 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
113 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
115 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
117 #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
118 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
120 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
122 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
124 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
125 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
127 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
128 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
130 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
131 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
132 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
133 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
135 #define AccentuateModulate ScaleCharToQuantum(80)
136 #define HighlightModulate ScaleCharToQuantum(125)
137 #define ShadowModulate ScaleCharToQuantum(135)
138 #define DepthModulate ScaleCharToQuantum(185)
139 #define TroughModulate ScaleCharToQuantum(110)
141 #define XLIB_ILLEGAL_ACCESS 1
143 #undef NorthWestGravity
145 #undef NorthEastGravity
149 #undef SouthWestGravity
151 #undef SouthEastGravity
158 #define XFD_SET fd_set
162 Enumeration declarations.
176 Typedef declarations.
178 typedef struct _DiversityPacket
193 Constant declaractions.
195 static MagickBooleanType
196 xerror_alert = MagickFalse;
202 *XVisualClassName(const int);
204 static MagickRealType
209 static MagickBooleanType
210 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
213 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
215 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
219 XSelectWindow(Display *,RectangleInfo *);
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % D e s t r o y X R e s o u r c e s %
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % DestroyXResources() destroys any X resources.
234 % The format of the DestroyXResources method is:
236 % void DestroyXResources()
238 % A description of each parameter follows:
241 MagickExport void DestroyXResources(void)
250 *magick_windows[MaxXWindows];
256 windows=XSetWindows((XWindows *) ~0);
257 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
260 magick_windows[number_windows++]=(&windows->context);
261 magick_windows[number_windows++]=(&windows->group_leader);
262 magick_windows[number_windows++]=(&windows->backdrop);
263 magick_windows[number_windows++]=(&windows->icon);
264 magick_windows[number_windows++]=(&windows->image);
265 magick_windows[number_windows++]=(&windows->info);
266 magick_windows[number_windows++]=(&windows->magnify);
267 magick_windows[number_windows++]=(&windows->pan);
268 magick_windows[number_windows++]=(&windows->command);
269 magick_windows[number_windows++]=(&windows->widget);
270 magick_windows[number_windows++]=(&windows->popup);
271 magick_windows[number_windows++]=(&windows->context);
272 for (i=0; i < (int) number_windows; i++)
274 if (magick_windows[i]->mapped != MagickFalse)
276 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
277 magick_windows[i]->screen);
278 magick_windows[i]->mapped=MagickFalse;
280 if (magick_windows[i]->name != (char *) NULL)
281 magick_windows[i]->name=(char *)
282 RelinquishMagickMemory(magick_windows[i]->name);
283 if (magick_windows[i]->icon_name != (char *) NULL)
284 magick_windows[i]->icon_name=(char *)
285 RelinquishMagickMemory(magick_windows[i]->icon_name);
286 if (magick_windows[i]->cursor != (Cursor) NULL)
288 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
289 magick_windows[i]->cursor=(Cursor) NULL;
291 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
293 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
294 magick_windows[i]->busy_cursor=(Cursor) NULL;
296 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
298 (void) XFreePixmap(windows->display,
299 magick_windows[i]->highlight_stipple);
300 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
302 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
304 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
305 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
307 if (magick_windows[i]->ximage != (XImage *) NULL)
309 XDestroyImage(magick_windows[i]->ximage);
310 magick_windows[i]->ximage=(XImage *) NULL;
312 if (magick_windows[i]->pixmap != (Pixmap) NULL)
314 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
315 magick_windows[i]->pixmap=(Pixmap) NULL;
317 if (magick_windows[i]->id != (Window) NULL)
319 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
320 magick_windows[i]->id=(Window) NULL;
322 if (magick_windows[i]->destroy != MagickFalse)
324 if (magick_windows[i]->image != (Image *) NULL)
326 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
327 magick_windows[i]->image=NewImageList();
329 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
331 (void) XFreePixmap(windows->display,
332 magick_windows[i]->matte_pixmap);
333 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
336 if (magick_windows[i]->segment_info != (void *) NULL)
338 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
342 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
343 if (segment_info != (XShmSegmentInfo *) NULL)
344 if (segment_info[0].shmid >= 0)
346 if (segment_info[0].shmaddr != NULL)
347 (void) shmdt(segment_info[0].shmaddr);
348 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
349 segment_info[0].shmaddr=NULL;
350 segment_info[0].shmid=(-1);
353 magick_windows[i]->segment_info=(void *)
354 RelinquishMagickMemory(magick_windows[i]->segment_info);
357 windows->icon_resources=(XResourceInfo *)
358 RelinquishMagickMemory(windows->icon_resources);
359 if (windows->icon_pixel != (XPixelInfo *) NULL)
361 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
362 windows->icon_pixel->pixels=(unsigned long *)
363 RelinquishMagickMemory(windows->icon_pixel->pixels);
364 if (windows->icon_pixel->annotate_context != (GC) NULL)
365 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
366 windows->icon_pixel=(XPixelInfo *)
367 RelinquishMagickMemory(windows->icon_pixel);
369 if (windows->pixel_info != (XPixelInfo *) NULL)
371 if (windows->pixel_info->pixels != (unsigned long *) NULL)
372 windows->pixel_info->pixels=(unsigned long *)
373 RelinquishMagickMemory(windows->pixel_info->pixels);
374 if (windows->pixel_info->annotate_context != (GC) NULL)
375 XFreeGC(windows->display,windows->pixel_info->annotate_context);
376 if (windows->pixel_info->widget_context != (GC) NULL)
377 XFreeGC(windows->display,windows->pixel_info->widget_context);
378 if (windows->pixel_info->highlight_context != (GC) NULL)
379 XFreeGC(windows->display,windows->pixel_info->highlight_context);
380 windows->pixel_info=(XPixelInfo *)
381 RelinquishMagickMemory(windows->pixel_info);
383 if (windows->font_info != (XFontStruct *) NULL)
385 XFreeFont(windows->display,windows->font_info);
386 windows->font_info=(XFontStruct *) NULL;
388 if (windows->class_hints != (XClassHint *) NULL)
390 if (windows->class_hints->res_name != (char *) NULL)
391 XFree(windows->class_hints->res_name);
392 if (windows->class_hints->res_class != (char *) NULL)
393 XFree(windows->class_hints->res_class);
394 XFree(windows->class_hints);
395 windows->class_hints=(XClassHint *) NULL;
397 if (windows->manager_hints != (XWMHints *) NULL)
399 XFree(windows->manager_hints);
400 windows->manager_hints=(XWMHints *) NULL;
402 if (windows->map_info != (XStandardColormap *) NULL)
404 XFree(windows->map_info);
405 windows->map_info=(XStandardColormap *) NULL;
407 if (windows->icon_map != (XStandardColormap *) NULL)
409 XFree(windows->icon_map);
410 windows->icon_map=(XStandardColormap *) NULL;
412 if (windows->visual_info != (XVisualInfo *) NULL)
414 XFree(windows->visual_info);
415 windows->visual_info=(XVisualInfo *) NULL;
417 if (windows->icon_visual != (XVisualInfo *) NULL)
419 XFree(windows->icon_visual);
420 windows->icon_visual=(XVisualInfo *) NULL;
422 (void) XSetWindows((XWindows *) NULL);
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % X A n n o t a t e I m a g e %
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 % XAnnotateImage() annotates the image with text.
438 % The format of the XAnnotateImage method is:
440 % MagickBooleanType XAnnotateImage(Display *display,
441 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
443 % A description of each parameter follows:
445 % o display: Specifies a connection to an X server; returned from
448 % o pixel: Specifies a pointer to a XPixelInfo structure.
450 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
452 % o image: the image.
455 MagickExport MagickBooleanType XAnnotateImage(Display *display,
456 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
495 Initialize annotated image.
497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
498 assert(display != (Display *) NULL);
499 assert(pixel != (XPixelInfo *) NULL);
500 assert(annotate_info != (XAnnotateInfo *) NULL);
501 assert(image != (Image *) NULL);
503 Initialize annotated pixmap.
505 root_window=XRootWindow(display,XDefaultScreen(display));
506 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
507 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
508 annotate_info->height,depth);
509 if (annotate_pixmap == (Pixmap) NULL)
512 Initialize graphics info.
514 context_values.background=0;
515 context_values.foreground=(size_t) (~0);
516 context_values.font=annotate_info->font_info->fid;
517 annotate_context=XCreateGC(display,root_window,(unsigned long)
518 (GCBackground | GCFont | GCForeground),&context_values);
519 if (annotate_context == (GC) NULL)
524 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
525 (int) annotate_info->font_info->ascent,annotate_info->text,
526 (int) strlen(annotate_info->text));
527 (void) XFreeGC(display,annotate_context);
529 Initialize annotated X image.
531 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
532 annotate_info->height,AllPlanes,ZPixmap);
533 if (annotate_ximage == (XImage *) NULL)
535 (void) XFreePixmap(display,annotate_pixmap);
537 Initialize annotated image.
539 annotate_image=AcquireImage((ImageInfo *) NULL);
540 if (annotate_image == (Image *) NULL)
542 annotate_image->columns=annotate_info->width;
543 annotate_image->rows=annotate_info->height;
545 Transfer annotated X image to image.
547 width=(unsigned int) image->columns;
548 height=(unsigned int) image->rows;
551 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
552 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
553 &annotate_image->background_color,&image->exception);
554 if (annotate_info->stencil == ForegroundStencil)
555 annotate_image->matte=MagickTrue;
556 exception=(&image->exception);
557 annotate_view=AcquireCacheView(annotate_image);
558 for (y=0; y < (int) annotate_image->rows; y++)
566 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
567 annotate_image->columns,1,exception);
568 if (q == (Quantum *) NULL)
570 for (x=0; x < (int) annotate_image->columns; x++)
572 SetPixelAlpha(annotate_image,OpaqueAlpha,q);
573 if (XGetPixel(annotate_ximage,x,y) == 0)
576 Set this pixel to the background color.
578 SetPixelRed(annotate_image,ScaleShortToQuantum(
579 pixel->box_color.red),q);
580 SetPixelGreen(annotate_image,ScaleShortToQuantum(
581 pixel->box_color.green),q);
582 SetPixelBlue(annotate_image,ScaleShortToQuantum(
583 pixel->box_color.blue),q);
584 if ((annotate_info->stencil == ForegroundStencil) ||
585 (annotate_info->stencil == OpaqueStencil))
586 SetPixelAlpha(annotate_image,TransparentAlpha,q);
591 Set this pixel to the pen color.
593 SetPixelRed(annotate_image,ScaleShortToQuantum(
594 pixel->pen_color.red),q);
595 SetPixelGreen(annotate_image,ScaleShortToQuantum(
596 pixel->pen_color.green),q);
597 SetPixelBlue(annotate_image,ScaleShortToQuantum(
598 pixel->pen_color.blue),q);
599 if (annotate_info->stencil == BackgroundStencil)
600 SetPixelAlpha(annotate_image,TransparentAlpha,q);
602 q+=GetPixelChannels(annotate_image);
604 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
607 annotate_view=DestroyCacheView(annotate_view);
608 XDestroyImage(annotate_ximage);
610 Determine annotate geometry.
612 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
613 if ((width != (unsigned int) annotate_image->columns) ||
614 (height != (unsigned int) annotate_image->rows))
617 image_geometry[MaxTextExtent];
622 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
624 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
626 if (annotate_info->degrees != 0.0)
641 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
642 if (rotate_image == (Image *) NULL)
644 annotate_image=DestroyImage(annotate_image);
645 annotate_image=rotate_image;
647 Annotation is relative to the degree of rotation.
649 normalized_degrees=annotate_info->degrees;
650 while (normalized_degrees < -45.0)
651 normalized_degrees+=360.0;
652 for (rotations=0; normalized_degrees > 45.0; rotations++)
653 normalized_degrees-=90.0;
654 switch (rotations % 4)
664 x-=(int) annotate_image->columns/2;
665 y+=(int) annotate_image->columns/2;
673 x=x-(int) annotate_image->columns;
681 x=x-(int) annotate_image->columns/2;
682 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
688 Composite text onto the image.
690 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
692 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
693 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
695 annotate_image=DestroyImage(annotate_image);
700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
704 % X B e s t F o n t %
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710 % XBestFont() returns the "best" font. "Best" is defined as a font specified
711 % in the X resource database or a font such that the text width displayed
712 % with the font does not exceed the specified maximum width.
714 % The format of the XBestFont method is:
716 % XFontStruct *XBestFont(Display *display,
717 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
719 % A description of each parameter follows:
721 % o font: XBestFont returns a pointer to a XFontStruct structure.
723 % o display: Specifies a connection to an X server; returned from
726 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
728 % o text_font: True is font should be mono-spaced (typewriter style).
732 static char **FontToList(char *font)
747 if (font == (char *) NULL)
748 return((char **) NULL);
750 Convert string to an ASCII list.
753 for (p=font; *p != '\0'; p++)
754 if ((*p == ':') || (*p == ';') || (*p == ','))
756 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
757 if (fontlist == (char **) NULL)
759 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
761 return((char **) NULL);
764 for (i=0; i < (int) fonts; i++)
766 for (q=p; *q != '\0'; q++)
767 if ((*q == ':') || (*q == ';') || (*q == ','))
769 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
770 sizeof(*fontlist[i]));
771 if (fontlist[i] == (char *) NULL)
773 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
775 return((char **) NULL);
777 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
780 fontlist[i]=(char *) NULL;
784 MagickExport XFontStruct *XBestFont(Display *display,
785 const XResourceInfo *resource_info,const MagickBooleanType text_font)
790 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
791 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
792 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
793 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
794 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
795 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
802 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
803 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
804 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
818 font_info=(XFontStruct *) NULL;
819 font_name=resource_info->font;
820 if (text_font != MagickFalse)
821 font_name=resource_info->text_font;
822 if ((font_name != (char *) NULL) && (*font_name != '\0'))
831 Load preferred font specified in the X resource database.
833 fontlist=FontToList(font_name);
834 if (fontlist != (char **) NULL)
836 for (i=0; fontlist[i] != (char *) NULL; i++)
838 if (font_info == (XFontStruct *) NULL)
839 font_info=XLoadQueryFont(display,fontlist[i]);
840 fontlist[i]=DestroyString(fontlist[i]);
842 fontlist=(char **) RelinquishMagickMemory(fontlist);
844 if (font_info == (XFontStruct *) NULL)
845 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
848 Load fonts from list of fonts until one is found.
851 if (text_font != MagickFalse)
853 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
855 while (*p != (char *) NULL)
857 if (font_info != (XFontStruct *) NULL)
859 font_info=XLoadQueryFont(display,(char *) *p);
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
870 % X B e s t I c o n S i z e %
874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
877 % size that maintains the aspect ratio of the image. If the window manager
878 % has preferred icon sizes, one of the preferred sizes is used.
880 % The format of the XBestIconSize method is:
882 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
884 % A description of each parameter follows:
886 % o display: Specifies a connection to an X server; returned from
889 % o image: the image.
892 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
916 Determine if the window manager has specified preferred icon sizes.
918 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
919 assert(display != (Display *) NULL);
920 assert(window != (XWindowInfo *) NULL);
921 assert(image != (Image *) NULL);
922 window->width=MaxIconSize;
923 window->height=MaxIconSize;
924 icon_size=(XIconSize *) NULL;
926 root_window=XRootWindow(display,window->screen);
927 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
928 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
930 if (icon_size == (XIconSize *) NULL)
933 Window manager does not restrict icon size.
935 icon_size=XAllocIconSize();
936 if (icon_size == (XIconSize *) NULL)
938 ThrowXWindowFatalException(ResourceLimitError,
939 "MemoryAllocationFailed",image->filename);
942 icon_size->min_width=1;
943 icon_size->max_width=MaxIconSize;
944 icon_size->min_height=1;
945 icon_size->max_height=MaxIconSize;
946 icon_size->width_inc=1;
947 icon_size->height_inc=1;
950 Determine aspect ratio of image.
952 width=(unsigned int) image->columns;
953 height=(unsigned int) image->rows;
955 if (window->crop_geometry)
956 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
958 Look for an icon size that maintains the aspect ratio of image.
960 scale_factor=(MagickRealType) icon_size->max_width/width;
961 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
962 scale_factor=(MagickRealType) icon_size->max_height/height;
963 icon_width=(unsigned int) icon_size->min_width;
964 while ((int) icon_width < icon_size->max_width)
966 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
968 icon_width+=icon_size->width_inc;
970 icon_height=(unsigned int) icon_size->min_height;
971 while ((int) icon_height < icon_size->max_height)
973 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
975 icon_height+=icon_size->height_inc;
977 (void) XFree((void *) icon_size);
978 window->width=icon_width;
979 window->height=icon_height;
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987 % X B e s t P i x e l %
991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 % XBestPixel() returns a pixel from an array of pixels that is closest to the
994 % requested color. If the color array is NULL, the colors are obtained from
997 % The format of the XBestPixel method is:
999 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
1000 % unsigned int number_colors,XColor *color)
1002 % A description of each parameter follows:
1004 % o pixel: XBestPixel returns the pixel value closest to the requested
1007 % o display: Specifies a connection to an X server; returned from
1010 % o colormap: Specifies the ID of the X server colormap.
1012 % o colors: Specifies an array of XColor structures.
1014 % o number_colors: Specifies the number of XColor structures in the
1015 % color definition array.
1017 % o color: Specifies the desired RGB value to find in the colors array.
1020 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1021 XColor *colors,unsigned int number_colors,XColor *color)
1032 register MagickRealType
1043 Find closest representation for the requested RGB color.
1045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1046 assert(display != (Display *) NULL);
1047 assert(color != (XColor *) NULL);
1048 status=XAllocColor(display,colormap,color);
1049 if (status != False)
1051 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1052 if (query_server != MagickFalse)
1055 Read X server colormap.
1057 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1058 if (colors == (XColor *) NULL)
1060 ThrowXWindowFatalException(ResourceLimitError,
1061 "MemoryAllocationFailed","...");
1064 for (i=0; i < (int) number_colors; i++)
1065 colors[i].pixel=(size_t) i;
1066 if (number_colors > 256)
1068 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1070 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1073 for (i=0; i < (int) number_colors; i++)
1075 pixel.red=colors[i].red-(MagickRealType) color->red;
1076 distance=pixel.red*pixel.red;
1077 if (distance > min_distance)
1079 pixel.green=colors[i].green-(MagickRealType) color->green;
1080 distance+=pixel.green*pixel.green;
1081 if (distance > min_distance)
1083 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1084 distance+=pixel.blue*pixel.blue;
1085 if (distance > min_distance)
1087 min_distance=distance;
1088 color->pixel=colors[i].pixel;
1091 (void) XAllocColor(display,colormap,&colors[j]);
1092 if (query_server != MagickFalse)
1093 colors=(XColor *) RelinquishMagickMemory(colors);
1097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1101 % X B e s t V i s u a l I n f o %
1105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1107 % XBestVisualInfo() returns visual information for a visual that is the "best"
1108 % the server supports. "Best" is defined as:
1110 % 1. Restrict the visual list to those supported by the default screen.
1112 % 2. If a visual type is specified, restrict the visual list to those of
1115 % 3. If a map type is specified, choose the visual that matches the id
1116 % specified by the Standard Colormap.
1118 % 4 From the list of visuals, choose one that can display the most
1119 % simultaneous colors. If more than one visual can display the same
1120 % number of simultaneous colors, one is chosen based on a rank.
1122 % The format of the XBestVisualInfo method is:
1124 % XVisualInfo *XBestVisualInfo(Display *display,
1125 % XStandardColormap *map_info,XResourceInfo *resource_info)
1127 % A description of each parameter follows:
1129 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1132 % o display: Specifies a connection to an X server; returned from
1135 % o map_info: If map_type is specified, this structure is initialized
1136 % with info from the Standard Colormap.
1138 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1142 static inline int MagickMax(const int x,const int y)
1149 static inline size_t MagickMin(const unsigned int x,
1150 const unsigned int y)
1157 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1158 XStandardColormap *map_info,XResourceInfo *resource_info)
1160 #define MaxStandardColormaps 7
1161 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1162 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1163 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1164 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1190 Restrict visual search by screen number.
1192 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1193 assert(display != (Display *) NULL);
1194 assert(map_info != (XStandardColormap *) NULL);
1195 assert(resource_info != (XResourceInfo *) NULL);
1196 map_type=resource_info->map_type;
1197 visual_type=resource_info->visual_type;
1198 visual_mask=VisualScreenMask;
1199 visual_template.screen=XDefaultScreen(display);
1200 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1202 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1203 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1204 visual_mask|=VisualDepthMask;
1205 if (visual_type != (char *) NULL)
1208 Restrict visual search by class or visual id.
1210 if (LocaleCompare("staticgray",visual_type) == 0)
1212 visual_mask|=VisualClassMask;
1213 visual_template.klass=StaticGray;
1216 if (LocaleCompare("grayscale",visual_type) == 0)
1218 visual_mask|=VisualClassMask;
1219 visual_template.klass=GrayScale;
1222 if (LocaleCompare("staticcolor",visual_type) == 0)
1224 visual_mask|=VisualClassMask;
1225 visual_template.klass=StaticColor;
1228 if (LocaleCompare("pseudocolor",visual_type) == 0)
1230 visual_mask|=VisualClassMask;
1231 visual_template.klass=PseudoColor;
1234 if (LocaleCompare("truecolor",visual_type) == 0)
1236 visual_mask|=VisualClassMask;
1237 visual_template.klass=TrueColor;
1240 if (LocaleCompare("directcolor",visual_type) == 0)
1242 visual_mask|=VisualClassMask;
1243 visual_template.klass=DirectColor;
1246 if (LocaleCompare("default",visual_type) == 0)
1248 visual_mask|=VisualIDMask;
1249 visual_template.visualid=XVisualIDFromVisual(
1250 XDefaultVisual(display,XDefaultScreen(display)));
1253 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1255 visual_mask|=VisualIDMask;
1256 visual_template.visualid=
1257 strtol(visual_type,(char **) NULL,0);
1260 ThrowXWindowFatalException(XServerError,
1261 "UnrecognizedVisualSpecifier",visual_type);
1264 Get all visuals that meet our criteria so far.
1267 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1269 visual_mask=VisualScreenMask | VisualIDMask;
1270 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1273 Failed to get visual; try using the default visual.
1275 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1277 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1278 XDefaultScreen(display)));
1279 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1281 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1282 return((XVisualInfo *) NULL);
1283 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1284 XVisualClassName(visual_list->klass));
1286 resource_info->color_recovery=MagickFalse;
1287 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1293 map_name[MaxTextExtent];
1309 Choose a visual associated with a standard colormap.
1311 root_window=XRootWindow(display,XDefaultScreen(display));
1313 if (LocaleCompare(map_type,"list") != 0)
1316 User specified Standard Colormap.
1318 (void) FormatLocaleString((char *) map_name,MaxTextExtent,
1319 "RGB_%s_MAP",map_type);
1320 LocaleUpper(map_name);
1321 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1322 if (map_property != (Atom) NULL)
1323 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1329 *colormap[MaxStandardColormaps]=
1331 "_HP_RGB_SMOOTH_MAP_LIST",
1341 Choose a standard colormap from a list.
1343 for (i=0; i < MaxStandardColormaps; i++)
1345 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1346 if (map_property == (Atom) NULL)
1348 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1350 if (status != False)
1353 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1355 if (status == False)
1357 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1359 return((XVisualInfo *) NULL);
1362 Search all Standard Colormaps and visuals for ids that match.
1364 *map_info=map_list[0];
1365 #if !defined(PRE_R4_ICCCM)
1366 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1367 for (i=0; i < number_maps; i++)
1368 for (j=0; j < number_visuals; j++)
1369 if (map_list[i].visualid ==
1370 XVisualIDFromVisual(visual_list[j].visual))
1372 *map_info=map_list[i];
1373 visual_template.visualid=XVisualIDFromVisual(
1374 visual_list[j].visual);
1377 if (map_info->visualid != visual_template.visualid)
1379 ThrowXWindowFatalException(XServerError,
1380 "UnableToMatchVisualToStandardColormap",map_type);
1381 return((XVisualInfo *) NULL);
1384 if (map_info->colormap == (Colormap) NULL)
1386 ThrowXWindowFatalException(XServerError,
1387 "StandardColormapIsNotInitialized",map_type);
1388 return((XVisualInfo *) NULL);
1390 (void) XFree((void *) map_list);
1394 static const unsigned int
1409 Pick one visual that displays the most simultaneous colors.
1411 visual_info=visual_list;
1413 for (i=1; i < number_visuals; i++)
1416 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1419 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1420 if (rank[p->klass] > rank[visual_info->klass])
1423 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1425 (void) XFree((void *) visual_list);
1427 Retrieve only one visual by its screen & id number.
1429 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1431 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1432 return((XVisualInfo *) NULL);
1433 return(visual_info);
1437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1441 % X C h e c k D e f i n e C u r s o r %
1445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1447 % XCheckDefineCursor() prevents cursor changes on the root window.
1449 % The format of the XXCheckDefineCursor method is:
1451 % XCheckDefineCursor(display,window,cursor)
1453 % A description of each parameter follows:
1455 % o display: Specifies a connection to an X server; returned from
1458 % o window: the window.
1460 % o cursor: the cursor.
1463 MagickExport int XCheckDefineCursor(Display *display,Window window,
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1467 assert(display != (Display *) NULL);
1468 if (window == XRootWindow(display,XDefaultScreen(display)))
1470 return(XDefineCursor(display,window,cursor));
1474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1478 % X C h e c k R e f r e s h W i n d o w s %
1482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % XCheckRefreshWindows() checks the X server for exposure events for a
1485 % particular window and updates the areassociated with the exposure event.
1487 % The format of the XCheckRefreshWindows method is:
1489 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1491 % A description of each parameter follows:
1493 % o display: Specifies a connection to an X server; returned from
1496 % o windows: Specifies a pointer to a XWindows structure.
1499 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1507 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1508 assert(display != (Display *) NULL);
1509 assert(windows != (XWindows *) NULL);
1510 XDelay(display,SuspendTime);
1511 id=windows->command.id;
1512 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1513 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1514 id=windows->image.id;
1515 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1516 XRefreshWindow(display,&windows->image,&event);
1517 XDelay(display,SuspendTime << 1);
1518 id=windows->command.id;
1519 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1520 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1521 id=windows->image.id;
1522 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1523 XRefreshWindow(display,&windows->image,&event);
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531 % X C l i e n t M e s s a g e %
1535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1538 % initialized with a particular protocol type and atom.
1540 % The format of the XClientMessage function is:
1542 % XClientMessage(display,window,protocol,reason,timestamp)
1544 % A description of each parameter follows:
1546 % o display: Specifies a pointer to the Display structure; returned from
1549 % o window: Specifies a pointer to a Window structure.
1551 % o protocol: Specifies an atom value.
1553 % o reason: Specifies an atom value which is the reason to send.
1555 % o timestamp: Specifies a value of type Time.
1558 MagickExport void XClientMessage(Display *display,const Window window,
1559 const Atom protocol,const Atom reason,const Time timestamp)
1564 assert(display != (Display *) NULL);
1565 client_event.type=ClientMessage;
1566 client_event.window=window;
1567 client_event.message_type=protocol;
1568 client_event.format=32;
1569 client_event.data.l[0]=(long) reason;
1570 client_event.data.l[1]=(long) timestamp;
1571 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1579 + X C l i e n t W i n d o w %
1583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1585 % XClientWindow() finds a window, at or below the specified window, which has
1586 % a WM_STATE property. If such a window is found, it is returned, otherwise
1587 % the argument window is returned.
1589 % The format of the XClientWindow function is:
1591 % client_window=XClientWindow(display,target_window)
1593 % A description of each parameter follows:
1595 % o client_window: XClientWindow returns a window, at or below the specified
1596 % window, which has a WM_STATE property otherwise the argument
1597 % target_window is returned.
1599 % o display: Specifies a pointer to the Display structure; returned from
1602 % o target_window: Specifies the window to find a WM_STATE property.
1605 static Window XClientWindow(Display *display,Window target_window)
1627 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1628 assert(display != (Display *) NULL);
1629 state=XInternAtom(display,"WM_STATE",MagickTrue);
1630 if (state == (Atom) NULL)
1631 return(target_window);
1633 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1634 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1635 if ((status == Success) && (type != (Atom) NULL))
1636 return(target_window);
1637 client_window=XWindowByProperty(display,target_window,state);
1638 if (client_window == (Window) NULL)
1639 return(target_window);
1640 return(client_window);
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 + X C o m p o n e n t T e r m i n u s %
1652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654 % XComponentTerminus() destroys the module component.
1656 % The format of the XComponentTerminus method is:
1658 % XComponentTerminus(void)
1661 MagickPrivate void XComponentTerminus(void)
1663 DestroyXResources();
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1671 % X C o n f i g u r e I m a g e C o l o r m a p %
1675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1677 % XConfigureImageColormap() creates a new X colormap.
1679 % The format of the XConfigureImageColormap method is:
1681 % void XConfigureImageColormap(Display *display,
1682 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1684 % A description of each parameter follows:
1686 % o display: Specifies a connection to an X server; returned from
1689 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1691 % o windows: Specifies a pointer to a XWindows structure.
1693 % o image: the image.
1696 MagickExport void XConfigureImageColormap(Display *display,
1697 XResourceInfo *resource_info,XWindows *windows,Image *image)
1703 Make standard colormap.
1705 XSetCursorState(display,windows,MagickTrue);
1706 XCheckRefreshWindows(display,windows);
1707 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1708 windows->map_info,windows->pixel_info);
1709 colormap=windows->map_info->colormap;
1710 (void) XSetWindowColormap(display,windows->image.id,colormap);
1711 (void) XSetWindowColormap(display,windows->command.id,colormap);
1712 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1713 if (windows->magnify.mapped != MagickFalse)
1714 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1715 if (windows->pan.mapped != MagickFalse)
1716 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1717 XSetCursorState(display,windows,MagickFalse);
1718 XClientMessage(display,windows->image.id,windows->im_protocols,
1719 windows->im_update_colormap,CurrentTime);
1723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1727 % X C o n s t r a i n W i n d o w P o s i t i o n %
1731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1733 % XConstrainWindowPosition() assures a window is positioned within the X
1734 % server boundaries.
1736 % The format of the XConstrainWindowPosition method is:
1738 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1740 % A description of each parameter follows:
1742 % o display: Specifies a pointer to the Display structure; returned from
1745 % o window_info: Specifies a pointer to a XWindowInfo structure.
1748 MagickExport void XConstrainWindowPosition(Display *display,
1749 XWindowInfo *window_info)
1754 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1755 assert(display != (Display *) NULL);
1756 assert(window_info != (XWindowInfo *) NULL);
1757 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1758 if (window_info->x < 0)
1761 if (window_info->x > (int) limit)
1762 window_info->x=(int) limit;
1763 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1764 if (window_info->y < 0)
1767 if (window_info->y > limit)
1768 window_info->y=limit;
1772 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1782 % XDelay() suspends program execution for the number of milliseconds
1785 % The format of the Delay method is:
1787 % void XDelay(Display *display,const size_t milliseconds)
1789 % A description of each parameter follows:
1791 % o display: Specifies a pointer to the Display structure; returned from
1794 % o milliseconds: Specifies the number of milliseconds to delay before
1798 MagickExport void XDelay(Display *display,const size_t milliseconds)
1800 assert(display != (Display *) NULL);
1801 (void) XFlush(display);
1802 MagickDelay(milliseconds);
1806 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1810 % X D e s t r o y R e s o u r c e I n f o %
1814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1816 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1819 % The format of the XDestroyResourceInfo method is:
1821 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1823 % A description of each parameter follows:
1825 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1828 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1830 if (resource_info->image_geometry != (char *) NULL)
1831 resource_info->image_geometry=(char *)
1832 RelinquishMagickMemory(resource_info->image_geometry);
1833 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1834 resource_info->quantize_info=DestroyQuantizeInfo(
1835 resource_info->quantize_info);
1836 if (resource_info->client_name != (char *) NULL)
1837 resource_info->client_name=(char *)
1838 RelinquishMagickMemory(resource_info->client_name);
1839 if (resource_info->name != (char *) NULL)
1840 resource_info->name=DestroyString(resource_info->name);
1841 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1849 % X D e s t r o y W i n d o w C o l o r s %
1853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 % XDestroyWindowColors() frees X11 color resources previously saved on a
1856 % window by XRetainWindowColors or programs like xsetroot.
1858 % The format of the XDestroyWindowColors method is:
1860 % void XDestroyWindowColors(Display *display,Window window)
1862 % A description of each parameter follows:
1864 % o display: Specifies a connection to an X server; returned from
1867 % o window: Specifies a pointer to a Window structure.
1870 MagickExport void XDestroyWindowColors(Display *display,Window window)
1890 If there are previous resources on the root window, destroy them.
1892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1893 assert(display != (Display *) NULL);
1894 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1895 if (property == (Atom) NULL)
1897 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1901 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1902 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1903 if (status != Success)
1905 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1907 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1908 (void) XDeleteProperty(display,window,property);
1911 (void) XFree((void *) data);
1915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1919 % X D i s p l a y I m a g e I n f o %
1923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1925 % XDisplayImageInfo() displays information about an X image.
1927 % The format of the XDisplayImageInfo method is:
1929 % void XDisplayImageInfo(Display *display,
1930 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1933 % A description of each parameter follows:
1935 % o display: Specifies a connection to an X server; returned from
1938 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1940 % o windows: Specifies a pointer to a XWindows structure.
1942 % o undo_image: the undo image.
1944 % o image: the image.
1947 MagickExport void XDisplayImageInfo(Display *display,
1948 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1952 filename[MaxTextExtent],
1975 Write info about the X server to a file.
1977 assert(display != (Display *) NULL);
1978 assert(resource_info != (XResourceInfo *) NULL);
1979 assert(windows != (XWindows *) NULL);
1980 assert(image != (Image *) NULL);
1982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1984 unique_file=AcquireUniqueFileResource(filename);
1985 if (unique_file != -1)
1986 file=fdopen(unique_file,"w");
1987 if ((unique_file == -1) || (file == (FILE *) NULL))
1989 XNoticeWidget(display,windows,"Unable to display image info",filename);
1992 if (resource_info->gamma_correct != MagickFalse)
1993 if (resource_info->display_gamma != (char *) NULL)
1994 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
1995 resource_info->display_gamma);
1997 Write info about the X image to a file.
1999 (void) FormatLocaleFile(file,"X\n visual: %s\n",
2000 XVisualClassName((int) windows->image.storage_class));
2001 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
2002 if (windows->visual_info->colormap_size != 0)
2003 (void) FormatLocaleFile(file," colormap size: %d\n",
2004 windows->visual_info->colormap_size);
2005 if (resource_info->colormap== SharedColormap)
2006 (void) FormatLocaleFile(file," colormap type: Shared\n");
2008 (void) FormatLocaleFile(file," colormap type: Private\n");
2009 (void) FormatLocaleFile(file," geometry: %dx%d\n",
2010 windows->image.ximage->width,windows->image.ximage->height);
2011 if (windows->image.crop_geometry != (char *) NULL)
2012 (void) FormatLocaleFile(file," crop geometry: %s\n",
2013 windows->image.crop_geometry);
2014 if (windows->image.pixmap == (Pixmap) NULL)
2015 (void) FormatLocaleFile(file," type: X Image\n");
2017 (void) FormatLocaleFile(file," type: Pixmap\n");
2018 if (windows->image.shape != MagickFalse)
2019 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2021 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2022 if (windows->image.shared_memory != MagickFalse)
2023 (void) FormatLocaleFile(file," shared memory: True\n");
2025 (void) FormatLocaleFile(file," shared memory: False\n");
2026 (void) FormatLocaleFile(file,"\n");
2027 if (resource_info->font != (char *) NULL)
2028 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2029 if (resource_info->text_font != (char *) NULL)
2030 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2032 Write info about the undo cache to a file.
2035 for (levels=0; undo_image != (Image *) NULL; levels++)
2037 number_pixels=undo_image->list->columns*undo_image->list->rows;
2038 bytes+=number_pixels*sizeof(PixelPacket);
2039 undo_image=GetPreviousImageInList(undo_image);
2041 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2042 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2043 ((bytes+(1 << 19)) >> 20));
2044 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2045 resource_info->undo_cache);
2047 Write info about the image to a file.
2049 (void) IdentifyImage(image,file,MagickTrue,&image->exception);
2050 (void) fclose(file);
2051 text=FileToString(filename,~0,&image->exception);
2052 (void) RelinquishUniqueFileResource(filename);
2053 if (text == (char *) NULL)
2055 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2056 "UnableToDisplayImageInfo");
2059 textlist=StringToList(text);
2060 if (textlist != (char **) NULL)
2063 title[MaxTextExtent];
2066 Display information about the image in the Text View widget.
2068 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2069 (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
2071 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2072 (char const **) textlist);
2073 for (i=0; textlist[i] != (char *) NULL; i++)
2074 textlist[i]=DestroyString(textlist[i]);
2075 textlist=(char **) RelinquishMagickMemory(textlist);
2077 text=DestroyString(text);
2081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2085 + X D i t h e r I m a g e %
2089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2091 % XDitherImage() dithers the reference image as required by the HP Color
2092 % Recovery algorithm. The color values are quantized to 3 bits of red and
2093 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2094 % standard colormap.
2096 % The format of the XDitherImage method is:
2098 % void XDitherImage(Image *image,XImage *ximage)
2100 % A description of each parameter follows:
2102 % o image: the image.
2104 % o ximage: Specifies a pointer to a XImage structure; returned from
2108 static void XDitherImage(Image *image,XImage *ximage)
2110 static const short int
2113 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2114 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2116 dither_green[2][16]=
2118 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2119 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2123 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2124 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2140 register const Quantum
2160 Allocate and initialize dither maps.
2162 for (i=0; i < 2; i++)
2163 for (j=0; j < 16; j++)
2165 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2167 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2168 sizeof(*green_map));
2169 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2171 if ((red_map[i][j] == (unsigned char *) NULL) ||
2172 (green_map[i][j] == (unsigned char *) NULL) ||
2173 (blue_map[i][j] == (unsigned char *) NULL))
2175 ThrowXWindowFatalException(ResourceLimitError,
2176 "MemoryAllocationFailed",image->filename);
2181 Initialize dither tables.
2183 for (i=0; i < 2; i++)
2184 for (j=0; j < 16; j++)
2185 for (x=0; x < 256; x++)
2190 value+=dither_red[i][j];
2191 red_map[i][j][x]=(unsigned char)
2192 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2196 value+=dither_green[i][j];
2197 green_map[i][j][x]=(unsigned char)
2198 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2202 value+=((size_t) dither_blue[i][j] << 1);
2203 blue_map[i][j][x]=(unsigned char)
2204 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2209 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2210 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2214 image_view=AcquireCacheView(image);
2215 for (y=0; y < (int) image->rows; y++)
2217 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2219 if (p == (const Quantum *) NULL)
2221 for (x=0; x < (int) image->columns; x++)
2223 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2224 ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2225 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2226 ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2227 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2228 ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2229 pixel=(size_t) (((size_t) color.red & 0xe0) |
2230 (((size_t) color.green & 0xe0) >> 3) |
2231 (((size_t) color.blue & 0xc0) >> 6));
2233 p+=GetPixelChannels(image);
2243 image_view=DestroyCacheView(image_view);
2245 Free allocated memory.
2247 for (i=0; i < 2; i++)
2248 for (j=0; j < 16; j++)
2250 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2251 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2252 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2261 % X D r a w I m a g e %
2265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2267 % XDrawImage() draws a line on the image.
2269 % The format of the XDrawImage method is:
2271 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2273 % A description of each parameter follows:
2275 % o display: Specifies a connection to an X server; returned from
2278 % o pixel: Specifies a pointer to a XPixelInfo structure.
2280 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2282 % o image: the image.
2285 MagickExport MagickBooleanType XDrawImage(Display *display,
2286 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2325 Initialize drawd image.
2327 assert(display != (Display *) NULL);
2328 assert(pixel != (XPixelInfo *) NULL);
2329 assert(draw_info != (XDrawInfo *) NULL);
2330 assert(image != (Image *) NULL);
2331 if (image->debug != MagickFalse)
2332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2334 Initialize drawd pixmap.
2336 root_window=XRootWindow(display,XDefaultScreen(display));
2337 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2338 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2339 draw_info->height,depth);
2340 if (draw_pixmap == (Pixmap) NULL)
2341 return(MagickFalse);
2343 Initialize graphics info.
2345 context_values.background=(size_t) (~0);
2346 context_values.foreground=0;
2347 context_values.line_width=(int) draw_info->line_width;
2348 draw_context=XCreateGC(display,root_window,(size_t)
2349 (GCBackground | GCForeground | GCLineWidth),&context_values);
2350 if (draw_context == (GC) NULL)
2351 return(MagickFalse);
2355 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2358 Draw line to pixmap.
2360 (void) XSetBackground(display,draw_context,0);
2361 (void) XSetForeground(display,draw_context,(size_t) (~0));
2362 if (draw_info->stipple != (Pixmap) NULL)
2364 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2365 (void) XSetStipple(display,draw_context,draw_info->stipple);
2367 switch (draw_info->element)
2372 (void) XDrawLines(display,draw_pixmap,draw_context,
2373 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2379 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2380 draw_info->line_info.y1,draw_info->line_info.x2,
2381 draw_info->line_info.y2);
2384 case RectangleElement:
2386 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2387 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2388 (unsigned int) draw_info->rectangle_info.width,
2389 (unsigned int) draw_info->rectangle_info.height);
2392 case FillRectangleElement:
2394 (void) XFillRectangle(display,draw_pixmap,draw_context,
2395 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2396 (unsigned int) draw_info->rectangle_info.width,
2397 (unsigned int) draw_info->rectangle_info.height);
2401 case EllipseElement:
2403 (void) XDrawArc(display,draw_pixmap,draw_context,
2404 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2405 (unsigned int) draw_info->rectangle_info.width,
2406 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2409 case FillCircleElement:
2410 case FillEllipseElement:
2412 (void) XFillArc(display,draw_pixmap,draw_context,
2413 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2414 (unsigned int) draw_info->rectangle_info.width,
2415 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2418 case PolygonElement:
2423 coordinate_info=draw_info->coordinate_info;
2424 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2425 (int) draw_info->number_coordinates,CoordModeOrigin);
2426 (void) XDrawLine(display,draw_pixmap,draw_context,
2427 coordinate_info[draw_info->number_coordinates-1].x,
2428 coordinate_info[draw_info->number_coordinates-1].y,
2429 coordinate_info[0].x,coordinate_info[0].y);
2432 case FillPolygonElement:
2434 (void) XFillPolygon(display,draw_pixmap,draw_context,
2435 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2440 (void) XFreeGC(display,draw_context);
2444 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2445 draw_info->height,AllPlanes,ZPixmap);
2446 if (draw_ximage == (XImage *) NULL)
2447 return(MagickFalse);
2448 (void) XFreePixmap(display,draw_pixmap);
2450 Initialize draw image.
2452 draw_image=AcquireImage((ImageInfo *) NULL);
2453 if (draw_image == (Image *) NULL)
2454 return(MagickFalse);
2455 draw_image->columns=draw_info->width;
2456 draw_image->rows=draw_info->height;
2458 Transfer drawn X image to image.
2460 width=(unsigned int) image->columns;
2461 height=(unsigned int) image->rows;
2464 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2465 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
2466 &draw_image->background_color,&image->exception);
2467 if (SetImageStorageClass(draw_image,DirectClass,&image->exception) == MagickFalse)
2468 return(MagickFalse);
2469 draw_image->matte=MagickTrue;
2470 exception=(&image->exception);
2471 draw_view=AcquireCacheView(draw_image);
2472 for (y=0; y < (int) draw_image->rows; y++)
2480 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2482 if (q == (Quantum *) NULL)
2484 for (x=0; x < (int) draw_image->columns; x++)
2486 if (XGetPixel(draw_ximage,x,y) == 0)
2489 Set this pixel to the background color.
2491 SetPixelPacket(draw_image,&draw_image->background_color,q);
2492 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2493 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2498 Set this pixel to the pen color.
2500 SetPixelRed(draw_image,ScaleShortToQuantum(
2501 pixel->pen_color.red),q);
2502 SetPixelGreen(draw_image,ScaleShortToQuantum(
2503 pixel->pen_color.green),q);
2504 SetPixelBlue(draw_image,ScaleShortToQuantum(
2505 pixel->pen_color.blue),q);
2506 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2507 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2509 q+=GetPixelChannels(draw_image);
2511 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2514 draw_view=DestroyCacheView(draw_view);
2515 XDestroyImage(draw_ximage);
2517 Determine draw geometry.
2519 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2520 if ((width != (unsigned int) draw_image->columns) ||
2521 (height != (unsigned int) draw_image->rows))
2524 image_geometry[MaxTextExtent];
2529 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
2531 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2533 if (draw_info->degrees != 0.0)
2547 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2548 if (rotate_image == (Image *) NULL)
2549 return(MagickFalse);
2550 draw_image=DestroyImage(draw_image);
2551 draw_image=rotate_image;
2553 Annotation is relative to the degree of rotation.
2555 normalized_degrees=draw_info->degrees;
2556 while (normalized_degrees < -45.0)
2557 normalized_degrees+=360.0;
2558 for (rotations=0; normalized_degrees > 45.0; rotations++)
2559 normalized_degrees-=90.0;
2560 switch (rotations % 4)
2570 x=x-(int) draw_image->columns/2;
2571 y=y+(int) draw_image->columns/2;
2579 x=x-(int) draw_image->columns;
2587 x=x-(int) draw_image->columns/2;
2588 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2594 Composite text onto the image.
2596 draw_view=AcquireCacheView(draw_image);
2597 for (y=0; y < (int) draw_image->rows; y++)
2605 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2607 if (q == (Quantum *) NULL)
2609 for (x=0; x < (int) draw_image->columns; x++)
2611 if (GetPixelAlpha(image,q) != TransparentAlpha)
2612 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2613 q+=GetPixelChannels(draw_image);
2615 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2618 draw_view=DestroyCacheView(draw_view);
2619 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2620 if (draw_info->stencil == TransparentStencil)
2621 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2626 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2630 draw_image=DestroyImage(draw_image);
2635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2645 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2646 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2647 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2650 % The format of the XError function is:
2652 % XError(display,error)
2654 % A description of each parameter follows:
2656 % o display: Specifies a pointer to the Display structure; returned from
2659 % o error: Specifies the error event.
2663 #if defined(__cplusplus) || defined(c_plusplus)
2667 MagickExport int XError(Display *display,XErrorEvent *error)
2669 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2670 assert(display != (Display *) NULL);
2671 assert(error != (XErrorEvent *) NULL);
2672 xerror_alert=MagickTrue;
2673 switch (error->request_code)
2677 if ((int) error->error_code == BadDrawable)
2678 return(MagickFalse);
2681 case X_GetWindowAttributes:
2684 if ((int) error->error_code == BadWindow)
2685 return(MagickFalse);
2690 if ((int) error->error_code == BadValue)
2691 return(MagickFalse);
2698 #if defined(__cplusplus) || defined(c_plusplus)
2703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2707 % X F r e e R e s o u r c e s %
2711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2713 % XFreeResources() frees X11 resources.
2715 % The format of the XFreeResources method is:
2717 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2718 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2719 % XResourceInfo *resource_info,XWindowInfo *window_info)
2720 % resource_info,window_info)
2722 % A description of each parameter follows:
2724 % o display: Specifies a connection to an X server; returned from
2727 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2728 % returned from XGetVisualInfo.
2730 % o map_info: If map_type is specified, this structure is initialized
2731 % with info from the Standard Colormap.
2733 % o pixel: Specifies a pointer to a XPixelInfo structure.
2735 % o font_info: Specifies a pointer to a XFontStruct structure.
2737 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2739 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2742 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2743 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2744 XResourceInfo *resource_info,XWindowInfo *window_info)
2746 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2747 assert(display != (Display *) NULL);
2748 assert(resource_info != (XResourceInfo *) NULL);
2749 if (window_info != (XWindowInfo *) NULL)
2754 if (window_info->ximage != (XImage *) NULL)
2755 XDestroyImage(window_info->ximage);
2756 if (window_info->id != (Window) NULL)
2759 Free destroy window and free cursors.
2761 if (window_info->id != XRootWindow(display,visual_info->screen))
2762 (void) XDestroyWindow(display,window_info->id);
2763 if (window_info->annotate_context != (GC) NULL)
2764 (void) XFreeGC(display,window_info->annotate_context);
2765 if (window_info->highlight_context != (GC) NULL)
2766 (void) XFreeGC(display,window_info->highlight_context);
2767 if (window_info->widget_context != (GC) NULL)
2768 (void) XFreeGC(display,window_info->widget_context);
2769 if (window_info->cursor != (Cursor) NULL)
2770 (void) XFreeCursor(display,window_info->cursor);
2771 window_info->cursor=(Cursor) NULL;
2772 if (window_info->busy_cursor != (Cursor) NULL)
2773 (void) XFreeCursor(display,window_info->busy_cursor);
2774 window_info->busy_cursor=(Cursor) NULL;
2780 if (font_info != (XFontStruct *) NULL)
2782 (void) XFreeFont(display,font_info);
2783 font_info=(XFontStruct *) NULL;
2785 if (map_info != (XStandardColormap *) NULL)
2788 Free X Standard Colormap.
2790 if (resource_info->map_type == (char *) NULL)
2791 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2792 (void) XFree((void *) map_info);
2797 if (visual_info != (XVisualInfo *) NULL)
2798 (void) XFree((void *) visual_info);
2799 if (resource_info->close_server != MagickFalse)
2800 (void) XCloseDisplay(display);
2804 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2808 % X F r e e S t a n d a r d C o l o r m a p %
2812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2814 % XFreeStandardColormap() frees an X11 colormap.
2816 % The format of the XFreeStandardColormap method is:
2818 % void XFreeStandardColormap(Display *display,
2819 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2820 % XPixelInfo *pixel)
2822 % A description of each parameter follows:
2824 % o display: Specifies a connection to an X server; returned from
2827 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2828 % returned from XGetVisualInfo.
2830 % o map_info: If map_type is specified, this structure is initialized
2831 % with info from the Standard Colormap.
2833 % o pixel: Specifies a pointer to a XPixelInfo structure.
2836 MagickExport void XFreeStandardColormap(Display *display,
2837 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2842 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2843 assert(display != (Display *) NULL);
2844 assert(visual_info != (XVisualInfo *) NULL);
2845 assert(map_info != (XStandardColormap *) NULL);
2846 (void) XFlush(display);
2847 if (map_info->colormap != (Colormap) NULL)
2849 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2850 (void) XFreeColormap(display,map_info->colormap);
2852 if (pixel != (XPixelInfo *) NULL)
2853 if ((visual_info->klass != TrueColor) &&
2854 (visual_info->klass != DirectColor))
2855 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2856 (int) pixel->colors,0);
2858 map_info->colormap=(Colormap) NULL;
2859 if (pixel != (XPixelInfo *) NULL)
2861 if (pixel->pixels != (unsigned long *) NULL)
2862 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2863 pixel->pixels=(unsigned long *) NULL;
2868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2872 % X G e t A n n o t a t e I n f o %
2876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2878 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2880 % The format of the XGetAnnotateInfo method is:
2882 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2884 % A description of each parameter follows:
2886 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2889 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2892 Initialize annotate structure.
2894 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2895 assert(annotate_info != (XAnnotateInfo *) NULL);
2898 annotate_info->width=0;
2899 annotate_info->height=0;
2900 annotate_info->stencil=ForegroundStencil;
2901 annotate_info->degrees=0.0;
2902 annotate_info->font_info=(XFontStruct *) NULL;
2903 annotate_info->text=(char *) NULL;
2904 *annotate_info->geometry='\0';
2905 annotate_info->previous=(XAnnotateInfo *) NULL;
2906 annotate_info->next=(XAnnotateInfo *) NULL;
2907 (void) XSupportsLocale();
2908 (void) XSetLocaleModifiers("");
2912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2916 % X G e t M a p I n f o %
2920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2922 % XGetMapInfo() initializes the XStandardColormap structure.
2924 % The format of the XStandardColormap method is:
2926 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2927 % XStandardColormap *map_info)
2929 % A description of each parameter follows:
2931 % o colormap: Specifies the ID of the X server colormap.
2933 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2934 % returned from XGetVisualInfo.
2936 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2939 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2940 const Colormap colormap,XStandardColormap *map_info)
2943 Initialize map info.
2945 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2946 assert(visual_info != (XVisualInfo *) NULL);
2947 assert(map_info != (XStandardColormap *) NULL);
2948 map_info->colormap=colormap;
2949 map_info->red_max=visual_info->red_mask;
2950 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2951 if (map_info->red_max != 0)
2952 while ((map_info->red_max & 0x01) == 0)
2954 map_info->red_max>>=1;
2955 map_info->red_mult<<=1;
2957 map_info->green_max=visual_info->green_mask;
2958 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2959 if (map_info->green_max != 0)
2960 while ((map_info->green_max & 0x01) == 0)
2962 map_info->green_max>>=1;
2963 map_info->green_mult<<=1;
2965 map_info->blue_max=visual_info->blue_mask;
2966 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2967 if (map_info->blue_max != 0)
2968 while ((map_info->blue_max & 0x01) == 0)
2970 map_info->blue_max>>=1;
2971 map_info->blue_mult<<=1;
2973 map_info->base_pixel=0;
2977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2981 % X G e t P i x e l I n f o %
2985 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2987 % XGetPixelInfo() initializes the PixelPacket structure.
2989 % The format of the XGetPixelInfo method is:
2991 % void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
2992 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2993 % Image *image,XPixelInfo *pixel)
2996 % A description of each parameter follows:
2998 % o display: Specifies a connection to an X server; returned from
3001 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
3002 % returned from XGetVisualInfo.
3004 % o map_info: If map_type is specified, this structure is initialized
3005 % with info from the Standard Colormap.
3007 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3009 % o image: the image.
3011 % o pixel: Specifies a pointer to a XPixelInfo structure.
3014 MagickExport void XGetPixelInfo(Display *display,
3015 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3016 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3019 *PenColors[MaxNumberPens]=
3021 "#000000000000", /* black */
3022 "#00000000ffff", /* blue */
3023 "#0000ffffffff", /* cyan */
3024 "#0000ffff0000", /* green */
3025 "#bdbdbdbdbdbd", /* gray */
3026 "#ffff00000000", /* red */
3027 "#ffff0000ffff", /* magenta */
3028 "#ffffffff0000", /* yellow */
3029 "#ffffffffffff", /* white */
3030 "#bdbdbdbdbdbd", /* gray */
3031 "#bdbdbdbdbdbd" /* gray */
3047 Initialize pixel info.
3049 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3050 assert(display != (Display *) NULL);
3051 assert(visual_info != (XVisualInfo *) NULL);
3052 assert(map_info != (XStandardColormap *) NULL);
3053 assert(resource_info != (XResourceInfo *) NULL);
3054 assert(pixel != (XPixelInfo *) NULL);
3056 if (image != (Image *) NULL)
3057 if (image->storage_class == PseudoClass)
3058 pixel->colors=(ssize_t) image->colors;
3059 packets=(unsigned int)
3060 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3061 if (pixel->pixels != (unsigned long *) NULL)
3062 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3063 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3064 sizeof(pixel->pixels));
3065 if (pixel->pixels == (unsigned long *) NULL)
3066 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3069 Set foreground color.
3071 colormap=map_info->colormap;
3072 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3073 &pixel->foreground_color);
3074 status=XParseColor(display,colormap,resource_info->foreground_color,
3075 &pixel->foreground_color);
3076 if (status == False)
3077 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3078 resource_info->foreground_color);
3079 pixel->foreground_color.pixel=
3080 XStandardPixel(map_info,&pixel->foreground_color);
3081 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3083 Set background color.
3085 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3086 status=XParseColor(display,colormap,resource_info->background_color,
3087 &pixel->background_color);
3088 if (status == False)
3089 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3090 resource_info->background_color);
3091 pixel->background_color.pixel=
3092 XStandardPixel(map_info,&pixel->background_color);
3093 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3097 (void) XParseColor(display,colormap,(char *) BorderColor,
3098 &pixel->border_color);
3099 status=XParseColor(display,colormap,resource_info->border_color,
3100 &pixel->border_color);
3101 if (status == False)
3102 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3103 resource_info->border_color);
3104 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3105 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3109 pixel->matte_color=pixel->background_color;
3110 if (resource_info->matte_color != (char *) NULL)
3113 Matte color is specified as a X resource or command line argument.
3115 status=XParseColor(display,colormap,resource_info->matte_color,
3116 &pixel->matte_color);
3117 if (status == False)
3118 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3119 resource_info->matte_color);
3120 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3121 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3124 Set highlight color.
3126 pixel->highlight_color.red=(unsigned short) ((
3127 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3128 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3129 pixel->highlight_color.green=(unsigned short) ((
3130 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3131 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3132 pixel->highlight_color.blue=(unsigned short) ((
3133 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3134 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3135 pixel->highlight_color.pixel=
3136 XStandardPixel(map_info,&pixel->highlight_color);
3137 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3141 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3142 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3143 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3144 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3145 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3146 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3147 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3148 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3152 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3153 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3154 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3155 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3156 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3157 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3158 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3159 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3163 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3164 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3165 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3166 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3167 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3168 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3169 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3170 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3174 for (i=0; i < MaxNumberPens; i++)
3176 (void) XParseColor(display,colormap,(char *) PenColors[i],
3177 &pixel->pen_colors[i]);
3178 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3179 &pixel->pen_colors[i]);
3180 if (status == False)
3181 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3182 resource_info->pen_colors[i]);
3183 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3184 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3186 pixel->box_color=pixel->background_color;
3187 pixel->pen_color=pixel->foreground_color;
3190 if (image != (Image *) NULL)
3192 if ((resource_info->gamma_correct != MagickFalse) &&
3193 (image->gamma != 0.0))
3202 Initialize map relative to display and image gamma.
3204 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3205 red_gamma=geometry_info.rho;
3206 green_gamma=geometry_info.sigma;
3207 if ((flags & SigmaValue) == 0)
3208 green_gamma=red_gamma;
3209 blue_gamma=geometry_info.xi;
3210 if ((flags & XiValue) == 0)
3211 blue_gamma=red_gamma;
3212 red_gamma*=image->gamma;
3213 green_gamma*=image->gamma;
3214 blue_gamma*=image->gamma;
3216 if (image->storage_class == PseudoClass)
3219 Initialize pixel array for images of type PseudoClass.
3221 for (i=0; i < (ssize_t) image->colors; i++)
3222 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3223 for (i=0; i < MaxNumberPens; i++)
3224 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3225 pixel->colors+=MaxNumberPens;
3231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3235 % X G e t R e s o u r c e C l a s s %
3239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3241 % XGetResourceClass() queries the X server for the specified resource name or
3242 % class. If the resource name or class is not defined in the database, the
3243 % supplied default value is returned.
3245 % The format of the XGetResourceClass method is:
3247 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3248 % const char *keyword,char *resource_default)
3250 % A description of each parameter follows:
3252 % o database: Specifies a resource database; returned from
3253 % XrmGetStringDatabase.
3255 % o client_name: Specifies the application name used to retrieve resource
3256 % info from the X server database.
3258 % o keyword: Specifies the keyword of the value being retrieved.
3260 % o resource_default: Specifies the default value to return if the query
3261 % fails to find the specified keyword/class.
3264 MagickExport char *XGetResourceClass(XrmDatabase database,
3265 const char *client_name,const char *keyword,char *resource_default)
3268 resource_class[MaxTextExtent],
3269 resource_name[MaxTextExtent];
3280 if (database == (XrmDatabase) NULL)
3281 return(resource_default);
3282 *resource_name='\0';
3283 *resource_class='\0';
3284 if (keyword != (char *) NULL)
3291 Initialize resource keyword and class.
3293 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
3294 client_name,keyword);
3295 c=(int) (*client_name);
3296 if ((c >= XK_a) && (c <= XK_z))
3299 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3300 c-=(XK_agrave-XK_Agrave);
3302 if ((c >= XK_oslash) && (c <= XK_thorn))
3303 c-=(XK_oslash-XK_Ooblique);
3305 if ((k >= XK_a) && (k <= XK_z))
3308 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3309 k-=(XK_agrave-XK_Agrave);
3311 if ((k >= XK_oslash) && (k <= XK_thorn))
3312 k-=(XK_oslash-XK_Ooblique);
3313 (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3314 client_name+1,k,keyword+1);
3316 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3318 if (status == False)
3319 return(resource_default);
3320 return(resource_value.addr);
3324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3328 % X G e t R e s o u r c e D a t a b a s e %
3332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3334 % XGetResourceDatabase() creates a new resource database and initializes it.
3336 % The format of the XGetResourceDatabase method is:
3338 % XrmDatabase XGetResourceDatabase(Display *display,
3339 % const char *client_name)
3341 % A description of each parameter follows:
3343 % o database: XGetResourceDatabase() returns the database after it is
3346 % o display: Specifies a connection to an X server; returned from
3349 % o client_name: Specifies the application name used to retrieve resource
3350 % info from the X server database.
3353 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3354 const char *client_name)
3357 filename[MaxTextExtent];
3369 if (display == (Display *) NULL)
3370 return((XrmDatabase) NULL);
3371 assert(client_name != (char *) NULL);
3373 Initialize resource database.
3376 (void) XGetDefault(display,(char *) client_name,"dummy");
3377 resource_database=XrmGetDatabase(display);
3379 Combine application database.
3381 if (client_name != (char *) NULL)
3384 Get basename of client.
3386 p=client_name+(strlen(client_name)-1);
3387 while ((p > client_name) && (*p != '/'))
3392 c=(int) (*client_name);
3393 if ((c >= XK_a) && (c <= XK_z))
3396 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3397 c-=(XK_agrave-XK_Agrave);
3399 if ((c >= XK_oslash) && (c <= XK_thorn))
3400 c-=(XK_oslash-XK_Ooblique);
3401 #if defined(X11_APPLICATION_PATH)
3402 (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
3403 X11_APPLICATION_PATH,c,client_name+1);
3404 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3406 if (XResourceManagerString(display) != (char *) NULL)
3409 Combine server database.
3411 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3412 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3415 Merge user preferences database.
3417 #if defined(X11_PREFERENCES_PATH)
3418 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
3419 X11_PREFERENCES_PATH,client_name);
3420 ExpandFilename(filename);
3421 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3423 return(resource_database);
3427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3431 % X G e t R e s o u r c e I n f o %
3435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3437 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3439 % The format of the XGetResourceInfo method is:
3441 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3442 % const char *client_name,XResourceInfo *resource_info)
3444 % A description of each parameter follows:
3446 % o image_info: the image info.
3448 % o database: Specifies a resource database; returned from
3449 % XrmGetStringDatabase.
3451 % o client_name: Specifies the application name used to retrieve
3452 % resource info from the X server database.
3454 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3457 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3458 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3465 Initialize resource info fields.
3467 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3468 assert(resource_info != (XResourceInfo *) NULL);
3469 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3470 resource_info->resource_database=database;
3471 resource_info->image_info=(ImageInfo *) image_info;
3472 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3473 XMagickProgressMonitor,(void *) NULL);
3474 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3475 resource_info->close_server=MagickTrue;
3476 resource_info->client_name=AcquireString(client_name);
3477 resource_value=XGetResourceClass(database,client_name,"backdrop",
3479 resource_info->backdrop=IsMagickTrue(resource_value);
3480 resource_info->background_color=XGetResourceInstance(database,client_name,
3481 "background",(char *) "#d6d6d6d6d6d6");
3482 resource_info->border_color=XGetResourceInstance(database,client_name,
3483 "borderColor",BorderColor);
3484 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3486 resource_info->border_width=(unsigned int) StringToUnsignedLong(
3488 resource_value=XGetResourceClass(database,client_name,"colormap",
3490 resource_info->colormap=UndefinedColormap;
3491 if (LocaleCompare("private",resource_value) == 0)
3492 resource_info->colormap=PrivateColormap;
3493 if (LocaleCompare("shared",resource_value) == 0)
3494 resource_info->colormap=SharedColormap;
3495 if (resource_info->colormap == UndefinedColormap)
3496 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3498 resource_value=XGetResourceClass(database,client_name,
3499 "colorRecovery",(char *) "False");
3500 resource_info->color_recovery=IsMagickTrue(resource_value);
3501 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3503 resource_info->confirm_exit=IsMagickTrue(resource_value);
3504 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3506 resource_info->confirm_edit=IsMagickTrue(resource_value);
3507 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3508 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3509 resource_info->display_gamma=XGetResourceClass(database,client_name,
3510 "displayGamma",(char *) "2.2");
3511 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3513 resource_info->display_warnings=IsMagickTrue(resource_value);
3514 resource_info->font=XGetResourceClass(database,client_name,"font",
3516 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3517 resource_info->font);
3518 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3520 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3521 (char *) "variable");
3522 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3524 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3526 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3527 (char *) "7x13bold");
3528 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3529 (char *) "8x13bold");
3530 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3531 (char *) "9x15bold");
3532 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3534 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3536 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3538 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3540 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3541 "foreground",ForegroundColor);
3542 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3544 resource_info->gamma_correct=IsMagickTrue(resource_value);
3545 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3546 client_name,"geometry",(char *) NULL));
3547 resource_value=XGetResourceClass(database,client_name,"gravity",
3549 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3550 MagickFalse,resource_value);
3551 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3553 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3554 "iconGeometry",(char *) NULL);
3555 resource_value=XGetResourceClass(database,client_name,"iconic",
3557 resource_info->iconic=IsMagickTrue(resource_value);
3558 resource_value=XGetResourceClass(database,client_name,"immutable",
3559 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3561 resource_info->immutable=IsMagickTrue(resource_value);
3562 resource_value=XGetResourceClass(database,client_name,"magnify",
3564 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3565 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3567 resource_info->matte_color=XGetResourceInstance(database,client_name,
3568 "mattecolor",(char *) NULL);
3569 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3570 "name",(char *) NULL));
3571 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3573 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3575 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3577 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3579 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3581 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3583 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3584 (char *) "magenta");
3585 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3587 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3589 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3591 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3593 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3594 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3595 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3596 resource_info->quantum=StringToLong(resource_value);
3597 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3598 "font",(char *) "fixed");
3599 resource_info->text_font=XGetResourceClass(database,client_name,
3600 "textFontList",resource_info->text_font);
3601 resource_info->title=XGetResourceClass(database,client_name,"title",
3603 resource_value=XGetResourceClass(database,client_name,"undoCache",
3605 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3606 resource_value=XGetResourceClass(database,client_name,"update",
3608 resource_info->update=IsMagickTrue(resource_value);
3609 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3611 resource_info->use_pixmap=IsMagickTrue(resource_value);
3612 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3614 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3615 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3617 resource_info->window_group=XGetResourceClass(database,client_name,
3618 "windowGroup",(char *) NULL);
3619 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3621 resource_info->write_filename=XGetResourceClass(database,client_name,
3622 "writeFilename",(char *) NULL);
3626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3630 % X G e t R e s o u r c e I n s t a n c e %
3634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3636 % XGetResourceInstance() queries the X server for the specified resource name.
3637 % If the resource name is not defined in the database, the supplied default
3638 % value is returned.
3640 % The format of the XGetResourceInstance method is:
3642 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3643 % const char *keyword,const char *resource_default)
3645 % A description of each parameter follows:
3647 % o database: Specifies a resource database; returned from
3648 % XrmGetStringDatabase.
3650 % o client_name: Specifies the application name used to retrieve
3651 % resource info from the X server database.
3653 % o keyword: Specifies the keyword of the value being retrieved.
3655 % o resource_default: Specifies the default value to return if the query
3656 % fails to find the specified keyword/class.
3659 MagickExport char *XGetResourceInstance(XrmDatabase database,
3660 const char *client_name,const char *keyword,const char *resource_default)
3664 resource_name[MaxTextExtent];
3672 if (database == (XrmDatabase) NULL)
3673 return((char *) resource_default);
3674 *resource_name='\0';
3675 if (keyword != (char *) NULL)
3676 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",client_name,
3678 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3680 if (status == False)
3681 return((char *) resource_default);
3682 return(resource_value.addr);
3686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3690 % X G e t S c r e e n D e n s i t y %
3694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3696 % XGetScreenDensity() returns the density of the X server screen in
3699 % The format of the XGetScreenDensity method is:
3701 % char *XGetScreenDensity(Display *display)
3703 % A description of each parameter follows:
3705 % o density: XGetScreenDensity() returns the density of the X screen in
3708 % o display: Specifies a connection to an X server; returned from
3712 MagickExport char *XGetScreenDensity(Display *display)
3715 density[MaxTextExtent];
3722 Set density as determined by screen size.
3724 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3725 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3726 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3727 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3728 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",x_density,
3730 return(GetPageGeometry(density));
3734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3738 + X G e t S u b w i n d o w %
3742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3744 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3745 % pointer and a button press.
3747 % The format of the XGetSubwindow method is:
3749 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3751 % A description of each parameter follows:
3753 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3754 % otherwise the subwindow is returned.
3756 % o display: Specifies a connection to an X server; returned from
3759 % o window: Specifies a pointer to a Window.
3761 % o x: the x coordinate of the pointer relative to the origin of the
3764 % o y: the y coordinate of the pointer relative to the origin of the
3768 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3781 assert(display != (Display *) NULL);
3782 source_window=XRootWindow(display,XDefaultScreen(display));
3783 if (window == (Window) NULL)
3784 return(source_window);
3785 target_window=window;
3788 status=XTranslateCoordinates(display,source_window,window,x,y,
3789 &x_offset,&y_offset,&target_window);
3792 if (target_window == (Window) NULL)
3794 source_window=window;
3795 window=target_window;
3799 if (target_window == (Window) NULL)
3800 target_window=window;
3801 return(target_window);
3805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3809 % X G e t W i n d o w C o l o r %
3813 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3815 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3818 % The format of the XGetWindowColor method is:
3820 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3823 % A description of each parameter follows:
3825 % o display: Specifies a connection to an X server; returned from
3828 % o windows: Specifies a pointer to a XWindows structure.
3830 % o name: the name of the color if found in the X Color Database is
3831 % returned in this character string.
3834 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3835 XWindows *windows,char *name)
3866 Choose a pixel from the X server.
3868 assert(display != (Display *) NULL);
3869 assert(name != (char *) NULL);
3870 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3872 target_window=XSelectWindow(display,&crop_info);
3873 if (target_window == (Window) NULL)
3874 return(MagickFalse);
3875 root_window=XRootWindow(display,XDefaultScreen(display));
3876 client_window=target_window;
3877 if (target_window != root_window)
3885 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3886 if (status != False)
3888 client_window=XClientWindow(display,target_window);
3889 target_window=client_window;
3893 Verify window is viewable.
3895 status=XGetWindowAttributes(display,target_window,&window_attributes);
3896 if ((status == False) || (window_attributes.map_state != IsViewable))
3897 return(MagickFalse);
3901 (void) XTranslateCoordinates(display,root_window,target_window,
3902 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3903 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3904 if (ximage == (XImage *) NULL)
3905 return(MagickFalse);
3906 color.pixel=XGetPixel(ximage,0,0);
3907 XDestroyImage(ximage);
3909 Match color against the color database.
3911 (void) XQueryColor(display,window_attributes.colormap,&color);
3912 pixel.red=ScaleShortToQuantum(color.red);
3913 pixel.green=ScaleShortToQuantum(color.green);
3914 pixel.blue=ScaleShortToQuantum(color.blue);
3915 pixel.alpha=OpaqueAlpha;
3916 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3917 &windows->image.image->exception);
3922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3926 + X G e t W i n d o w I m a g e %
3930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3932 % XGetWindowImage() reads an image from the target X window and returns it.
3933 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3934 % target image with each child image in an optimized fashion. Any child
3935 % window that have the same visual, colormap, and are contained by its parent
3938 % The format of the XGetWindowImage method is:
3940 % Image *XGetWindowImage(Display *display,const Window window,
3941 % const unsigned int borders,const unsigned int level)
3943 % A description of each parameter follows:
3945 % o display: Specifies a connection to an X server; returned from
3948 % o window: Specifies the window to obtain the image from.
3950 % o borders: Specifies whether borders pixels are to be saved with
3953 % o level: Specifies an unsigned integer representing the level of
3954 % decent in the window hierarchy. This value must be zero or one on
3955 % the initial call to XGetWindowImage. A value of zero returns after
3956 % one call. A value of one causes the function to descend the window
3957 % hierarchy and overlay the target image with each subwindow image.
3960 static Image *XGetWindowImage(Display *display,const Window window,
3961 const unsigned int borders,const unsigned int level)
3963 typedef struct _ColormapInfo
3971 struct _ColormapInfo
3975 typedef struct _WindowInfo
4011 *colormap_info = (ColormapInfo *) NULL;
4031 Verify window is viewable.
4033 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4034 assert(display != (Display *) NULL);
4035 status=XGetWindowAttributes(display,window,&window_attributes);
4036 if ((status == False) || (window_attributes.map_state != IsViewable))
4037 return((Image *) NULL);
4039 Cropping rectangle is relative to root window.
4041 root_window=XRootWindow(display,XDefaultScreen(display));
4042 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4044 crop_info.x=(ssize_t) x_offset;
4045 crop_info.y=(ssize_t) y_offset;
4046 crop_info.width=(size_t) window_attributes.width;
4047 crop_info.height=(size_t) window_attributes.height;
4048 if (borders != MagickFalse)
4051 Include border in image.
4053 crop_info.x-=(ssize_t) window_attributes.border_width;
4054 crop_info.y-=(ssize_t) window_attributes.border_width;
4055 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4056 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4059 Crop to root window.
4061 if (crop_info.x < 0)
4063 crop_info.width+=crop_info.x;
4066 if (crop_info.y < 0)
4068 crop_info.height+=crop_info.y;
4071 display_width=XDisplayWidth(display,XDefaultScreen(display));
4072 if ((int) (crop_info.x+crop_info.width) > display_width)
4073 crop_info.width=(size_t) (display_width-crop_info.x);
4074 display_height=XDisplayHeight(display,XDefaultScreen(display));
4075 if ((int) (crop_info.y+crop_info.height) > display_height)
4076 crop_info.height=(size_t) (display_height-crop_info.y);
4078 Initialize window info attributes.
4080 if (number_windows >= max_windows)
4083 Allocate or resize window info buffer.
4086 if (window_info == (WindowInfo *) NULL)
4087 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4088 sizeof(*window_info));
4090 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4091 max_windows,sizeof(*window_info));
4093 if (window_info == (WindowInfo *) NULL)
4095 ThrowXWindowFatalException(ResourceLimitError,
4096 "MemoryAllocationFailed","...");
4097 return((Image *) NULL);
4099 id=number_windows++;
4100 window_info[id].window=window;
4101 window_info[id].visual=window_attributes.visual;
4102 window_info[id].colormap=window_attributes.colormap;
4103 window_info[id].bounds.x1=(short) crop_info.x;
4104 window_info[id].bounds.y1=(short) crop_info.y;
4105 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4106 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4107 crop_info.x-=x_offset;
4108 crop_info.y-=y_offset;
4109 window_info[id].crop_info=crop_info;
4119 Descend the window hierarchy.
4121 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4122 &children,&number_children);
4123 for (i=0; i < id; i++)
4124 if ((window_info[i].window == window_info[id].parent) &&
4125 (window_info[i].visual == window_info[id].visual) &&
4126 (window_info[i].colormap == window_info[id].colormap))
4128 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4129 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4130 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4131 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4134 Eliminate windows not circumscribed by their parent.
4140 if ((status == True) && (number_children != 0))
4142 for (i=0; i < (int) number_children; i++)
4143 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4144 (void) XFree((void *) children);
4188 Get X image for each window in the list.
4190 image=NewImageList();
4191 for (id=0; id < number_windows; id++)
4194 Does target window intersect top level window?
4197 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4198 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4199 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4200 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4201 MagickTrue : MagickFalse;
4203 Is target window contained by another window with the same colormap?
4205 for (j=0; j < id; j++)
4206 if ((window_info[id].visual == window_info[j].visual) &&
4207 (window_info[id].colormap == window_info[j].colormap))
4209 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4210 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4211 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4212 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4216 if ((window_info[id].visual != window_info[j].visual) ||
4217 (window_info[id].colormap != window_info[j].colormap))
4219 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4220 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4221 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4222 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4225 if (import == MagickFalse)
4230 ximage=XGetImage(display,window_info[id].window,(int)
4231 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4232 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4233 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4234 if (ximage == (XImage *) NULL)
4237 Initialize window colormap.
4240 colors=(XColor *) NULL;
4241 if (window_info[id].colormap != (Colormap) NULL)
4247 Search colormap list for window colormap.
4249 number_colors=(unsigned int) window_info[id].visual->map_entries;
4250 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4251 if (p->colormap == window_info[id].colormap)
4253 if (p == (ColormapInfo *) NULL)
4256 Get the window colormap.
4258 colors=(XColor *) AcquireQuantumMemory(number_colors,
4260 if (colors == (XColor *) NULL)
4262 XDestroyImage(ximage);
4263 return((Image *) NULL);
4265 if ((window_info[id].visual->klass != DirectColor) &&
4266 (window_info[id].visual->klass != TrueColor))
4267 for (i=0; i < (int) number_colors; i++)
4269 colors[i].pixel=(size_t) i;
4283 DirectColor or TrueColor visual.
4288 red_bit=window_info[id].visual->red_mask &
4289 (~(window_info[id].visual->red_mask)+1);
4290 green_bit=window_info[id].visual->green_mask &
4291 (~(window_info[id].visual->green_mask)+1);
4292 blue_bit=window_info[id].visual->blue_mask &
4293 (~(window_info[id].visual->blue_mask)+1);
4294 for (i=0; i < (int) number_colors; i++)
4296 colors[i].pixel=(unsigned long) (red | green | blue);
4299 if (red > window_info[id].visual->red_mask)
4302 if (green > window_info[id].visual->green_mask)
4305 if (blue > window_info[id].visual->blue_mask)
4309 (void) XQueryColors(display,window_info[id].colormap,colors,
4310 (int) number_colors);
4312 Append colormap to colormap list.
4314 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4315 if (p == (ColormapInfo *) NULL)
4316 return((Image *) NULL);
4317 p->colormap=window_info[id].colormap;
4319 p->next=colormap_info;
4325 Allocate image structure.
4327 composite_image=AcquireImage((ImageInfo *) NULL);
4328 if (composite_image == (Image *) NULL)
4330 XDestroyImage(ximage);
4331 return((Image *) NULL);
4334 Convert X image to MIFF format.
4336 if ((window_info[id].visual->klass != TrueColor) &&
4337 (window_info[id].visual->klass != DirectColor))
4338 composite_image->storage_class=PseudoClass;
4339 composite_image->columns=(size_t) ximage->width;
4340 composite_image->rows=(size_t) ximage->height;
4341 exception=(&composite_image->exception);
4342 composite_view=AcquireCacheView(composite_image);
4343 switch (composite_image->storage_class)
4361 Determine shift and mask for red, green, and blue.
4363 red_mask=window_info[id].visual->red_mask;
4365 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4370 green_mask=window_info[id].visual->green_mask;
4372 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4377 blue_mask=window_info[id].visual->blue_mask;
4379 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4385 Convert X image to DirectClass packets.
4387 if ((number_colors != 0) &&
4388 (window_info[id].visual->klass == DirectColor))
4389 for (y=0; y < (int) composite_image->rows; y++)
4391 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4392 composite_image->columns,1,exception);
4393 if (q == (Quantum *) NULL)
4395 for (x=0; x < (int) composite_image->columns; x++)
4397 pixel=XGetPixel(ximage,x,y);
4398 index=(pixel >> red_shift) & red_mask;
4399 SetPixelRed(composite_image,
4400 ScaleShortToQuantum(colors[index].red),q);
4401 index=(pixel >> green_shift) & green_mask;
4402 SetPixelGreen(composite_image,
4403 ScaleShortToQuantum(colors[index].green),q);
4404 index=(pixel >> blue_shift) & blue_mask;
4405 SetPixelBlue(composite_image,
4406 ScaleShortToQuantum(colors[index].blue),q);
4407 q+=GetPixelChannels(composite_image);
4409 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4413 for (y=0; y < (int) composite_image->rows; y++)
4415 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4416 composite_image->columns,1,exception);
4417 if (q == (Quantum *) NULL)
4419 for (x=0; x < (int) composite_image->columns; x++)
4421 pixel=XGetPixel(ximage,x,y);
4422 color=(pixel >> red_shift) & red_mask;
4423 color=(65535UL*color)/red_mask;
4424 SetPixelRed(composite_image,
4425 ScaleShortToQuantum((unsigned short) color),q);
4426 color=(pixel >> green_shift) & green_mask;
4427 color=(65535UL*color)/green_mask;
4428 SetPixelGreen(composite_image,
4429 ScaleShortToQuantum((unsigned short) color),q);
4430 color=(pixel >> blue_shift) & blue_mask;
4431 color=(65535UL*color)/blue_mask;
4432 SetPixelBlue(composite_image,
4433 ScaleShortToQuantum((unsigned short) color),q);
4434 q+=GetPixelChannels(composite_image);
4436 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4446 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4448 XDestroyImage(ximage);
4449 composite_image=DestroyImage(composite_image);
4450 return((Image *) NULL);
4452 for (i=0; i < (int) composite_image->colors; i++)
4454 composite_image->colormap[colors[i].pixel].red=
4455 ScaleShortToQuantum(colors[i].red);
4456 composite_image->colormap[colors[i].pixel].green=
4457 ScaleShortToQuantum(colors[i].green);
4458 composite_image->colormap[colors[i].pixel].blue=
4459 ScaleShortToQuantum(colors[i].blue);
4462 Convert X image to PseudoClass packets.
4464 for (y=0; y < (int) composite_image->rows; y++)
4466 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4467 composite_image->columns,1,exception);
4468 if (q == (Quantum *) NULL)
4470 for (x=0; x < (int) composite_image->columns; x++)
4472 index=(Quantum) XGetPixel(ximage,x,y);
4473 SetPixelIndex(composite_image,index,q);
4474 SetPixelPacket(composite_image,
4475 composite_image->colormap+(ssize_t) index,q);
4476 q+=GetPixelChannels(composite_image);
4478 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4484 composite_view=DestroyCacheView(composite_view);
4485 XDestroyImage(ximage);
4486 if (image == (Image *) NULL)
4488 image=composite_image;
4492 Composite any children in back-to-front order.
4494 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4495 &x_offset,&y_offset,&child);
4496 x_offset-=(int) crop_info.x;
4499 y_offset-=(int) crop_info.y;
4502 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4503 x_offset,(ssize_t) y_offset);
4506 Relinquish resources.
4508 while (colormap_info != (ColormapInfo *) NULL)
4510 next=colormap_info->next;
4511 colormap_info->colors=(XColor *)
4512 RelinquishMagickMemory(colormap_info->colors);
4513 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4517 Relinquish resources and restore initial state.
4519 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4522 colormap_info=(ColormapInfo *) NULL;
4525 return((Image *) NULL);
4529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4533 % X G e t W i n d o w I n f o %
4537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4539 % XGetWindowInfo() initializes the XWindowInfo structure.
4541 % The format of the XGetWindowInfo method is:
4543 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4544 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4545 % XResourceInfo *resource_info,XWindowInfo *window)
4546 % resource_info,window)
4548 % A description of each parameter follows:
4550 % o display: Specifies a connection to an X server; returned from
4553 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4554 % returned from XGetVisualInfo.
4556 % o map_info: If map_type is specified, this structure is initialized
4557 % with info from the Standard Colormap.
4559 % o pixel: Specifies a pointer to a XPixelInfo structure.
4561 % o font_info: Specifies a pointer to a XFontStruct structure.
4563 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4566 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4567 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4568 XResourceInfo *resource_info,XWindowInfo *window)
4571 Initialize window info.
4573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4574 assert(display != (Display *) NULL);
4575 assert(visual_info != (XVisualInfo *) NULL);
4576 assert(map_info != (XStandardColormap *) NULL);
4577 assert(pixel != (XPixelInfo *) NULL);
4578 assert(resource_info != (XResourceInfo *) NULL);
4579 assert(window != (XWindowInfo *) NULL);
4580 if (window->id != (Window) NULL)
4582 if (window->cursor != (Cursor) NULL)
4583 (void) XFreeCursor(display,window->cursor);
4584 if (window->busy_cursor != (Cursor) NULL)
4585 (void) XFreeCursor(display,window->busy_cursor);
4586 if (window->highlight_stipple != (Pixmap) NULL)
4587 (void) XFreePixmap(display,window->highlight_stipple);
4588 if (window->shadow_stipple != (Pixmap) NULL)
4589 (void) XFreePixmap(display,window->shadow_stipple);
4590 if (window->name == (char *) NULL)
4591 window->name=AcquireString("");
4592 if (window->icon_name == (char *) NULL)
4593 window->icon_name=AcquireString("");
4598 Initialize these attributes just once.
4600 window->id=(Window) NULL;
4601 if (window->name == (char *) NULL)
4602 window->name=AcquireString("");
4603 if (window->icon_name == (char *) NULL)
4604 window->icon_name=AcquireString("");
4605 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4606 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4607 window->ximage=(XImage *) NULL;
4608 window->matte_image=(XImage *) NULL;
4609 window->pixmap=(Pixmap) NULL;
4610 window->matte_pixmap=(Pixmap) NULL;
4611 window->mapped=MagickFalse;
4612 window->stasis=MagickFalse;
4613 window->shared_memory=MagickTrue;
4614 window->segment_info=(void *) NULL;
4615 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4620 if (window->segment_info == (void *) NULL)
4621 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4622 segment_info=(XShmSegmentInfo *) window->segment_info;
4623 segment_info[0].shmid=(-1);
4624 segment_info[0].shmaddr=(char *) NULL;
4625 segment_info[1].shmid=(-1);
4626 segment_info[1].shmaddr=(char *) NULL;
4631 Initialize these attributes every time function is called.
4633 window->screen=visual_info->screen;
4634 window->root=XRootWindow(display,visual_info->screen);
4635 window->visual=visual_info->visual;
4636 window->storage_class=(unsigned int) visual_info->klass;
4637 window->depth=(unsigned int) visual_info->depth;
4638 window->visual_info=visual_info;
4639 window->map_info=map_info;
4640 window->pixel_info=pixel;
4641 window->font_info=font_info;
4642 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4643 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4644 window->geometry=(char *) NULL;
4645 window->icon_geometry=(char *) NULL;
4646 if (resource_info->icon_geometry != (char *) NULL)
4647 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4648 window->crop_geometry=(char *) NULL;
4649 window->flags=(size_t) PSize;
4652 window->min_width=1;
4653 window->min_height=1;
4654 window->width_inc=1;
4655 window->height_inc=1;
4656 window->border_width=resource_info->border_width;
4657 window->annotate_context=pixel->annotate_context;
4658 window->highlight_context=pixel->highlight_context;
4659 window->widget_context=pixel->widget_context;
4660 window->shadow_stipple=(Pixmap) NULL;
4661 window->highlight_stipple=(Pixmap) NULL;
4662 window->use_pixmap=MagickTrue;
4663 window->immutable=MagickFalse;
4664 window->shape=MagickFalse;
4666 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4667 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4668 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4669 window->attributes.background_pixel=pixel->background_color.pixel;
4670 window->attributes.background_pixmap=(Pixmap) NULL;
4671 window->attributes.bit_gravity=ForgetGravity;
4672 window->attributes.backing_store=WhenMapped;
4673 window->attributes.save_under=MagickTrue;
4674 window->attributes.border_pixel=pixel->border_color.pixel;
4675 window->attributes.colormap=map_info->colormap;
4676 window->attributes.cursor=window->cursor;
4677 window->attributes.do_not_propagate_mask=NoEventMask;
4678 window->attributes.event_mask=NoEventMask;
4679 window->attributes.override_redirect=MagickFalse;
4680 window->attributes.win_gravity=NorthWestGravity;
4681 window->orphan=MagickFalse;
4685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4689 % X H i g h l i g h t E l l i p s e %
4693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4695 % XHighlightEllipse() puts a border on the X server around a region defined by
4698 % The format of the XHighlightEllipse method is:
4700 % void XHighlightEllipse(Display *display,Window window,
4701 % GC annotate_context,const RectangleInfo *highlight_info)
4703 % A description of each parameter follows:
4705 % o display: Specifies a connection to an X server; returned from
4708 % o window: Specifies a pointer to a Window structure.
4710 % o annotate_context: Specifies a pointer to a GC structure.
4712 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4713 % contains the extents of any highlighting rectangle.
4716 MagickExport void XHighlightEllipse(Display *display,Window window,
4717 GC annotate_context,const RectangleInfo *highlight_info)
4719 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4720 assert(display != (Display *) NULL);
4721 assert(window != (Window) NULL);
4722 assert(annotate_context != (GC) NULL);
4723 assert(highlight_info != (RectangleInfo *) NULL);
4724 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4726 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4727 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4728 (unsigned int) highlight_info->height-1,0,360*64);
4729 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4730 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4731 (unsigned int) highlight_info->height-3,0,360*64);
4735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4739 % X H i g h l i g h t L i n e %
4743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4745 % XHighlightLine() puts a border on the X server around a region defined by
4748 % The format of the XHighlightLine method is:
4750 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4751 % const XSegment *highlight_info)
4753 % A description of each parameter follows:
4755 % o display: Specifies a connection to an X server; returned from
4758 % o window: Specifies a pointer to a Window structure.
4760 % o annotate_context: Specifies a pointer to a GC structure.
4762 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4763 % contains the extents of any highlighting rectangle.
4766 MagickExport void XHighlightLine(Display *display,Window window,
4767 GC annotate_context,const XSegment *highlight_info)
4769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4770 assert(display != (Display *) NULL);
4771 assert(window != (Window) NULL);
4772 assert(annotate_context != (GC) NULL);
4773 assert(highlight_info != (XSegment *) NULL);
4774 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4775 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4783 % X H i g h l i g h t R e c t a n g l e %
4787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4789 % XHighlightRectangle() puts a border on the X server around a region defined
4790 % by highlight_info.
4792 % The format of the XHighlightRectangle method is:
4794 % void XHighlightRectangle(Display *display,Window window,
4795 % GC annotate_context,const RectangleInfo *highlight_info)
4797 % A description of each parameter follows:
4799 % o display: Specifies a connection to an X server; returned from
4802 % o window: Specifies a pointer to a Window structure.
4804 % o annotate_context: Specifies a pointer to a GC structure.
4806 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4807 % contains the extents of any highlighting rectangle.
4810 MagickExport void XHighlightRectangle(Display *display,Window window,
4811 GC annotate_context,const RectangleInfo *highlight_info)
4813 assert(display != (Display *) NULL);
4814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4815 assert(window != (Window) NULL);
4816 assert(annotate_context != (GC) NULL);
4817 assert(highlight_info != (RectangleInfo *) NULL);
4818 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4820 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4821 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4822 (unsigned int) highlight_info->height-1);
4823 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4824 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4825 (unsigned int) highlight_info->height-3);
4829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4833 % X I m p o r t I m a g e %
4837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4839 % XImportImage() reads an image from an X window.
4841 % The format of the XImportImage method is:
4843 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4845 % A description of each parameter follows:
4847 % o image_info: the image info.
4849 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4852 MagickExport Image *XImportImage(const ImageInfo *image_info,
4853 XImportInfo *ximage_info)
4886 Open X server connection.
4888 assert(image_info != (const ImageInfo *) NULL);
4889 assert(image_info->signature == MagickSignature);
4890 if (image_info->debug != MagickFalse)
4891 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4892 image_info->filename);
4893 assert(ximage_info != (XImportInfo *) NULL);
4894 display=XOpenDisplay(image_info->server_name);
4895 if (display == (Display *) NULL)
4897 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4898 XDisplayName(image_info->server_name));
4899 return((Image *) NULL);
4902 Set our forgiving exception handler.
4904 (void) XSetErrorHandler(XError);
4906 Select target window.
4912 root=XRootWindow(display,XDefaultScreen(display));
4913 target=(Window) NULL;
4914 if ((image_info->filename != (char *) NULL) &&
4915 (*image_info->filename != '\0'))
4917 if (LocaleCompare(image_info->filename,"root") == 0)
4922 Select window by ID or name.
4924 if (isdigit((unsigned char) *image_info->filename) != 0)
4925 target=XWindowByID(display,root,(Window)
4926 strtol(image_info->filename,(char **) NULL,0));
4927 if (target == (Window) NULL)
4928 target=XWindowByName(display,root,image_info->filename);
4929 if (target == (Window) NULL)
4930 ThrowXWindowFatalException(XServerError,
4931 "NoWindowWithSpecifiedIDExists",image_info->filename);
4935 If target window is not defined, interactively select one.
4937 prior_target=target;
4938 if (target == (Window) NULL)
4939 target=XSelectWindow(display,&crop_info);
4940 if (target == (Window) NULL)
4941 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4942 image_info->filename);
4943 client=target; /* obsolete */
4949 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4950 if (status != False)
4958 Find window manager frame.
4960 status=XQueryTree(display,target,&root,&parent,&children,&d);
4961 if ((status != False) && (children != (Window *) NULL))
4962 (void) XFree((char *) children);
4963 if ((status == False) || (parent == (Window) NULL) ||
4971 client=XClientWindow(display,target);
4972 if (ximage_info->frame == MagickFalse)
4974 if ((ximage_info->frame == MagickFalse) &&
4975 (prior_target != MagickFalse))
4976 target=prior_target;
4977 XDelay(display,SuspendTime << 4);
4980 if (ximage_info->screen)
4992 Obtain window image directly from screen.
4994 status=XGetWindowAttributes(display,target,&window_attributes);
4995 if (status == False)
4997 ThrowXWindowFatalException(XServerError,
4998 "UnableToReadXWindowAttributes",image_info->filename);
4999 (void) XCloseDisplay(display);
5000 return((Image *) NULL);
5002 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5003 crop_info.x=(ssize_t) x;
5004 crop_info.y=(ssize_t) y;
5005 crop_info.width=(size_t) window_attributes.width;
5006 crop_info.height=(size_t) window_attributes.height;
5007 if (ximage_info->borders != 0)
5010 Include border in image.
5012 crop_info.x-=window_attributes.border_width;
5013 crop_info.y-=window_attributes.border_width;
5014 crop_info.width+=window_attributes.border_width << 1;
5015 crop_info.height+=window_attributes.border_width << 1;
5020 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
5023 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5024 if ((status == True) && (number_windows > 0))
5026 ximage_info->descend=MagickTrue;
5027 (void) XFree ((char *) children);
5029 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5030 if (number_colormaps > 0)
5032 if (number_colormaps > 1)
5033 ximage_info->descend=MagickTrue;
5034 (void) XFree((char *) colormaps);
5037 Alert the user not to alter the screen.
5039 if (ximage_info->silent == MagickFalse)
5040 (void) XBell(display,0);
5042 Get image by window id.
5044 (void) XGrabServer(display);
5045 image=XGetWindowImage(display,target,ximage_info->borders,
5046 ximage_info->descend ? 1U : 0U);
5047 (void) XUngrabServer(display);
5048 if (image == (Image *) NULL)
5049 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5050 image_info->filename)
5053 (void) CopyMagickString(image->filename,image_info->filename,
5055 if ((crop_info.width != 0) && (crop_info.height != 0))
5062 Crop image as defined by the cropping rectangle.
5064 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5065 if (clone_image != (Image *) NULL)
5067 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5068 if (crop_image != (Image *) NULL)
5070 image=DestroyImage(image);
5075 status=XGetWMName(display,target,&window_name);
5078 if ((image_info->filename != (char *) NULL) &&
5079 (*image_info->filename == '\0'))
5080 (void) CopyMagickString(image->filename,(char *) window_name.value,
5081 (size_t) window_name.nitems+1);
5082 (void) XFree((void *) window_name.value);
5085 if (ximage_info->silent == MagickFalse)
5088 Alert the user we're done.
5090 (void) XBell(display,0);
5091 (void) XBell(display,0);
5093 (void) XCloseDisplay(display);
5098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5102 % X I n i t i a l i z e W i n d o w s %
5106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5108 % XInitializeWindows() initializes the XWindows structure.
5110 % The format of the XInitializeWindows method is:
5112 % XWindows *XInitializeWindows(Display *display,
5113 % XResourceInfo *resource_info)
5115 % A description of each parameter follows:
5117 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5119 % o display: Specifies a connection to an X server; returned from
5122 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5125 MagickExport XWindows *XInitializeWindows(Display *display,
5126 XResourceInfo *resource_info)
5135 Allocate windows structure.
5137 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5138 if (windows == (XWindows *) NULL)
5140 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5142 return((XWindows *) NULL);
5144 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5145 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5146 sizeof(*windows->pixel_info));
5147 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5148 sizeof(*windows->icon_pixel));
5149 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5150 sizeof(*windows->icon_resources));
5151 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5152 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5153 (windows->icon_resources == (XResourceInfo *) NULL))
5155 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5157 return((XWindows *) NULL);
5160 Initialize windows structure.
5162 windows->display=display;
5163 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5164 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5165 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5166 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5167 windows->im_remote_command=
5168 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5169 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5170 windows->im_update_colormap=
5171 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5172 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5173 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5174 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5175 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5176 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5177 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5178 (void) XSynchronize(display,IsWindows95());
5180 if (IsEventLogging())
5182 (void) XSynchronize(display,MagickTrue);
5183 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5184 GetMagickVersion((size_t *) NULL));
5185 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5186 (void) LogMagickEvent(X11Event,GetMagickModule(),
5187 " Window Manager: 0x%lx",windows->wm_protocols);
5188 (void) LogMagickEvent(X11Event,GetMagickModule(),
5189 " delete window: 0x%lx",windows->wm_delete_window);
5190 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5191 windows->wm_take_focus);
5192 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5193 windows->im_protocols);
5194 (void) LogMagickEvent(X11Event,GetMagickModule(),
5195 " remote command: 0x%lx",windows->im_remote_command);
5196 (void) LogMagickEvent(X11Event,GetMagickModule(),
5197 " update widget: 0x%lx",windows->im_update_widget);
5198 (void) LogMagickEvent(X11Event,GetMagickModule(),
5199 " update colormap: 0x%lx",windows->im_update_colormap);
5200 (void) LogMagickEvent(X11Event,GetMagickModule(),
5201 " former image: 0x%lx",windows->im_former_image);
5202 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5203 windows->im_next_image);
5204 (void) LogMagickEvent(X11Event,GetMagickModule(),
5205 " retain colors: 0x%lx",windows->im_retain_colors);
5206 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5208 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5209 windows->dnd_protocols);
5212 Allocate standard colormap.
5214 windows->map_info=XAllocStandardColormap();
5215 windows->icon_map=XAllocStandardColormap();
5216 if ((windows->map_info == (XStandardColormap *) NULL) ||
5217 (windows->icon_map == (XStandardColormap *) NULL))
5218 ThrowXWindowFatalException(ResourceLimitFatalError,
5219 "MemoryAllocationFailed","...");
5220 windows->map_info->colormap=(Colormap) NULL;
5221 windows->icon_map->colormap=(Colormap) NULL;
5222 windows->pixel_info->pixels=(unsigned long *) NULL;
5223 windows->pixel_info->annotate_context=(GC) NULL;
5224 windows->pixel_info->highlight_context=(GC) NULL;
5225 windows->pixel_info->widget_context=(GC) NULL;
5226 windows->font_info=(XFontStruct *) NULL;
5227 windows->icon_pixel->annotate_context=(GC) NULL;
5228 windows->icon_pixel->pixels=(unsigned long *) NULL;
5232 *windows->icon_resources=(*resource_info);
5233 windows->icon_resources->visual_type=(char *) "default";
5234 windows->icon_resources->colormap=SharedColormap;
5235 windows->visual_info=
5236 XBestVisualInfo(display,windows->map_info,resource_info);
5237 windows->icon_visual=
5238 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5239 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5240 (windows->icon_visual == (XVisualInfo *) NULL))
5241 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5242 resource_info->visual_type);
5243 if (IsEventLogging())
5245 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5246 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5247 windows->visual_info->visualid);
5248 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5249 XVisualClassName(windows->visual_info->klass));
5250 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5251 windows->visual_info->depth);
5252 (void) LogMagickEvent(X11Event,GetMagickModule(),
5253 " size of colormap: %d entries",windows->visual_info->colormap_size);
5254 (void) LogMagickEvent(X11Event,GetMagickModule(),
5255 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5256 windows->visual_info->red_mask,windows->visual_info->green_mask,
5257 windows->visual_info->blue_mask);
5258 (void) LogMagickEvent(X11Event,GetMagickModule(),
5259 " significant bits in color: %d bits",
5260 windows->visual_info->bits_per_rgb);
5263 Allocate class and manager hints.
5265 windows->class_hints=XAllocClassHint();
5266 windows->manager_hints=XAllocWMHints();
5267 if ((windows->class_hints == (XClassHint *) NULL) ||
5268 (windows->manager_hints == (XWMHints *) NULL))
5269 ThrowXWindowFatalException(ResourceLimitFatalError,
5270 "MemoryAllocationFailed","...");
5272 Determine group leader if we have one.
5274 root_window=XRootWindow(display,windows->visual_info->screen);
5275 windows->group_leader.id=(Window) NULL;
5276 if (resource_info->window_group != (char *) NULL)
5278 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5279 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5280 strtol((char *) resource_info->window_group,(char **) NULL,0));
5281 if (windows->group_leader.id == (Window) NULL)
5282 windows->group_leader.id=
5283 XWindowByName(display,root_window,resource_info->window_group);
5289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5293 % X M a k e C u r s o r %
5297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5299 % XMakeCursor() creates a crosshairs X11 cursor.
5301 % The format of the XMakeCursor method is:
5303 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5304 % char *background_color,char *foreground_color)
5306 % A description of each parameter follows:
5308 % o display: Specifies a connection to an X server; returned from
5311 % o window: Specifies the ID of the window for which the cursor is
5314 % o colormap: Specifies the ID of the colormap from which the background
5315 % and foreground color will be retrieved.
5317 % o background_color: Specifies the color to use for the cursor background.
5319 % o foreground_color: Specifies the color to use for the cursor foreground.
5322 MagickExport Cursor XMakeCursor(Display *display,Window window,
5323 Colormap colormap,char *background_color,char *foreground_color)
5325 #define scope_height 17
5326 #define scope_x_hot 8
5327 #define scope_y_hot 8
5328 #define scope_width 17
5330 static const unsigned char
5333 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5334 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5335 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5336 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5337 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5341 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5342 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5343 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5344 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5345 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5359 assert(display != (Display *) NULL);
5360 assert(window != (Window) NULL);
5361 assert(colormap != (Colormap) NULL);
5362 assert(background_color != (char *) NULL);
5363 assert(foreground_color != (char *) NULL);
5364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5365 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5367 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5368 scope_width,scope_height);
5369 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5371 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5372 return((Cursor) NULL);
5374 (void) XParseColor(display,colormap,background_color,&background);
5375 (void) XParseColor(display,colormap,foreground_color,&foreground);
5376 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5377 scope_x_hot,scope_y_hot);
5378 (void) XFreePixmap(display,source);
5379 (void) XFreePixmap(display,mask);
5384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5388 % X M a k e I m a g e %
5392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5394 % XMakeImage() creates an X11 image. If the image size differs from the X11
5395 % image size, the image is first resized.
5397 % The format of the XMakeImage method is:
5399 % MagickBooleanType XMakeImage(Display *display,
5400 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5401 % unsigned int width,unsigned int height,ExceptionInfo *exception)
5403 % A description of each parameter follows:
5405 % o display: Specifies a connection to an X server; returned from
5408 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5410 % o window: Specifies a pointer to a XWindowInfo structure.
5412 % o image: the image.
5414 % o width: Specifies the width in pixels of the rectangular area to
5417 % o height: Specifies the height in pixels of the rectangular area to
5420 % o exception: return any errors or warnings in this structure.
5423 MagickExport MagickBooleanType XMakeImage(Display *display,
5424 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5425 unsigned int width,unsigned int height,ExceptionInfo *exception)
5427 #define CheckOverflowException(length,width,height) \
5428 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5441 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5442 assert(display != (Display *) NULL);
5443 assert(resource_info != (XResourceInfo *) NULL);
5444 assert(window != (XWindowInfo *) NULL);
5446 assert(height != 0);
5447 if ((window->width == 0) || (window->height == 0))
5448 return(MagickFalse);
5450 Apply user transforms to the image.
5452 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5453 (void) XFlush(display);
5454 depth=(int) window->depth;
5455 if (window->destroy)
5456 window->image=DestroyImage(window->image);
5457 window->image=image;
5458 window->destroy=MagickFalse;
5459 if (window->image != (Image *) NULL)
5461 if (window->crop_geometry != (char *) NULL)
5472 window->image->page.x=0;
5473 window->image->page.y=0;
5474 (void) ParsePageGeometry(window->image,window->crop_geometry,
5475 &crop_info,&image->exception);
5476 crop_image=CropImage(window->image,&crop_info,&image->exception);
5477 if (crop_image != (Image *) NULL)
5479 if (window->image != image)
5480 window->image=DestroyImage(window->image);
5481 window->image=crop_image;
5482 window->destroy=MagickTrue;
5485 if ((width != (unsigned int) window->image->columns) ||
5486 (height != (unsigned int) window->image->rows))
5494 resize_image=NewImageList();
5495 if (window->pixel_info->colors != 0)
5496 resize_image=SampleImage(window->image,width,height,
5499 resize_image=ThumbnailImage(window->image,width,height,
5501 if (resize_image != (Image *) NULL)
5503 if (window->image != image)
5504 window->image=DestroyImage(window->image);
5505 window->image=resize_image;
5506 window->destroy=MagickTrue;
5509 width=(unsigned int) window->image->columns;
5510 assert((size_t) width == window->image->columns);
5511 height=(unsigned int) window->image->rows;
5512 assert((size_t) height == window->image->rows);
5517 ximage=(XImage *) NULL;
5518 format=(depth == 1) ? XYBitmap : ZPixmap;
5519 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5520 if (window->shared_memory != MagickFalse)
5525 segment_info=(XShmSegmentInfo *) window->segment_info;
5526 segment_info[1].shmid=(-1);
5527 segment_info[1].shmaddr=(char *) NULL;
5528 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5529 (char *) NULL,&segment_info[1],width,height);
5530 if (ximage == (XImage *) NULL)
5531 window->shared_memory=MagickFalse;
5532 length=(size_t) ximage->bytes_per_line*ximage->height;
5533 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5534 window->shared_memory=MagickFalse;
5535 if (window->shared_memory != MagickFalse)
5536 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5537 if (window->shared_memory != MagickFalse)
5538 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5539 if (segment_info[1].shmid < 0)
5540 window->shared_memory=MagickFalse;
5541 if (window->shared_memory != MagickFalse)
5542 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5545 if (ximage != (XImage *) NULL)
5546 XDestroyImage(ximage);
5547 ximage=(XImage *) NULL;
5548 if (segment_info[1].shmaddr)
5550 (void) shmdt(segment_info[1].shmaddr);
5551 segment_info[1].shmaddr=(char *) NULL;
5553 if (segment_info[1].shmid >= 0)
5555 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5556 segment_info[1].shmid=(-1);
5562 Allocate X image pixel data.
5564 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5565 if (window->shared_memory)
5573 (void) XSync(display,MagickFalse);
5574 xerror_alert=MagickFalse;
5575 segment_info=(XShmSegmentInfo *) window->segment_info;
5576 ximage->data=segment_info[1].shmaddr;
5577 segment_info[1].readOnly=MagickFalse;
5578 status=XShmAttach(display,&segment_info[1]);
5579 if (status != False)
5580 (void) XSync(display,MagickFalse);
5581 if ((status == False) || (xerror_alert != MagickFalse))
5583 window->shared_memory=MagickFalse;
5584 if (status != False)
5585 XShmDetach(display,&segment_info[1]);
5586 if (ximage != (XImage *) NULL)
5589 XDestroyImage(ximage);
5590 ximage=(XImage *) NULL;
5592 if (segment_info[1].shmid >= 0)
5594 if (segment_info[1].shmaddr != NULL)
5595 (void) shmdt(segment_info[1].shmaddr);
5596 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5597 segment_info[1].shmid=(-1);
5598 segment_info[1].shmaddr=(char *) NULL;
5603 if (window->shared_memory == MagickFalse)
5604 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5605 (char *) NULL,width,height,XBitmapPad(display),0);
5606 if (ximage == (XImage *) NULL)
5609 Unable to create X image.
5611 (void) XCheckDefineCursor(display,window->id,window->cursor);
5612 return(MagickFalse);
5614 length=(size_t) ximage->bytes_per_line*ximage->height;
5615 if (IsEventLogging())
5617 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5618 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5619 ximage->width,ximage->height);
5620 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5622 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5623 ximage->byte_order);
5624 (void) LogMagickEvent(X11Event,GetMagickModule(),
5625 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5626 ximage->bitmap_bit_order,ximage->bitmap_pad);
5627 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5629 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5630 ximage->bytes_per_line);
5631 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5632 ximage->bits_per_pixel);
5633 (void) LogMagickEvent(X11Event,GetMagickModule(),
5634 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5635 ximage->green_mask,ximage->blue_mask);
5637 if (window->shared_memory == MagickFalse)
5639 if (ximage->format != XYBitmap)
5640 ximage->data=(char *) AcquireQuantumMemory((size_t)
5641 ximage->bytes_per_line,(size_t) ximage->height);
5643 ximage->data=(char *) AcquireQuantumMemory((size_t)
5644 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5646 if (ximage->data == (char *) NULL)
5649 Unable to allocate pixel data.
5651 XDestroyImage(ximage);
5652 ximage=(XImage *) NULL;
5653 (void) XCheckDefineCursor(display,window->id,window->cursor);
5654 return(MagickFalse);
5656 if (window->ximage != (XImage *) NULL)
5659 Destroy previous X image.
5661 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5662 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5663 if (window->segment_info != (XShmSegmentInfo *) NULL)
5668 segment_info=(XShmSegmentInfo *) window->segment_info;
5669 if (segment_info[0].shmid >= 0)
5671 (void) XSync(display,MagickFalse);
5672 (void) XShmDetach(display,&segment_info[0]);
5673 (void) XSync(display,MagickFalse);
5674 if (segment_info[0].shmaddr != (char *) NULL)
5675 (void) shmdt(segment_info[0].shmaddr);
5676 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5677 segment_info[0].shmid=(-1);
5678 segment_info[0].shmaddr=(char *) NULL;
5679 window->ximage->data=(char *) NULL;
5683 if (window->ximage->data != (char *) NULL)
5684 free(window->ximage->data);
5685 window->ximage->data=(char *) NULL;
5686 XDestroyImage(window->ximage);
5687 window->ximage=(XImage *) NULL;
5689 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5690 if (window->segment_info != (XShmSegmentInfo *) NULL)
5695 segment_info=(XShmSegmentInfo *) window->segment_info;
5696 segment_info[0]=segment_info[1];
5699 window->ximage=ximage;
5700 matte_image=(XImage *) NULL;
5701 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5702 if ((window->image->matte != MagickFalse) &&
5703 ((int) width <= XDisplayWidth(display,window->screen)) &&
5704 ((int) height <= XDisplayHeight(display,window->screen)))
5709 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5710 (char *) NULL,width,height,XBitmapPad(display),0);
5711 if (IsEventLogging())
5713 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5714 (void) LogMagickEvent(X11Event,GetMagickModule(),
5715 " width, height: %dx%d",matte_image->width,matte_image->height);
5717 if (matte_image != (XImage *) NULL)
5720 Allocate matte image pixel data.
5722 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5723 matte_image->bytes_per_line*matte_image->depth,
5724 (size_t) matte_image->height);
5725 if (matte_image->data == (char *) NULL)
5727 XDestroyImage(matte_image);
5728 matte_image=(XImage *) NULL;
5732 if (window->matte_image != (XImage *) NULL)
5737 if (window->matte_image->data != (char *) NULL)
5738 free(window->matte_image->data);
5739 window->matte_image->data=(char *) NULL;
5740 XDestroyImage(window->matte_image);
5741 window->matte_image=(XImage *) NULL;
5743 window->matte_image=matte_image;
5744 if (window->matte_pixmap != (Pixmap) NULL)
5746 (void) XFreePixmap(display,window->matte_pixmap);
5747 window->matte_pixmap=(Pixmap) NULL;
5748 #if defined(MAGICKCORE_HAVE_SHAPE)
5749 if (window->shape != MagickFalse)
5750 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5753 window->stasis=MagickFalse;
5755 Convert pixels to X image data.
5757 if (window->image != (Image *) NULL)
5759 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5760 (ximage->bitmap_bit_order == LSBFirst)))
5761 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5764 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5767 if (window->matte_image != (XImage *) NULL)
5770 Create matte pixmap.
5772 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5773 if (window->matte_pixmap != (Pixmap) NULL)
5782 Copy matte image to matte pixmap.
5784 context_values.background=0;
5785 context_values.foreground=1;
5786 graphics_context=XCreateGC(display,window->matte_pixmap,
5787 (size_t) (GCBackground | GCForeground),&context_values);
5788 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5789 window->matte_image,0,0,0,0,width,height);
5790 (void) XFreeGC(display,graphics_context);
5791 #if defined(MAGICKCORE_HAVE_SHAPE)
5792 if (window->shape != MagickFalse)
5793 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5794 window->matte_pixmap,ShapeSet);
5798 (void) XMakePixmap(display,resource_info,window);
5802 (void) XCheckDefineCursor(display,window->id,window->cursor);
5807 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5811 + X M a k e I m a g e L S B F i r s t %
5815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5817 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5818 % pixels are copied in least-significant bit and byte first order. The
5819 % server's scanline pad is respected. Rather than using one or two general
5820 % cases, many special cases are found here to help speed up the image
5823 % The format of the XMakeImageLSBFirst method is:
5825 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5827 % A description of each parameter follows:
5829 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5831 % o window: Specifies a pointer to a XWindowInfo structure.
5833 % o image: the image.
5835 % o ximage: Specifies a pointer to a XImage structure; returned from
5838 % o matte_image: Specifies a pointer to a XImage structure; returned from
5842 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5843 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5854 register const Quantum
5860 register unsigned char
5877 assert(resource_info != (XResourceInfo *) NULL);
5878 assert(window != (XWindowInfo *) NULL);
5879 assert(image != (Image *) NULL);
5880 if (image->debug != MagickFalse)
5881 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5883 if ((window->immutable == MagickFalse) &&
5884 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5887 size[MaxTextExtent];
5895 image_info=AcquireImageInfo();
5896 (void) CopyMagickString(image_info->filename,
5897 resource_info->image_info->texture != (char *) NULL ?
5898 resource_info->image_info->texture : "pattern:checkerboard",
5900 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5901 image->columns,(double) image->rows);
5902 image_info->size=ConstantString(size);
5903 pattern=ReadImage(image_info,&image->exception);
5904 image_info=DestroyImageInfo(image_info);
5905 if (pattern != (Image *) NULL)
5907 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5908 if (canvas != (Image *) NULL)
5909 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5910 pattern=DestroyImage(pattern);
5913 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5914 ximage->bits_per_pixel) >> 3));
5915 map_info=window->map_info;
5916 pixels=window->pixel_info->pixels;
5917 q=(unsigned char *) ximage->data;
5919 canvas_view=AcquireCacheView(canvas);
5920 if (ximage->format == XYBitmap)
5922 register unsigned short
5930 Convert canvas to big-endian bitmap.
5932 background=(unsigned char)
5933 (XPixelIntensity(&window->pixel_info->foreground_color) <
5934 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5935 foreground=(unsigned char)
5936 (XPixelIntensity(&window->pixel_info->background_color) <
5937 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5938 polarity=(unsigned short) ((GetPixelPacketIntensity(
5939 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5940 if (canvas->colors == 2)
5941 polarity=GetPixelPacketIntensity(&canvas->colormap[0]) <
5942 GetPixelPacketIntensity(&canvas->colormap[1]);
5943 for (y=0; y < (int) canvas->rows; y++)
5945 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5946 &canvas->exception);
5947 if (p == (const Quantum *) NULL)
5951 for (x=0; x < (int) canvas->columns; x++)
5954 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
5965 p+=GetPixelChannels(canvas);
5973 if (window->pixel_info->colors != 0)
5974 switch (ximage->bits_per_pixel)
5978 register unsigned int
5982 Convert to 2 bit color-mapped X canvas.
5984 for (y=0; y < (int) canvas->rows; y++)
5986 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
5987 canvas->columns,1,&canvas->exception);
5988 if (p == (const Quantum *) NULL)
5991 for (x=0; x < (int) canvas->columns; x++)
5993 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
5998 *q=(unsigned char) pixel;
6004 *q|=(unsigned char) (pixel << 2);
6010 *q|=(unsigned char) (pixel << 4);
6016 *q|=(unsigned char) (pixel << 6);
6022 p+=GetPixelChannels(canvas);
6030 register unsigned int
6034 Convert to 4 bit color-mapped X canvas.
6036 for (y=0; y < (int) canvas->rows; y++)
6038 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6039 canvas->columns,1,&canvas->exception);
6040 if (p == (const Quantum *) NULL)
6043 for (x=0; x < (int) canvas->columns; x++)
6045 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6050 *q=(unsigned char) pixel;
6056 *q|=(unsigned char) (pixel << 4);
6062 p+=GetPixelChannels(canvas);
6072 Convert to 8 bit color-mapped X canvas.
6074 if (resource_info->color_recovery &&
6075 resource_info->quantize_info->dither)
6077 XDitherImage(canvas,ximage);
6080 for (y=0; y < (int) canvas->rows; y++)
6082 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6083 canvas->columns,1,&canvas->exception);
6084 if (p == (const Quantum *) NULL)
6086 for (x=0; x < (int) canvas->columns; x++)
6088 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6089 *q++=(unsigned char) pixel;
6090 p+=GetPixelChannels(canvas);
6101 register unsigned int
6105 channel[sizeof(size_t)];
6108 Convert to multi-byte color-mapped X canvas.
6110 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6111 for (y=0; y < (int) canvas->rows; y++)
6113 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6114 canvas->columns,1,&canvas->exception);
6115 if (p == (const Quantum *) NULL)
6117 for (x=0; x < (int) canvas->columns; x++)
6119 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6120 for (k=0; k < (int) bytes_per_pixel; k++)
6122 channel[k]=(unsigned char) pixel;
6125 for (k=0; k < (int) bytes_per_pixel; k++)
6127 p+=GetPixelChannels(canvas);
6135 switch (ximage->bits_per_pixel)
6139 register unsigned int
6143 Convert to contiguous 2 bit continuous-tone X canvas.
6145 for (y=0; y < (int) canvas->rows; y++)
6148 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6149 canvas->columns,1,&canvas->exception);
6150 if (p == (const Quantum *) NULL)
6152 for (x=0; x < (int) canvas->columns; x++)
6154 pixel=XGammaPixel(canvas,map_info,p);
6160 *q=(unsigned char) pixel;
6166 *q|=(unsigned char) (pixel << 2);
6172 *q|=(unsigned char) (pixel << 4);
6178 *q|=(unsigned char) (pixel << 6);
6184 p+=GetPixelChannels(canvas);
6192 register unsigned int
6196 Convert to contiguous 4 bit continuous-tone X canvas.
6198 for (y=0; y < (int) canvas->rows; y++)
6200 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6201 canvas->columns,1,&canvas->exception);
6202 if (p == (const Quantum *) NULL)
6205 for (x=0; x < (int) canvas->columns; x++)
6207 pixel=XGammaPixel(canvas,map_info,p);
6213 *q=(unsigned char) pixel;
6219 *q|=(unsigned char) (pixel << 4);
6225 p+=GetPixelChannels(canvas);
6235 Convert to contiguous 8 bit continuous-tone X canvas.
6237 if (resource_info->color_recovery &&
6238 resource_info->quantize_info->dither)
6240 XDitherImage(canvas,ximage);
6243 for (y=0; y < (int) canvas->rows; y++)
6245 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6246 canvas->columns,1,&canvas->exception);
6247 if (p == (const Quantum *) NULL)
6249 for (x=0; x < (int) canvas->columns; x++)
6251 pixel=XGammaPixel(canvas,map_info,p);
6252 *q++=(unsigned char) pixel;
6253 p+=GetPixelChannels(canvas);
6261 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6262 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6263 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6264 (map_info->blue_mult == 1))
6267 Convert to 32 bit continuous-tone X canvas.
6269 for (y=0; y < (int) canvas->rows; y++)
6271 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6272 canvas->columns,1,&canvas->exception);
6273 if (p == (const Quantum *) NULL)
6275 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6276 (blue_gamma != 1.0))
6279 Gamma correct canvas.
6281 for (x=(int) canvas->columns-1; x >= 0; x--)
6283 *q++=ScaleQuantumToChar(XBlueGamma(
6284 GetPixelBlue(canvas,p)));
6285 *q++=ScaleQuantumToChar(XGreenGamma(
6286 GetPixelGreen(canvas,p)));
6287 *q++=ScaleQuantumToChar(XRedGamma(
6288 GetPixelRed(canvas,p)));
6290 p+=GetPixelChannels(canvas);
6294 for (x=(int) canvas->columns-1; x >= 0; x--)
6296 *q++=ScaleQuantumToChar((Quantum)
6297 GetPixelBlue(canvas,p));
6298 *q++=ScaleQuantumToChar((Quantum)
6299 GetPixelGreen(canvas,p));
6300 *q++=ScaleQuantumToChar((Quantum)
6301 GetPixelRed(canvas,p));
6303 p+=GetPixelChannels(canvas);
6308 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6309 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6310 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6311 (map_info->blue_mult == 65536L))
6314 Convert to 32 bit continuous-tone X canvas.
6316 for (y=0; y < (int) canvas->rows; y++)
6318 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6319 canvas->columns,1,&canvas->exception);
6320 if (p == (const Quantum *) NULL)
6322 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6323 (blue_gamma != 1.0))
6326 Gamma correct canvas.
6328 for (x=(int) canvas->columns-1; x >= 0; x--)
6330 *q++=ScaleQuantumToChar(XRedGamma(
6331 GetPixelRed(canvas,p)));
6332 *q++=ScaleQuantumToChar(XGreenGamma(
6333 GetPixelGreen(canvas,p)));
6334 *q++=ScaleQuantumToChar(XBlueGamma(
6335 GetPixelBlue(canvas,p)));
6337 p+=GetPixelChannels(canvas);
6341 for (x=(int) canvas->columns-1; x >= 0; x--)
6343 *q++=ScaleQuantumToChar((Quantum)
6344 GetPixelRed(canvas,p));
6345 *q++=ScaleQuantumToChar((Quantum)
6346 GetPixelGreen(canvas,p));
6347 *q++=ScaleQuantumToChar((Quantum)
6348 GetPixelBlue(canvas,p));
6350 p+=GetPixelChannels(canvas);
6359 register unsigned int
6363 channel[sizeof(size_t)];
6366 Convert to multi-byte continuous-tone X canvas.
6368 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6369 for (y=0; y < (int) canvas->rows; y++)
6371 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6372 canvas->columns,1,&canvas->exception);
6373 if (p == (const Quantum *) NULL)
6375 for (x=0; x < (int) canvas->columns; x++)
6377 pixel=XGammaPixel(canvas,map_info,p);
6378 for (k=0; k < (int) bytes_per_pixel; k++)
6380 channel[k]=(unsigned char) pixel;
6383 for (k=0; k < (int) bytes_per_pixel; k++)
6385 p+=GetPixelChannels(canvas);
6393 if (matte_image != (XImage *) NULL)
6396 Initialize matte canvas.
6398 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6399 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6400 q=(unsigned char *) matte_image->data;
6401 for (y=0; y < (int) canvas->rows; y++)
6403 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6404 &canvas->exception);
6405 if (p == (const Quantum *) NULL)
6409 for (x=(int) canvas->columns-1; x >= 0; x--)
6412 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6421 p+=GetPixelChannels(canvas);
6428 canvas_view=DestroyCacheView(canvas_view);
6429 if (canvas != image)
6430 canvas=DestroyImage(canvas);
6434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6438 + X M a k e I m a g e M S B F i r s t %
6442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6444 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6445 % image pixels are copied in most-significant bit and byte first order. The
6446 % server's scanline pad is also respected. Rather than using one or two
6447 % general cases, many special cases are found here to help speed up the image
6450 % The format of the XMakeImageMSBFirst method is:
6452 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6454 % A description of each parameter follows:
6456 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6458 % o window: Specifies a pointer to a XWindowInfo structure.
6460 % o image: the image.
6462 % o ximage: Specifies a pointer to a XImage structure; returned from
6465 % o matte_image: Specifies a pointer to a XImage structure; returned from
6469 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6470 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6484 register const Quantum
6487 register unsigned char
6504 assert(resource_info != (XResourceInfo *) NULL);
6505 assert(window != (XWindowInfo *) NULL);
6506 assert(image != (Image *) NULL);
6507 if (image->debug != MagickFalse)
6508 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6510 if ((window->immutable != MagickFalse) &&
6511 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6514 size[MaxTextExtent];
6522 image_info=AcquireImageInfo();
6523 (void) CopyMagickString(image_info->filename,
6524 resource_info->image_info->texture != (char *) NULL ?
6525 resource_info->image_info->texture : "pattern:checkerboard",
6527 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6528 image->columns,(double) image->rows);
6529 image_info->size=ConstantString(size);
6530 pattern=ReadImage(image_info,&image->exception);
6531 image_info=DestroyImageInfo(image_info);
6532 if (pattern != (Image *) NULL)
6534 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6535 if (canvas != (Image *) NULL)
6536 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6537 pattern=DestroyImage(pattern);
6540 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
6541 ximage->bits_per_pixel) >> 3));
6542 map_info=window->map_info;
6543 pixels=window->pixel_info->pixels;
6544 q=(unsigned char *) ximage->data;
6546 canvas_view=AcquireCacheView(canvas);
6547 if (ximage->format == XYBitmap)
6549 register unsigned short
6557 Convert canvas to big-endian bitmap.
6559 background=(unsigned char)
6560 (XPixelIntensity(&window->pixel_info->foreground_color) <
6561 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6562 foreground=(unsigned char)
6563 (XPixelIntensity(&window->pixel_info->background_color) <
6564 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6565 polarity=(unsigned short) ((GetPixelPacketIntensity(
6566 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6567 if (canvas->colors == 2)
6568 polarity=GetPixelPacketIntensity(&canvas->colormap[0]) <
6569 GetPixelPacketIntensity(&canvas->colormap[1]);
6570 for (y=0; y < (int) canvas->rows; y++)
6572 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6573 &canvas->exception);
6574 if (p == (const Quantum *) NULL)
6578 for (x=(int) canvas->columns-1; x >= 0; x--)
6581 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6592 p+=GetPixelChannels(canvas);
6600 if (window->pixel_info->colors != 0)
6601 switch (ximage->bits_per_pixel)
6605 register unsigned int
6609 Convert to 2 bit color-mapped X canvas.
6611 for (y=0; y < (int) canvas->rows; y++)
6613 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6614 canvas->columns,1,&canvas->exception);
6615 if (p == (const Quantum *) NULL)
6618 for (x=0; x < (int) canvas->columns; x++)
6620 pixel=pixels[(ssize_t)
6621 GetPixelIndex(canvas,p)] & 0xf;
6626 *q=(unsigned char) (pixel << 6);
6632 *q|=(unsigned char) (pixel << 4);
6638 *q|=(unsigned char) (pixel << 2);
6644 *q|=(unsigned char) pixel;
6650 p+=GetPixelChannels(canvas);
6658 register unsigned int
6662 Convert to 4 bit color-mapped X canvas.
6664 for (y=0; y < (int) canvas->rows; y++)
6666 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6667 canvas->columns,1,&canvas->exception);
6668 if (p == (const Quantum *) NULL)
6671 for (x=0; x < (int) canvas->columns; x++)
6673 pixel=pixels[(ssize_t)
6674 GetPixelIndex(canvas,p)] & 0xf;
6679 *q=(unsigned char) (pixel << 4);
6685 *q|=(unsigned char) pixel;
6691 p+=GetPixelChannels(canvas);
6701 Convert to 8 bit color-mapped X canvas.
6703 if (resource_info->color_recovery &&
6704 resource_info->quantize_info->dither)
6706 XDitherImage(canvas,ximage);
6709 for (y=0; y < (int) canvas->rows; y++)
6711 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6712 canvas->columns,1,&canvas->exception);
6713 if (p == (const Quantum *) NULL)
6715 for (x=0; x < (int) canvas->columns; x++)
6717 pixel=pixels[(ssize_t)
6718 GetPixelIndex(canvas,p)];
6719 *q++=(unsigned char) pixel;
6720 p+=GetPixelChannels(canvas);
6731 register unsigned int
6735 channel[sizeof(size_t)];
6738 Convert to 8 bit color-mapped X canvas.
6740 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6741 for (y=0; y < (int) canvas->rows; y++)
6743 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6744 canvas->columns,1,&canvas->exception);
6745 if (p == (const Quantum *) NULL)
6747 for (x=0; x < (int) canvas->columns; x++)
6749 pixel=pixels[(ssize_t)
6750 GetPixelIndex(canvas,p)];
6751 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6753 channel[k]=(unsigned char) pixel;
6756 for (k=0; k < (int) bytes_per_pixel; k++)
6758 p+=GetPixelChannels(canvas);
6766 switch (ximage->bits_per_pixel)
6770 register unsigned int
6774 Convert to 4 bit continuous-tone X canvas.
6776 for (y=0; y < (int) canvas->rows; y++)
6778 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6779 canvas->columns,1,&canvas->exception);
6780 if (p == (const Quantum *) NULL)
6783 for (x=(int) canvas->columns-1; x >= 0; x--)
6785 pixel=XGammaPixel(canvas,map_info,p);
6791 *q=(unsigned char) (pixel << 6);
6797 *q|=(unsigned char) (pixel << 4);
6803 *q|=(unsigned char) (pixel << 2);
6809 *q|=(unsigned char) pixel;
6815 p+=GetPixelChannels(canvas);
6823 register unsigned int
6827 Convert to 4 bit continuous-tone X canvas.
6829 for (y=0; y < (int) canvas->rows; y++)
6831 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6832 canvas->columns,1,&canvas->exception);
6833 if (p == (const Quantum *) NULL)
6836 for (x=(int) canvas->columns-1; x >= 0; x--)
6838 pixel=XGammaPixel(canvas,map_info,p);
6844 *q=(unsigned char) (pixel << 4);
6850 *q|=(unsigned char) pixel;
6856 p+=GetPixelChannels(canvas);
6866 Convert to 8 bit continuous-tone X canvas.
6868 if (resource_info->color_recovery &&
6869 resource_info->quantize_info->dither)
6871 XDitherImage(canvas,ximage);
6874 for (y=0; y < (int) canvas->rows; y++)
6876 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6877 canvas->columns,1,&canvas->exception);
6878 if (p == (const Quantum *) NULL)
6880 for (x=(int) canvas->columns-1; x >= 0; x--)
6882 pixel=XGammaPixel(canvas,map_info,p);
6883 *q++=(unsigned char) pixel;
6884 p+=GetPixelChannels(canvas);
6892 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6893 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6894 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6895 (map_info->blue_mult == 1))
6898 Convert to 32 bit continuous-tone X canvas.
6900 for (y=0; y < (int) canvas->rows; y++)
6902 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6903 canvas->columns,1,&canvas->exception);
6904 if (p == (const Quantum *) NULL)
6906 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6907 (blue_gamma != 1.0))
6910 Gamma correct canvas.
6912 for (x=(int) canvas->columns-1; x >= 0; x--)
6915 *q++=ScaleQuantumToChar(XRedGamma(
6916 GetPixelRed(canvas,p)));
6917 *q++=ScaleQuantumToChar(XGreenGamma(
6918 GetPixelGreen(canvas,p)));
6919 *q++=ScaleQuantumToChar(XBlueGamma(
6920 GetPixelBlue(canvas,p)));
6921 p+=GetPixelChannels(canvas);
6925 for (x=(int) canvas->columns-1; x >= 0; x--)
6928 *q++=ScaleQuantumToChar((Quantum)
6929 GetPixelRed(canvas,p));
6930 *q++=ScaleQuantumToChar((Quantum)
6931 GetPixelGreen(canvas,p));
6932 *q++=ScaleQuantumToChar((Quantum)
6933 GetPixelBlue(canvas,p));
6934 p+=GetPixelChannels(canvas);
6939 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6940 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6941 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6942 (map_info->blue_mult == 65536L))
6945 Convert to 32 bit continuous-tone X canvas.
6947 for (y=0; y < (int) canvas->rows; y++)
6949 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6950 canvas->columns,1,&canvas->exception);
6951 if (p == (const Quantum *) NULL)
6953 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6954 (blue_gamma != 1.0))
6957 Gamma correct canvas.
6959 for (x=(int) canvas->columns-1; x >= 0; x--)
6962 *q++=ScaleQuantumToChar(XBlueGamma(
6963 GetPixelBlue(canvas,p)));
6964 *q++=ScaleQuantumToChar(XGreenGamma(
6965 GetPixelGreen(canvas,p)));
6966 *q++=ScaleQuantumToChar(XRedGamma(
6967 GetPixelRed(canvas,p)));
6968 p+=GetPixelChannels(canvas);
6972 for (x=(int) canvas->columns-1; x >= 0; x--)
6975 *q++=ScaleQuantumToChar((Quantum)
6976 GetPixelBlue(canvas,p));
6977 *q++=ScaleQuantumToChar((Quantum)
6978 GetPixelGreen(canvas,p));
6979 *q++=ScaleQuantumToChar((Quantum)
6980 GetPixelRed(canvas,p));
6981 p+=GetPixelChannels(canvas);
6990 register unsigned int
6994 channel[sizeof(size_t)];
6997 Convert to multi-byte continuous-tone X canvas.
6999 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
7000 for (y=0; y < (int) canvas->rows; y++)
7002 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7003 canvas->columns,1,&canvas->exception);
7004 if (p == (const Quantum *) NULL)
7006 for (x=(int) canvas->columns-1; x >= 0; x--)
7008 pixel=XGammaPixel(canvas,map_info,p);
7009 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
7011 channel[k]=(unsigned char) pixel;
7014 for (k=0; k < (int) bytes_per_pixel; k++)
7016 p+=GetPixelChannels(canvas);
7024 if (matte_image != (XImage *) NULL)
7027 Initialize matte canvas.
7029 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7030 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7031 q=(unsigned char *) matte_image->data;
7032 for (y=0; y < (int) canvas->rows; y++)
7034 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7035 &canvas->exception);
7036 if (p == (const Quantum *) NULL)
7040 for (x=(int) canvas->columns-1; x >= 0; x--)
7043 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7052 p+=GetPixelChannels(canvas);
7059 canvas_view=DestroyCacheView(canvas_view);
7060 if (canvas != image)
7061 canvas=DestroyImage(canvas);
7065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7069 % X M a k e M a g n i f y I m a g e %
7073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7075 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7077 % The format of the XMakeMagnifyImage method is:
7079 % void XMakeMagnifyImage(display,windows)
7081 % A description of each parameter follows:
7083 % o display: Specifies a connection to an X server; returned from
7086 % o windows: Specifies a pointer to a XWindows structure.
7089 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7092 tuple[MaxTextExtent];
7106 register unsigned char
7114 previous_magnify = 0;
7132 Check boundary conditions.
7134 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7135 assert(display != (Display *) NULL);
7136 assert(windows != (XWindows *) NULL);
7138 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7140 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7142 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7144 while (magnify > windows->magnify.width)
7146 while (magnify > windows->magnify.height)
7148 if (magnify != previous_magnify)
7157 New magnify factor: update magnify window name.
7160 while ((1 << i) <= (int) magnify)
7162 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7163 "Magnify %.20gX",(double) i);
7164 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7165 if (status != False)
7167 XSetWMName(display,windows->magnify.id,&window_name);
7168 XSetWMIconName(display,windows->magnify.id,&window_name);
7169 (void) XFree((void *) window_name.value);
7172 previous_magnify=magnify;
7173 ximage=windows->image.ximage;
7174 width=(unsigned int) windows->magnify.ximage->width;
7175 height=(unsigned int) windows->magnify.ximage->height;
7176 if ((windows->magnify.x < 0) ||
7177 (windows->magnify.x >= windows->image.ximage->width))
7178 windows->magnify.x=windows->image.ximage->width >> 1;
7179 x=windows->magnify.x-((width/magnify) >> 1);
7183 if (x > (int) (ximage->width-(width/magnify)))
7184 x=ximage->width-width/magnify;
7185 if ((windows->magnify.y < 0) ||
7186 (windows->magnify.y >= windows->image.ximage->height))
7187 windows->magnify.y=windows->image.ximage->height >> 1;
7188 y=windows->magnify.y-((height/magnify) >> 1);
7192 if (y > (int) (ximage->height-(height/magnify)))
7193 y=ximage->height-height/magnify;
7194 q=(unsigned char *) windows->magnify.ximage->data;
7195 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7196 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7197 if (ximage->bits_per_pixel < 8)
7199 register unsigned char
7206 register unsigned int
7212 pixel_info=windows->magnify.pixel_info;
7213 switch (ximage->bitmap_bit_order)
7218 Magnify little-endian bitmap.
7222 if (ximage->format == XYBitmap)
7224 background=(unsigned char)
7225 (XPixelIntensity(&pixel_info->foreground_color) <
7226 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7227 foreground=(unsigned char)
7228 (XPixelIntensity(&pixel_info->background_color) <
7229 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7230 if (windows->magnify.depth > 1)
7231 Swap(background,foreground);
7233 for (i=0; i < (ssize_t) height; i+=magnify)
7236 Propogate pixel magnify rows.
7238 for (j=0; j < magnify; j++)
7240 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7241 ((x*ximage->bits_per_pixel) >> 3);
7242 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7245 for (k=0; k < width; k+=magnify)
7248 Propogate pixel magnify columns.
7250 for (l=0; l < magnify; l++)
7253 Propogate each bit plane.
7255 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7258 if (*p & (0x01 << (p_bit+plane)))
7271 p_bit+=ximage->bits_per_pixel;
7278 *q=byte >> (8-q_bit);
7290 Magnify big-endian bitmap.
7294 if (ximage->format == XYBitmap)
7296 background=(unsigned char)
7297 (XPixelIntensity(&pixel_info->foreground_color) <
7298 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7299 foreground=(unsigned char)
7300 (XPixelIntensity(&pixel_info->background_color) <
7301 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7302 if (windows->magnify.depth > 1)
7303 Swap(background,foreground);
7305 for (i=0; i < (ssize_t) height; i+=magnify)
7308 Propogate pixel magnify rows.
7310 for (j=0; j < magnify; j++)
7312 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7313 ((x*ximage->bits_per_pixel) >> 3);
7314 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7317 for (k=0; k < width; k+=magnify)
7320 Propogate pixel magnify columns.
7322 for (l=0; l < magnify; l++)
7325 Propogate each bit plane.
7327 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7330 if (*p & (0x80 >> (p_bit+plane)))
7343 p_bit+=ximage->bits_per_pixel;
7350 *q=byte << (8-q_bit);
7361 switch (ximage->bits_per_pixel)
7367 Magnify 8 bit X image.
7369 for (i=0; i < (ssize_t) height; i+=magnify)
7372 Propogate pixel magnify rows.
7374 for (j=0; j < magnify; j++)
7376 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7377 ((x*ximage->bits_per_pixel) >> 3);
7378 for (k=0; k < width; k+=magnify)
7381 Propogate pixel magnify columns.
7383 for (l=0; l < magnify; l++)
7395 register unsigned int
7400 Magnify multi-byte X image.
7402 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7403 for (i=0; i < (ssize_t) height; i+=magnify)
7406 Propogate pixel magnify rows.
7408 for (j=0; j < magnify; j++)
7410 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7411 ((x*ximage->bits_per_pixel) >> 3);
7412 for (k=0; k < width; k+=magnify)
7415 Propogate pixel magnify columns.
7417 for (l=0; l < magnify; l++)
7418 for (m=0; m < bytes_per_pixel; m++)
7430 Copy X image to magnify pixmap.
7432 x=windows->magnify.x-((width/magnify) >> 1);
7434 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7436 if (x > (int) (ximage->width-(width/magnify)))
7437 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7440 y=windows->magnify.y-((height/magnify) >> 1);
7442 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7444 if (y > (int) (ximage->height-(height/magnify)))
7445 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7448 if ((x != 0) || (y != 0))
7449 (void) XFillRectangle(display,windows->magnify.pixmap,
7450 windows->magnify.annotate_context,0,0,width,height);
7451 (void) XPutImage(display,windows->magnify.pixmap,
7452 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7454 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7455 (magnify <= (height >> 1))))
7461 Highlight center pixel.
7463 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7464 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7465 highlight_info.width=magnify;
7466 highlight_info.height=magnify;
7467 (void) XDrawRectangle(display,windows->magnify.pixmap,
7468 windows->magnify.highlight_context,(int) highlight_info.x,
7469 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7470 (unsigned int) highlight_info.height-1);
7472 (void) XDrawRectangle(display,windows->magnify.pixmap,
7473 windows->magnify.annotate_context,(int) highlight_info.x+1,
7474 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7475 (unsigned int) highlight_info.height-3);
7478 Show center pixel color.
7480 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7481 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7482 &windows->image.image->exception);
7483 (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
7484 windows->magnify.x,windows->magnify.y);
7485 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7486 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7487 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7488 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7489 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7490 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7491 if (pixel.colorspace == CMYKColorspace)
7493 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7494 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7496 if (pixel.matte != MagickFalse)
7498 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7499 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7501 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7502 height=(unsigned int) windows->magnify.font_info->ascent+
7503 windows->magnify.font_info->descent;
7504 x=windows->magnify.font_info->max_bounds.width >> 1;
7505 y=windows->magnify.font_info->ascent+(height >> 2);
7506 (void) XDrawImageString(display,windows->magnify.pixmap,
7507 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7508 GetColorTuple(&pixel,MagickTrue,tuple);
7510 (void) XDrawImageString(display,windows->magnify.pixmap,
7511 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7512 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7513 &windows->image.image->exception);
7515 (void) XDrawImageString(display,windows->magnify.pixmap,
7516 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7518 Refresh magnify window.
7520 magnify_window=windows->magnify;
7523 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7531 % X M a k e P i x m a p %
7535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7537 % XMakePixmap() creates an X11 pixmap.
7539 % The format of the XMakePixmap method is:
7541 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7542 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7543 % XPixelInfo *pixel)
7545 % A description of each parameter follows:
7547 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7549 % o display: Specifies a connection to an X server; returned from
7552 % o window: Specifies a pointer to a XWindowInfo structure.
7555 static MagickBooleanType XMakePixmap(Display *display,
7556 const XResourceInfo *resource_info,XWindowInfo *window)
7562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7563 assert(display != (Display *) NULL);
7564 assert(resource_info != (XResourceInfo *) NULL);
7565 assert(window != (XWindowInfo *) NULL);
7566 if (window->pixmap != (Pixmap) NULL)
7569 Destroy previous X pixmap.
7571 (void) XFreePixmap(display,window->pixmap);
7572 window->pixmap=(Pixmap) NULL;
7574 if (window->use_pixmap == MagickFalse)
7575 return(MagickFalse);
7576 if (window->ximage == (XImage *) NULL)
7577 return(MagickFalse);
7579 Display busy cursor.
7581 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7582 (void) XFlush(display);
7586 width=(unsigned int) window->ximage->width;
7587 height=(unsigned int) window->ximage->height;
7588 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7589 if (window->pixmap == (Pixmap) NULL)
7592 Unable to allocate pixmap.
7594 (void) XCheckDefineCursor(display,window->id,window->cursor);
7595 return(MagickFalse);
7598 Copy X image to pixmap.
7600 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7601 if (window->shared_memory)
7602 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7603 window->ximage,0,0,0,0,width,height,MagickTrue);
7605 if (window->shared_memory == MagickFalse)
7606 (void) XPutImage(display,window->pixmap,window->annotate_context,
7607 window->ximage,0,0,0,0,width,height);
7608 if (IsEventLogging())
7610 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7611 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7617 (void) XCheckDefineCursor(display,window->id,window->cursor);
7622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7626 % X M a k e S t a n d a r d C o l o r m a p %
7630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7632 % XMakeStandardColormap() creates an X11 Standard Colormap.
7634 % The format of the XMakeStandardColormap method is:
7636 % XMakeStandardColormap(display,visual_info,resource_info,image,
7639 % A description of each parameter follows:
7641 % o display: Specifies a connection to an X server; returned from
7644 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7645 % returned from XGetVisualInfo.
7647 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7649 % o image: the image.
7651 % o map_info: If a Standard Colormap type is specified, this structure is
7652 % initialized with info from the Standard Colormap.
7654 % o pixel: Specifies a pointer to a XPixelInfo structure.
7658 #if defined(__cplusplus) || defined(c_plusplus)
7662 static inline MagickRealType DiversityPixelIntensity(
7663 const DiversityPacket *pixel)
7668 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7672 static int IntensityCompare(const void *x,const void *y)
7681 color_1=(DiversityPacket *) x;
7682 color_2=(DiversityPacket *) y;
7683 diversity=(int) (DiversityPixelIntensity(color_2)-
7684 DiversityPixelIntensity(color_1));
7688 static int PopularityCompare(const void *x,const void *y)
7694 color_1=(DiversityPacket *) x;
7695 color_2=(DiversityPacket *) y;
7696 return((int) color_2->count-(int) color_1->count);
7699 #if defined(__cplusplus) || defined(c_plusplus)
7703 static inline Quantum ScaleXToQuantum(const size_t x,
7706 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7709 MagickExport void XMakeStandardColormap(Display *display,
7710 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7711 XStandardColormap *map_info,XPixelInfo *pixel)
7737 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7738 assert(display != (Display *) NULL);
7739 assert(visual_info != (XVisualInfo *) NULL);
7740 assert(map_info != (XStandardColormap *) NULL);
7741 assert(resource_info != (XResourceInfo *) NULL);
7742 assert(pixel != (XPixelInfo *) NULL);
7743 exception=(&image->exception);
7744 if (resource_info->map_type != (char *) NULL)
7747 Standard Colormap is already defined (i.e. xstdcmap).
7749 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7751 number_colors=(unsigned int) (map_info->base_pixel+
7752 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7753 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7754 if ((image->matte == MagickFalse) &&
7755 (resource_info->color_recovery == MagickFalse) &&
7756 resource_info->quantize_info->dither &&
7757 (number_colors < MaxColormapSize))
7766 Improve image appearance with error diffusion.
7768 affinity_image=AcquireImage((ImageInfo *) NULL);
7769 if (affinity_image == (Image *) NULL)
7770 ThrowXWindowFatalException(ResourceLimitFatalError,
7771 "UnableToDitherImage",image->filename);
7772 affinity_image->columns=number_colors;
7773 affinity_image->rows=1;
7775 Initialize colormap image.
7777 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7779 if (q != (Quantum *) NULL)
7781 for (i=0; i < (ssize_t) number_colors; i++)
7783 SetPixelRed(affinity_image,0,q);
7784 if (map_info->red_max != 0)
7785 SetPixelRed(affinity_image,
7786 ScaleXToQuantum((size_t) (i/map_info->red_mult),
7787 map_info->red_max),q);
7788 SetPixelGreen(affinity_image,0,q);
7789 if (map_info->green_max != 0)
7790 SetPixelGreen(affinity_image,
7791 ScaleXToQuantum((size_t) ((i/map_info->green_mult) %
7792 (map_info->green_max+1)),map_info->green_max),q);
7793 SetPixelBlue(affinity_image,0,q);
7794 if (map_info->blue_max != 0)
7795 SetPixelBlue(affinity_image,
7796 ScaleXToQuantum((size_t) (i % map_info->green_mult),
7797 map_info->blue_max),q);
7798 SetPixelAlpha(affinity_image,
7799 TransparentAlpha,q);
7800 q+=GetPixelChannels(affinity_image);
7802 (void) SyncAuthenticPixels(affinity_image,exception);
7803 (void) RemapImage(resource_info->quantize_info,image,
7806 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7808 (void) SetImageStorageClass(image,DirectClass,exception);
7809 affinity_image=DestroyImage(affinity_image);
7811 if (IsEventLogging())
7813 (void) LogMagickEvent(X11Event,GetMagickModule(),
7814 "Standard Colormap:");
7815 (void) LogMagickEvent(X11Event,GetMagickModule(),
7816 " colormap id: 0x%lx",map_info->colormap);
7817 (void) LogMagickEvent(X11Event,GetMagickModule(),
7818 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7819 map_info->green_max,map_info->blue_max);
7820 (void) LogMagickEvent(X11Event,GetMagickModule(),
7821 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7822 map_info->green_mult,map_info->blue_mult);
7826 if ((visual_info->klass != DirectColor) &&
7827 (visual_info->klass != TrueColor))
7828 if ((image->storage_class == DirectClass) ||
7829 ((int) image->colors > visual_info->colormap_size))
7835 Image has more colors than the visual supports.
7837 quantize_info=(*resource_info->quantize_info);
7838 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7839 (void) QuantizeImage(&quantize_info,image);
7842 Free previous and create new colormap.
7844 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7845 colormap=XDefaultColormap(display,visual_info->screen);
7846 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7847 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7848 visual_info->visual,visual_info->klass == DirectColor ?
7849 AllocAll : AllocNone);
7850 if (colormap == (Colormap) NULL)
7851 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7854 Initialize the map and pixel info structures.
7856 XGetMapInfo(visual_info,colormap,map_info);
7857 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7859 Allocating colors in server colormap is based on visual class.
7861 switch (visual_info->klass)
7867 Define Standard Colormap for StaticGray or StaticColor visual.
7869 number_colors=image->colors;
7870 colors=(XColor *) AcquireQuantumMemory((size_t)
7871 visual_info->colormap_size,sizeof(*colors));
7872 if (colors == (XColor *) NULL)
7873 ThrowXWindowFatalException(ResourceLimitFatalError,
7874 "UnableToCreateColormap",image->filename);
7876 color.flags=(char) (DoRed | DoGreen | DoBlue);
7877 for (i=0; i < (ssize_t) image->colors; i++)
7879 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7880 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7881 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7882 if (visual_info->klass != StaticColor)
7884 gray_value=(unsigned short) XPixelIntensity(&color);
7885 color.red=gray_value;
7886 color.green=gray_value;
7887 color.blue=gray_value;
7889 status=XAllocColor(display,colormap,&color);
7890 if (status == False)
7892 colormap=XCopyColormapAndFree(display,colormap);
7893 (void) XAllocColor(display,colormap,&color);
7895 pixel->pixels[i]=color.pixel;
7907 Define Standard Colormap for GrayScale or PseudoColor visual.
7909 number_colors=image->colors;
7910 colors=(XColor *) AcquireQuantumMemory((size_t)
7911 visual_info->colormap_size,sizeof(*colors));
7912 if (colors == (XColor *) NULL)
7913 ThrowXWindowFatalException(ResourceLimitFatalError,
7914 "UnableToCreateColormap",image->filename);
7916 Preallocate our GUI colors.
7918 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7919 (void) XAllocColor(display,colormap,&pixel->background_color);
7920 (void) XAllocColor(display,colormap,&pixel->border_color);
7921 (void) XAllocColor(display,colormap,&pixel->matte_color);
7922 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7923 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7924 (void) XAllocColor(display,colormap,&pixel->depth_color);
7925 (void) XAllocColor(display,colormap,&pixel->trough_color);
7926 for (i=0; i < MaxNumberPens; i++)
7927 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7929 Determine if image colors will "fit" into X server colormap.
7931 colormap_type=resource_info->colormap;
7932 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7933 NULL,0,pixel->pixels,(unsigned int) image->colors);
7934 if (status != False)
7935 colormap_type=PrivateColormap;
7936 if (colormap_type == SharedColormap)
7957 Define Standard colormap for shared GrayScale or PseudoColor visual.
7959 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7960 sizeof(*diversity));
7961 if (diversity == (DiversityPacket *) NULL)
7962 ThrowXWindowFatalException(ResourceLimitFatalError,
7963 "UnableToCreateColormap",image->filename);
7964 for (i=0; i < (ssize_t) image->colors; i++)
7966 diversity[i].red=image->colormap[i].red;
7967 diversity[i].green=image->colormap[i].green;
7968 diversity[i].blue=image->colormap[i].blue;
7969 diversity[i].index=(unsigned short) i;
7970 diversity[i].count=0;
7972 image_view=AcquireCacheView(image);
7973 for (y=0; y < (int) image->rows; y++)
7978 register const Quantum
7981 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7982 image->columns,1,exception);
7983 if (p == (const Quantum *) NULL)
7985 for (x=(int) image->columns-1; x >= 0; x--)
7987 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
7988 p+=GetPixelChannels(image);
7991 image_view=DestroyCacheView(image_view);
7993 Sort colors by decreasing intensity.
7995 qsort((void *) diversity,image->colors,sizeof(*diversity),
7997 for (i=0; i < (ssize_t) image->colors; )
7999 diversity[i].count<<=4; /* increase this colors popularity */
8000 i+=MagickMax((int) (image->colors >> 4),2);
8002 diversity[image->colors-1].count<<=4;
8003 qsort((void *) diversity,image->colors,sizeof(*diversity),
8009 color.flags=(char) (DoRed | DoGreen | DoBlue);
8010 for (i=0; i < (ssize_t) image->colors; i++)
8012 index=diversity[i].index;
8014 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8016 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8018 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8019 if (visual_info->klass != PseudoColor)
8021 gray_value=(unsigned short) XPixelIntensity(&color);
8022 color.red=gray_value;
8023 color.green=gray_value;
8024 color.blue=gray_value;
8026 status=XAllocColor(display,colormap,&color);
8027 if (status == False)
8029 pixel->pixels[index]=color.pixel;
8033 Read X server colormap.
8035 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8036 visual_info->colormap_size,sizeof(*server_colors));
8037 if (server_colors == (XColor *) NULL)
8038 ThrowXWindowFatalException(ResourceLimitFatalError,
8039 "UnableToCreateColormap",image->filename);
8040 for (x=visual_info->colormap_size-1; x >= 0; x--)
8041 server_colors[x].pixel=(size_t) x;
8042 (void) XQueryColors(display,colormap,server_colors,
8043 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8045 Select remaining colors from X server colormap.
8047 for (; i < (ssize_t) image->colors; i++)
8049 index=diversity[i].index;
8051 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8053 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8055 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8056 if (visual_info->klass != PseudoColor)
8058 gray_value=(unsigned short) XPixelIntensity(&color);
8059 color.red=gray_value;
8060 color.green=gray_value;
8061 color.blue=gray_value;
8063 XBestPixel(display,colormap,server_colors,(unsigned int)
8064 visual_info->colormap_size,&color);
8065 pixel->pixels[index]=color.pixel;
8068 if ((int) image->colors < visual_info->colormap_size)
8071 Fill up colors array-- more choices for pen colors.
8073 retain_colors=MagickMin((unsigned int)
8074 (visual_info->colormap_size-image->colors),256);
8075 for (i=0; i < (ssize_t) retain_colors; i++)
8076 *p++=server_colors[i];
8077 number_colors+=retain_colors;
8079 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8080 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8084 Define Standard colormap for private GrayScale or PseudoColor visual.
8086 if (status == False)
8089 Not enough colormap entries in the colormap-- Create a new colormap.
8091 colormap=XCreateColormap(display,
8092 XRootWindow(display,visual_info->screen),visual_info->visual,
8094 if (colormap == (Colormap) NULL)
8095 ThrowXWindowFatalException(ResourceLimitFatalError,
8096 "UnableToCreateColormap",image->filename);
8097 map_info->colormap=colormap;
8098 if ((int) image->colors < visual_info->colormap_size)
8101 Retain colors from the default colormap to help lessens the
8102 effects of colormap flashing.
8104 retain_colors=MagickMin((unsigned int)
8105 (visual_info->colormap_size-image->colors),256);
8106 p=colors+image->colors;
8107 for (i=0; i < (ssize_t) retain_colors; i++)
8109 p->pixel=(unsigned long) i;
8112 (void) XQueryColors(display,
8113 XDefaultColormap(display,visual_info->screen),
8114 colors+image->colors,(int) retain_colors);
8116 Transfer colors from default to private colormap.
8118 (void) XAllocColorCells(display,colormap,MagickFalse,
8119 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8121 p=colors+image->colors;
8122 for (i=0; i < (ssize_t) retain_colors; i++)
8124 p->pixel=pixel->pixels[i];
8127 (void) XStoreColors(display,colormap,colors+image->colors,
8128 (int) retain_colors);
8129 number_colors+=retain_colors;
8131 (void) XAllocColorCells(display,colormap,MagickFalse,
8132 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8136 Store the image colormap.
8139 color.flags=(char) (DoRed | DoGreen | DoBlue);
8140 for (i=0; i < (ssize_t) image->colors; i++)
8142 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8143 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8144 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8145 if (visual_info->klass != PseudoColor)
8147 gray_value=(unsigned short) XPixelIntensity(&color);
8148 color.red=gray_value;
8149 color.green=gray_value;
8150 color.blue=gray_value;
8152 color.pixel=pixel->pixels[i];
8155 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8166 Define Standard Colormap for TrueColor or DirectColor visual.
8168 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8169 (map_info->green_max*map_info->green_mult)+
8170 (map_info->blue_max*map_info->blue_mult)+1);
8171 linear_colormap=(number_colors > 4096) ||
8172 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8173 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8174 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8175 MagickTrue : MagickFalse;
8176 if (linear_colormap != MagickFalse)
8177 number_colors=(size_t) visual_info->colormap_size;
8179 Allocate color array.
8181 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8182 if (colors == (XColor *) NULL)
8183 ThrowXWindowFatalException(ResourceLimitFatalError,
8184 "UnableToCreateColormap",image->filename);
8186 Initialize linear color ramp.
8189 color.flags=(char) (DoRed | DoGreen | DoBlue);
8190 if (linear_colormap != MagickFalse)
8191 for (i=0; i < (ssize_t) number_colors; i++)
8193 color.blue=(unsigned short) 0;
8194 if (map_info->blue_max != 0)
8195 color.blue=(unsigned short) ((size_t)
8196 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8197 color.green=color.blue;
8198 color.red=color.blue;
8199 color.pixel=XStandardPixel(map_info,&color);
8203 for (i=0; i < (ssize_t) number_colors; i++)
8205 color.red=(unsigned short) 0;
8206 if (map_info->red_max != 0)
8207 color.red=(unsigned short) ((size_t)
8208 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8209 color.green=(unsigned int) 0;
8210 if (map_info->green_max != 0)
8211 color.green=(unsigned short) ((size_t)
8212 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8213 map_info->green_max));
8214 color.blue=(unsigned short) 0;
8215 if (map_info->blue_max != 0)
8216 color.blue=(unsigned short) ((size_t)
8217 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8218 color.pixel=XStandardPixel(map_info,&color);
8221 if ((visual_info->klass == DirectColor) &&
8222 (colormap != XDefaultColormap(display,visual_info->screen)))
8223 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8225 for (i=0; i < (ssize_t) number_colors; i++)
8226 (void) XAllocColor(display,colormap,&colors[i]);
8230 if ((visual_info->klass != DirectColor) &&
8231 (visual_info->klass != TrueColor))
8234 Set foreground, background, border, etc. pixels.
8236 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8237 &pixel->foreground_color);
8238 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8239 &pixel->background_color);
8240 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8243 Foreground and background colors must differ.
8245 pixel->background_color.red=(~pixel->foreground_color.red);
8246 pixel->background_color.green=
8247 (~pixel->foreground_color.green);
8248 pixel->background_color.blue=
8249 (~pixel->foreground_color.blue);
8250 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8251 &pixel->background_color);
8253 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8254 &pixel->border_color);
8255 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8256 &pixel->matte_color);
8257 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8258 &pixel->highlight_color);
8259 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8260 &pixel->shadow_color);
8261 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8262 &pixel->depth_color);
8263 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8264 &pixel->trough_color);
8265 for (i=0; i < MaxNumberPens; i++)
8267 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8268 &pixel->pen_colors[i]);
8269 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8271 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8273 colors=(XColor *) RelinquishMagickMemory(colors);
8274 if (IsEventLogging())
8276 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8277 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8278 map_info->colormap);
8279 (void) LogMagickEvent(X11Event,GetMagickModule(),
8280 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8281 map_info->green_max,map_info->blue_max);
8282 (void) LogMagickEvent(X11Event,GetMagickModule(),
8283 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8284 map_info->green_mult,map_info->blue_mult);
8289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8293 % X M a k e W i n d o w %
8297 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8299 % XMakeWindow() creates an X11 window.
8301 % The format of the XMakeWindow method is:
8303 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8304 % XClassHint *class_hint,XWMHints *manager_hints,
8305 % XWindowInfo *window_info)
8307 % A description of each parameter follows:
8309 % o display: Specifies a connection to an X server; returned from
8312 % o parent: Specifies the parent window_info.
8314 % o argv: Specifies the application's argument list.
8316 % o argc: Specifies the number of arguments.
8318 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8320 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8322 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8325 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8326 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8327 XWindowInfo *window_info)
8329 #define MinWindowSize 64
8337 static XTextProperty
8348 Set window info hints.
8350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8351 assert(display != (Display *) NULL);
8352 assert(window_info != (XWindowInfo *) NULL);
8353 size_hints=XAllocSizeHints();
8354 if (size_hints == (XSizeHints *) NULL)
8355 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8356 size_hints->flags=(int) window_info->flags;
8357 size_hints->x=window_info->x;
8358 size_hints->y=window_info->y;
8359 size_hints->width=(int) window_info->width;
8360 size_hints->height=(int) window_info->height;
8361 if (window_info->immutable != MagickFalse)
8364 Window size cannot be changed.
8366 size_hints->min_width=size_hints->width;
8367 size_hints->min_height=size_hints->height;
8368 size_hints->max_width=size_hints->width;
8369 size_hints->max_height=size_hints->height;
8370 size_hints->flags|=PMinSize;
8371 size_hints->flags|=PMaxSize;
8376 Window size can be changed.
8378 size_hints->min_width=(int) window_info->min_width;
8379 size_hints->min_height=(int) window_info->min_height;
8380 size_hints->flags|=PResizeInc;
8381 size_hints->width_inc=(int) window_info->width_inc;
8382 size_hints->height_inc=(int) window_info->height_inc;
8383 #if !defined(PRE_R4_ICCCM)
8384 size_hints->flags|=PBaseSize;
8385 size_hints->base_width=size_hints->width_inc;
8386 size_hints->base_height=size_hints->height_inc;
8389 gravity=NorthWestGravity;
8390 if (window_info->geometry != (char *) NULL)
8393 default_geometry[MaxTextExtent],
8394 geometry[MaxTextExtent];
8403 User specified geometry.
8405 (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
8406 size_hints->width,size_hints->height);
8407 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8409 while (strlen(p) != 0)
8411 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8414 (void) CopyMagickString(p,p+1,MaxTextExtent);
8416 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8417 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8418 &size_hints->width,&size_hints->height,&gravity);
8419 if ((flags & WidthValue) && (flags & HeightValue))
8420 size_hints->flags|=USSize;
8421 if ((flags & XValue) && (flags & YValue))
8423 size_hints->flags|=USPosition;
8424 window_info->x=size_hints->x;
8425 window_info->y=size_hints->y;
8428 #if !defined(PRE_R4_ICCCM)
8429 size_hints->win_gravity=gravity;
8430 size_hints->flags|=PWinGravity;
8432 if (window_info->id == (Window) NULL)
8433 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8434 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8435 window_info->border_width,(int) window_info->depth,InputOutput,
8436 window_info->visual,(unsigned long) window_info->mask,
8437 &window_info->attributes);
8450 Window already exists; change relevant attributes.
8452 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8453 window_info->mask,&window_info->attributes);
8454 mask=ConfigureNotify;
8455 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8456 window_changes.x=window_info->x;
8457 window_changes.y=window_info->y;
8458 window_changes.width=(int) window_info->width;
8459 window_changes.height=(int) window_info->height;
8460 mask=(MagickStatusType) (CWWidth | CWHeight);
8461 if (window_info->flags & USPosition)
8463 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8464 mask,&window_changes);
8466 if (window_info->id == (Window) NULL)
8467 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8469 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8470 if (status == False)
8471 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8473 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8474 if (status == False)
8475 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8476 window_info->icon_name);
8477 if (window_info->icon_geometry != (char *) NULL)
8485 User specified icon geometry.
8487 size_hints->flags|=USPosition;
8488 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8489 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8490 &manager_hints->icon_y,&width,&height,&gravity);
8491 if ((flags & XValue) && (flags & YValue))
8492 manager_hints->flags|=IconPositionHint;
8494 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8495 size_hints,manager_hints,class_hint);
8496 if (window_name.value != (void *) NULL)
8498 (void) XFree((void *) window_name.value);
8499 window_name.value=(unsigned char *) NULL;
8500 window_name.nitems=0;
8502 if (icon_name.value != (void *) NULL)
8504 (void) XFree((void *) icon_name.value);
8505 icon_name.value=(unsigned char *) NULL;
8508 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8509 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8510 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8511 (void) XFree((void *) size_hints);
8512 if (window_info->shape != MagickFalse)
8514 #if defined(MAGICKCORE_HAVE_SHAPE)
8520 Can we apply a non-rectangular shaping mask?
8524 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8525 window_info->shape=MagickFalse;
8527 window_info->shape=MagickFalse;
8530 if (window_info->shared_memory)
8532 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8534 Can we use shared memory with this window?
8536 if (XShmQueryExtension(display) == 0)
8537 window_info->shared_memory=MagickFalse;
8539 window_info->shared_memory=MagickFalse;
8542 window_info->image=NewImageList();
8543 window_info->destroy=MagickFalse;
8547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8551 % X M a g i c k P r o g r e s s M o n i t o r %
8555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8557 % XMagickProgressMonitor() displays the progress a task is making in
8558 % completing a task.
8560 % The format of the XMagickProgressMonitor method is:
8562 % void XMagickProgressMonitor(const char *task,
8563 % const MagickOffsetType quantum,const MagickSizeType span,
8564 % void *client_data)
8566 % A description of each parameter follows:
8568 % o task: Identifies the task in progress.
8570 % o quantum: Specifies the quantum position within the span which represents
8571 % how much progress has been made in completing a task.
8573 % o span: Specifies the span relative to completing a task.
8575 % o client_data: Pointer to any client data.
8579 static const char *GetLocaleMonitorMessage(const char *text)
8582 message[MaxTextExtent],
8591 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8593 if (p != (char *) NULL)
8595 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
8596 locale_message=GetLocaleMessage(message);
8597 if (locale_message == message)
8599 return(locale_message);
8602 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8603 const MagickOffsetType quantum,const MagickSizeType span,
8604 void *magick_unused(client_data))
8609 windows=XSetWindows((XWindows *) ~0);
8610 if (windows == (XWindows *) NULL)
8612 if (windows->info.mapped != MagickFalse)
8613 XProgressMonitorWidget(windows->display,windows,
8614 GetLocaleMonitorMessage(tag),quantum,span);
8619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8623 % X Q u e r y C o l o r D a t a b a s e %
8627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8629 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8632 % The format of the XQueryColorDatabase method is:
8634 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8636 % A description of each parameter follows:
8638 % o target: Specifies the color to lookup in the X color database.
8640 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8641 % color is returned as this value.
8644 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8651 *display = (Display *) NULL;
8660 Initialize color return value.
8662 assert(color != (XColor *) NULL);
8666 color->flags=(char) (DoRed | DoGreen | DoBlue);
8667 if ((target == (char *) NULL) || (*target == '\0'))
8668 target="#ffffffffffff";
8670 Let the X server define the color for us.
8672 if (display == (Display *) NULL)
8673 display=XOpenDisplay((char *) NULL);
8674 if (display == (Display *) NULL)
8676 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8677 return(MagickFalse);
8679 colormap=XDefaultColormap(display,XDefaultScreen(display));
8680 status=XParseColor(display,colormap,(char *) target,&xcolor);
8681 if (status == False)
8682 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8685 color->red=xcolor.red;
8686 color->green=xcolor.green;
8687 color->blue=xcolor.blue;
8688 color->flags=xcolor.flags;
8690 return(status != False ? MagickTrue : MagickFalse);
8694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8698 % X Q u e r y P o s i t i o n %
8702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8704 % XQueryPosition() gets the pointer coordinates relative to a window.
8706 % The format of the XQueryPosition method is:
8708 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8710 % A description of each parameter follows:
8712 % o display: Specifies a connection to an X server; returned from
8715 % o window: Specifies a pointer to a Window.
8717 % o x: Return the x coordinate of the pointer relative to the origin of the
8720 % o y: Return the y coordinate of the pointer relative to the origin of the
8724 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8736 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8737 assert(display != (Display *) NULL);
8738 assert(window != (Window) NULL);
8739 assert(x != (int *) NULL);
8740 assert(y != (int *) NULL);
8741 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8750 % X R e f r e s h W i n d o w %
8754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8756 % XRefreshWindow() refreshes an image in a X window.
8758 % The format of the XRefreshWindow method is:
8760 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8761 % const XEvent *event)
8763 % A description of each parameter follows:
8765 % o display: Specifies a connection to an X server; returned from
8768 % o window: Specifies a pointer to a XWindowInfo structure.
8770 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8771 % the entire image is refreshed.
8774 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8775 const XEvent *event)
8785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8786 assert(display != (Display *) NULL);
8787 assert(window != (XWindowInfo *) NULL);
8788 if (window->ximage == (XImage *) NULL)
8790 if (event != (XEvent *) NULL)
8793 Determine geometry from expose event.
8797 width=(unsigned int) event->xexpose.width;
8798 height=(unsigned int) event->xexpose.height;
8806 Refresh entire window; discard outstanding expose events.
8810 width=window->width;
8811 height=window->height;
8812 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8813 if (window->matte_pixmap != (Pixmap) NULL)
8815 #if defined(MAGICKCORE_HAVE_SHAPE)
8816 if (window->shape != MagickFalse)
8817 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8818 window->matte_pixmap,ShapeSet);
8823 Check boundary conditions.
8825 if ((window->ximage->width-(x+window->x)) < (int) width)
8826 width=(unsigned int) (window->ximage->width-(x+window->x));
8827 if ((window->ximage->height-(y+window->y)) < (int) height)
8828 height=(unsigned int) (window->ximage->height-(y+window->y));
8832 if (window->matte_pixmap != (Pixmap) NULL)
8833 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8834 if (window->pixmap != (Pixmap) NULL)
8836 if (window->depth > 1)
8837 (void) XCopyArea(display,window->pixmap,window->id,
8838 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8840 (void) XCopyPlane(display,window->pixmap,window->id,
8841 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8846 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8847 if (window->shared_memory)
8848 (void) XShmPutImage(display,window->id,window->annotate_context,
8849 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8851 if (window->shared_memory == MagickFalse)
8852 (void) XPutImage(display,window->id,window->annotate_context,
8853 window->ximage,x+window->x,y+window->y,x,y,width,height);
8855 if (window->matte_pixmap != (Pixmap) NULL)
8856 (void) XSetClipMask(display,window->annotate_context,None);
8857 (void) XFlush(display);
8861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8865 % X R e m o t e C o m m a n d %
8869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8871 % XRemoteCommand() forces a remote display(1) to display the specified
8874 % The format of the XRemoteCommand method is:
8876 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8877 % const char *filename)
8879 % A description of each parameter follows:
8881 % o display: Specifies a connection to an X server; returned from
8884 % o window: Specifies the name or id of an X window.
8886 % o filename: the name of the image filename to display.
8889 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8890 const char *window,const char *filename)
8899 assert(filename != (char *) NULL);
8900 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8901 if (display == (Display *) NULL)
8902 display=XOpenDisplay((char *) NULL);
8903 if (display == (Display *) NULL)
8905 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8906 return(MagickFalse);
8908 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8909 remote_window=(Window) NULL;
8910 root_window=XRootWindow(display,XDefaultScreen(display));
8911 if (window != (char *) NULL)
8914 Search window hierarchy and identify any clients by name or ID.
8916 if (isdigit((unsigned char) *window) != 0)
8917 remote_window=XWindowByID(display,root_window,(Window)
8918 strtol((char *) window,(char **) NULL,0));
8919 if (remote_window == (Window) NULL)
8920 remote_window=XWindowByName(display,root_window,window);
8922 if (remote_window == (Window) NULL)
8923 remote_window=XWindowByProperty(display,root_window,remote_atom);
8924 if (remote_window == (Window) NULL)
8926 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8928 return(MagickFalse);
8931 Send remote command.
8933 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8934 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8935 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8936 (void) XSync(display,MagickFalse);
8941 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8945 % X R e t a i n W i n d o w C o l o r s %
8949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8951 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8952 % the colors associated with an image displayed on the window.
8954 % The format of the XRetainWindowColors method is:
8956 % void XRetainWindowColors(Display *display,const Window window)
8958 % A description of each parameter follows:
8960 % o display: Specifies a connection to an X server; returned from
8963 % o window: Specifies a pointer to a XWindowInfo structure.
8966 MagickExport void XRetainWindowColors(Display *display,const Window window)
8975 Put property on the window.
8977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8978 assert(display != (Display *) NULL);
8979 assert(window != (Window) NULL);
8980 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8981 if (property == (Atom) NULL)
8983 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8987 pixmap=XCreatePixmap(display,window,1,1,1);
8988 if (pixmap == (Pixmap) NULL)
8990 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8993 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8994 (unsigned char *) &pixmap,1);
8995 (void) XSetCloseDownMode(display,RetainPermanent);
8999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9003 % X S e l e c t W i n d o w %
9007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9009 % XSelectWindow() allows a user to select a window using the mouse. If the
9010 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
9011 % is returned in the crop_info structure.
9013 % The format of the XSelectWindow function is:
9015 % target_window=XSelectWindow(display,crop_info)
9017 % A description of each parameter follows:
9019 % o window: XSelectWindow returns the window id.
9021 % o display: Specifies a pointer to the Display structure; returned from
9024 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9025 % contains the extents of any cropping rectangle.
9028 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9030 #define MinimumCropArea (unsigned int) 9
9057 Initialize graphic context.
9059 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9060 assert(display != (Display *) NULL);
9061 assert(crop_info != (RectangleInfo *) NULL);
9062 root_window=XRootWindow(display,XDefaultScreen(display));
9063 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9064 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9065 context_values.function=GXinvert;
9066 context_values.plane_mask=
9067 context_values.background ^ context_values.foreground;
9068 context_values.subwindow_mode=IncludeInferiors;
9069 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9070 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9071 if (annotate_context == (GC) NULL)
9072 return(MagickFalse);
9074 Grab the pointer using target cursor.
9076 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9077 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9078 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9079 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9080 GrabModeAsync,root_window,target_cursor,CurrentTime);
9081 if (status != GrabSuccess)
9083 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9084 return((Window) NULL);
9090 crop_info->height=0;
9092 target_window=(Window) NULL;
9097 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9098 (void) XDrawRectangle(display,root_window,annotate_context,
9099 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9100 (unsigned int) crop_info->height-1);
9102 Allow another event.
9104 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9105 (void) XWindowEvent(display,root_window,ButtonPressMask |
9106 ButtonReleaseMask | ButtonMotionMask,&event);
9107 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9108 (void) XDrawRectangle(display,root_window,annotate_context,
9109 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9110 (unsigned int) crop_info->height-1);
9115 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9116 event.xbutton.x,event.xbutton.y);
9117 if (target_window == (Window) NULL)
9118 target_window=root_window;
9119 x_offset=event.xbutton.x_root;
9120 y_offset=event.xbutton.y_root;
9121 crop_info->x=(ssize_t) x_offset;
9122 crop_info->y=(ssize_t) y_offset;
9124 crop_info->height=0;
9136 Discard pending button motion events.
9138 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9139 crop_info->x=(ssize_t) event.xmotion.x;
9140 crop_info->y=(ssize_t) event.xmotion.y;
9142 Check boundary conditions.
9144 if ((int) crop_info->x < x_offset)
9145 crop_info->width=(size_t) (x_offset-crop_info->x);
9148 crop_info->width=(size_t) (crop_info->x-x_offset);
9149 crop_info->x=(ssize_t) x_offset;
9151 if ((int) crop_info->y < y_offset)
9152 crop_info->height=(size_t) (y_offset-crop_info->y);
9155 crop_info->height=(size_t) (crop_info->y-y_offset);
9156 crop_info->y=(ssize_t) y_offset;
9162 } while ((target_window == (Window) NULL) || (presses > 0));
9163 (void) XUngrabPointer(display,CurrentTime);
9164 (void) XFreeCursor(display,target_cursor);
9165 (void) XFreeGC(display,annotate_context);
9166 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9169 crop_info->height=0;
9171 if ((crop_info->width != 0) && (crop_info->height != 0))
9172 target_window=root_window;
9173 return(target_window);
9177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9181 % X S e t C u r s o r S t a t e %
9185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9187 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9188 % reset to their default.
9190 % The format of the XXSetCursorState method is:
9192 % XSetCursorState(display,windows,const MagickStatusType state)
9194 % A description of each parameter follows:
9196 % o display: Specifies a connection to an X server; returned from
9199 % o windows: Specifies a pointer to a XWindows structure.
9201 % o state: An unsigned integer greater than 0 sets the cursor state
9202 % to busy, otherwise the cursor are reset to their default.
9205 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9206 const MagickStatusType state)
9208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9209 assert(display != (Display *) NULL);
9210 assert(windows != (XWindows *) NULL);
9213 (void) XCheckDefineCursor(display,windows->image.id,
9214 windows->image.busy_cursor);
9215 (void) XCheckDefineCursor(display,windows->pan.id,
9216 windows->pan.busy_cursor);
9217 (void) XCheckDefineCursor(display,windows->magnify.id,
9218 windows->magnify.busy_cursor);
9219 (void) XCheckDefineCursor(display,windows->command.id,
9220 windows->command.busy_cursor);
9224 (void) XCheckDefineCursor(display,windows->image.id,
9225 windows->image.cursor);
9226 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9227 (void) XCheckDefineCursor(display,windows->magnify.id,
9228 windows->magnify.cursor);
9229 (void) XCheckDefineCursor(display,windows->command.id,
9230 windows->command.cursor);
9231 (void) XCheckDefineCursor(display,windows->command.id,
9232 windows->widget.cursor);
9233 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9235 windows->info.mapped=MagickFalse;
9239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9243 % X S e t W i n d o w s %
9247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9249 % XSetWindows() sets the X windows structure if the windows info is specified.
9250 % Otherwise the current windows structure is returned.
9252 % The format of the XSetWindows method is:
9254 % XWindows *XSetWindows(XWindows *windows_info)
9256 % A description of each parameter follows:
9258 % o windows_info: Initialize the Windows structure with this information.
9261 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9264 *windows = (XWindows *) NULL;
9266 if (windows_info != (XWindows *) ~0)
9268 windows=(XWindows *) RelinquishMagickMemory(windows);
9269 windows=windows_info;
9274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9278 % X U s e r P r e f e r e n c e s %
9282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9284 % XUserPreferences() saves the preferences in a configuration file in the
9285 % users' home directory.
9287 % The format of the XUserPreferences method is:
9289 % void XUserPreferences(XResourceInfo *resource_info)
9291 % A description of each parameter follows:
9293 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9296 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9298 #if defined(X11_PREFERENCES_PATH)
9300 cache[MaxTextExtent],
9301 filename[MaxTextExtent],
9302 specifier[MaxTextExtent];
9309 preferences_database;
9312 Save user preferences to the client configuration file.
9314 assert(resource_info != (XResourceInfo *) NULL);
9315 client_name=GetClientName();
9316 preferences_database=XrmGetStringDatabase("");
9317 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9318 value=resource_info->backdrop ? "True" : "False";
9319 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9320 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
9321 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9322 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9323 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9325 value=resource_info->confirm_exit ? "True" : "False";
9326 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9327 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9329 value=resource_info->confirm_edit ? "True" : "False";
9330 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9331 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9333 value=resource_info->display_warnings ? "True" : "False";
9334 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9335 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
9336 value=resource_info->quantize_info->dither ? "True" : "False";
9337 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9338 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9340 value=resource_info->gamma_correct ? "True" : "False";
9341 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9342 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9343 (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
9344 resource_info->undo_cache);
9345 XrmPutStringResource(&preferences_database,specifier,cache);
9346 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9347 value=resource_info->use_pixmap ? "True" : "False";
9348 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9349 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9350 X11_PREFERENCES_PATH,client_name);
9351 ExpandFilename(filename);
9352 XrmPutFileDatabase(preferences_database,filename);
9357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9361 % X V i s u a l C l a s s N a m e %
9365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9367 % XVisualClassName() returns the visual class name as a character string.
9369 % The format of the XVisualClassName method is:
9371 % char *XVisualClassName(const int visual_class)
9373 % A description of each parameter follows:
9375 % o visual_type: XVisualClassName returns the visual class as a character
9378 % o class: Specifies the visual class.
9381 static const char *XVisualClassName(const int visual_class)
9383 switch (visual_class)
9385 case StaticGray: return("StaticGray");
9386 case GrayScale: return("GrayScale");
9387 case StaticColor: return("StaticColor");
9388 case PseudoColor: return("PseudoColor");
9389 case TrueColor: return("TrueColor");
9390 case DirectColor: return("DirectColor");
9392 return("unknown visual class");
9396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9406 % XWarning() displays a warning reason in a Notice widget.
9408 % The format of the XWarning method is:
9410 % void XWarning(const unsigned int warning,const char *reason,
9411 % const char *description)
9413 % A description of each parameter follows:
9415 % o warning: Specifies the numeric warning category.
9417 % o reason: Specifies the reason to display before terminating the
9420 % o description: Specifies any description to the reason.
9423 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9424 const char *reason,const char *description)
9427 text[MaxTextExtent];
9432 if (reason == (char *) NULL)
9434 (void) CopyMagickString(text,reason,MaxTextExtent);
9435 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9436 windows=XSetWindows((XWindows *) ~0);
9437 XNoticeWidget(windows->display,windows,text,(char *) description);
9441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9445 % X W i n d o w B y I D %
9449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9451 % XWindowByID() locates a child window with a given ID. If not window with
9452 % the given name is found, 0 is returned. Only the window specified and its
9453 % subwindows are searched.
9455 % The format of the XWindowByID function is:
9457 % child=XWindowByID(display,window,id)
9459 % A description of each parameter follows:
9461 % o child: XWindowByID returns the window with the specified
9462 % id. If no windows are found, XWindowByID returns 0.
9464 % o display: Specifies a pointer to the Display structure; returned from
9467 % o id: Specifies the id of the window to locate.
9470 MagickExport Window XWindowByID(Display *display,const Window root_window,
9490 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9491 assert(display != (Display *) NULL);
9492 assert(root_window != (Window) NULL);
9494 return(XSelectWindow(display,&rectangle_info));
9495 if (root_window == id)
9496 return(root_window);
9497 status=XQueryTree(display,root_window,&child,&child,&children,
9499 if (status == False)
9500 return((Window) NULL);
9501 window=(Window) NULL;
9502 for (i=0; i < (int) number_children; i++)
9505 Search each child and their children.
9507 window=XWindowByID(display,children[i],id);
9508 if (window != (Window) NULL)
9511 if (children != (Window *) NULL)
9512 (void) XFree((void *) children);
9517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9521 % X W i n d o w B y N a m e %
9525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9527 % XWindowByName() locates a window with a given name on a display. If no
9528 % window with the given name is found, 0 is returned. If more than one window
9529 % has the given name, the first one is returned. Only root and its children
9532 % The format of the XWindowByName function is:
9534 % window=XWindowByName(display,root_window,name)
9536 % A description of each parameter follows:
9538 % o window: XWindowByName returns the window id.
9540 % o display: Specifies a pointer to the Display structure; returned from
9543 % o root_window: Specifies the id of the root window.
9545 % o name: Specifies the name of the window to locate.
9548 MagickExport Window XWindowByName(Display *display,const Window root_window,
9568 assert(display != (Display *) NULL);
9569 assert(root_window != (Window) NULL);
9570 assert(name != (char *) NULL);
9571 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9572 if (XGetWMName(display,root_window,&window_name) != 0)
9573 if (LocaleCompare((char *) window_name.value,name) == 0)
9574 return(root_window);
9575 status=XQueryTree(display,root_window,&child,&child,&children,
9577 if (status == False)
9578 return((Window) NULL);
9579 window=(Window) NULL;
9580 for (i=0; i < (int) number_children; i++)
9583 Search each child and their children.
9585 window=XWindowByName(display,children[i],name);
9586 if (window != (Window) NULL)
9589 if (children != (Window *) NULL)
9590 (void) XFree((void *) children);
9595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9599 % X W i n d o w B y P r o p e r y %
9603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9605 % XWindowByProperty() locates a child window with a given property. If not
9606 % window with the given name is found, 0 is returned. If more than one window
9607 % has the given property, the first one is returned. Only the window
9608 % specified and its subwindows are searched.
9610 % The format of the XWindowByProperty function is:
9612 % child=XWindowByProperty(display,window,property)
9614 % A description of each parameter follows:
9616 % o child: XWindowByProperty returns the window id with the specified
9617 % property. If no windows are found, XWindowByProperty returns 0.
9619 % o display: Specifies a pointer to the Display structure; returned from
9622 % o property: Specifies the property of the window to locate.
9625 MagickExport Window XWindowByProperty(Display *display,const Window window,
9626 const Atom property)
9654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9655 assert(display != (Display *) NULL);
9656 assert(window != (Window) NULL);
9657 assert(property != (Atom) NULL);
9658 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9659 if (status == False)
9660 return((Window) NULL);
9662 child=(Window) NULL;
9663 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9665 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9666 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9668 (void) XFree((void *) data);
9669 if ((status == Success) && (type != (Atom) NULL))
9672 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9673 child=XWindowByProperty(display,children[i],property);
9674 if (children != (Window *) NULL)
9675 (void) XFree((void *) children);
9681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9685 % X I m p o r t I m a g e %
9689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9691 % XImportImage() reads an image from an X window.
9693 % The format of the XImportImage method is:
9695 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9697 % A description of each parameter follows:
9699 % o image_info: the image info..
9701 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9704 MagickExport Image *XImportImage(const ImageInfo *image_info,
9705 XImportInfo *ximage_info)
9707 assert(image_info != (const ImageInfo *) NULL);
9708 assert(image_info->signature == MagickSignature);
9709 if (image_info->debug != MagickFalse)
9710 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9711 image_info->filename);
9712 assert(ximage_info != (XImportInfo *) NULL);
9713 return((Image *) NULL);
9718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9722 + X C o m p o n e n t G e n e s i s %
9726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9728 % XComponentGenesis() instantiates the X component.
9730 % The format of the XComponentGenesis method is:
9732 % MagickBooleanType XComponentGenesis(void)
9735 MagickPrivate MagickBooleanType XComponentGenesis(void)
9741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9745 % X G e t I m p o r t I n f o %
9749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9751 % XGetImportInfo() initializes the XImportInfo structure.
9753 % The format of the XGetImportInfo method is:
9755 % void XGetImportInfo(XImportInfo *ximage_info)
9757 % A description of each parameter follows:
9759 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9762 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9764 assert(ximage_info != (XImportInfo *) NULL);
9765 ximage_info->frame=MagickFalse;
9766 ximage_info->borders=MagickFalse;
9767 ximage_info->screen=MagickFalse;
9768 ximage_info->descend=MagickTrue;
9769 ximage_info->silent=MagickFalse;