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-2018 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 % https://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/constitute.h"
53 #include "MagickCore/display.h"
54 #include "MagickCore/distort.h"
55 #include "MagickCore/exception.h"
56 #include "MagickCore/exception-private.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/identify.h"
59 #include "MagickCore/image.h"
60 #include "MagickCore/image-private.h"
61 #include "MagickCore/list.h"
62 #include "MagickCore/locale_.h"
63 #include "MagickCore/log.h"
64 #include "MagickCore/magick.h"
65 #include "MagickCore/memory_.h"
66 #include "MagickCore/memory-private.h"
67 #include "MagickCore/monitor.h"
68 #include "MagickCore/nt-base-private.h"
69 #include "MagickCore/option.h"
70 #include "MagickCore/pixel-accessor.h"
71 #include "MagickCore/quantize.h"
72 #include "MagickCore/quantum.h"
73 #include "MagickCore/quantum-private.h"
74 #include "MagickCore/resource_.h"
75 #include "MagickCore/resize.h"
76 #include "MagickCore/statistic.h"
77 #include "MagickCore/string_.h"
78 #include "MagickCore/string-private.h"
79 #include "MagickCore/transform.h"
80 #include "MagickCore/transform-private.h"
81 #include "MagickCore/token.h"
82 #include "MagickCore/utility.h"
83 #include "MagickCore/utility-private.h"
84 #include "MagickCore/widget.h"
85 #include "MagickCore/widget-private.h"
86 #include "MagickCore/xwindow.h"
87 #include "MagickCore/xwindow-private.h"
88 #include "MagickCore/version.h"
92 #if defined(MAGICKCORE_X11_DELEGATE)
93 #include <X11/Xproto.h>
94 #include <X11/Xlocale.h>
95 #if defined(MAGICK_HAVE_POLL)
96 # include <sys/poll.h>
98 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
99 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
100 # include <machine/param.h>
104 #include <X11/extensions/XShm.h>
106 #if defined(MAGICKCORE_HAVE_SHAPE)
107 #include <X11/extensions/shape.h>
113 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
114 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
116 #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
117 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
119 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
121 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
123 #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
124 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
126 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
128 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
130 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
131 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
133 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
134 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
136 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
137 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
138 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
139 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
141 #define AccentuateModulate ScaleCharToQuantum(80)
142 #define HighlightModulate ScaleCharToQuantum(125)
143 #define ShadowModulate ScaleCharToQuantum(135)
144 #define DepthModulate ScaleCharToQuantum(185)
145 #define TroughModulate ScaleCharToQuantum(110)
147 #define XLIB_ILLEGAL_ACCESS 1
149 #undef NorthWestGravity
151 #undef NorthEastGravity
155 #undef SouthWestGravity
157 #undef SouthEastGravity
164 #define XFD_SET fd_set
168 Enumeration declarations.
182 Typedef declarations.
184 typedef struct _DiversityPacket
199 Constant declaractions.
201 static MagickBooleanType
202 xerror_alert = MagickFalse;
208 *XVisualClassName(const int);
215 static MagickBooleanType
216 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
219 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
220 XImage *,XImage *,ExceptionInfo *),
221 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
222 XImage *,XImage *,ExceptionInfo *);
225 XSelectWindow(Display *,RectangleInfo *);
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % D e s t r o y X R e s o u r c e s %
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % DestroyXResources() destroys any X resources.
240 % The format of the DestroyXResources method is:
242 % void DestroyXResources()
244 % A description of each parameter follows:
247 MagickExport void DestroyXResources(void)
256 *magick_windows[MaxXWindows];
262 windows=XSetWindows((XWindows *) ~0);
263 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
266 magick_windows[number_windows++]=(&windows->context);
267 magick_windows[number_windows++]=(&windows->group_leader);
268 magick_windows[number_windows++]=(&windows->backdrop);
269 magick_windows[number_windows++]=(&windows->icon);
270 magick_windows[number_windows++]=(&windows->image);
271 magick_windows[number_windows++]=(&windows->info);
272 magick_windows[number_windows++]=(&windows->magnify);
273 magick_windows[number_windows++]=(&windows->pan);
274 magick_windows[number_windows++]=(&windows->command);
275 magick_windows[number_windows++]=(&windows->widget);
276 magick_windows[number_windows++]=(&windows->popup);
277 for (i=0; i < (int) number_windows; i++)
279 if (magick_windows[i]->mapped != MagickFalse)
281 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
282 magick_windows[i]->screen);
283 magick_windows[i]->mapped=MagickFalse;
285 if (magick_windows[i]->name != (char *) NULL)
286 magick_windows[i]->name=(char *)
287 RelinquishMagickMemory(magick_windows[i]->name);
288 if (magick_windows[i]->icon_name != (char *) NULL)
289 magick_windows[i]->icon_name=(char *)
290 RelinquishMagickMemory(magick_windows[i]->icon_name);
291 if (magick_windows[i]->cursor != (Cursor) NULL)
293 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
294 magick_windows[i]->cursor=(Cursor) NULL;
296 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
298 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
299 magick_windows[i]->busy_cursor=(Cursor) NULL;
301 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
303 (void) XFreePixmap(windows->display,
304 magick_windows[i]->highlight_stipple);
305 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
307 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
309 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
310 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
312 if (magick_windows[i]->ximage != (XImage *) NULL)
314 XDestroyImage(magick_windows[i]->ximage);
315 magick_windows[i]->ximage=(XImage *) NULL;
317 if (magick_windows[i]->pixmap != (Pixmap) NULL)
319 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
320 magick_windows[i]->pixmap=(Pixmap) NULL;
322 if (magick_windows[i]->id != (Window) NULL)
324 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
325 magick_windows[i]->id=(Window) NULL;
327 if (magick_windows[i]->destroy != MagickFalse)
329 if (magick_windows[i]->image != (Image *) NULL)
331 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
332 magick_windows[i]->image=NewImageList();
334 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
336 (void) XFreePixmap(windows->display,
337 magick_windows[i]->matte_pixmap);
338 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
341 if (magick_windows[i]->segment_info != (void *) NULL)
343 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
347 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
348 if (segment_info != (XShmSegmentInfo *) NULL)
349 if (segment_info[0].shmid >= 0)
351 if (segment_info[0].shmaddr != NULL)
352 (void) shmdt(segment_info[0].shmaddr);
353 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
354 segment_info[0].shmaddr=NULL;
355 segment_info[0].shmid=(-1);
358 magick_windows[i]->segment_info=(void *)
359 RelinquishMagickMemory(magick_windows[i]->segment_info);
362 windows->icon_resources=(XResourceInfo *)
363 RelinquishMagickMemory(windows->icon_resources);
364 if (windows->icon_pixel != (XPixelInfo *) NULL)
366 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
367 windows->icon_pixel->pixels=(unsigned long *)
368 RelinquishMagickMemory(windows->icon_pixel->pixels);
369 if (windows->icon_pixel->annotate_context != (GC) NULL)
370 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
371 windows->icon_pixel=(XPixelInfo *)
372 RelinquishMagickMemory(windows->icon_pixel);
374 if (windows->pixel_info != (XPixelInfo *) NULL)
376 if (windows->pixel_info->pixels != (unsigned long *) NULL)
377 windows->pixel_info->pixels=(unsigned long *)
378 RelinquishMagickMemory(windows->pixel_info->pixels);
379 if (windows->pixel_info->annotate_context != (GC) NULL)
380 XFreeGC(windows->display,windows->pixel_info->annotate_context);
381 if (windows->pixel_info->widget_context != (GC) NULL)
382 XFreeGC(windows->display,windows->pixel_info->widget_context);
383 if (windows->pixel_info->highlight_context != (GC) NULL)
384 XFreeGC(windows->display,windows->pixel_info->highlight_context);
385 windows->pixel_info=(XPixelInfo *)
386 RelinquishMagickMemory(windows->pixel_info);
388 if (windows->font_info != (XFontStruct *) NULL)
390 XFreeFont(windows->display,windows->font_info);
391 windows->font_info=(XFontStruct *) NULL;
393 if (windows->class_hints != (XClassHint *) NULL)
395 if (windows->class_hints->res_name != (char *) NULL)
396 windows->class_hints->res_name=DestroyString(
397 windows->class_hints->res_name);
398 if (windows->class_hints->res_class != (char *) NULL)
399 windows->class_hints->res_class=DestroyString(
400 windows->class_hints->res_class);
401 XFree(windows->class_hints);
402 windows->class_hints=(XClassHint *) NULL;
404 if (windows->manager_hints != (XWMHints *) NULL)
406 XFree(windows->manager_hints);
407 windows->manager_hints=(XWMHints *) NULL;
409 if (windows->map_info != (XStandardColormap *) NULL)
411 XFree(windows->map_info);
412 windows->map_info=(XStandardColormap *) NULL;
414 if (windows->icon_map != (XStandardColormap *) NULL)
416 XFree(windows->icon_map);
417 windows->icon_map=(XStandardColormap *) NULL;
419 if (windows->visual_info != (XVisualInfo *) NULL)
421 XFree(windows->visual_info);
422 windows->visual_info=(XVisualInfo *) NULL;
424 if (windows->icon_visual != (XVisualInfo *) NULL)
426 XFree(windows->icon_visual);
427 windows->icon_visual=(XVisualInfo *) NULL;
429 (void) XSetWindows((XWindows *) NULL);
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 % X A n n o t a t e I m a g e %
441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 % XAnnotateImage() annotates the image with text.
445 % The format of the XAnnotateImage method is:
447 % MagickBooleanType XAnnotateImage(Display *display,
448 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
449 % ExceptionInfo *exception)
451 % A description of each parameter follows:
453 % o display: Specifies a connection to an X server; returned from
456 % o pixel: Specifies a pointer to a XPixelInfo structure.
458 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
460 % o image: the image.
462 % o exception: return any errors or warnings in this structure.
465 MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
466 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
467 ExceptionInfo *exception)
503 Initialize annotated image.
505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
506 assert(display != (Display *) NULL);
507 assert(pixel != (XPixelInfo *) NULL);
508 assert(annotate_info != (XAnnotateInfo *) NULL);
509 assert(image != (Image *) NULL);
511 Initialize annotated pixmap.
513 root_window=XRootWindow(display,XDefaultScreen(display));
514 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
515 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
516 annotate_info->height,depth);
517 if (annotate_pixmap == (Pixmap) NULL)
520 Initialize graphics info.
522 context_values.background=0;
523 context_values.foreground=(size_t) (~0);
524 context_values.font=annotate_info->font_info->fid;
525 annotate_context=XCreateGC(display,root_window,(unsigned long)
526 (GCBackground | GCFont | GCForeground),&context_values);
527 if (annotate_context == (GC) NULL)
532 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
533 (int) annotate_info->font_info->ascent,annotate_info->text,
534 (int) strlen(annotate_info->text));
535 (void) XFreeGC(display,annotate_context);
537 Initialize annotated X image.
539 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
540 annotate_info->height,AllPlanes,ZPixmap);
541 if (annotate_ximage == (XImage *) NULL)
543 (void) XFreePixmap(display,annotate_pixmap);
545 Initialize annotated image.
547 annotate_image=AcquireImage((ImageInfo *) NULL,exception);
548 if (annotate_image == (Image *) NULL)
550 annotate_image->columns=annotate_info->width;
551 annotate_image->rows=annotate_info->height;
553 Transfer annotated X image to image.
555 width=(unsigned int) image->columns;
556 height=(unsigned int) image->rows;
559 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
560 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
561 (ssize_t) y,&annotate_image->background_color,exception);
562 if (annotate_info->stencil == ForegroundStencil)
563 annotate_image->alpha_trait=BlendPixelTrait;
564 annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
565 for (y=0; y < (int) annotate_image->rows; y++)
573 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
574 annotate_image->columns,1,exception);
575 if (q == (Quantum *) NULL)
577 for (x=0; x < (int) annotate_image->columns; x++)
579 SetPixelAlpha(annotate_image,OpaqueAlpha,q);
580 if (XGetPixel(annotate_ximage,x,y) == 0)
583 Set this pixel to the background color.
585 SetPixelRed(annotate_image,ScaleShortToQuantum(
586 pixel->box_color.red),q);
587 SetPixelGreen(annotate_image,ScaleShortToQuantum(
588 pixel->box_color.green),q);
589 SetPixelBlue(annotate_image,ScaleShortToQuantum(
590 pixel->box_color.blue),q);
591 if ((annotate_info->stencil == ForegroundStencil) ||
592 (annotate_info->stencil == OpaqueStencil))
593 SetPixelAlpha(annotate_image,TransparentAlpha,q);
598 Set this pixel to the pen color.
600 SetPixelRed(annotate_image,ScaleShortToQuantum(
601 pixel->pen_color.red),q);
602 SetPixelGreen(annotate_image,ScaleShortToQuantum(
603 pixel->pen_color.green),q);
604 SetPixelBlue(annotate_image,ScaleShortToQuantum(
605 pixel->pen_color.blue),q);
606 if (annotate_info->stencil == BackgroundStencil)
607 SetPixelAlpha(annotate_image,TransparentAlpha,q);
609 q+=GetPixelChannels(annotate_image);
611 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
614 annotate_view=DestroyCacheView(annotate_view);
615 XDestroyImage(annotate_ximage);
617 Determine annotate geometry.
619 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
620 if ((width != (unsigned int) annotate_image->columns) ||
621 (height != (unsigned int) annotate_image->rows))
624 image_geometry[MagickPathExtent];
629 (void) FormatLocaleString(image_geometry,MagickPathExtent,"%ux%u",
631 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
634 if (annotate_info->degrees != 0.0)
648 rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
649 if (rotate_image == (Image *) NULL)
651 annotate_image=DestroyImage(annotate_image);
652 annotate_image=rotate_image;
654 Annotation is relative to the degree of rotation.
656 normalized_degrees=annotate_info->degrees;
657 while (normalized_degrees < -45.0)
658 normalized_degrees+=360.0;
659 for (rotations=0; normalized_degrees > 45.0; rotations++)
660 normalized_degrees-=90.0;
661 switch (rotations % 4)
671 x-=(int) annotate_image->columns/2;
672 y+=(int) annotate_image->columns/2;
680 x=x-(int) annotate_image->columns;
688 x=x-(int) annotate_image->columns/2;
689 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
695 Composite text onto the image.
697 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
698 alpha_trait=image->alpha_trait;
699 (void) CompositeImage(image,annotate_image,
700 annotate_image->alpha_trait != UndefinedPixelTrait ? OverCompositeOp :
701 CopyCompositeOp,MagickTrue,(ssize_t) x,(ssize_t) y,exception);
702 image->alpha_trait=alpha_trait;
703 annotate_image=DestroyImage(annotate_image);
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 % X B e s t F o n t %
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
718 % XBestFont() returns the "best" font. "Best" is defined as a font specified
719 % in the X resource database or a font such that the text width displayed
720 % with the font does not exceed the specified maximum width.
722 % The format of the XBestFont method is:
724 % XFontStruct *XBestFont(Display *display,
725 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
727 % A description of each parameter follows:
729 % o font: XBestFont returns a pointer to a XFontStruct structure.
731 % o display: Specifies a connection to an X server; returned from
734 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
736 % o text_font: True is font should be mono-spaced (typewriter style).
740 static char **FontToList(char *font)
755 if (font == (char *) NULL)
756 return((char **) NULL);
758 Convert string to an ASCII list.
761 for (p=font; *p != '\0'; p++)
762 if ((*p == ':') || (*p == ';') || (*p == ','))
764 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
765 if (fontlist == (char **) NULL)
767 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
768 return((char **) NULL);
771 for (i=0; i < (int) fonts; i++)
773 for (q=p; *q != '\0'; q++)
774 if ((*q == ':') || (*q == ';') || (*q == ','))
776 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
777 sizeof(*fontlist[i]));
778 if (fontlist[i] == (char *) NULL)
780 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
781 return((char **) NULL);
783 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
786 fontlist[i]=(char *) NULL;
790 MagickPrivate XFontStruct *XBestFont(Display *display,
791 const XResourceInfo *resource_info,const MagickBooleanType text_font)
796 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
797 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
798 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
799 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
800 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
801 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
808 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
809 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
810 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
824 font_info=(XFontStruct *) NULL;
825 font_name=resource_info->font;
826 if (text_font != MagickFalse)
827 font_name=resource_info->text_font;
828 if ((font_name != (char *) NULL) && (*font_name != '\0'))
837 Load preferred font specified in the X resource database.
839 fontlist=FontToList(font_name);
840 if (fontlist != (char **) NULL)
842 for (i=0; fontlist[i] != (char *) NULL; i++)
844 if (font_info == (XFontStruct *) NULL)
845 font_info=XLoadQueryFont(display,fontlist[i]);
846 fontlist[i]=DestroyString(fontlist[i]);
848 fontlist=(char **) RelinquishMagickMemory(fontlist);
850 if (font_info == (XFontStruct *) NULL)
851 ThrowXWindowException(XServerError,"UnableToLoadFont",font_name);
854 Load fonts from list of fonts until one is found.
857 if (text_font != MagickFalse)
859 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
861 while (*p != (char *) NULL)
863 if (font_info != (XFontStruct *) NULL)
865 font_info=XLoadQueryFont(display,(char *) *p);
872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % X B e s t I c o n S i z e %
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
883 % size that maintains the aspect ratio of the image. If the window manager
884 % has preferred icon sizes, one of the preferred sizes is used.
886 % The format of the XBestIconSize method is:
888 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
890 % A description of each parameter follows:
892 % o display: Specifies a connection to an X server; returned from
895 % o image: the image.
898 MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
922 Determine if the window manager has specified preferred icon sizes.
924 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
925 assert(display != (Display *) NULL);
926 assert(window != (XWindowInfo *) NULL);
927 assert(image != (Image *) NULL);
928 window->width=MaxIconSize;
929 window->height=MaxIconSize;
930 icon_size=(XIconSize *) NULL;
932 root_window=XRootWindow(display,window->screen);
933 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
934 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
936 if (icon_size == (XIconSize *) NULL)
939 Window manager does not restrict icon size.
941 icon_size=XAllocIconSize();
942 if (icon_size == (XIconSize *) NULL)
944 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
948 icon_size->min_width=1;
949 icon_size->max_width=MaxIconSize;
950 icon_size->min_height=1;
951 icon_size->max_height=MaxIconSize;
952 icon_size->width_inc=1;
953 icon_size->height_inc=1;
956 Determine aspect ratio of image.
958 width=(unsigned int) image->columns;
959 height=(unsigned int) image->rows;
961 if (window->crop_geometry)
962 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
964 Look for an icon size that maintains the aspect ratio of image.
966 scale_factor=(double) icon_size->max_width/width;
967 if (scale_factor > ((double) icon_size->max_height/height))
968 scale_factor=(double) icon_size->max_height/height;
969 icon_width=(unsigned int) icon_size->min_width;
970 while ((int) icon_width < icon_size->max_width)
972 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
974 icon_width+=icon_size->width_inc;
976 icon_height=(unsigned int) icon_size->min_height;
977 while ((int) icon_height < icon_size->max_height)
979 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
981 icon_height+=icon_size->height_inc;
983 (void) XFree((void *) icon_size);
984 window->width=icon_width;
985 window->height=icon_height;
989 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993 % X B e s t P i x e l %
997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
999 % XBestPixel() returns a pixel from an array of pixels that is closest to the
1000 % requested color. If the color array is NULL, the colors are obtained from
1003 % The format of the XBestPixel method is:
1005 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
1006 % unsigned int number_colors,XColor *color)
1008 % A description of each parameter follows:
1010 % o pixel: XBestPixel returns the pixel value closest to the requested
1013 % o display: Specifies a connection to an X server; returned from
1016 % o colormap: Specifies the ID of the X server colormap.
1018 % o colors: Specifies an array of XColor structures.
1020 % o number_colors: Specifies the number of XColor structures in the
1021 % color definition array.
1023 % o color: Specifies the desired RGB value to find in the colors array.
1026 MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
1027 XColor *colors,unsigned int number_colors,XColor *color)
1049 Find closest representation for the requested RGB color.
1051 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1052 assert(display != (Display *) NULL);
1053 assert(color != (XColor *) NULL);
1054 status=XAllocColor(display,colormap,color);
1055 if (status != False)
1057 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1058 if (query_server != MagickFalse)
1061 Read X server colormap.
1063 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1064 if (colors == (XColor *) NULL)
1066 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
1070 for (i=0; i < (int) number_colors; i++)
1071 colors[i].pixel=(size_t) i;
1072 if (number_colors > 256)
1074 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1076 min_distance=3.0*((double) QuantumRange+1.0)*((double)
1079 for (i=0; i < (int) number_colors; i++)
1081 pixel.red=colors[i].red-(double) color->red;
1082 distance=pixel.red*pixel.red;
1083 if (distance > min_distance)
1085 pixel.green=colors[i].green-(double) color->green;
1086 distance+=pixel.green*pixel.green;
1087 if (distance > min_distance)
1089 pixel.blue=colors[i].blue-(double) color->blue;
1090 distance+=pixel.blue*pixel.blue;
1091 if (distance > min_distance)
1093 min_distance=distance;
1094 color->pixel=colors[i].pixel;
1097 (void) XAllocColor(display,colormap,&colors[j]);
1098 if (query_server != MagickFalse)
1099 colors=(XColor *) RelinquishMagickMemory(colors);
1103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1107 % X B e s t V i s u a l I n f o %
1111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1113 % XBestVisualInfo() returns visual information for a visual that is the "best"
1114 % the server supports. "Best" is defined as:
1116 % 1. Restrict the visual list to those supported by the default screen.
1118 % 2. If a visual type is specified, restrict the visual list to those of
1121 % 3. If a map type is specified, choose the visual that matches the id
1122 % specified by the Standard Colormap.
1124 % 4 From the list of visuals, choose one that can display the most
1125 % simultaneous colors. If more than one visual can display the same
1126 % number of simultaneous colors, one is chosen based on a rank.
1128 % The format of the XBestVisualInfo method is:
1130 % XVisualInfo *XBestVisualInfo(Display *display,
1131 % XStandardColormap *map_info,XResourceInfo *resource_info)
1133 % A description of each parameter follows:
1135 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1138 % o display: Specifies a connection to an X server; returned from
1141 % o map_info: If map_type is specified, this structure is initialized
1142 % with info from the Standard Colormap.
1144 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1147 MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1148 XStandardColormap *map_info,XResourceInfo *resource_info)
1150 #define MaxStandardColormaps 7
1151 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1152 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1153 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1154 (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
1180 Restrict visual search by screen number.
1182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1183 assert(display != (Display *) NULL);
1184 assert(map_info != (XStandardColormap *) NULL);
1185 assert(resource_info != (XResourceInfo *) NULL);
1186 map_type=resource_info->map_type;
1187 visual_type=resource_info->visual_type;
1188 visual_mask=VisualScreenMask;
1189 visual_template.screen=XDefaultScreen(display);
1190 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1192 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1193 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1194 visual_mask|=VisualDepthMask;
1195 if (visual_type != (char *) NULL)
1198 Restrict visual search by class or visual id.
1200 if (LocaleCompare("staticgray",visual_type) == 0)
1202 visual_mask|=VisualClassMask;
1203 visual_template.klass=StaticGray;
1206 if (LocaleCompare("grayscale",visual_type) == 0)
1208 visual_mask|=VisualClassMask;
1209 visual_template.klass=GrayScale;
1212 if (LocaleCompare("staticcolor",visual_type) == 0)
1214 visual_mask|=VisualClassMask;
1215 visual_template.klass=StaticColor;
1218 if (LocaleCompare("pseudocolor",visual_type) == 0)
1220 visual_mask|=VisualClassMask;
1221 visual_template.klass=PseudoColor;
1224 if (LocaleCompare("truecolor",visual_type) == 0)
1226 visual_mask|=VisualClassMask;
1227 visual_template.klass=TrueColor;
1230 if (LocaleCompare("directcolor",visual_type) == 0)
1232 visual_mask|=VisualClassMask;
1233 visual_template.klass=DirectColor;
1236 if (LocaleCompare("default",visual_type) == 0)
1238 visual_mask|=VisualIDMask;
1239 visual_template.visualid=XVisualIDFromVisual(
1240 XDefaultVisual(display,XDefaultScreen(display)));
1243 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1245 visual_mask|=VisualIDMask;
1246 visual_template.visualid=
1247 strtol(visual_type,(char **) NULL,0);
1250 ThrowXWindowException(XServerError,
1251 "UnrecognizedVisualSpecifier",visual_type);
1254 Get all visuals that meet our criteria so far.
1257 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1259 visual_mask=VisualScreenMask | VisualIDMask;
1260 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1263 Failed to get visual; try using the default visual.
1265 ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
1266 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1267 XDefaultScreen(display)));
1268 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1270 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1271 return((XVisualInfo *) NULL);
1272 ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
1273 XVisualClassName(visual_list->klass));
1275 resource_info->color_recovery=MagickFalse;
1276 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1282 map_name[MagickPathExtent];
1298 Choose a visual associated with a standard colormap.
1300 root_window=XRootWindow(display,XDefaultScreen(display));
1303 if (LocaleCompare(map_type,"list") != 0)
1306 User specified Standard Colormap.
1308 (void) FormatLocaleString((char *) map_name,MagickPathExtent,
1309 "RGB_%s_MAP",map_type);
1310 LocaleUpper(map_name);
1311 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1312 if (map_property != (Atom) NULL)
1313 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1319 *colormap[MaxStandardColormaps]=
1321 "_HP_RGB_SMOOTH_MAP_LIST",
1331 Choose a standard colormap from a list.
1333 for (i=0; i < MaxStandardColormaps; i++)
1335 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1336 if (map_property == (Atom) NULL)
1338 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1340 if (status != False)
1343 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1345 if (status == False)
1347 ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
1349 return((XVisualInfo *) NULL);
1352 Search all Standard Colormaps and visuals for ids that match.
1354 *map_info=map_list[0];
1355 #if !defined(PRE_R4_ICCCM)
1356 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1357 for (i=0; i < number_maps; i++)
1358 for (j=0; j < number_visuals; j++)
1359 if (map_list[i].visualid ==
1360 XVisualIDFromVisual(visual_list[j].visual))
1362 *map_info=map_list[i];
1363 visual_template.visualid=XVisualIDFromVisual(
1364 visual_list[j].visual);
1367 if (map_info->visualid != visual_template.visualid)
1369 ThrowXWindowException(XServerError,
1370 "UnableToMatchVisualToStandardColormap",map_type);
1371 return((XVisualInfo *) NULL);
1374 if (map_info->colormap == (Colormap) NULL)
1376 ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
1378 return((XVisualInfo *) NULL);
1380 (void) XFree((void *) map_list);
1384 static const unsigned int
1399 Pick one visual that displays the most simultaneous colors.
1401 visual_info=visual_list;
1403 for (i=1; i < number_visuals; i++)
1406 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1409 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1410 if (rank[p->klass] > rank[visual_info->klass])
1413 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1415 (void) XFree((void *) visual_list);
1417 Retrieve only one visual by its screen & id number.
1419 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1421 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1422 return((XVisualInfo *) NULL);
1423 return(visual_info);
1427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1431 % X C h e c k D e f i n e C u r s o r %
1435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1437 % XCheckDefineCursor() prevents cursor changes on the root window.
1439 % The format of the XXCheckDefineCursor method is:
1441 % XCheckDefineCursor(display,window,cursor)
1443 % A description of each parameter follows:
1445 % o display: Specifies a connection to an X server; returned from
1448 % o window: the window.
1450 % o cursor: the cursor.
1453 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1456 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1457 assert(display != (Display *) NULL);
1458 if (window == XRootWindow(display,XDefaultScreen(display)))
1460 return(XDefineCursor(display,window,cursor));
1464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1468 % X C h e c k R e f r e s h W i n d o w s %
1472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1474 % XCheckRefreshWindows() checks the X server for exposure events for a
1475 % particular window and updates the areassociated with the exposure event.
1477 % The format of the XCheckRefreshWindows method is:
1479 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1481 % A description of each parameter follows:
1483 % o display: Specifies a connection to an X server; returned from
1486 % o windows: Specifies a pointer to a XWindows structure.
1489 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1498 assert(display != (Display *) NULL);
1499 assert(windows != (XWindows *) NULL);
1500 XDelay(display,SuspendTime);
1501 id=windows->command.id;
1502 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1503 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1504 id=windows->image.id;
1505 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1506 XRefreshWindow(display,&windows->image,&event);
1507 XDelay(display,SuspendTime << 1);
1508 id=windows->command.id;
1509 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1510 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1511 id=windows->image.id;
1512 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1513 XRefreshWindow(display,&windows->image,&event);
1517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1521 % X C l i e n t M e s s a g e %
1525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1527 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1528 % initialized with a particular protocol type and atom.
1530 % The format of the XClientMessage function is:
1532 % XClientMessage(display,window,protocol,reason,timestamp)
1534 % A description of each parameter follows:
1536 % o display: Specifies a pointer to the Display structure; returned from
1539 % o window: Specifies a pointer to a Window structure.
1541 % o protocol: Specifies an atom value.
1543 % o reason: Specifies an atom value which is the reason to send.
1545 % o timestamp: Specifies a value of type Time.
1548 MagickPrivate void XClientMessage(Display *display,const Window window,
1549 const Atom protocol,const Atom reason,const Time timestamp)
1554 assert(display != (Display *) NULL);
1555 (void) memset(&client_event,0,sizeof(client_event));
1556 client_event.type=ClientMessage;
1557 client_event.window=window;
1558 client_event.message_type=protocol;
1559 client_event.format=32;
1560 client_event.data.l[0]=(long) reason;
1561 client_event.data.l[1]=(long) timestamp;
1562 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *)
1567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 + X C l i e n t W i n d o w %
1575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % XClientWindow() finds a window, at or below the specified window, which has
1578 % a WM_STATE property. If such a window is found, it is returned, otherwise
1579 % the argument window is returned.
1581 % The format of the XClientWindow function is:
1583 % client_window=XClientWindow(display,target_window)
1585 % A description of each parameter follows:
1587 % o client_window: XClientWindow returns a window, at or below the specified
1588 % window, which has a WM_STATE property otherwise the argument
1589 % target_window is returned.
1591 % o display: Specifies a pointer to the Display structure; returned from
1594 % o target_window: Specifies the window to find a WM_STATE property.
1597 static Window XClientWindow(Display *display,Window target_window)
1619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1620 assert(display != (Display *) NULL);
1621 state=XInternAtom(display,"WM_STATE",MagickTrue);
1622 if (state == (Atom) NULL)
1623 return(target_window);
1625 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1626 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1627 if ((status == Success) && (type != (Atom) NULL))
1628 return(target_window);
1629 client_window=XWindowByProperty(display,target_window,state);
1630 if (client_window == (Window) NULL)
1631 return(target_window);
1632 return(client_window);
1636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 + X C o m p o n e n t T e r m i n u s %
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1646 % XComponentTerminus() destroys the module component.
1648 % The format of the XComponentTerminus method is:
1650 % XComponentTerminus(void)
1653 MagickPrivate void XComponentTerminus(void)
1655 DestroyXResources();
1659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663 % X C o n f i g u r e I m a g e C o l o r m a p %
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1669 % XConfigureImageColormap() creates a new X colormap.
1671 % The format of the XConfigureImageColormap method is:
1673 % void XConfigureImageColormap(Display *display,
1674 % XResourceInfo *resource_info,XWindows *windows,Image *image,
1675 % ExceptionInfo *exception)
1677 % A description of each parameter follows:
1679 % o display: Specifies a connection to an X server; returned from
1682 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1684 % o windows: Specifies a pointer to a XWindows structure.
1686 % o image: the image.
1688 % o exception: return any errors or warnings in this structure.
1691 MagickPrivate void XConfigureImageColormap(Display *display,
1692 XResourceInfo *resource_info,XWindows *windows,Image *image,
1693 ExceptionInfo *exception)
1699 Make standard colormap.
1701 XSetCursorState(display,windows,MagickTrue);
1702 XCheckRefreshWindows(display,windows);
1703 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1704 windows->map_info,windows->pixel_info,exception);
1705 colormap=windows->map_info->colormap;
1706 (void) XSetWindowColormap(display,windows->image.id,colormap);
1707 (void) XSetWindowColormap(display,windows->command.id,colormap);
1708 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1709 if (windows->magnify.mapped != MagickFalse)
1710 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1711 if (windows->pan.mapped != MagickFalse)
1712 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1713 XSetCursorState(display,windows,MagickFalse);
1714 XClientMessage(display,windows->image.id,windows->im_protocols,
1715 windows->im_update_colormap,CurrentTime);
1719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1723 % X C o n s t r a i n W i n d o w P o s i t i o n %
1727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1729 % XConstrainWindowPosition() assures a window is positioned within the X
1730 % server boundaries.
1732 % The format of the XConstrainWindowPosition method is:
1734 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1736 % A description of each parameter follows:
1738 % o display: Specifies a pointer to the Display structure; returned from
1741 % o window_info: Specifies a pointer to a XWindowInfo structure.
1744 MagickPrivate void XConstrainWindowPosition(Display *display,
1745 XWindowInfo *window_info)
1750 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1751 assert(display != (Display *) NULL);
1752 assert(window_info != (XWindowInfo *) NULL);
1753 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1754 if (window_info->x < 0)
1757 if (window_info->x > (int) limit)
1758 window_info->x=(int) limit;
1759 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1760 if (window_info->y < 0)
1763 if (window_info->y > limit)
1764 window_info->y=limit;
1768 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1778 % XDelay() suspends program execution for the number of milliseconds
1781 % The format of the Delay method is:
1783 % void XDelay(Display *display,const size_t milliseconds)
1785 % A description of each parameter follows:
1787 % o display: Specifies a pointer to the Display structure; returned from
1790 % o milliseconds: Specifies the number of milliseconds to delay before
1794 MagickPrivate void XDelay(Display *display,const size_t milliseconds)
1796 assert(display != (Display *) NULL);
1797 (void) XFlush(display);
1798 MagickDelay(milliseconds);
1802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1806 % X D e s t r o y R e s o u r c e I n f o %
1810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1812 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1815 % The format of the XDestroyResourceInfo method is:
1817 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1819 % A description of each parameter follows:
1821 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1824 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1826 if (resource_info->image_geometry != (char *) NULL)
1827 resource_info->image_geometry=(char *)
1828 RelinquishMagickMemory(resource_info->image_geometry);
1829 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1830 resource_info->quantize_info=DestroyQuantizeInfo(
1831 resource_info->quantize_info);
1832 if (resource_info->client_name != (char *) NULL)
1833 resource_info->client_name=(char *)
1834 RelinquishMagickMemory(resource_info->client_name);
1835 if (resource_info->name != (char *) NULL)
1836 resource_info->name=DestroyString(resource_info->name);
1837 (void) memset(resource_info,0,sizeof(*resource_info));
1841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1845 % X D e s t r o y W i n d o w C o l o r s %
1849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1851 % XDestroyWindowColors() frees X11 color resources previously saved on a
1852 % window by XRetainWindowColors or programs like xsetroot.
1854 % The format of the XDestroyWindowColors method is:
1856 % void XDestroyWindowColors(Display *display,Window window)
1858 % A description of each parameter follows:
1860 % o display: Specifies a connection to an X server; returned from
1863 % o window: Specifies a pointer to a Window structure.
1866 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1886 If there are previous resources on the root window, destroy them.
1888 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1889 assert(display != (Display *) NULL);
1890 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1891 if (property == (Atom) NULL)
1893 ThrowXWindowException(XServerError,"UnableToCreateProperty",
1897 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1898 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1899 if (status != Success)
1901 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1903 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1904 (void) XDeleteProperty(display,window,property);
1907 (void) XFree((void *) data);
1911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1915 % X D i s p l a y I m a g e I n f o %
1919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1921 % XDisplayImageInfo() displays information about an X image.
1923 % The format of the XDisplayImageInfo method is:
1925 % void XDisplayImageInfo(Display *display,
1926 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1927 % Image *image,ExceptionInfo *exception)
1929 % A description of each parameter follows:
1931 % o display: Specifies a connection to an X server; returned from
1934 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1936 % o windows: Specifies a pointer to a XWindows structure.
1938 % o undo_image: the undo image.
1940 % o image: the image.
1942 % o exception: return any errors or warnings in this structure.
1945 MagickPrivate void XDisplayImageInfo(Display *display,
1946 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1947 Image *image,ExceptionInfo *exception)
1950 filename[MagickPathExtent],
1973 Write info about the X server to a file.
1975 assert(display != (Display *) NULL);
1976 assert(resource_info != (XResourceInfo *) NULL);
1977 assert(windows != (XWindows *) NULL);
1978 assert(image != (Image *) NULL);
1980 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1982 unique_file=AcquireUniqueFileResource(filename);
1983 if (unique_file != -1)
1984 file=fdopen(unique_file,"w");
1985 if ((unique_file == -1) || (file == (FILE *) NULL))
1987 XNoticeWidget(display,windows,"Unable to display image info",filename);
1990 if (resource_info->gamma_correct != MagickFalse)
1991 if (resource_info->display_gamma != (char *) NULL)
1992 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
1993 resource_info->display_gamma);
1995 Write info about the X image to a file.
1997 (void) FormatLocaleFile(file,"X\n visual: %s\n",
1998 XVisualClassName((int) windows->image.storage_class));
1999 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
2000 if (windows->visual_info->colormap_size != 0)
2001 (void) FormatLocaleFile(file," colormap size: %d\n",
2002 windows->visual_info->colormap_size);
2003 if (resource_info->colormap== SharedColormap)
2004 (void) FormatLocaleFile(file," colormap type: Shared\n");
2006 (void) FormatLocaleFile(file," colormap type: Private\n");
2007 (void) FormatLocaleFile(file," geometry: %dx%d\n",
2008 windows->image.ximage->width,windows->image.ximage->height);
2009 if (windows->image.crop_geometry != (char *) NULL)
2010 (void) FormatLocaleFile(file," crop geometry: %s\n",
2011 windows->image.crop_geometry);
2012 if (windows->image.pixmap == (Pixmap) NULL)
2013 (void) FormatLocaleFile(file," type: X Image\n");
2015 (void) FormatLocaleFile(file," type: Pixmap\n");
2016 if (windows->image.shape != MagickFalse)
2017 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2019 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2020 if (windows->image.shared_memory != MagickFalse)
2021 (void) FormatLocaleFile(file," shared memory: True\n");
2023 (void) FormatLocaleFile(file," shared memory: False\n");
2024 (void) FormatLocaleFile(file,"\n");
2025 if (resource_info->font != (char *) NULL)
2026 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2027 if (resource_info->text_font != (char *) NULL)
2028 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2030 Write info about the undo cache to a file.
2033 for (levels=0; undo_image != (Image *) NULL; levels++)
2035 number_pixels=undo_image->list->columns*undo_image->list->rows;
2036 bytes+=number_pixels*sizeof(PixelInfo);
2037 undo_image=GetPreviousImageInList(undo_image);
2039 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2040 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2041 ((bytes+(1 << 19)) >> 20));
2042 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2043 resource_info->undo_cache);
2045 Write info about the image to a file.
2047 (void) IdentifyImage(image,file,MagickTrue,exception);
2048 (void) fclose(file);
2049 text=FileToString(filename,~0UL,exception);
2050 (void) RelinquishUniqueFileResource(filename);
2051 if (text == (char *) NULL)
2053 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2054 "UnableToDisplayImageInfo");
2057 textlist=StringToList(text);
2058 if (textlist != (char **) NULL)
2061 title[MagickPathExtent];
2064 Display information about the image in the Text View widget.
2066 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2067 (void) FormatLocaleString(title,MagickPathExtent,"Image Info: %s",
2069 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2070 (char const **) textlist);
2071 for (i=0; textlist[i] != (char *) NULL; i++)
2072 textlist[i]=DestroyString(textlist[i]);
2073 textlist=(char **) RelinquishMagickMemory(textlist);
2075 text=DestroyString(text);
2079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2083 + X D i t h e r I m a g e %
2087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 % XDitherImage() dithers the reference image as required by the HP Color
2090 % Recovery algorithm. The color values are quantized to 3 bits of red and
2091 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2092 % standard colormap.
2094 % The format of the XDitherImage method is:
2096 % void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
2098 % A description of each parameter follows:
2100 % o image: the image.
2102 % o ximage: Specifies a pointer to a XImage structure; returned from
2105 % o exception: return any errors or warnings in this structure.
2108 static void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
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 *) AcquireCriticalMemory(256UL*
2167 green_map[i][j]=(unsigned char *) AcquireCriticalMemory(256UL*
2168 sizeof(*green_map));
2169 blue_map[i][j]=(unsigned char *) AcquireCriticalMemory(256UL*
2173 Initialize dither tables.
2175 for (i=0; i < 2; i++)
2176 for (j=0; j < 16; j++)
2177 for (x=0; x < 256; x++)
2182 value+=dither_red[i][j];
2183 red_map[i][j][x]=(unsigned char)
2184 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2188 value+=dither_green[i][j];
2189 green_map[i][j][x]=(unsigned char)
2190 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2194 value+=((size_t) dither_blue[i][j] << 1);
2195 blue_map[i][j][x]=(unsigned char)
2196 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2201 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2202 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2206 image_view=AcquireVirtualCacheView(image,exception);
2207 for (y=0; y < (int) image->rows; y++)
2209 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2211 if (p == (const Quantum *) NULL)
2213 for (x=0; x < (int) image->columns; x++)
2215 color.red=(double) ClampToQuantum((double) (red_map[i][j][
2216 (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2217 color.green=(double) ClampToQuantum((double) (green_map[i][j][
2218 (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2219 color.blue=(double) ClampToQuantum((double) (blue_map[i][j][
2220 (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2221 pixel=(size_t) (((size_t) color.red & 0xe0) |
2222 (((size_t) color.green & 0xe0) >> 3) |
2223 (((size_t) color.blue & 0xc0) >> 6));
2225 p+=GetPixelChannels(image);
2235 image_view=DestroyCacheView(image_view);
2237 Free allocated memory.
2239 for (i=0; i < 2; i++)
2240 for (j=0; j < 16; j++)
2242 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2243 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2244 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2253 % X D r a w I m a g e %
2257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2259 % XDrawImage() draws a line on the image.
2261 % The format of the XDrawImage method is:
2263 % MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
2264 % XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
2266 % A description of each parameter follows:
2268 % o display: Specifies a connection to an X server; returned from
2271 % o pixel: Specifies a pointer to a XPixelInfo structure.
2273 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2275 % o image: the image.
2277 % o exception: return any errors or warnings in this structure.
2280 MagickPrivate MagickBooleanType XDrawImage(Display *display,
2281 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
2282 ExceptionInfo *exception)
2318 Initialize drawd image.
2320 assert(display != (Display *) NULL);
2321 assert(pixel != (XPixelInfo *) NULL);
2322 assert(draw_info != (XDrawInfo *) NULL);
2323 assert(image != (Image *) NULL);
2324 if (image->debug != MagickFalse)
2325 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2327 Initialize drawd pixmap.
2329 root_window=XRootWindow(display,XDefaultScreen(display));
2330 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2331 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2332 draw_info->height,depth);
2333 if (draw_pixmap == (Pixmap) NULL)
2334 return(MagickFalse);
2336 Initialize graphics info.
2338 context_values.background=(size_t) (~0);
2339 context_values.foreground=0;
2340 context_values.line_width=(int) draw_info->line_width;
2341 draw_context=XCreateGC(display,root_window,(size_t)
2342 (GCBackground | GCForeground | GCLineWidth),&context_values);
2343 if (draw_context == (GC) NULL)
2344 return(MagickFalse);
2348 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2351 Draw line to pixmap.
2353 (void) XSetBackground(display,draw_context,0);
2354 (void) XSetForeground(display,draw_context,(size_t) (~0));
2355 if (draw_info->stipple != (Pixmap) NULL)
2357 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2358 (void) XSetStipple(display,draw_context,draw_info->stipple);
2360 switch (draw_info->element)
2365 (void) XDrawLines(display,draw_pixmap,draw_context,
2366 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2372 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2373 draw_info->line_info.y1,draw_info->line_info.x2,
2374 draw_info->line_info.y2);
2377 case RectangleElement:
2379 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2380 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2381 (unsigned int) draw_info->rectangle_info.width,
2382 (unsigned int) draw_info->rectangle_info.height);
2385 case FillRectangleElement:
2387 (void) XFillRectangle(display,draw_pixmap,draw_context,
2388 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2389 (unsigned int) draw_info->rectangle_info.width,
2390 (unsigned int) draw_info->rectangle_info.height);
2394 case EllipseElement:
2396 (void) XDrawArc(display,draw_pixmap,draw_context,
2397 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2398 (unsigned int) draw_info->rectangle_info.width,
2399 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2402 case FillCircleElement:
2403 case FillEllipseElement:
2405 (void) XFillArc(display,draw_pixmap,draw_context,
2406 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2407 (unsigned int) draw_info->rectangle_info.width,
2408 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2411 case PolygonElement:
2416 coordinate_info=draw_info->coordinate_info;
2417 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2418 (int) draw_info->number_coordinates,CoordModeOrigin);
2419 (void) XDrawLine(display,draw_pixmap,draw_context,
2420 coordinate_info[draw_info->number_coordinates-1].x,
2421 coordinate_info[draw_info->number_coordinates-1].y,
2422 coordinate_info[0].x,coordinate_info[0].y);
2425 case FillPolygonElement:
2427 (void) XFillPolygon(display,draw_pixmap,draw_context,
2428 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2433 (void) XFreeGC(display,draw_context);
2437 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2438 draw_info->height,AllPlanes,ZPixmap);
2439 if (draw_ximage == (XImage *) NULL)
2440 return(MagickFalse);
2441 (void) XFreePixmap(display,draw_pixmap);
2443 Initialize draw image.
2445 draw_image=AcquireImage((ImageInfo *) NULL,exception);
2446 if (draw_image == (Image *) NULL)
2447 return(MagickFalse);
2448 draw_image->columns=draw_info->width;
2449 draw_image->rows=draw_info->height;
2451 Transfer drawn X image to image.
2453 width=(unsigned int) image->columns;
2454 height=(unsigned int) image->rows;
2457 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2458 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
2459 (ssize_t) y,&draw_image->background_color,exception);
2460 if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
2461 return(MagickFalse);
2462 draw_image->alpha_trait=BlendPixelTrait;
2463 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2464 for (y=0; y < (int) draw_image->rows; y++)
2472 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2474 if (q == (Quantum *) NULL)
2476 for (x=0; x < (int) draw_image->columns; x++)
2478 if (XGetPixel(draw_ximage,x,y) == 0)
2481 Set this pixel to the background color.
2483 SetPixelViaPixelInfo(draw_image,&draw_image->background_color,q);
2484 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2485 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2490 Set this pixel to the pen color.
2492 SetPixelRed(draw_image,ScaleShortToQuantum(
2493 pixel->pen_color.red),q);
2494 SetPixelGreen(draw_image,ScaleShortToQuantum(
2495 pixel->pen_color.green),q);
2496 SetPixelBlue(draw_image,ScaleShortToQuantum(
2497 pixel->pen_color.blue),q);
2498 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2499 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2501 q+=GetPixelChannels(draw_image);
2503 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2506 draw_view=DestroyCacheView(draw_view);
2507 XDestroyImage(draw_ximage);
2509 Determine draw geometry.
2511 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2512 if ((width != (unsigned int) draw_image->columns) ||
2513 (height != (unsigned int) draw_image->rows))
2516 image_geometry[MagickPathExtent];
2521 (void) FormatLocaleString(image_geometry,MagickPathExtent,"%ux%u",
2523 (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2526 if (draw_info->degrees != 0.0)
2540 rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
2541 if (rotate_image == (Image *) NULL)
2542 return(MagickFalse);
2543 draw_image=DestroyImage(draw_image);
2544 draw_image=rotate_image;
2546 Annotation is relative to the degree of rotation.
2548 normalized_degrees=draw_info->degrees;
2549 while (normalized_degrees < -45.0)
2550 normalized_degrees+=360.0;
2551 for (rotations=0; normalized_degrees > 45.0; rotations++)
2552 normalized_degrees-=90.0;
2553 switch (rotations % 4)
2563 x=x-(int) draw_image->columns/2;
2564 y=y+(int) draw_image->columns/2;
2572 x=x-(int) draw_image->columns;
2580 x=x-(int) draw_image->columns/2;
2581 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2587 Composite text onto the image.
2589 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2590 for (y=0; y < (int) draw_image->rows; y++)
2598 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2600 if (q == (Quantum *) NULL)
2602 for (x=0; x < (int) draw_image->columns; x++)
2604 if (GetPixelAlpha(image,q) != TransparentAlpha)
2605 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2606 q+=GetPixelChannels(draw_image);
2608 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2611 draw_view=DestroyCacheView(draw_view);
2612 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2613 if (draw_info->stencil == TransparentStencil)
2614 (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
2615 (ssize_t) x,(ssize_t) y,exception);
2618 alpha_trait=image->alpha_trait;
2619 (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
2620 (ssize_t) x,(ssize_t) y,exception);
2621 image->alpha_trait=alpha_trait;
2623 draw_image=DestroyImage(draw_image);
2628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2638 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2639 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2640 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it
2643 % The format of the XError function is:
2645 % int XError(display,error)
2647 % A description of each parameter follows:
2649 % o display: Specifies a pointer to the Display structure; returned from
2652 % o error: Specifies the error event.
2656 #if defined(__cplusplus) || defined(c_plusplus)
2660 MagickExport int XError(Display *display,XErrorEvent *error)
2662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2663 assert(display != (Display *) NULL);
2664 assert(error != (XErrorEvent *) NULL);
2665 xerror_alert=MagickTrue;
2666 switch (error->request_code)
2670 if ((int) error->error_code == BadDrawable)
2671 return(MagickFalse);
2674 case X_GetWindowAttributes:
2677 if ((int) error->error_code == BadWindow)
2678 return(MagickFalse);
2683 if ((int) error->error_code == BadValue)
2684 return(MagickFalse);
2691 #if defined(__cplusplus) || defined(c_plusplus)
2696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2700 % X F r e e R e s o u r c e s %
2704 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2706 % XFreeResources() frees X11 resources.
2708 % The format of the XFreeResources method is:
2710 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2711 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2712 % XResourceInfo *resource_info,XWindowInfo *window_info)
2713 % resource_info,window_info)
2715 % A description of each parameter follows:
2717 % o display: Specifies a connection to an X server; returned from
2720 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2721 % returned from XGetVisualInfo.
2723 % o map_info: If map_type is specified, this structure is initialized
2724 % with info from the Standard Colormap.
2726 % o pixel: Specifies a pointer to a XPixelInfo structure.
2728 % o font_info: Specifies a pointer to a XFontStruct structure.
2730 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2732 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2735 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2736 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2737 XResourceInfo *resource_info,XWindowInfo *window_info)
2739 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2740 assert(display != (Display *) NULL);
2741 assert(resource_info != (XResourceInfo *) NULL);
2742 if (window_info != (XWindowInfo *) NULL)
2747 if (window_info->ximage != (XImage *) NULL)
2748 XDestroyImage(window_info->ximage);
2749 if (window_info->id != (Window) NULL)
2752 Free destroy window and free cursors.
2754 if (window_info->id != XRootWindow(display,visual_info->screen))
2755 (void) XDestroyWindow(display,window_info->id);
2756 if (window_info->annotate_context != (GC) NULL)
2757 (void) XFreeGC(display,window_info->annotate_context);
2758 if (window_info->highlight_context != (GC) NULL)
2759 (void) XFreeGC(display,window_info->highlight_context);
2760 if (window_info->widget_context != (GC) NULL)
2761 (void) XFreeGC(display,window_info->widget_context);
2762 if (window_info->cursor != (Cursor) NULL)
2763 (void) XFreeCursor(display,window_info->cursor);
2764 window_info->cursor=(Cursor) NULL;
2765 if (window_info->busy_cursor != (Cursor) NULL)
2766 (void) XFreeCursor(display,window_info->busy_cursor);
2767 window_info->busy_cursor=(Cursor) NULL;
2773 if (font_info != (XFontStruct *) NULL)
2775 (void) XFreeFont(display,font_info);
2776 font_info=(XFontStruct *) NULL;
2778 if (map_info != (XStandardColormap *) NULL)
2781 Free X Standard Colormap.
2783 if (resource_info->map_type == (char *) NULL)
2784 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2785 (void) XFree((void *) map_info);
2790 if (visual_info != (XVisualInfo *) NULL)
2791 (void) XFree((void *) visual_info);
2792 if (resource_info->close_server != MagickFalse)
2793 (void) XCloseDisplay(display);
2797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2801 % X F r e e S t a n d a r d C o l o r m a p %
2805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2807 % XFreeStandardColormap() frees an X11 colormap.
2809 % The format of the XFreeStandardColormap method is:
2811 % void XFreeStandardColormap(Display *display,
2812 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2813 % XPixelInfo *pixel)
2815 % A description of each parameter follows:
2817 % o display: Specifies a connection to an X server; returned from
2820 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2821 % returned from XGetVisualInfo.
2823 % o map_info: If map_type is specified, this structure is initialized
2824 % with info from the Standard Colormap.
2826 % o pixel: Specifies a pointer to a XPixelInfo structure.
2829 MagickPrivate void XFreeStandardColormap(Display *display,
2830 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2836 assert(display != (Display *) NULL);
2837 assert(visual_info != (XVisualInfo *) NULL);
2838 assert(map_info != (XStandardColormap *) NULL);
2839 (void) XFlush(display);
2840 if (map_info->colormap != (Colormap) NULL)
2842 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2843 (void) XFreeColormap(display,map_info->colormap);
2845 if (pixel != (XPixelInfo *) NULL)
2846 if ((visual_info->klass != TrueColor) &&
2847 (visual_info->klass != DirectColor))
2848 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2849 (int) pixel->colors,0);
2851 map_info->colormap=(Colormap) NULL;
2852 if (pixel != (XPixelInfo *) NULL)
2854 if (pixel->pixels != (unsigned long *) NULL)
2855 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2856 pixel->pixels=(unsigned long *) NULL;
2861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2865 % X G e t A n n o t a t e I n f o %
2869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2871 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2873 % The format of the XGetAnnotateInfo method is:
2875 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2877 % A description of each parameter follows:
2879 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2882 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2885 Initialize annotate structure.
2887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2888 assert(annotate_info != (XAnnotateInfo *) NULL);
2891 annotate_info->width=0;
2892 annotate_info->height=0;
2893 annotate_info->stencil=ForegroundStencil;
2894 annotate_info->degrees=0.0;
2895 annotate_info->font_info=(XFontStruct *) NULL;
2896 annotate_info->text=(char *) NULL;
2897 *annotate_info->geometry='\0';
2898 annotate_info->previous=(XAnnotateInfo *) NULL;
2899 annotate_info->next=(XAnnotateInfo *) NULL;
2900 (void) XSupportsLocale();
2901 (void) XSetLocaleModifiers("");
2905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2909 % X G e t M a p I n f o %
2913 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2915 % XGetMapInfo() initializes the XStandardColormap structure.
2917 % The format of the XStandardColormap method is:
2919 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2920 % XStandardColormap *map_info)
2922 % A description of each parameter follows:
2924 % o colormap: Specifies the ID of the X server colormap.
2926 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2927 % returned from XGetVisualInfo.
2929 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2932 MagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
2933 const Colormap colormap,XStandardColormap *map_info)
2936 Initialize map info.
2938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2939 assert(visual_info != (XVisualInfo *) NULL);
2940 assert(map_info != (XStandardColormap *) NULL);
2941 map_info->colormap=colormap;
2942 map_info->red_max=visual_info->red_mask;
2943 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2944 if (map_info->red_max != 0)
2945 while ((map_info->red_max & 0x01) == 0)
2947 map_info->red_max>>=1;
2948 map_info->red_mult<<=1;
2950 map_info->green_max=visual_info->green_mask;
2951 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2952 if (map_info->green_max != 0)
2953 while ((map_info->green_max & 0x01) == 0)
2955 map_info->green_max>>=1;
2956 map_info->green_mult<<=1;
2958 map_info->blue_max=visual_info->blue_mask;
2959 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2960 if (map_info->blue_max != 0)
2961 while ((map_info->blue_max & 0x01) == 0)
2963 map_info->blue_max>>=1;
2964 map_info->blue_mult<<=1;
2966 map_info->base_pixel=0;
2970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2974 % X G e t P i x e l I n f o %
2978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2980 % XGetPixelInfo() initializes the PixelInfo structure.
2982 % The format of the XGetPixelInfo method is:
2984 % void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
2985 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2986 % Image *image,XPixelInfo *pixel)
2989 % A description of each parameter follows:
2991 % o display: Specifies a connection to an X server; returned from
2994 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2995 % returned from XGetVisualInfo.
2997 % o map_info: If map_type is specified, this structure is initialized
2998 % with info from the Standard Colormap.
3000 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3002 % o image: the image.
3004 % o pixel: Specifies a pointer to a XPixelInfo structure.
3007 MagickPrivate void XGetPixelInfo(Display *display,
3008 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3009 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3012 *PenColors[MaxNumberPens]=
3014 "#000000000000", /* black */
3015 "#00000000ffff", /* blue */
3016 "#0000ffffffff", /* cyan */
3017 "#0000ffff0000", /* green */
3018 "#bdbdbdbdbdbd", /* gray */
3019 "#ffff00000000", /* red */
3020 "#ffff0000ffff", /* magenta */
3021 "#ffffffff0000", /* yellow */
3022 "#ffffffffffff", /* white */
3023 "#bdbdbdbdbdbd", /* gray */
3024 "#bdbdbdbdbdbd" /* gray */
3044 Initialize pixel info.
3046 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3047 assert(display != (Display *) NULL);
3048 assert(visual_info != (XVisualInfo *) NULL);
3049 assert(map_info != (XStandardColormap *) NULL);
3050 assert(resource_info != (XResourceInfo *) NULL);
3051 assert(pixel != (XPixelInfo *) NULL);
3053 if (image != (Image *) NULL)
3054 if (image->storage_class == PseudoClass)
3055 pixel->colors=(ssize_t) image->colors;
3056 packets=(unsigned int)
3057 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3058 if (pixel->pixels != (unsigned long *) NULL)
3059 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3060 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3061 sizeof(*pixel->pixels));
3062 if (pixel->pixels == (unsigned long *) NULL)
3063 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3066 Set foreground color.
3068 colormap=map_info->colormap;
3069 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3070 &pixel->foreground_color);
3071 status=XParseColor(display,colormap,resource_info->foreground_color,
3072 &pixel->foreground_color);
3073 if (status == False)
3074 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3075 resource_info->foreground_color);
3076 pixel->foreground_color.pixel=
3077 XStandardPixel(map_info,&pixel->foreground_color);
3078 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3080 Set background color.
3082 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3083 status=XParseColor(display,colormap,resource_info->background_color,
3084 &pixel->background_color);
3085 if (status == False)
3086 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3087 resource_info->background_color);
3088 pixel->background_color.pixel=
3089 XStandardPixel(map_info,&pixel->background_color);
3090 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3094 (void) XParseColor(display,colormap,(char *) BorderColor,
3095 &pixel->border_color);
3096 status=XParseColor(display,colormap,resource_info->border_color,
3097 &pixel->border_color);
3098 if (status == False)
3099 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3100 resource_info->border_color);
3101 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3102 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3106 pixel->matte_color=pixel->background_color;
3107 if (resource_info->matte_color != (char *) NULL)
3110 Matte color is specified as a X resource or command line argument.
3112 status=XParseColor(display,colormap,resource_info->matte_color,
3113 &pixel->matte_color);
3114 if (status == False)
3115 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3116 resource_info->matte_color);
3117 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3118 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3121 Set highlight color.
3123 pixel->highlight_color.red=(unsigned short) (((double)
3124 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3125 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3126 pixel->highlight_color.green=(unsigned short) (((double)
3127 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3128 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3129 pixel->highlight_color.blue=(unsigned short) (((double)
3130 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3131 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3132 pixel->highlight_color.pixel=XStandardPixel(map_info,&pixel->highlight_color);
3133 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3137 pixel->shadow_color.red=(unsigned short) (((double)
3138 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3139 pixel->shadow_color.green=(unsigned short) (((double)
3140 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3141 pixel->shadow_color.blue=(unsigned short) (((double)
3142 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3143 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3144 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3148 pixel->depth_color.red=(unsigned short) (((double)
3149 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3150 pixel->depth_color.green=(unsigned short) (((double)
3151 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3152 pixel->depth_color.blue=(unsigned short) (((double)
3153 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3154 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3155 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3159 pixel->trough_color.red=(unsigned short) (((double)
3160 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3161 pixel->trough_color.green=(unsigned short) (((double)
3162 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3163 pixel->trough_color.blue=(unsigned short) (((double)
3164 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3165 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3166 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3170 for (i=0; i < MaxNumberPens; i++)
3172 (void) XParseColor(display,colormap,(char *) PenColors[i],
3173 &pixel->pen_colors[i]);
3174 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3175 &pixel->pen_colors[i]);
3176 if (status == False)
3177 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3178 resource_info->pen_colors[i]);
3179 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3180 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3182 pixel->box_color=pixel->background_color;
3183 pixel->pen_color=pixel->foreground_color;
3186 if (image != (Image *) NULL)
3188 if ((resource_info->gamma_correct != MagickFalse) &&
3189 (image->gamma != 0.0))
3198 Initialize map relative to display and image gamma.
3200 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3201 red_gamma=geometry_info.rho;
3202 green_gamma=geometry_info.sigma;
3203 if ((flags & SigmaValue) == 0)
3204 green_gamma=red_gamma;
3205 blue_gamma=geometry_info.xi;
3206 if ((flags & XiValue) == 0)
3207 blue_gamma=red_gamma;
3208 red_gamma*=image->gamma;
3209 green_gamma*=image->gamma;
3210 blue_gamma*=image->gamma;
3212 if (image->storage_class == PseudoClass)
3215 Initialize pixel array for images of type PseudoClass.
3217 for (i=0; i < (ssize_t) image->colors; i++)
3218 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3219 for (i=0; i < MaxNumberPens; i++)
3220 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3221 pixel->colors+=MaxNumberPens;
3227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3231 % X G e t R e s o u r c e C l a s s %
3235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3237 % XGetResourceClass() queries the X server for the specified resource name or
3238 % class. If the resource name or class is not defined in the database, the
3239 % supplied default value is returned.
3241 % The format of the XGetResourceClass method is:
3243 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3244 % const char *keyword,char *resource_default)
3246 % A description of each parameter follows:
3248 % o database: Specifies a resource database; returned from
3249 % XrmGetStringDatabase.
3251 % o client_name: Specifies the application name used to retrieve resource
3252 % info from the X server database.
3254 % o keyword: Specifies the keyword of the value being retrieved.
3256 % o resource_default: Specifies the default value to return if the query
3257 % fails to find the specified keyword/class.
3260 MagickExport char *XGetResourceClass(XrmDatabase database,
3261 const char *client_name,const char *keyword,char *resource_default)
3264 resource_class[MagickPathExtent],
3265 resource_name[MagickPathExtent];
3276 if (database == (XrmDatabase) NULL)
3277 return(resource_default);
3278 *resource_name='\0';
3279 *resource_class='\0';
3280 if (keyword != (char *) NULL)
3287 Initialize resource keyword and class.
3289 (void) FormatLocaleString(resource_name,MagickPathExtent,"%s.%s",
3290 client_name,keyword);
3291 c=(int) (*client_name);
3292 if ((c >= XK_a) && (c <= XK_z))
3295 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3296 c-=(XK_agrave-XK_Agrave);
3298 if ((c >= XK_oslash) && (c <= XK_thorn))
3299 c-=(XK_oslash-XK_Ooblique);
3301 if ((k >= XK_a) && (k <= XK_z))
3304 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3305 k-=(XK_agrave-XK_Agrave);
3307 if ((k >= XK_oslash) && (k <= XK_thorn))
3308 k-=(XK_oslash-XK_Ooblique);
3309 (void) FormatLocaleString(resource_class,MagickPathExtent,"%c%s.%c%s",c,
3310 client_name+1,k,keyword+1);
3312 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3314 if (status == False)
3315 return(resource_default);
3316 return(resource_value.addr);
3320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324 % X G e t R e s o u r c e D a t a b a s e %
3328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3330 % XGetResourceDatabase() creates a new resource database and initializes it.
3332 % The format of the XGetResourceDatabase method is:
3334 % XrmDatabase XGetResourceDatabase(Display *display,
3335 % const char *client_name)
3337 % A description of each parameter follows:
3339 % o database: XGetResourceDatabase() returns the database after it is
3342 % o display: Specifies a connection to an X server; returned from
3345 % o client_name: Specifies the application name used to retrieve resource
3346 % info from the X server database.
3349 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3350 const char *client_name)
3353 filename[MagickPathExtent];
3365 if (display == (Display *) NULL)
3366 return((XrmDatabase) NULL);
3367 assert(client_name != (char *) NULL);
3369 Initialize resource database.
3372 (void) XGetDefault(display,(char *) client_name,"dummy");
3373 resource_database=XrmGetDatabase(display);
3375 Combine application database.
3377 if (client_name != (char *) NULL)
3380 Get basename of client.
3382 p=client_name+(strlen(client_name)-1);
3383 while ((p > client_name) && (*p != '/'))
3388 c=(int) (*client_name);
3389 if ((c >= XK_a) && (c <= XK_z))
3392 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3393 c-=(XK_agrave-XK_Agrave);
3395 if ((c >= XK_oslash) && (c <= XK_thorn))
3396 c-=(XK_oslash-XK_Ooblique);
3397 #if defined(X11_APPLICATION_PATH)
3398 (void) FormatLocaleString(filename,MagickPathExtent,"%s%c%s",
3399 X11_APPLICATION_PATH,c,client_name+1);
3400 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3402 if (XResourceManagerString(display) != (char *) NULL)
3405 Combine server database.
3407 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3408 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3411 Merge user preferences database.
3413 #if defined(X11_PREFERENCES_PATH)
3414 (void) FormatLocaleString(filename,MagickPathExtent,"%s%src",
3415 X11_PREFERENCES_PATH,client_name);
3416 ExpandFilename(filename);
3417 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3419 return(resource_database);
3423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3427 % X G e t R e s o u r c e I n f o %
3431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3433 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3435 % The format of the XGetResourceInfo method is:
3437 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3438 % const char *client_name,XResourceInfo *resource_info)
3440 % A description of each parameter follows:
3442 % o image_info: the image info.
3444 % o database: Specifies a resource database; returned from
3445 % XrmGetStringDatabase.
3447 % o client_name: Specifies the application name used to retrieve
3448 % resource info from the X server database.
3450 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3453 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3454 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) memset(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=IsStringTrue(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 ThrowXWindowException(OptionError,"UnrecognizedColormapType",
3498 resource_value=XGetResourceClass(database,client_name,
3499 "colorRecovery",(char *) "False");
3500 resource_info->color_recovery=IsStringTrue(resource_value);
3501 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3503 resource_info->confirm_exit=IsStringTrue(resource_value);
3504 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3506 resource_info->confirm_edit=IsStringTrue(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=IsStringTrue(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=IsStringTrue(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,MagickPathExtent);
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=IsStringTrue(resource_value);
3558 resource_value=XGetResourceClass(database,client_name,"immutable",
3559 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3561 resource_info->immutable=IsStringTrue(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=IsStringTrue(resource_value);
3609 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3611 resource_info->use_pixmap=IsStringTrue(resource_value);
3612 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3614 resource_info->use_shared_memory=IsStringTrue(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[MagickPathExtent];
3672 if (database == (XrmDatabase) NULL)
3673 return((char *) resource_default);
3674 *resource_name='\0';
3675 if (keyword != (char *) NULL)
3676 (void) FormatLocaleString(resource_name,MagickPathExtent,"%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[MagickPathExtent];
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,MagickPathExtent,"%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,
3821 % char *name,ExceptionInfo *exception)
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.
3833 % o exception: return any errors or warnings in this structure.
3836 MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
3837 XWindows *windows,char *name,ExceptionInfo *exception)
3868 Choose a pixel from the X server.
3870 assert(display != (Display *) NULL);
3871 assert(name != (char *) NULL);
3872 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3874 target_window=XSelectWindow(display,&crop_info);
3875 if (target_window == (Window) NULL)
3876 return(MagickFalse);
3877 root_window=XRootWindow(display,XDefaultScreen(display));
3878 client_window=target_window;
3879 if (target_window != root_window)
3887 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3888 if (status != False)
3890 client_window=XClientWindow(display,target_window);
3891 target_window=client_window;
3895 Verify window is viewable.
3897 status=XGetWindowAttributes(display,target_window,&window_attributes);
3898 if ((status == False) || (window_attributes.map_state != IsViewable))
3899 return(MagickFalse);
3903 (void) XTranslateCoordinates(display,root_window,target_window,
3904 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3905 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3906 if (ximage == (XImage *) NULL)
3907 return(MagickFalse);
3908 color.pixel=XGetPixel(ximage,0,0);
3909 XDestroyImage(ximage);
3911 Match color against the color database.
3913 (void) XQueryColor(display,window_attributes.colormap,&color);
3914 pixel.red=(double) ScaleShortToQuantum(color.red);
3915 pixel.green=(double) ScaleShortToQuantum(color.green);
3916 pixel.blue=(double) ScaleShortToQuantum(color.blue);
3917 pixel.alpha=(MagickRealType) OpaqueAlpha;
3918 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3928 + X G e t W i n d o w I m a g e %
3932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3934 % XGetWindowImage() reads an image from the target X window and returns it.
3935 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3936 % target image with each child image in an optimized fashion. Any child
3937 % window that have the same visual, colormap, and are contained by its parent
3940 % The format of the XGetWindowImage method is:
3942 % Image *XGetWindowImage(Display *display,const Window window,
3943 % const unsigned int borders,const unsigned int level,
3944 % ExceptionInfo *exception)
3946 % A description of each parameter follows:
3948 % o display: Specifies a connection to an X server; returned from
3951 % o window: Specifies the window to obtain the image from.
3953 % o borders: Specifies whether borders pixels are to be saved with
3956 % o level: Specifies an unsigned integer representing the level of
3957 % decent in the window hierarchy. This value must be zero or one on
3958 % the initial call to XGetWindowImage. A value of zero returns after
3959 % one call. A value of one causes the function to descend the window
3960 % hierarchy and overlay the target image with each subwindow image.
3962 % o exception: return any errors or warnings in this structure.
3965 static Image *XGetWindowImage(Display *display,const Window window,
3966 const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
3968 typedef struct _ColormapInfo
3976 struct _ColormapInfo
3980 typedef struct _WindowInfo
4016 *colormap_info = (ColormapInfo *) NULL;
4036 Verify window is viewable.
4038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4039 assert(display != (Display *) NULL);
4040 status=XGetWindowAttributes(display,window,&window_attributes);
4041 if ((status == False) || (window_attributes.map_state != IsViewable))
4042 return((Image *) NULL);
4044 Cropping rectangle is relative to root window.
4046 root_window=XRootWindow(display,XDefaultScreen(display));
4047 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4049 crop_info.x=(ssize_t) x_offset;
4050 crop_info.y=(ssize_t) y_offset;
4051 crop_info.width=(size_t) window_attributes.width;
4052 crop_info.height=(size_t) window_attributes.height;
4053 if (borders != MagickFalse)
4056 Include border in image.
4058 crop_info.x-=(ssize_t) window_attributes.border_width;
4059 crop_info.y-=(ssize_t) window_attributes.border_width;
4060 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4061 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4064 Crop to root window.
4066 if (crop_info.x < 0)
4068 crop_info.width+=crop_info.x;
4071 if (crop_info.y < 0)
4073 crop_info.height+=crop_info.y;
4076 display_width=XDisplayWidth(display,XDefaultScreen(display));
4077 if ((int) (crop_info.x+crop_info.width) > display_width)
4078 crop_info.width=(size_t) (display_width-crop_info.x);
4079 display_height=XDisplayHeight(display,XDefaultScreen(display));
4080 if ((int) (crop_info.y+crop_info.height) > display_height)
4081 crop_info.height=(size_t) (display_height-crop_info.y);
4083 Initialize window info attributes.
4085 if (number_windows >= max_windows)
4088 Allocate or resize window info buffer.
4091 if (window_info == (WindowInfo *) NULL)
4092 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4093 sizeof(*window_info));
4095 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4096 max_windows,sizeof(*window_info));
4098 if (window_info == (WindowInfo *) NULL)
4100 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
4101 return((Image *) NULL);
4103 id=number_windows++;
4104 window_info[id].window=window;
4105 window_info[id].visual=window_attributes.visual;
4106 window_info[id].colormap=window_attributes.colormap;
4107 window_info[id].bounds.x1=(short) crop_info.x;
4108 window_info[id].bounds.y1=(short) crop_info.y;
4109 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4110 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4111 crop_info.x-=x_offset;
4112 crop_info.y-=y_offset;
4113 window_info[id].crop_info=crop_info;
4123 Descend the window hierarchy.
4125 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4126 &children,&number_children);
4127 for (i=0; i < id; i++)
4128 if ((window_info[i].window == window_info[id].parent) &&
4129 (window_info[i].visual == window_info[id].visual) &&
4130 (window_info[i].colormap == window_info[id].colormap))
4132 if ((window_info[id].bounds.x1 < window_info[i].bounds.x1) ||
4133 (window_info[id].bounds.x2 > window_info[i].bounds.x2) ||
4134 (window_info[id].bounds.y1 < window_info[i].bounds.y1) ||
4135 (window_info[id].bounds.y2 > window_info[i].bounds.y2))
4138 Eliminate windows not circumscribed by their parent.
4144 if ((status == True) && (number_children != 0))
4146 for (i=0; i < (int) number_children; i++)
4147 (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
4149 (void) XFree((void *) children);
4190 Get X image for each window in the list.
4192 image=NewImageList();
4193 for (id=0; id < number_windows; id++)
4196 Does target window intersect top level window?
4198 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4199 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4200 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4201 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4202 MagickTrue : MagickFalse;
4204 Is target window contained by another window with the same colormap?
4206 for (j=0; j < id; j++)
4207 if ((window_info[id].visual == window_info[j].visual) &&
4208 (window_info[id].colormap == window_info[j].colormap))
4210 if ((window_info[id].bounds.x1 >= window_info[j].bounds.x1) &&
4211 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4212 (window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
4213 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4216 if (import == MagickFalse)
4221 ximage=XGetImage(display,window_info[id].window,(int)
4222 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4223 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4224 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4225 if (ximage == (XImage *) NULL)
4228 Initialize window colormap.
4231 colors=(XColor *) NULL;
4232 if (window_info[id].colormap != (Colormap) NULL)
4238 Search colormap list for window colormap.
4240 number_colors=(unsigned int) window_info[id].visual->map_entries;
4241 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4242 if (p->colormap == window_info[id].colormap)
4244 if (p == (ColormapInfo *) NULL)
4247 Get the window colormap.
4249 colors=(XColor *) AcquireQuantumMemory(number_colors,
4251 if (colors == (XColor *) NULL)
4253 XDestroyImage(ximage);
4254 return((Image *) NULL);
4256 if ((window_info[id].visual->klass != DirectColor) &&
4257 (window_info[id].visual->klass != TrueColor))
4258 for (i=0; i < (int) number_colors; i++)
4260 colors[i].pixel=(size_t) i;
4274 DirectColor or TrueColor visual.
4279 red_bit=window_info[id].visual->red_mask &
4280 (~(window_info[id].visual->red_mask)+1);
4281 green_bit=window_info[id].visual->green_mask &
4282 (~(window_info[id].visual->green_mask)+1);
4283 blue_bit=window_info[id].visual->blue_mask &
4284 (~(window_info[id].visual->blue_mask)+1);
4285 for (i=0; i < (int) number_colors; i++)
4287 colors[i].pixel=(unsigned long) (red | green | blue);
4290 if (red > window_info[id].visual->red_mask)
4293 if (green > window_info[id].visual->green_mask)
4296 if (blue > window_info[id].visual->blue_mask)
4300 (void) XQueryColors(display,window_info[id].colormap,colors,
4301 (int) number_colors);
4303 Append colormap to colormap list.
4305 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4306 if (p == (ColormapInfo *) NULL)
4307 return((Image *) NULL);
4308 p->colormap=window_info[id].colormap;
4310 p->next=colormap_info;
4316 Allocate image structure.
4318 composite_image=AcquireImage((ImageInfo *) NULL,exception);
4319 if (composite_image == (Image *) NULL)
4321 XDestroyImage(ximage);
4322 return((Image *) NULL);
4325 Convert X image to MIFF format.
4327 if ((window_info[id].visual->klass != TrueColor) &&
4328 (window_info[id].visual->klass != DirectColor))
4329 composite_image->storage_class=PseudoClass;
4330 composite_image->columns=(size_t) ximage->width;
4331 composite_image->rows=(size_t) ximage->height;
4332 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4333 switch (composite_image->storage_class)
4351 Determine shift and mask for red, green, and blue.
4353 red_mask=window_info[id].visual->red_mask;
4355 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4360 green_mask=window_info[id].visual->green_mask;
4362 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4367 blue_mask=window_info[id].visual->blue_mask;
4369 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4375 Convert X image to DirectClass packets.
4377 if ((number_colors != 0) &&
4378 (window_info[id].visual->klass == DirectColor))
4379 for (y=0; y < (int) composite_image->rows; y++)
4381 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4382 composite_image->columns,1,exception);
4383 if (q == (Quantum *) NULL)
4385 for (x=0; x < (int) composite_image->columns; x++)
4387 pixel=XGetPixel(ximage,x,y);
4388 index=(pixel >> red_shift) & red_mask;
4389 SetPixelRed(composite_image,
4390 ScaleShortToQuantum(colors[index].red),q);
4391 index=(pixel >> green_shift) & green_mask;
4392 SetPixelGreen(composite_image,
4393 ScaleShortToQuantum(colors[index].green),q);
4394 index=(pixel >> blue_shift) & blue_mask;
4395 SetPixelBlue(composite_image,
4396 ScaleShortToQuantum(colors[index].blue),q);
4397 q+=GetPixelChannels(composite_image);
4399 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4400 if (status == MagickFalse)
4404 for (y=0; y < (int) composite_image->rows; y++)
4406 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4407 composite_image->columns,1,exception);
4408 if (q == (Quantum *) NULL)
4410 for (x=0; x < (int) composite_image->columns; x++)
4412 pixel=XGetPixel(ximage,x,y);
4413 color=(pixel >> red_shift) & red_mask;
4415 color=(65535UL*color)/red_mask;
4416 SetPixelRed(composite_image,ScaleShortToQuantum(
4417 (unsigned short) color),q);
4418 color=(pixel >> green_shift) & green_mask;
4419 if (green_mask != 0)
4420 color=(65535UL*color)/green_mask;
4421 SetPixelGreen(composite_image,ScaleShortToQuantum(
4422 (unsigned short) color),q);
4423 color=(pixel >> blue_shift) & blue_mask;
4425 color=(65535UL*color)/blue_mask;
4426 SetPixelBlue(composite_image,ScaleShortToQuantum(
4427 (unsigned short) color),q);
4428 q+=GetPixelChannels(composite_image);
4430 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4431 if (status == MagickFalse)
4441 status=AcquireImageColormap(composite_image,number_colors,
4443 if (status == MagickFalse)
4445 XDestroyImage(ximage);
4446 composite_image=DestroyImage(composite_image);
4447 return((Image *) NULL);
4449 for (i=0; i < (int) composite_image->colors; i++)
4451 composite_image->colormap[colors[i].pixel].red=(double)
4452 ScaleShortToQuantum(colors[i].red);
4453 composite_image->colormap[colors[i].pixel].green=(double)
4454 ScaleShortToQuantum(colors[i].green);
4455 composite_image->colormap[colors[i].pixel].blue=(double)
4456 ScaleShortToQuantum(colors[i].blue);
4459 Convert X image to PseudoClass packets.
4461 for (y=0; y < (int) composite_image->rows; y++)
4463 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4464 composite_image->columns,1,exception);
4465 if (q == (Quantum *) NULL)
4467 for (x=0; x < (int) composite_image->columns; x++)
4469 index=(Quantum) XGetPixel(ximage,x,y);
4470 SetPixelIndex(composite_image,index,q);
4471 SetPixelViaPixelInfo(composite_image,
4472 composite_image->colormap+(ssize_t) index,q);
4473 q+=GetPixelChannels(composite_image);
4475 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4476 if (status == MagickFalse)
4482 composite_view=DestroyCacheView(composite_view);
4483 XDestroyImage(ximage);
4484 if (image == (Image *) NULL)
4486 image=composite_image;
4490 Composite any children in back-to-front order.
4492 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4493 &x_offset,&y_offset,&child);
4494 x_offset-=(int) crop_info.x;
4497 y_offset-=(int) crop_info.y;
4500 (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
4501 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4502 composite_image=DestroyImage(composite_image);
4505 Relinquish resources.
4507 while (colormap_info != (ColormapInfo *) NULL)
4509 next=colormap_info->next;
4510 colormap_info->colors=(XColor *) RelinquishMagickMemory(
4511 colormap_info->colors);
4512 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4516 Relinquish resources and restore initial state.
4518 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4521 colormap_info=(ColormapInfo *) NULL;
4524 return((Image *) NULL);
4528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4532 % X G e t W i n d o w I n f o %
4536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4538 % XGetWindowInfo() initializes the XWindowInfo structure.
4540 % The format of the XGetWindowInfo method is:
4542 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4543 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4544 % XResourceInfo *resource_info,XWindowInfo *window)
4545 % resource_info,window)
4547 % A description of each parameter follows:
4549 % o display: Specifies a connection to an X server; returned from
4552 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4553 % returned from XGetVisualInfo.
4555 % o map_info: If map_type is specified, this structure is initialized
4556 % with info from the Standard Colormap.
4558 % o pixel: Specifies a pointer to a XPixelInfo structure.
4560 % o font_info: Specifies a pointer to a XFontStruct structure.
4562 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4565 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4566 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4567 XResourceInfo *resource_info,XWindowInfo *window)
4570 Initialize window info.
4572 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4573 assert(display != (Display *) NULL);
4574 assert(visual_info != (XVisualInfo *) NULL);
4575 assert(map_info != (XStandardColormap *) NULL);
4576 assert(pixel != (XPixelInfo *) NULL);
4577 assert(resource_info != (XResourceInfo *) NULL);
4578 assert(window != (XWindowInfo *) NULL);
4579 if (window->id != (Window) NULL)
4581 if (window->cursor != (Cursor) NULL)
4582 (void) XFreeCursor(display,window->cursor);
4583 if (window->busy_cursor != (Cursor) NULL)
4584 (void) XFreeCursor(display,window->busy_cursor);
4585 if (window->highlight_stipple != (Pixmap) NULL)
4586 (void) XFreePixmap(display,window->highlight_stipple);
4587 if (window->shadow_stipple != (Pixmap) NULL)
4588 (void) XFreePixmap(display,window->shadow_stipple);
4589 if (window->name == (char *) NULL)
4590 window->name=AcquireString("");
4591 if (window->icon_name == (char *) NULL)
4592 window->icon_name=AcquireString("");
4597 Initialize these attributes just once.
4599 window->id=(Window) NULL;
4600 if (window->name == (char *) NULL)
4601 window->name=AcquireString("");
4602 if (window->icon_name == (char *) NULL)
4603 window->icon_name=AcquireString("");
4604 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4605 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4606 window->ximage=(XImage *) NULL;
4607 window->matte_image=(XImage *) NULL;
4608 window->pixmap=(Pixmap) NULL;
4609 window->matte_pixmap=(Pixmap) NULL;
4610 window->mapped=MagickFalse;
4611 window->stasis=MagickFalse;
4612 window->shared_memory=MagickTrue;
4613 window->segment_info=(void *) NULL;
4614 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4619 if (window->segment_info == (void *) NULL)
4620 window->segment_info=AcquireCriticalMemory(2*sizeof(*segment_info));
4621 segment_info=(XShmSegmentInfo *) window->segment_info;
4622 segment_info[0].shmid=(-1);
4623 segment_info[0].shmaddr=(char *) NULL;
4624 segment_info[1].shmid=(-1);
4625 segment_info[1].shmaddr=(char *) NULL;
4630 Initialize these attributes every time function is called.
4632 window->screen=visual_info->screen;
4633 window->root=XRootWindow(display,visual_info->screen);
4634 window->visual=visual_info->visual;
4635 window->storage_class=(unsigned int) visual_info->klass;
4636 window->depth=(unsigned int) visual_info->depth;
4637 window->visual_info=visual_info;
4638 window->map_info=map_info;
4639 window->pixel_info=pixel;
4640 window->font_info=font_info;
4641 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4642 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4643 window->geometry=(char *) NULL;
4644 window->icon_geometry=(char *) NULL;
4645 if (resource_info->icon_geometry != (char *) NULL)
4646 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4647 window->crop_geometry=(char *) NULL;
4648 window->flags=(size_t) PSize;
4651 window->min_width=1;
4652 window->min_height=1;
4653 window->width_inc=1;
4654 window->height_inc=1;
4655 window->border_width=resource_info->border_width;
4656 window->annotate_context=pixel->annotate_context;
4657 window->highlight_context=pixel->highlight_context;
4658 window->widget_context=pixel->widget_context;
4659 window->shadow_stipple=(Pixmap) NULL;
4660 window->highlight_stipple=(Pixmap) NULL;
4661 window->use_pixmap=MagickTrue;
4662 window->immutable=MagickFalse;
4663 window->shape=MagickFalse;
4665 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4666 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4667 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4668 window->attributes.background_pixel=pixel->background_color.pixel;
4669 window->attributes.background_pixmap=(Pixmap) NULL;
4670 window->attributes.bit_gravity=ForgetGravity;
4671 window->attributes.backing_store=WhenMapped;
4672 window->attributes.save_under=MagickTrue;
4673 window->attributes.border_pixel=pixel->border_color.pixel;
4674 window->attributes.colormap=map_info->colormap;
4675 window->attributes.cursor=window->cursor;
4676 window->attributes.do_not_propagate_mask=NoEventMask;
4677 window->attributes.event_mask=NoEventMask;
4678 window->attributes.override_redirect=MagickFalse;
4679 window->attributes.win_gravity=NorthWestGravity;
4680 window->orphan=MagickFalse;
4684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4688 % X H i g h l i g h t E l l i p s e %
4692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4694 % XHighlightEllipse() puts a border on the X server around a region defined by
4697 % The format of the XHighlightEllipse method is:
4699 % void XHighlightEllipse(Display *display,Window window,
4700 % GC annotate_context,const RectangleInfo *highlight_info)
4702 % A description of each parameter follows:
4704 % o display: Specifies a connection to an X server; returned from
4707 % o window: Specifies a pointer to a Window structure.
4709 % o annotate_context: Specifies a pointer to a GC structure.
4711 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4712 % contains the extents of any highlighting rectangle.
4715 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4716 GC annotate_context,const RectangleInfo *highlight_info)
4718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4719 assert(display != (Display *) NULL);
4720 assert(window != (Window) NULL);
4721 assert(annotate_context != (GC) NULL);
4722 assert(highlight_info != (RectangleInfo *) NULL);
4723 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4725 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4726 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4727 (unsigned int) highlight_info->height-1,0,360*64);
4728 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4729 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4730 (unsigned int) highlight_info->height-3,0,360*64);
4734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4738 % X H i g h l i g h t L i n e %
4742 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4744 % XHighlightLine() puts a border on the X server around a region defined by
4747 % The format of the XHighlightLine method is:
4749 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4750 % const XSegment *highlight_info)
4752 % A description of each parameter follows:
4754 % o display: Specifies a connection to an X server; returned from
4757 % o window: Specifies a pointer to a Window structure.
4759 % o annotate_context: Specifies a pointer to a GC structure.
4761 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4762 % contains the extents of any highlighting rectangle.
4765 MagickPrivate void XHighlightLine(Display *display,Window window,
4766 GC annotate_context,const XSegment *highlight_info)
4768 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4769 assert(display != (Display *) NULL);
4770 assert(window != (Window) NULL);
4771 assert(annotate_context != (GC) NULL);
4772 assert(highlight_info != (XSegment *) NULL);
4773 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4774 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4782 % X H i g h l i g h t R e c t a n g l e %
4786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4788 % XHighlightRectangle() puts a border on the X server around a region defined
4789 % by highlight_info.
4791 % The format of the XHighlightRectangle method is:
4793 % void XHighlightRectangle(Display *display,Window window,
4794 % GC annotate_context,const RectangleInfo *highlight_info)
4796 % A description of each parameter follows:
4798 % o display: Specifies a connection to an X server; returned from
4801 % o window: Specifies a pointer to a Window structure.
4803 % o annotate_context: Specifies a pointer to a GC structure.
4805 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4806 % contains the extents of any highlighting rectangle.
4809 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4810 GC annotate_context,const RectangleInfo *highlight_info)
4812 assert(display != (Display *) NULL);
4813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4814 assert(window != (Window) NULL);
4815 assert(annotate_context != (GC) NULL);
4816 assert(highlight_info != (RectangleInfo *) NULL);
4817 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4819 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4820 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4821 (unsigned int) highlight_info->height-1);
4822 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4823 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4824 (unsigned int) highlight_info->height-3);
4828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4832 % X I m p o r t I m a g e %
4836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4838 % XImportImage() reads an image from an X window.
4840 % The format of the XImportImage method is:
4842 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
4843 % ExceptionInfo *exception)
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.
4851 % o exception: return any errors or warnings in this structure.
4854 MagickExport Image *XImportImage(const ImageInfo *image_info,
4855 XImportInfo *ximage_info,ExceptionInfo *exception)
4888 Open X server connection.
4890 assert(image_info != (const ImageInfo *) NULL);
4891 assert(image_info->signature == MagickCoreSignature);
4892 if (image_info->debug != MagickFalse)
4893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4894 image_info->filename);
4895 assert(ximage_info != (XImportInfo *) NULL);
4896 display=XOpenDisplay(image_info->server_name);
4897 if (display == (Display *) NULL)
4899 ThrowXWindowException(XServerError,"UnableToOpenXServer",
4900 XDisplayName(image_info->server_name));
4901 return((Image *) NULL);
4904 Set our forgiving exception handler.
4906 (void) XSetErrorHandler(XError);
4908 Select target window.
4914 root=XRootWindow(display,XDefaultScreen(display));
4915 target=(Window) NULL;
4916 if (*image_info->filename != '\0')
4918 if (LocaleCompare(image_info->filename,"root") == 0)
4923 Select window by ID or name.
4925 if (isdigit((int) ((unsigned char) *image_info->filename)) != 0)
4926 target=XWindowByID(display,root,(Window)
4927 strtol(image_info->filename,(char **) NULL,0));
4928 if (target == (Window) NULL)
4929 target=XWindowByName(display,root,image_info->filename);
4930 if (target == (Window) NULL)
4931 ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
4932 image_info->filename);
4936 If target window is not defined, interactively select one.
4938 prior_target=target;
4939 if (target == (Window) NULL)
4940 target=XSelectWindow(display,&crop_info);
4941 if (target == (Window) NULL)
4942 ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
4943 image_info->filename);
4944 client=target; /* obsolete */
4950 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4951 if (status != False)
4959 Find window manager frame.
4961 status=XQueryTree(display,target,&root,&parent,&children,&d);
4962 if ((status != False) && (children != (Window *) NULL))
4963 (void) XFree((char *) children);
4964 if ((status == False) || (parent == (Window) NULL) ||
4972 client=XClientWindow(display,target);
4973 if (ximage_info->frame == MagickFalse)
4975 if ((ximage_info->frame == MagickFalse) &&
4976 (prior_target != MagickFalse))
4977 target=prior_target;
4980 if (ximage_info->screen)
4992 Obtain window image directly from screen.
4994 status=XGetWindowAttributes(display,target,&window_attributes);
4995 if (status == False)
4997 ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
4998 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,exception);
5047 (void) XUngrabServer(display);
5048 if (image == (Image *) NULL)
5049 ThrowXWindowException(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,exception);
5065 if (clone_image != (Image *) NULL)
5067 crop_image=CropImage(clone_image,&crop_info,exception);
5068 if (crop_image != (Image *) NULL)
5070 image=DestroyImage(image);
5075 status=XGetWMName(display,target,&window_name);
5078 if (*image_info->filename == '\0')
5079 (void) CopyMagickString(image->filename,(char *) window_name.value,
5080 (size_t) window_name.nitems+1);
5081 (void) XFree((void *) window_name.value);
5084 if (ximage_info->silent == MagickFalse)
5087 Alert the user we're done.
5089 (void) XBell(display,0);
5090 (void) XBell(display,0);
5092 (void) XCloseDisplay(display);
5097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5101 % X I n i t i a l i z e W i n d o w s %
5105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5107 % XInitializeWindows() initializes the XWindows structure.
5109 % The format of the XInitializeWindows method is:
5111 % XWindows *XInitializeWindows(Display *display,
5112 % XResourceInfo *resource_info)
5114 % A description of each parameter follows:
5116 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5118 % o display: Specifies a connection to an X server; returned from
5121 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5124 MagickPrivate XWindows *XInitializeWindows(Display *display,
5125 XResourceInfo *resource_info)
5134 Allocate windows structure.
5136 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5137 if (windows == (XWindows *) NULL)
5139 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5141 return((XWindows *) NULL);
5143 (void) memset(windows,0,sizeof(*windows));
5144 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5145 sizeof(*windows->pixel_info));
5146 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5147 sizeof(*windows->icon_pixel));
5148 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5149 sizeof(*windows->icon_resources));
5150 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5151 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5152 (windows->icon_resources == (XResourceInfo *) NULL))
5154 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5156 return((XWindows *) NULL);
5159 Initialize windows structure.
5161 windows->display=display;
5162 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5163 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5164 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5165 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5166 windows->im_remote_command=
5167 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5168 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5169 windows->im_update_colormap=
5170 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5171 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5172 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5173 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5174 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5175 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5176 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5177 (void) XSynchronize(display,IsWindows95());
5179 if (IsEventLogging())
5181 (void) XSynchronize(display,MagickTrue);
5182 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5183 GetMagickVersion((size_t *) NULL));
5184 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5185 (void) LogMagickEvent(X11Event,GetMagickModule(),
5186 " Window Manager: 0x%lx",windows->wm_protocols);
5187 (void) LogMagickEvent(X11Event,GetMagickModule(),
5188 " delete window: 0x%lx",windows->wm_delete_window);
5189 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5190 windows->wm_take_focus);
5191 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5192 windows->im_protocols);
5193 (void) LogMagickEvent(X11Event,GetMagickModule(),
5194 " remote command: 0x%lx",windows->im_remote_command);
5195 (void) LogMagickEvent(X11Event,GetMagickModule(),
5196 " update widget: 0x%lx",windows->im_update_widget);
5197 (void) LogMagickEvent(X11Event,GetMagickModule(),
5198 " update colormap: 0x%lx",windows->im_update_colormap);
5199 (void) LogMagickEvent(X11Event,GetMagickModule(),
5200 " former image: 0x%lx",windows->im_former_image);
5201 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5202 windows->im_next_image);
5203 (void) LogMagickEvent(X11Event,GetMagickModule(),
5204 " retain colors: 0x%lx",windows->im_retain_colors);
5205 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5207 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5208 windows->dnd_protocols);
5211 Allocate standard colormap.
5213 windows->map_info=XAllocStandardColormap();
5214 windows->icon_map=XAllocStandardColormap();
5215 if ((windows->map_info == (XStandardColormap *) NULL) ||
5216 (windows->icon_map == (XStandardColormap *) NULL))
5217 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5219 windows->map_info->colormap=(Colormap) NULL;
5220 windows->icon_map->colormap=(Colormap) NULL;
5221 windows->pixel_info->pixels=(unsigned long *) NULL;
5222 windows->pixel_info->annotate_context=(GC) NULL;
5223 windows->pixel_info->highlight_context=(GC) NULL;
5224 windows->pixel_info->widget_context=(GC) NULL;
5225 windows->font_info=(XFontStruct *) NULL;
5226 windows->icon_pixel->annotate_context=(GC) NULL;
5227 windows->icon_pixel->pixels=(unsigned long *) NULL;
5231 *windows->icon_resources=(*resource_info);
5232 windows->icon_resources->visual_type=(char *) "default";
5233 windows->icon_resources->colormap=SharedColormap;
5234 windows->visual_info=
5235 XBestVisualInfo(display,windows->map_info,resource_info);
5236 windows->icon_visual=
5237 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5238 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5239 (windows->icon_visual == (XVisualInfo *) NULL))
5240 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5241 resource_info->visual_type);
5242 if (IsEventLogging())
5244 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5245 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5246 windows->visual_info->visualid);
5247 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5248 XVisualClassName(windows->visual_info->klass));
5249 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5250 windows->visual_info->depth);
5251 (void) LogMagickEvent(X11Event,GetMagickModule(),
5252 " size of colormap: %d entries",windows->visual_info->colormap_size);
5253 (void) LogMagickEvent(X11Event,GetMagickModule(),
5254 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5255 windows->visual_info->red_mask,windows->visual_info->green_mask,
5256 windows->visual_info->blue_mask);
5257 (void) LogMagickEvent(X11Event,GetMagickModule(),
5258 " significant bits in color: %d bits",
5259 windows->visual_info->bits_per_rgb);
5262 Allocate class and manager hints.
5264 windows->class_hints=XAllocClassHint();
5265 windows->manager_hints=XAllocWMHints();
5266 if ((windows->class_hints == (XClassHint *) NULL) ||
5267 (windows->manager_hints == (XWMHints *) NULL))
5268 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5271 Determine group leader if we have one.
5273 root_window=XRootWindow(display,windows->visual_info->screen);
5274 windows->group_leader.id=(Window) NULL;
5275 if (resource_info->window_group != (char *) NULL)
5277 if (isdigit((int) ((unsigned char) *resource_info->window_group)) != 0)
5278 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5279 strtol((char *) resource_info->window_group,(char **) NULL,0));
5280 if (windows->group_leader.id == (Window) NULL)
5281 windows->group_leader.id=
5282 XWindowByName(display,root_window,resource_info->window_group);
5288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5292 % X M a k e C u r s o r %
5296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5298 % XMakeCursor() creates a crosshairs X11 cursor.
5300 % The format of the XMakeCursor method is:
5302 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5303 % char *background_color,char *foreground_color)
5305 % A description of each parameter follows:
5307 % o display: Specifies a connection to an X server; returned from
5310 % o window: Specifies the ID of the window for which the cursor is
5313 % o colormap: Specifies the ID of the colormap from which the background
5314 % and foreground color will be retrieved.
5316 % o background_color: Specifies the color to use for the cursor background.
5318 % o foreground_color: Specifies the color to use for the cursor foreground.
5321 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5322 Colormap colormap,char *background_color,char *foreground_color)
5324 #define scope_height 17
5325 #define scope_x_hot 8
5326 #define scope_y_hot 8
5327 #define scope_width 17
5329 static const unsigned char
5332 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5333 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5334 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5335 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5336 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5340 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5341 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5342 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5343 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5344 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5358 assert(display != (Display *) NULL);
5359 assert(window != (Window) NULL);
5360 assert(colormap != (Colormap) NULL);
5361 assert(background_color != (char *) NULL);
5362 assert(foreground_color != (char *) NULL);
5363 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5364 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5366 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5367 scope_width,scope_height);
5368 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5370 ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
5371 return((Cursor) NULL);
5373 (void) XParseColor(display,colormap,background_color,&background);
5374 (void) XParseColor(display,colormap,foreground_color,&foreground);
5375 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5376 scope_x_hot,scope_y_hot);
5377 (void) XFreePixmap(display,source);
5378 (void) XFreePixmap(display,mask);
5383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5387 % X M a k e I m a g e %
5391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5393 % XMakeImage() creates an X11 image. If the image size differs from the X11
5394 % image size, the image is first resized.
5396 % The format of the XMakeImage method is:
5398 % MagickBooleanType XMakeImage(Display *display,
5399 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5400 % unsigned int width,unsigned int height,ExceptionInfo *exception)
5402 % A description of each parameter follows:
5404 % o display: Specifies a connection to an X server; returned from
5407 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5409 % o window: Specifies a pointer to a XWindowInfo structure.
5411 % o image: the image.
5413 % o width: Specifies the width in pixels of the rectangular area to
5416 % o height: Specifies the height in pixels of the rectangular area to
5419 % o exception: return any errors or warnings in this structure.
5422 MagickPrivate MagickBooleanType XMakeImage(Display *display,
5423 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5424 unsigned int width,unsigned int height,ExceptionInfo *exception)
5426 #define CheckOverflowException(length,width,height) \
5427 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5440 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5441 assert(display != (Display *) NULL);
5442 assert(resource_info != (XResourceInfo *) NULL);
5443 assert(window != (XWindowInfo *) NULL);
5445 assert(height != 0);
5446 if ((window->width == 0) || (window->height == 0))
5447 return(MagickFalse);
5449 Apply user transforms to the image.
5451 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5452 (void) XFlush(display);
5453 depth=(int) window->depth;
5454 if (window->destroy)
5455 window->image=DestroyImage(window->image);
5456 window->image=image;
5457 window->destroy=MagickFalse;
5458 if (window->image != (Image *) NULL)
5460 if (window->crop_geometry != (char *) NULL)
5471 window->image->page.x=0;
5472 window->image->page.y=0;
5473 (void) ParsePageGeometry(window->image,window->crop_geometry,
5474 &crop_info,exception);
5475 crop_image=CropImage(window->image,&crop_info,exception);
5476 if (crop_image != (Image *) NULL)
5478 if (window->image != image)
5479 window->image=DestroyImage(window->image);
5480 window->image=crop_image;
5481 window->destroy=MagickTrue;
5484 if ((width != (unsigned int) window->image->columns) ||
5485 (height != (unsigned int) window->image->rows))
5493 resize_image=NewImageList();
5494 if ((window->pixel_info->colors == 0) &&
5495 (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
5496 (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
5497 resize_image=ResizeImage(window->image,width,height,
5498 image->filter,exception);
5501 if (window->image->storage_class == PseudoClass)
5502 resize_image=SampleImage(window->image,width,height,
5505 resize_image=ThumbnailImage(window->image,width,height,
5508 if (resize_image != (Image *) NULL)
5510 if (window->image != image)
5511 window->image=DestroyImage(window->image);
5512 window->image=resize_image;
5513 window->destroy=MagickTrue;
5516 width=(unsigned int) window->image->columns;
5517 assert((size_t) width == window->image->columns);
5518 height=(unsigned int) window->image->rows;
5519 assert((size_t) height == window->image->rows);
5524 ximage=(XImage *) NULL;
5525 format=(depth == 1) ? XYBitmap : ZPixmap;
5526 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5527 if (window->shared_memory != MagickFalse)
5532 segment_info=(XShmSegmentInfo *) window->segment_info;
5533 segment_info[1].shmid=(-1);
5534 segment_info[1].shmaddr=(char *) NULL;
5535 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5536 (char *) NULL,&segment_info[1],width,height);
5537 if (ximage == (XImage *) NULL)
5538 window->shared_memory=MagickFalse;
5541 length=(size_t) ximage->bytes_per_line*ximage->height;
5542 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5543 window->shared_memory=MagickFalse;
5545 if (window->shared_memory != MagickFalse)
5546 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5547 if (window->shared_memory != MagickFalse)
5548 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5549 if (segment_info[1].shmid < 0)
5550 window->shared_memory=MagickFalse;
5551 if (window->shared_memory != MagickFalse)
5552 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5555 if (ximage != (XImage *) NULL)
5556 XDestroyImage(ximage);
5557 ximage=(XImage *) NULL;
5558 if (segment_info[1].shmaddr)
5560 (void) shmdt(segment_info[1].shmaddr);
5561 segment_info[1].shmaddr=(char *) NULL;
5563 if (segment_info[1].shmid >= 0)
5565 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5566 segment_info[1].shmid=(-1);
5572 Allocate X image pixel data.
5574 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5575 if (window->shared_memory)
5583 (void) XSync(display,MagickFalse);
5584 xerror_alert=MagickFalse;
5585 segment_info=(XShmSegmentInfo *) window->segment_info;
5586 ximage->data=segment_info[1].shmaddr;
5587 segment_info[1].readOnly=MagickFalse;
5588 status=XShmAttach(display,&segment_info[1]);
5589 if (status != False)
5590 (void) XSync(display,MagickFalse);
5591 if ((status == False) || (xerror_alert != MagickFalse))
5593 window->shared_memory=MagickFalse;
5594 if (status != False)
5595 XShmDetach(display,&segment_info[1]);
5597 XDestroyImage(ximage);
5598 ximage=(XImage *) NULL;
5599 if (segment_info[1].shmid >= 0)
5601 if (segment_info[1].shmaddr != NULL)
5602 (void) shmdt(segment_info[1].shmaddr);
5603 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5604 segment_info[1].shmid=(-1);
5605 segment_info[1].shmaddr=(char *) NULL;
5610 if (window->shared_memory == MagickFalse)
5611 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5612 (char *) NULL,width,height,XBitmapPad(display),0);
5613 if (ximage == (XImage *) NULL)
5616 Unable to create X image.
5618 (void) XCheckDefineCursor(display,window->id,window->cursor);
5619 return(MagickFalse);
5621 length=(size_t) ximage->bytes_per_line*ximage->height;
5622 if (IsEventLogging())
5624 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5625 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5626 ximage->width,ximage->height);
5627 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5629 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5630 ximage->byte_order);
5631 (void) LogMagickEvent(X11Event,GetMagickModule(),
5632 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5633 ximage->bitmap_bit_order,ximage->bitmap_pad);
5634 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5636 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5637 ximage->bytes_per_line);
5638 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5639 ximage->bits_per_pixel);
5640 (void) LogMagickEvent(X11Event,GetMagickModule(),
5641 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5642 ximage->green_mask,ximage->blue_mask);
5644 if (window->shared_memory == MagickFalse)
5646 if (ximage->format == XYBitmap)
5648 ximage->data=(char *) AcquireQuantumMemory((size_t)
5649 ximage->bytes_per_line,(size_t) ximage->depth*ximage->height);
5650 if (ximage->data != (char *) NULL)
5651 (void) memset(ximage->data,0,(size_t)
5652 ximage->bytes_per_line*ximage->depth*ximage->height);
5656 ximage->data=(char *) AcquireQuantumMemory((size_t)
5657 ximage->bytes_per_line,(size_t) ximage->height);
5658 if (ximage->data != (char *) NULL)
5659 (void) memset(ximage->data,0,(size_t)
5660 ximage->bytes_per_line*ximage->height);
5663 if (ximage->data == (char *) NULL)
5666 Unable to allocate pixel data.
5668 XDestroyImage(ximage);
5669 ximage=(XImage *) NULL;
5670 (void) XCheckDefineCursor(display,window->id,window->cursor);
5671 return(MagickFalse);
5673 if (window->ximage != (XImage *) NULL)
5676 Destroy previous X image.
5678 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5679 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5680 if (window->segment_info != (XShmSegmentInfo *) NULL)
5685 segment_info=(XShmSegmentInfo *) window->segment_info;
5686 if (segment_info[0].shmid >= 0)
5688 (void) XSync(display,MagickFalse);
5689 (void) XShmDetach(display,&segment_info[0]);
5690 (void) XSync(display,MagickFalse);
5691 if (segment_info[0].shmaddr != (char *) NULL)
5692 (void) shmdt(segment_info[0].shmaddr);
5693 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5694 segment_info[0].shmid=(-1);
5695 segment_info[0].shmaddr=(char *) NULL;
5696 window->ximage->data=(char *) NULL;
5700 if (window->ximage->data != (char *) NULL)
5701 free(window->ximage->data);
5702 window->ximage->data=(char *) NULL;
5703 XDestroyImage(window->ximage);
5704 window->ximage=(XImage *) NULL;
5706 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5707 if (window->segment_info != (XShmSegmentInfo *) NULL)
5712 segment_info=(XShmSegmentInfo *) window->segment_info;
5713 segment_info[0]=segment_info[1];
5716 window->ximage=ximage;
5717 matte_image=(XImage *) NULL;
5718 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5719 if ((window->image->alpha_trait != UndefinedPixelTrait) &&
5720 ((int) width <= XDisplayWidth(display,window->screen)) &&
5721 ((int) height <= XDisplayHeight(display,window->screen)))
5726 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5727 (char *) NULL,width,height,XBitmapPad(display),0);
5728 if (IsEventLogging())
5730 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5731 (void) LogMagickEvent(X11Event,GetMagickModule(),
5732 " width, height: %dx%d",matte_image->width,matte_image->height);
5734 if (matte_image != (XImage *) NULL)
5737 Allocate matte image pixel data.
5739 matte_image->data=(char *) malloc((size_t)
5740 matte_image->bytes_per_line*matte_image->depth*
5741 matte_image->height);
5742 if (matte_image->data == (char *) NULL)
5744 XDestroyImage(matte_image);
5745 matte_image=(XImage *) NULL;
5749 if (window->matte_image != (XImage *) NULL)
5754 if (window->matte_image->data != (char *) NULL)
5755 free(window->matte_image->data);
5756 window->matte_image->data=(char *) NULL;
5757 XDestroyImage(window->matte_image);
5758 window->matte_image=(XImage *) NULL;
5760 window->matte_image=matte_image;
5761 if (window->matte_pixmap != (Pixmap) NULL)
5763 (void) XFreePixmap(display,window->matte_pixmap);
5764 window->matte_pixmap=(Pixmap) NULL;
5765 #if defined(MAGICKCORE_HAVE_SHAPE)
5766 if (window->shape != MagickFalse)
5767 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5770 window->stasis=MagickFalse;
5772 Convert pixels to X image data.
5774 if (window->image != (Image *) NULL)
5776 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5777 (ximage->bitmap_bit_order == LSBFirst)))
5778 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5779 matte_image,exception);
5781 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5782 matte_image,exception);
5784 if (window->matte_image != (XImage *) NULL)
5787 Create matte pixmap.
5789 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5790 if (window->matte_pixmap != (Pixmap) NULL)
5799 Copy matte image to matte pixmap.
5801 context_values.background=0;
5802 context_values.foreground=1;
5803 graphics_context=XCreateGC(display,window->matte_pixmap,
5804 (size_t) (GCBackground | GCForeground),&context_values);
5805 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5806 window->matte_image,0,0,0,0,width,height);
5807 (void) XFreeGC(display,graphics_context);
5808 #if defined(MAGICKCORE_HAVE_SHAPE)
5809 if (window->shape != MagickFalse)
5810 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5811 window->matte_pixmap,ShapeSet);
5815 (void) XMakePixmap(display,resource_info,window);
5819 (void) XCheckDefineCursor(display,window->id,window->cursor);
5824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5828 + X M a k e I m a g e L S B F i r s t %
5832 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5834 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5835 % pixels are copied in least-significant bit and byte first order. The
5836 % server's scanline pad is respected. Rather than using one or two general
5837 % cases, many special cases are found here to help speed up the image
5840 % The format of the XMakeImageLSBFirst method is:
5842 % void XMakeImageLSBFirst(Display *display,XWindows *windows,
5843 % ExceptionInfo *exception)
5845 % A description of each parameter follows:
5847 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5849 % o window: Specifies a pointer to a XWindowInfo structure.
5851 % o image: the image.
5853 % o ximage: Specifies a pointer to a XImage structure; returned from
5856 % o matte_image: Specifies a pointer to a XImage structure; returned from
5859 % o exception: return any errors or warnings in this structure.
5862 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5863 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5864 ExceptionInfo *exception)
5875 register const Quantum
5881 register unsigned char
5898 assert(resource_info != (XResourceInfo *) NULL);
5899 assert(window != (XWindowInfo *) NULL);
5900 assert(image != (Image *) NULL);
5901 if (image->debug != MagickFalse)
5902 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5904 if ((window->immutable == MagickFalse) &&
5905 (image->storage_class == DirectClass) && (image->alpha_trait != UndefinedPixelTrait))
5908 size[MagickPathExtent];
5916 image_info=AcquireImageInfo();
5917 (void) CopyMagickString(image_info->filename,
5918 resource_info->image_info->texture != (char *) NULL ?
5919 resource_info->image_info->texture : "pattern:checkerboard",
5921 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",(double)
5922 image->columns,(double) image->rows);
5923 image_info->size=ConstantString(size);
5924 pattern=ReadImage(image_info,exception);
5925 image_info=DestroyImageInfo(image_info);
5926 if (pattern != (Image *) NULL)
5928 canvas=CloneImage(image,0,0,MagickTrue,exception);
5929 if (canvas != (Image *) NULL)
5930 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5932 pattern=DestroyImage(pattern);
5935 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5936 ximage->bits_per_pixel) >> 3));
5937 map_info=window->map_info;
5938 pixels=window->pixel_info->pixels;
5939 q=(unsigned char *) ximage->data;
5941 canvas_view=AcquireVirtualCacheView(canvas,exception);
5942 if (ximage->format == XYBitmap)
5944 register unsigned short
5952 Convert canvas to big-endian bitmap.
5954 background=(unsigned char)
5955 (XPixelIntensity(&window->pixel_info->foreground_color) <
5956 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5957 foreground=(unsigned char)
5958 (XPixelIntensity(&window->pixel_info->background_color) <
5959 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5960 polarity=(unsigned short) ((GetPixelInfoIntensity(image,
5961 &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
5962 if (canvas->colors == 2)
5963 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
5964 GetPixelInfoIntensity(image,&canvas->colormap[1]);
5965 for (y=0; y < (int) canvas->rows; y++)
5967 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5969 if (p == (const Quantum *) NULL)
5973 for (x=0; x < (int) canvas->columns; x++)
5976 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
5987 p+=GetPixelChannels(canvas);
5995 if (window->pixel_info->colors != 0)
5996 switch (ximage->bits_per_pixel)
6000 register unsigned int
6004 Convert to 2 bit color-mapped X canvas.
6006 for (y=0; y < (int) canvas->rows; y++)
6008 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6009 canvas->columns,1,exception);
6010 if (p == (const Quantum *) NULL)
6013 for (x=0; x < (int) canvas->columns; x++)
6015 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6020 *q=(unsigned char) pixel;
6026 *q|=(unsigned char) (pixel << 2);
6032 *q|=(unsigned char) (pixel << 4);
6038 *q|=(unsigned char) (pixel << 6);
6044 p+=GetPixelChannels(canvas);
6052 register unsigned int
6056 Convert to 4 bit color-mapped X canvas.
6058 for (y=0; y < (int) canvas->rows; y++)
6060 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6061 canvas->columns,1,exception);
6062 if (p == (const Quantum *) NULL)
6065 for (x=0; x < (int) canvas->columns; x++)
6067 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6072 *q=(unsigned char) pixel;
6078 *q|=(unsigned char) (pixel << 4);
6084 p+=GetPixelChannels(canvas);
6094 Convert to 8 bit color-mapped X canvas.
6096 if (resource_info->color_recovery &&
6097 resource_info->quantize_info->dither_method != NoDitherMethod)
6099 XDitherImage(canvas,ximage,exception);
6102 for (y=0; y < (int) canvas->rows; y++)
6104 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6105 canvas->columns,1,exception);
6106 if (p == (const Quantum *) NULL)
6108 for (x=0; x < (int) canvas->columns; x++)
6110 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6111 *q++=(unsigned char) pixel;
6112 p+=GetPixelChannels(canvas);
6123 register unsigned int
6127 Convert to multi-byte color-mapped X canvas.
6129 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6130 for (y=0; y < (int) canvas->rows; y++)
6132 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6133 canvas->columns,1,exception);
6134 if (p == (const Quantum *) NULL)
6136 for (x=0; x < (int) canvas->columns; x++)
6138 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6139 for (k=0; k < (int) bytes_per_pixel; k++)
6141 *q++=(unsigned char) (pixel & 0xff);
6144 p+=GetPixelChannels(canvas);
6152 switch (ximage->bits_per_pixel)
6156 register unsigned int
6160 Convert to contiguous 2 bit continuous-tone X canvas.
6162 for (y=0; y < (int) canvas->rows; y++)
6165 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6166 canvas->columns,1,exception);
6167 if (p == (const Quantum *) NULL)
6169 for (x=0; x < (int) canvas->columns; x++)
6171 pixel=XGammaPixel(canvas,map_info,p);
6177 *q=(unsigned char) pixel;
6183 *q|=(unsigned char) (pixel << 2);
6189 *q|=(unsigned char) (pixel << 4);
6195 *q|=(unsigned char) (pixel << 6);
6201 p+=GetPixelChannels(canvas);
6209 register unsigned int
6213 Convert to contiguous 4 bit continuous-tone X canvas.
6215 for (y=0; y < (int) canvas->rows; y++)
6217 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6218 canvas->columns,1,exception);
6219 if (p == (const Quantum *) NULL)
6222 for (x=0; x < (int) canvas->columns; x++)
6224 pixel=XGammaPixel(canvas,map_info,p);
6230 *q=(unsigned char) pixel;
6236 *q|=(unsigned char) (pixel << 4);
6242 p+=GetPixelChannels(canvas);
6252 Convert to contiguous 8 bit continuous-tone X canvas.
6254 if (resource_info->color_recovery &&
6255 resource_info->quantize_info->dither_method != NoDitherMethod)
6257 XDitherImage(canvas,ximage,exception);
6260 for (y=0; y < (int) canvas->rows; y++)
6262 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6263 canvas->columns,1,exception);
6264 if (p == (const Quantum *) NULL)
6266 for (x=0; x < (int) canvas->columns; x++)
6268 pixel=XGammaPixel(canvas,map_info,p);
6269 *q++=(unsigned char) pixel;
6270 p+=GetPixelChannels(canvas);
6278 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6279 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6280 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6281 (map_info->blue_mult == 1))
6284 Convert to 32 bit continuous-tone X canvas.
6286 for (y=0; y < (int) canvas->rows; y++)
6288 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6289 canvas->columns,1,exception);
6290 if (p == (const Quantum *) NULL)
6292 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6293 (blue_gamma != 1.0))
6296 Gamma correct canvas.
6298 for (x=(int) canvas->columns-1; x >= 0; x--)
6300 *q++=ScaleQuantumToChar(XBlueGamma(
6301 GetPixelBlue(canvas,p)));
6302 *q++=ScaleQuantumToChar(XGreenGamma(
6303 GetPixelGreen(canvas,p)));
6304 *q++=ScaleQuantumToChar(XRedGamma(
6305 GetPixelRed(canvas,p)));
6307 p+=GetPixelChannels(canvas);
6311 for (x=(int) canvas->columns-1; x >= 0; x--)
6313 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6314 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6315 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6317 p+=GetPixelChannels(canvas);
6322 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6323 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6324 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6325 (map_info->blue_mult == 65536L))
6328 Convert to 32 bit continuous-tone X canvas.
6330 for (y=0; y < (int) canvas->rows; y++)
6332 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6333 canvas->columns,1,exception);
6334 if (p == (const Quantum *) NULL)
6336 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6337 (blue_gamma != 1.0))
6340 Gamma correct canvas.
6342 for (x=(int) canvas->columns-1; x >= 0; x--)
6344 *q++=ScaleQuantumToChar(XRedGamma(
6345 GetPixelRed(canvas,p)));
6346 *q++=ScaleQuantumToChar(XGreenGamma(
6347 GetPixelGreen(canvas,p)));
6348 *q++=ScaleQuantumToChar(XBlueGamma(
6349 GetPixelBlue(canvas,p)));
6351 p+=GetPixelChannels(canvas);
6355 for (x=(int) canvas->columns-1; x >= 0; x--)
6357 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6358 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6359 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6361 p+=GetPixelChannels(canvas);
6370 register unsigned int
6374 Convert to multi-byte continuous-tone X canvas.
6376 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6377 for (y=0; y < (int) canvas->rows; y++)
6379 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6380 canvas->columns,1,exception);
6381 if (p == (const Quantum *) NULL)
6383 for (x=0; x < (int) canvas->columns; x++)
6385 pixel=XGammaPixel(canvas,map_info,p);
6386 for (k=0; k < (int) bytes_per_pixel; k++)
6388 *q++=(unsigned char) (pixel & 0xff);
6391 p+=GetPixelChannels(canvas);
6399 if (matte_image != (XImage *) NULL)
6402 Initialize matte canvas.
6404 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6405 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6406 q=(unsigned char *) matte_image->data;
6407 for (y=0; y < (int) canvas->rows; y++)
6409 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6411 if (p == (const Quantum *) NULL)
6415 for (x=(int) canvas->columns-1; x >= 0; x--)
6418 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6427 p+=GetPixelChannels(canvas);
6434 canvas_view=DestroyCacheView(canvas_view);
6435 if (canvas != image)
6436 canvas=DestroyImage(canvas);
6440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6444 + X M a k e I m a g e M S B F i r s t %
6448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6450 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6451 % image pixels are copied in most-significant bit and byte first order. The
6452 % server's scanline pad is also respected. Rather than using one or two
6453 % general cases, many special cases are found here to help speed up the image
6456 % The format of the XMakeImageMSBFirst method is:
6458 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6459 % ExceptionInfo *exception)
6461 % A description of each parameter follows:
6463 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6465 % o window: Specifies a pointer to a XWindowInfo structure.
6467 % o image: the image.
6469 % o ximage: Specifies a pointer to a XImage structure; returned from
6472 % o matte_image: Specifies a pointer to a XImage structure; returned from
6475 % o exception: return any errors or warnings in this structure.
6478 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6479 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6480 ExceptionInfo *exception)
6494 register const Quantum
6497 register unsigned char
6514 assert(resource_info != (XResourceInfo *) NULL);
6515 assert(window != (XWindowInfo *) NULL);
6516 assert(image != (Image *) NULL);
6517 if (image->debug != MagickFalse)
6518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6520 if ((window->immutable != MagickFalse) &&
6521 (image->storage_class == DirectClass) &&
6522 (image->alpha_trait != UndefinedPixelTrait))
6525 size[MagickPathExtent];
6533 image_info=AcquireImageInfo();
6534 (void) CopyMagickString(image_info->filename,
6535 resource_info->image_info->texture != (char *) NULL ?
6536 resource_info->image_info->texture : "pattern:checkerboard",
6538 (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",(double)
6539 image->columns,(double) image->rows);
6540 image_info->size=ConstantString(size);
6541 pattern=ReadImage(image_info,exception);
6542 image_info=DestroyImageInfo(image_info);
6543 if (pattern != (Image *) NULL)
6545 canvas=CloneImage(image,0,0,MagickTrue,exception);
6546 if (canvas != (Image *) NULL)
6547 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6549 pattern=DestroyImage(pattern);
6552 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
6553 ximage->bits_per_pixel) >> 3));
6554 map_info=window->map_info;
6555 pixels=window->pixel_info->pixels;
6556 q=(unsigned char *) ximage->data;
6558 canvas_view=AcquireVirtualCacheView(canvas,exception);
6559 if (ximage->format == XYBitmap)
6561 register unsigned short
6569 Convert canvas to big-endian bitmap.
6571 background=(unsigned char)
6572 (XPixelIntensity(&window->pixel_info->foreground_color) <
6573 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6574 foreground=(unsigned char)
6575 (XPixelIntensity(&window->pixel_info->background_color) <
6576 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6577 polarity=(unsigned short) ((GetPixelInfoIntensity(image,
6578 &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
6579 if (canvas->colors == 2)
6580 polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
6581 GetPixelInfoIntensity(image,&canvas->colormap[1]);
6582 for (y=0; y < (int) canvas->rows; y++)
6584 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6586 if (p == (const Quantum *) NULL)
6590 for (x=(int) canvas->columns-1; x >= 0; x--)
6593 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6604 p+=GetPixelChannels(canvas);
6612 if (window->pixel_info->colors != 0)
6613 switch (ximage->bits_per_pixel)
6617 register unsigned int
6621 Convert to 2 bit color-mapped X canvas.
6623 for (y=0; y < (int) canvas->rows; y++)
6625 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6626 canvas->columns,1,exception);
6627 if (p == (const Quantum *) NULL)
6630 for (x=0; x < (int) canvas->columns; x++)
6632 pixel=pixels[(ssize_t)
6633 GetPixelIndex(canvas,p)] & 0xf;
6638 *q=(unsigned char) (pixel << 6);
6644 *q|=(unsigned char) (pixel << 4);
6650 *q|=(unsigned char) (pixel << 2);
6656 *q|=(unsigned char) pixel;
6662 p+=GetPixelChannels(canvas);
6670 register unsigned int
6674 Convert to 4 bit color-mapped X canvas.
6676 for (y=0; y < (int) canvas->rows; y++)
6678 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6679 canvas->columns,1,exception);
6680 if (p == (const Quantum *) NULL)
6683 for (x=0; x < (int) canvas->columns; x++)
6685 pixel=pixels[(ssize_t)
6686 GetPixelIndex(canvas,p)] & 0xf;
6691 *q=(unsigned char) (pixel << 4);
6697 *q|=(unsigned char) pixel;
6703 p+=GetPixelChannels(canvas);
6713 Convert to 8 bit color-mapped X canvas.
6715 if (resource_info->color_recovery &&
6716 resource_info->quantize_info->dither_method != NoDitherMethod)
6718 XDitherImage(canvas,ximage,exception);
6721 for (y=0; y < (int) canvas->rows; y++)
6723 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6724 canvas->columns,1,exception);
6725 if (p == (const Quantum *) NULL)
6727 for (x=0; x < (int) canvas->columns; x++)
6729 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6730 *q++=(unsigned char) pixel;
6731 p+=GetPixelChannels(canvas);
6742 register unsigned int
6746 channel[sizeof(size_t)];
6749 Convert to 8 bit color-mapped X canvas.
6751 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6752 for (y=0; y < (int) canvas->rows; y++)
6754 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6755 canvas->columns,1,exception);
6756 if (p == (const Quantum *) NULL)
6758 for (x=0; x < (int) canvas->columns; x++)
6760 pixel=pixels[(ssize_t)
6761 GetPixelIndex(canvas,p)];
6762 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6764 channel[k]=(unsigned char) pixel;
6767 for (k=0; k < (int) bytes_per_pixel; k++)
6769 p+=GetPixelChannels(canvas);
6777 switch (ximage->bits_per_pixel)
6781 register unsigned int
6785 Convert to 4 bit continuous-tone X canvas.
6787 for (y=0; y < (int) canvas->rows; y++)
6789 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6790 canvas->columns,1,exception);
6791 if (p == (const Quantum *) NULL)
6794 for (x=(int) canvas->columns-1; x >= 0; x--)
6796 pixel=XGammaPixel(canvas,map_info,p);
6802 *q=(unsigned char) (pixel << 6);
6808 *q|=(unsigned char) (pixel << 4);
6814 *q|=(unsigned char) (pixel << 2);
6820 *q|=(unsigned char) pixel;
6826 p+=GetPixelChannels(canvas);
6834 register unsigned int
6838 Convert to 4 bit continuous-tone X canvas.
6840 for (y=0; y < (int) canvas->rows; y++)
6842 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6843 canvas->columns,1,exception);
6844 if (p == (const Quantum *) NULL)
6847 for (x=(int) canvas->columns-1; x >= 0; x--)
6849 pixel=XGammaPixel(canvas,map_info,p);
6855 *q=(unsigned char) (pixel << 4);
6861 *q|=(unsigned char) pixel;
6867 p+=GetPixelChannels(canvas);
6877 Convert to 8 bit continuous-tone X canvas.
6879 if (resource_info->color_recovery &&
6880 resource_info->quantize_info->dither_method != NoDitherMethod)
6882 XDitherImage(canvas,ximage,exception);
6885 for (y=0; y < (int) canvas->rows; y++)
6887 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6888 canvas->columns,1,exception);
6889 if (p == (const Quantum *) NULL)
6891 for (x=(int) canvas->columns-1; x >= 0; x--)
6893 pixel=XGammaPixel(canvas,map_info,p);
6894 *q++=(unsigned char) pixel;
6895 p+=GetPixelChannels(canvas);
6903 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6904 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6905 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6906 (map_info->blue_mult == 1))
6909 Convert to 32 bit continuous-tone X canvas.
6911 for (y=0; y < (int) canvas->rows; y++)
6913 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6914 canvas->columns,1,exception);
6915 if (p == (const Quantum *) NULL)
6917 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6918 (blue_gamma != 1.0))
6921 Gamma correct canvas.
6923 for (x=(int) canvas->columns-1; x >= 0; x--)
6926 *q++=ScaleQuantumToChar(XRedGamma(
6927 GetPixelRed(canvas,p)));
6928 *q++=ScaleQuantumToChar(XGreenGamma(
6929 GetPixelGreen(canvas,p)));
6930 *q++=ScaleQuantumToChar(XBlueGamma(
6931 GetPixelBlue(canvas,p)));
6932 p+=GetPixelChannels(canvas);
6936 for (x=(int) canvas->columns-1; x >= 0; x--)
6939 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6940 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6941 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6942 p+=GetPixelChannels(canvas);
6947 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6948 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6949 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6950 (map_info->blue_mult == 65536L))
6953 Convert to 32 bit continuous-tone X canvas.
6955 for (y=0; y < (int) canvas->rows; y++)
6957 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6958 canvas->columns,1,exception);
6959 if (p == (const Quantum *) NULL)
6961 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6962 (blue_gamma != 1.0))
6965 Gamma correct canvas.
6967 for (x=(int) canvas->columns-1; x >= 0; x--)
6970 *q++=ScaleQuantumToChar(XBlueGamma(
6971 GetPixelBlue(canvas,p)));
6972 *q++=ScaleQuantumToChar(XGreenGamma(
6973 GetPixelGreen(canvas,p)));
6974 *q++=ScaleQuantumToChar(XRedGamma(
6975 GetPixelRed(canvas,p)));
6976 p+=GetPixelChannels(canvas);
6980 for (x=(int) canvas->columns-1; x >= 0; x--)
6983 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6984 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6985 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6986 p+=GetPixelChannels(canvas);
6995 register unsigned int
6999 channel[sizeof(size_t)];
7002 Convert to multi-byte continuous-tone X canvas.
7004 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
7005 for (y=0; y < (int) canvas->rows; y++)
7007 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7008 canvas->columns,1,exception);
7009 if (p == (const Quantum *) NULL)
7011 for (x=(int) canvas->columns-1; x >= 0; x--)
7013 pixel=XGammaPixel(canvas,map_info,p);
7014 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
7016 channel[k]=(unsigned char) pixel;
7019 for (k=0; k < (int) bytes_per_pixel; k++)
7021 p+=GetPixelChannels(canvas);
7029 if (matte_image != (XImage *) NULL)
7032 Initialize matte canvas.
7034 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7035 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7036 q=(unsigned char *) matte_image->data;
7037 for (y=0; y < (int) canvas->rows; y++)
7039 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7041 if (p == (const Quantum *) NULL)
7045 for (x=(int) canvas->columns-1; x >= 0; x--)
7048 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7057 p+=GetPixelChannels(canvas);
7064 canvas_view=DestroyCacheView(canvas_view);
7065 if (canvas != image)
7066 canvas=DestroyImage(canvas);
7070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7074 % X M a k e M a g n i f y I m a g e %
7078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7080 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7082 % The format of the XMakeMagnifyImage method is:
7084 % void XMakeMagnifyImage(Display *display,XWindows *windows,
7085 % ExceptionInfo *exception)
7087 % A description of each parameter follows:
7089 % o display: Specifies a connection to an X server; returned from
7092 % o windows: Specifies a pointer to a XWindows structure.
7094 % o exception: return any errors or warnings in this structure.
7097 MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
7098 ExceptionInfo *exception)
7101 tuple[MagickPathExtent];
7115 register unsigned char
7123 previous_magnify = 0;
7141 Check boundary conditions.
7143 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7144 assert(display != (Display *) NULL);
7145 assert(windows != (XWindows *) NULL);
7147 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7149 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7151 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7153 while (magnify > windows->magnify.width)
7155 while (magnify > windows->magnify.height)
7159 if (magnify != previous_magnify)
7168 New magnify factor: update magnify window name.
7171 while ((1 << i) <= (int) magnify)
7173 (void) FormatLocaleString(windows->magnify.name,MagickPathExtent,
7174 "Magnify %.20gX",(double) i);
7175 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7176 if (status != False)
7178 XSetWMName(display,windows->magnify.id,&window_name);
7179 XSetWMIconName(display,windows->magnify.id,&window_name);
7180 (void) XFree((void *) window_name.value);
7183 previous_magnify=magnify;
7184 ximage=windows->image.ximage;
7185 width=(unsigned int) windows->magnify.ximage->width;
7186 height=(unsigned int) windows->magnify.ximage->height;
7187 if ((windows->magnify.x < 0) ||
7188 (windows->magnify.x >= windows->image.ximage->width))
7189 windows->magnify.x=windows->image.ximage->width >> 1;
7190 x=windows->magnify.x-((width/magnify) >> 1);
7194 if (x > (int) (ximage->width-(width/magnify)))
7195 x=ximage->width-width/magnify;
7196 if ((windows->magnify.y < 0) ||
7197 (windows->magnify.y >= windows->image.ximage->height))
7198 windows->magnify.y=windows->image.ximage->height >> 1;
7199 y=windows->magnify.y-((height/magnify) >> 1);
7203 if (y > (int) (ximage->height-(height/magnify)))
7204 y=ximage->height-height/magnify;
7205 q=(unsigned char *) windows->magnify.ximage->data;
7206 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7207 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7208 if (ximage->bits_per_pixel < 8)
7210 register unsigned char
7217 register unsigned int
7223 pixel_info=windows->magnify.pixel_info;
7224 switch (ximage->bitmap_bit_order)
7229 Magnify little-endian bitmap.
7233 if (ximage->format == XYBitmap)
7235 background=(unsigned char)
7236 (XPixelIntensity(&pixel_info->foreground_color) <
7237 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7238 foreground=(unsigned char)
7239 (XPixelIntensity(&pixel_info->background_color) <
7240 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7241 if (windows->magnify.depth > 1)
7242 Swap(background,foreground);
7244 for (i=0; i < (ssize_t) height; i+=magnify)
7247 Propogate pixel magnify rows.
7249 for (j=0; j < magnify; j++)
7251 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7252 ((x*ximage->bits_per_pixel) >> 3);
7253 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7256 for (k=0; k < width; k+=magnify)
7259 Propogate pixel magnify columns.
7261 for (l=0; l < magnify; l++)
7264 Propogate each bit plane.
7266 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7269 if (*p & (0x01 << (p_bit+plane)))
7282 p_bit+=ximage->bits_per_pixel;
7289 *q=byte >> (8-q_bit);
7301 Magnify big-endian bitmap.
7305 if (ximage->format == XYBitmap)
7307 background=(unsigned char)
7308 (XPixelIntensity(&pixel_info->foreground_color) <
7309 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7310 foreground=(unsigned char)
7311 (XPixelIntensity(&pixel_info->background_color) <
7312 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7313 if (windows->magnify.depth > 1)
7314 Swap(background,foreground);
7316 for (i=0; i < (ssize_t) height; i+=magnify)
7319 Propogate pixel magnify rows.
7321 for (j=0; j < magnify; j++)
7323 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7324 ((x*ximage->bits_per_pixel) >> 3);
7325 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7328 for (k=0; k < width; k+=magnify)
7331 Propogate pixel magnify columns.
7333 for (l=0; l < magnify; l++)
7336 Propogate each bit plane.
7338 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7341 if (*p & (0x80 >> (p_bit+plane)))
7354 p_bit+=ximage->bits_per_pixel;
7361 *q=byte << (8-q_bit);
7372 switch (ximage->bits_per_pixel)
7378 Magnify 8 bit X image.
7380 for (i=0; i < (ssize_t) height; i+=magnify)
7383 Propogate pixel magnify rows.
7385 for (j=0; j < magnify; j++)
7387 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7388 ((x*ximage->bits_per_pixel) >> 3);
7389 for (k=0; k < width; k+=magnify)
7392 Propogate pixel magnify columns.
7394 for (l=0; l < magnify; l++)
7406 register unsigned int
7411 Magnify multi-byte X image.
7413 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7414 for (i=0; i < (ssize_t) height; i+=magnify)
7417 Propogate pixel magnify rows.
7419 for (j=0; j < magnify; j++)
7421 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7422 ((x*ximage->bits_per_pixel) >> 3);
7423 for (k=0; k < width; k+=magnify)
7426 Propogate pixel magnify columns.
7428 for (l=0; l < magnify; l++)
7429 for (m=0; m < bytes_per_pixel; m++)
7441 Copy X image to magnify pixmap.
7443 x=windows->magnify.x-((width/magnify) >> 1);
7445 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7447 if (x > (int) (ximage->width-(width/magnify)))
7448 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7451 y=windows->magnify.y-((height/magnify) >> 1);
7453 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7455 if (y > (int) (ximage->height-(height/magnify)))
7456 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7459 if ((x != 0) || (y != 0))
7460 (void) XFillRectangle(display,windows->magnify.pixmap,
7461 windows->magnify.annotate_context,0,0,width,height);
7462 (void) XPutImage(display,windows->magnify.pixmap,
7463 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7465 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7466 (magnify <= (height >> 1))))
7472 Highlight center pixel.
7474 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7475 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7476 highlight_info.width=magnify;
7477 highlight_info.height=magnify;
7478 (void) XDrawRectangle(display,windows->magnify.pixmap,
7479 windows->magnify.highlight_context,(int) highlight_info.x,
7480 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7481 (unsigned int) highlight_info.height-1);
7483 (void) XDrawRectangle(display,windows->magnify.pixmap,
7484 windows->magnify.annotate_context,(int) highlight_info.x+1,
7485 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7486 (unsigned int) highlight_info.height-3);
7489 Show center pixel color.
7491 (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
7492 (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7493 (void) FormatLocaleString(tuple,MagickPathExtent,"%d,%d: ",
7494 windows->magnify.x,windows->magnify.y);
7495 (void) ConcatenateMagickString(tuple,"(",MagickPathExtent);
7496 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7497 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7498 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7499 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7500 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7501 if (pixel.colorspace == CMYKColorspace)
7503 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7504 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7506 if (pixel.alpha_trait != UndefinedPixelTrait)
7508 (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7509 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7511 (void) ConcatenateMagickString(tuple,")",MagickPathExtent);
7512 height=(unsigned int) windows->magnify.font_info->ascent+
7513 windows->magnify.font_info->descent;
7514 x=windows->magnify.font_info->max_bounds.width >> 1;
7515 y=windows->magnify.font_info->ascent+(height >> 2);
7516 (void) XDrawImageString(display,windows->magnify.pixmap,
7517 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7518 GetColorTuple(&pixel,MagickTrue,tuple);
7520 (void) XDrawImageString(display,windows->magnify.pixmap,
7521 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7522 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7525 (void) XDrawImageString(display,windows->magnify.pixmap,
7526 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7528 Refresh magnify window.
7530 magnify_window=windows->magnify;
7533 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7541 % X M a k e P i x m a p %
7545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7547 % XMakePixmap() creates an X11 pixmap.
7549 % The format of the XMakePixmap method is:
7551 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7552 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7553 % XPixelInfo *pixel)
7555 % A description of each parameter follows:
7557 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7559 % o display: Specifies a connection to an X server; returned from
7562 % o window: Specifies a pointer to a XWindowInfo structure.
7565 static MagickBooleanType XMakePixmap(Display *display,
7566 const XResourceInfo *resource_info,XWindowInfo *window)
7572 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7573 assert(display != (Display *) NULL);
7574 assert(resource_info != (XResourceInfo *) NULL);
7575 assert(window != (XWindowInfo *) NULL);
7576 if (window->pixmap != (Pixmap) NULL)
7579 Destroy previous X pixmap.
7581 (void) XFreePixmap(display,window->pixmap);
7582 window->pixmap=(Pixmap) NULL;
7584 if (window->use_pixmap == MagickFalse)
7585 return(MagickFalse);
7586 if (window->ximage == (XImage *) NULL)
7587 return(MagickFalse);
7589 Display busy cursor.
7591 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7592 (void) XFlush(display);
7596 width=(unsigned int) window->ximage->width;
7597 height=(unsigned int) window->ximage->height;
7598 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7599 if (window->pixmap == (Pixmap) NULL)
7602 Unable to allocate pixmap.
7604 (void) XCheckDefineCursor(display,window->id,window->cursor);
7605 return(MagickFalse);
7608 Copy X image to pixmap.
7610 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7611 if (window->shared_memory)
7612 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7613 window->ximage,0,0,0,0,width,height,MagickTrue);
7615 if (window->shared_memory == MagickFalse)
7616 (void) XPutImage(display,window->pixmap,window->annotate_context,
7617 window->ximage,0,0,0,0,width,height);
7618 if (IsEventLogging())
7620 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7621 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7627 (void) XCheckDefineCursor(display,window->id,window->cursor);
7632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7636 % X M a k e S t a n d a r d C o l o r m a p %
7640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7642 % XMakeStandardColormap() creates an X11 Standard Colormap.
7644 % The format of the XMakeStandardColormap method is:
7646 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7647 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7648 % XPixelInfo *pixel,ExceptionInfo *exception)
7650 % A description of each parameter follows:
7652 % o display: Specifies a connection to an X server; returned from
7655 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7656 % returned from XGetVisualInfo.
7658 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7660 % o image: the image.
7662 % o map_info: If a Standard Colormap type is specified, this structure is
7663 % initialized with info from the Standard Colormap.
7665 % o pixel: Specifies a pointer to a XPixelInfo structure.
7667 % o exception: return any errors or warnings in this structure.
7671 #if defined(__cplusplus) || defined(c_plusplus)
7675 static inline double DiversityPixelIntensity(
7676 const DiversityPacket *pixel)
7681 intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
7685 static int IntensityCompare(const void *x,const void *y)
7694 color_1=(DiversityPacket *) x;
7695 color_2=(DiversityPacket *) y;
7696 diversity=(int) (DiversityPixelIntensity(color_2)-
7697 DiversityPixelIntensity(color_1));
7701 static int PopularityCompare(const void *x,const void *y)
7707 color_1=(DiversityPacket *) x;
7708 color_2=(DiversityPacket *) y;
7709 return((int) color_2->count-(int) color_1->count);
7712 #if defined(__cplusplus) || defined(c_plusplus)
7716 static inline Quantum ScaleXToQuantum(const size_t x,
7719 return((Quantum) (((double) QuantumRange*x)/scale+0.5));
7722 MagickPrivate void XMakeStandardColormap(Display *display,
7723 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7724 XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
7747 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7748 assert(display != (Display *) NULL);
7749 assert(visual_info != (XVisualInfo *) NULL);
7750 assert(map_info != (XStandardColormap *) NULL);
7751 assert(resource_info != (XResourceInfo *) NULL);
7752 assert(pixel != (XPixelInfo *) NULL);
7753 if (resource_info->map_type != (char *) NULL)
7756 Standard Colormap is already defined (i.e. xstdcmap).
7758 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7760 number_colors=(unsigned int) (map_info->base_pixel+
7761 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7762 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7763 if ((image->alpha_trait == UndefinedPixelTrait) &&
7764 (resource_info->color_recovery == MagickFalse) &&
7765 (resource_info->quantize_info->dither_method != NoDitherMethod) &&
7766 (number_colors < MaxColormapSize))
7775 Improve image appearance with error diffusion.
7777 affinity_image=AcquireImage((ImageInfo *) NULL,exception);
7778 if (affinity_image == (Image *) NULL)
7779 ThrowXWindowFatalException(ResourceLimitFatalError,
7780 "UnableToDitherImage",image->filename);
7781 affinity_image->columns=number_colors;
7782 affinity_image->rows=1;
7784 Initialize colormap image.
7786 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7788 if (q != (Quantum *) NULL)
7790 for (i=0; i < (ssize_t) number_colors; i++)
7792 SetPixelRed(affinity_image,0,q);
7793 if (map_info->red_max != 0)
7794 SetPixelRed(affinity_image,ScaleXToQuantum((size_t)
7795 (i/map_info->red_mult),map_info->red_max),q);
7796 SetPixelGreen(affinity_image,0,q);
7797 if (map_info->green_max != 0)
7798 SetPixelGreen(affinity_image,ScaleXToQuantum((size_t)
7799 ((i/map_info->green_mult) % (map_info->green_max+1)),
7800 map_info->green_max),q);
7801 SetPixelBlue(affinity_image,0,q);
7802 if (map_info->blue_max != 0)
7803 SetPixelBlue(affinity_image,ScaleXToQuantum((size_t)
7804 (i % map_info->green_mult),map_info->blue_max),q);
7805 SetPixelAlpha(affinity_image,
7806 TransparentAlpha,q);
7807 q+=GetPixelChannels(affinity_image);
7809 (void) SyncAuthenticPixels(affinity_image,exception);
7810 (void) RemapImage(resource_info->quantize_info,image,
7811 affinity_image,exception);
7813 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7815 (void) SetImageStorageClass(image,DirectClass,exception);
7816 affinity_image=DestroyImage(affinity_image);
7818 if (IsEventLogging())
7820 (void) LogMagickEvent(X11Event,GetMagickModule(),
7821 "Standard Colormap:");
7822 (void) LogMagickEvent(X11Event,GetMagickModule(),
7823 " colormap id: 0x%lx",map_info->colormap);
7824 (void) LogMagickEvent(X11Event,GetMagickModule(),
7825 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7826 map_info->green_max,map_info->blue_max);
7827 (void) LogMagickEvent(X11Event,GetMagickModule(),
7828 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7829 map_info->green_mult,map_info->blue_mult);
7833 if ((visual_info->klass != DirectColor) &&
7834 (visual_info->klass != TrueColor))
7835 if ((image->storage_class == DirectClass) ||
7836 ((int) image->colors > visual_info->colormap_size))
7842 Image has more colors than the visual supports.
7844 quantize_info=(*resource_info->quantize_info);
7845 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7846 (void) QuantizeImage(&quantize_info,image,exception);
7849 Free previous and create new colormap.
7851 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7852 colormap=XDefaultColormap(display,visual_info->screen);
7853 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7854 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7855 visual_info->visual,visual_info->klass == DirectColor ?
7856 AllocAll : AllocNone);
7857 if (colormap == (Colormap) NULL)
7858 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7861 Initialize the map and pixel info structures.
7863 XGetMapInfo(visual_info,colormap,map_info);
7864 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7866 Allocating colors in server colormap is based on visual class.
7868 switch (visual_info->klass)
7874 Define Standard Colormap for StaticGray or StaticColor visual.
7876 number_colors=image->colors;
7877 colors=(XColor *) AcquireQuantumMemory((size_t)
7878 visual_info->colormap_size,sizeof(*colors));
7879 if (colors == (XColor *) NULL)
7880 ThrowXWindowFatalException(ResourceLimitFatalError,
7881 "UnableToCreateColormap",image->filename);
7883 color.flags=(char) (DoRed | DoGreen | DoBlue);
7884 for (i=0; i < (ssize_t) image->colors; i++)
7886 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7887 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7888 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7889 if (visual_info->klass != StaticColor)
7891 gray_value=(unsigned short) XPixelIntensity(&color);
7892 color.red=gray_value;
7893 color.green=gray_value;
7894 color.blue=gray_value;
7896 status=XAllocColor(display,colormap,&color);
7897 if (status == False)
7899 colormap=XCopyColormapAndFree(display,colormap);
7900 (void) XAllocColor(display,colormap,&color);
7902 pixel->pixels[i]=color.pixel;
7914 Define Standard Colormap for GrayScale or PseudoColor visual.
7916 number_colors=image->colors;
7917 colors=(XColor *) AcquireQuantumMemory((size_t)
7918 visual_info->colormap_size,sizeof(*colors));
7919 if (colors == (XColor *) NULL)
7920 ThrowXWindowFatalException(ResourceLimitFatalError,
7921 "UnableToCreateColormap",image->filename);
7923 Preallocate our GUI colors.
7925 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7926 (void) XAllocColor(display,colormap,&pixel->background_color);
7927 (void) XAllocColor(display,colormap,&pixel->border_color);
7928 (void) XAllocColor(display,colormap,&pixel->matte_color);
7929 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7930 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7931 (void) XAllocColor(display,colormap,&pixel->depth_color);
7932 (void) XAllocColor(display,colormap,&pixel->trough_color);
7933 for (i=0; i < MaxNumberPens; i++)
7934 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7936 Determine if image colors will "fit" into X server colormap.
7938 colormap_type=resource_info->colormap;
7939 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7940 NULL,0,pixel->pixels,(unsigned int) image->colors);
7941 if (status != False)
7942 colormap_type=PrivateColormap;
7943 if (colormap_type == SharedColormap)
7964 Define Standard colormap for shared GrayScale or PseudoColor visual.
7966 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7967 sizeof(*diversity));
7968 if (diversity == (DiversityPacket *) NULL)
7969 ThrowXWindowFatalException(ResourceLimitFatalError,
7970 "UnableToCreateColormap",image->filename);
7971 for (i=0; i < (ssize_t) image->colors; i++)
7973 diversity[i].red=ClampToQuantum(image->colormap[i].red);
7974 diversity[i].green=ClampToQuantum(image->colormap[i].green);
7975 diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
7976 diversity[i].index=(unsigned short) i;
7977 diversity[i].count=0;
7979 image_view=AcquireAuthenticCacheView(image,exception);
7980 for (y=0; y < (int) image->rows; y++)
7985 register const Quantum
7988 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7989 image->columns,1,exception);
7990 if (p == (const Quantum *) NULL)
7992 for (x=(int) image->columns-1; x >= 0; x--)
7994 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
7995 p+=GetPixelChannels(image);
7998 image_view=DestroyCacheView(image_view);
8000 Sort colors by decreasing intensity.
8002 qsort((void *) diversity,image->colors,sizeof(*diversity),
8004 for (i=0; i < (ssize_t) image->colors; )
8006 diversity[i].count<<=4; /* increase this colors popularity */
8007 i+=MagickMax((int) (image->colors >> 4),2);
8009 diversity[image->colors-1].count<<=4;
8010 qsort((void *) diversity,image->colors,sizeof(*diversity),
8016 color.flags=(char) (DoRed | DoGreen | DoBlue);
8017 for (i=0; i < (ssize_t) image->colors; i++)
8019 index=diversity[i].index;
8021 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8023 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8025 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8026 if (visual_info->klass != PseudoColor)
8028 gray_value=(unsigned short) XPixelIntensity(&color);
8029 color.red=gray_value;
8030 color.green=gray_value;
8031 color.blue=gray_value;
8033 status=XAllocColor(display,colormap,&color);
8034 if (status == False)
8036 pixel->pixels[index]=color.pixel;
8040 Read X server colormap.
8042 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8043 visual_info->colormap_size,sizeof(*server_colors));
8044 if (server_colors == (XColor *) NULL)
8045 ThrowXWindowFatalException(ResourceLimitFatalError,
8046 "UnableToCreateColormap",image->filename);
8047 for (x=visual_info->colormap_size-1; x >= 0; x--)
8048 server_colors[x].pixel=(size_t) x;
8049 (void) XQueryColors(display,colormap,server_colors,
8050 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8052 Select remaining colors from X server colormap.
8054 for (; i < (ssize_t) image->colors; i++)
8056 index=diversity[i].index;
8057 color.red=ScaleQuantumToShort(
8058 XRedGamma(image->colormap[index].red));
8059 color.green=ScaleQuantumToShort(
8060 XGreenGamma(image->colormap[index].green));
8061 color.blue=ScaleQuantumToShort(
8062 XBlueGamma(image->colormap[index].blue));
8063 if (visual_info->klass != PseudoColor)
8065 gray_value=(unsigned short) XPixelIntensity(&color);
8066 color.red=gray_value;
8067 color.green=gray_value;
8068 color.blue=gray_value;
8070 XBestPixel(display,colormap,server_colors,(unsigned int)
8071 visual_info->colormap_size,&color);
8072 pixel->pixels[index]=color.pixel;
8075 if ((int) image->colors < visual_info->colormap_size)
8078 Fill up colors array-- more choices for pen colors.
8080 retain_colors=MagickMin((unsigned int)
8081 (visual_info->colormap_size-image->colors),256);
8082 for (i=0; i < (ssize_t) retain_colors; i++)
8083 *p++=server_colors[i];
8084 number_colors+=retain_colors;
8086 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8087 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8091 Define Standard colormap for private GrayScale or PseudoColor visual.
8093 if (status == False)
8096 Not enough colormap entries in the colormap-- Create a new colormap.
8098 colormap=XCreateColormap(display,
8099 XRootWindow(display,visual_info->screen),visual_info->visual,
8101 if (colormap == (Colormap) NULL)
8102 ThrowXWindowFatalException(ResourceLimitFatalError,
8103 "UnableToCreateColormap",image->filename);
8104 map_info->colormap=colormap;
8105 if ((int) image->colors < visual_info->colormap_size)
8108 Retain colors from the default colormap to help lessens the
8109 effects of colormap flashing.
8111 retain_colors=MagickMin((unsigned int)
8112 (visual_info->colormap_size-image->colors),256);
8113 p=colors+image->colors;
8114 for (i=0; i < (ssize_t) retain_colors; i++)
8116 p->pixel=(unsigned long) i;
8119 (void) XQueryColors(display,
8120 XDefaultColormap(display,visual_info->screen),
8121 colors+image->colors,(int) retain_colors);
8123 Transfer colors from default to private colormap.
8125 (void) XAllocColorCells(display,colormap,MagickFalse,
8126 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8128 p=colors+image->colors;
8129 for (i=0; i < (ssize_t) retain_colors; i++)
8131 p->pixel=pixel->pixels[i];
8134 (void) XStoreColors(display,colormap,colors+image->colors,
8135 (int) retain_colors);
8136 number_colors+=retain_colors;
8138 (void) XAllocColorCells(display,colormap,MagickFalse,
8139 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8143 Store the image colormap.
8146 color.flags=(char) (DoRed | DoGreen | DoBlue);
8147 for (i=0; i < (ssize_t) image->colors; i++)
8149 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8150 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8151 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8152 if (visual_info->klass != PseudoColor)
8154 gray_value=(unsigned short) XPixelIntensity(&color);
8155 color.red=gray_value;
8156 color.green=gray_value;
8157 color.blue=gray_value;
8159 color.pixel=pixel->pixels[i];
8162 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8173 Define Standard Colormap for TrueColor or DirectColor visual.
8175 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8176 (map_info->green_max*map_info->green_mult)+
8177 (map_info->blue_max*map_info->blue_mult)+1);
8178 linear_colormap=(number_colors > 4096) ||
8179 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8180 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8181 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8182 MagickTrue : MagickFalse;
8183 if (linear_colormap != MagickFalse)
8184 number_colors=(size_t) visual_info->colormap_size;
8186 Allocate color array.
8188 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8189 if (colors == (XColor *) NULL)
8190 ThrowXWindowFatalException(ResourceLimitFatalError,
8191 "UnableToCreateColormap",image->filename);
8193 Initialize linear color ramp.
8196 color.flags=(char) (DoRed | DoGreen | DoBlue);
8197 if (linear_colormap != MagickFalse)
8198 for (i=0; i < (ssize_t) number_colors; i++)
8200 color.blue=(unsigned short) 0;
8201 if (map_info->blue_max != 0)
8202 color.blue=(unsigned short) ((size_t)
8203 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8204 color.green=color.blue;
8205 color.red=color.blue;
8206 color.pixel=XStandardPixel(map_info,&color);
8210 for (i=0; i < (ssize_t) number_colors; i++)
8212 color.red=(unsigned short) 0;
8213 if (map_info->red_max != 0)
8214 color.red=(unsigned short) ((size_t)
8215 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8216 color.green=(unsigned int) 0;
8217 if (map_info->green_max != 0)
8218 color.green=(unsigned short) ((size_t)
8219 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8220 map_info->green_max));
8221 color.blue=(unsigned short) 0;
8222 if (map_info->blue_max != 0)
8223 color.blue=(unsigned short) ((size_t)
8224 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8225 color.pixel=XStandardPixel(map_info,&color);
8228 if ((visual_info->klass == DirectColor) &&
8229 (colormap != XDefaultColormap(display,visual_info->screen)))
8230 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8232 for (i=0; i < (ssize_t) number_colors; i++)
8233 (void) XAllocColor(display,colormap,&colors[i]);
8237 if ((visual_info->klass != DirectColor) &&
8238 (visual_info->klass != TrueColor))
8241 Set foreground, background, border, etc. pixels.
8243 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8244 &pixel->foreground_color);
8245 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8246 &pixel->background_color);
8247 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8250 Foreground and background colors must differ.
8252 pixel->background_color.red=(~pixel->foreground_color.red);
8253 pixel->background_color.green=
8254 (~pixel->foreground_color.green);
8255 pixel->background_color.blue=
8256 (~pixel->foreground_color.blue);
8257 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8258 &pixel->background_color);
8260 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8261 &pixel->border_color);
8262 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8263 &pixel->matte_color);
8264 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8265 &pixel->highlight_color);
8266 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8267 &pixel->shadow_color);
8268 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8269 &pixel->depth_color);
8270 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8271 &pixel->trough_color);
8272 for (i=0; i < MaxNumberPens; i++)
8274 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8275 &pixel->pen_colors[i]);
8276 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8278 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8280 colors=(XColor *) RelinquishMagickMemory(colors);
8281 if (IsEventLogging())
8283 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8284 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8285 map_info->colormap);
8286 (void) LogMagickEvent(X11Event,GetMagickModule(),
8287 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8288 map_info->green_max,map_info->blue_max);
8289 (void) LogMagickEvent(X11Event,GetMagickModule(),
8290 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8291 map_info->green_mult,map_info->blue_mult);
8296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8300 % X M a k e W i n d o w %
8304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8306 % XMakeWindow() creates an X11 window.
8308 % The format of the XMakeWindow method is:
8310 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8311 % XClassHint *class_hint,XWMHints *manager_hints,
8312 % XWindowInfo *window_info)
8314 % A description of each parameter follows:
8316 % o display: Specifies a connection to an X server; returned from
8319 % o parent: Specifies the parent window_info.
8321 % o argv: Specifies the application's argument list.
8323 % o argc: Specifies the number of arguments.
8325 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8327 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8329 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8332 MagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
8333 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8334 XWindowInfo *window_info)
8336 #define MinWindowSize 64
8344 static XTextProperty
8355 Set window info hints.
8357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8358 assert(display != (Display *) NULL);
8359 assert(window_info != (XWindowInfo *) NULL);
8360 size_hints=XAllocSizeHints();
8361 if (size_hints == (XSizeHints *) NULL)
8362 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8363 size_hints->flags=(int) window_info->flags;
8364 size_hints->x=window_info->x;
8365 size_hints->y=window_info->y;
8366 size_hints->width=(int) window_info->width;
8367 size_hints->height=(int) window_info->height;
8368 if (window_info->immutable != MagickFalse)
8371 Window size cannot be changed.
8373 size_hints->min_width=size_hints->width;
8374 size_hints->min_height=size_hints->height;
8375 size_hints->max_width=size_hints->width;
8376 size_hints->max_height=size_hints->height;
8377 size_hints->flags|=PMinSize;
8378 size_hints->flags|=PMaxSize;
8383 Window size can be changed.
8385 size_hints->min_width=(int) window_info->min_width;
8386 size_hints->min_height=(int) window_info->min_height;
8387 size_hints->flags|=PResizeInc;
8388 size_hints->width_inc=(int) window_info->width_inc;
8389 size_hints->height_inc=(int) window_info->height_inc;
8390 #if !defined(PRE_R4_ICCCM)
8391 size_hints->flags|=PBaseSize;
8392 size_hints->base_width=size_hints->width_inc;
8393 size_hints->base_height=size_hints->height_inc;
8396 gravity=NorthWestGravity;
8397 if (window_info->geometry != (char *) NULL)
8400 default_geometry[MagickPathExtent],
8401 geometry[MagickPathExtent];
8410 User specified geometry.
8412 (void) FormatLocaleString(default_geometry,MagickPathExtent,"%dx%d",
8413 size_hints->width,size_hints->height);
8414 (void) CopyMagickString(geometry,window_info->geometry,MagickPathExtent);
8416 while (strlen(p) != 0)
8418 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8421 (void) memmove(p,p+1,MagickPathExtent-(p-geometry));
8423 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8424 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8425 &size_hints->width,&size_hints->height,&gravity);
8426 if ((flags & WidthValue) && (flags & HeightValue))
8427 size_hints->flags|=USSize;
8428 if ((flags & XValue) && (flags & YValue))
8430 size_hints->flags|=USPosition;
8431 window_info->x=size_hints->x;
8432 window_info->y=size_hints->y;
8435 #if !defined(PRE_R4_ICCCM)
8436 size_hints->win_gravity=gravity;
8437 size_hints->flags|=PWinGravity;
8439 if (window_info->id == (Window) NULL)
8440 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8441 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8442 window_info->border_width,(int) window_info->depth,InputOutput,
8443 window_info->visual,(unsigned long) window_info->mask,
8444 &window_info->attributes);
8457 Window already exists; change relevant attributes.
8459 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8460 window_info->mask,&window_info->attributes);
8461 mask=ConfigureNotify;
8462 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8463 window_changes.x=window_info->x;
8464 window_changes.y=window_info->y;
8465 window_changes.width=(int) window_info->width;
8466 window_changes.height=(int) window_info->height;
8467 mask=(MagickStatusType) (CWWidth | CWHeight);
8468 if (window_info->flags & USPosition)
8470 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8471 mask,&window_changes);
8473 if (window_info->id == (Window) NULL)
8474 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8476 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8477 if (status == False)
8478 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8480 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8481 if (status == False)
8482 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8483 window_info->icon_name);
8484 if (window_info->icon_geometry != (char *) NULL)
8492 User specified icon geometry.
8494 size_hints->flags|=USPosition;
8495 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8496 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8497 &manager_hints->icon_y,&width,&height,&gravity);
8498 if ((flags & XValue) && (flags & YValue))
8499 manager_hints->flags|=IconPositionHint;
8501 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8502 size_hints,manager_hints,class_hint);
8503 if (window_name.value != (void *) NULL)
8505 (void) XFree((void *) window_name.value);
8506 window_name.value=(unsigned char *) NULL;
8507 window_name.nitems=0;
8509 if (icon_name.value != (void *) NULL)
8511 (void) XFree((void *) icon_name.value);
8512 icon_name.value=(unsigned char *) NULL;
8515 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8516 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8517 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8518 (void) XFree((void *) size_hints);
8519 if (window_info->shape != MagickFalse)
8521 #if defined(MAGICKCORE_HAVE_SHAPE)
8527 Can we apply a non-rectangular shaping mask?
8531 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8532 window_info->shape=MagickFalse;
8534 window_info->shape=MagickFalse;
8537 if (window_info->shared_memory)
8539 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8541 Can we use shared memory with this window?
8543 if (XShmQueryExtension(display) == 0)
8544 window_info->shared_memory=MagickFalse;
8546 window_info->shared_memory=MagickFalse;
8549 window_info->image=NewImageList();
8550 window_info->destroy=MagickFalse;
8554 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8558 % X M a g i c k P r o g r e s s M o n i t o r %
8562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8564 % XMagickProgressMonitor() displays the progress a task is making in
8565 % completing a task.
8567 % The format of the XMagickProgressMonitor method is:
8569 % void XMagickProgressMonitor(const char *task,
8570 % const MagickOffsetType quantum,const MagickSizeType span,
8571 % void *client_data)
8573 % A description of each parameter follows:
8575 % o task: Identifies the task in progress.
8577 % o quantum: Specifies the quantum position within the span which represents
8578 % how much progress has been made in completing a task.
8580 % o span: Specifies the span relative to completing a task.
8582 % o client_data: Pointer to any client data.
8586 static const char *GetLocaleMonitorMessage(const char *text)
8589 message[MagickPathExtent],
8590 tag[MagickPathExtent];
8598 (void) CopyMagickString(tag,text,MagickPathExtent);
8600 if (p != (char *) NULL)
8602 (void) FormatLocaleString(message,MagickPathExtent,"Monitor/%s",tag);
8603 locale_message=GetLocaleMessage(message);
8604 if (locale_message == message)
8606 return(locale_message);
8609 MagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
8610 const MagickOffsetType quantum,const MagickSizeType span,
8611 void *magick_unused(client_data))
8616 windows=XSetWindows((XWindows *) ~0);
8617 if (windows == (XWindows *) NULL)
8619 if (windows->info.mapped != MagickFalse)
8620 XProgressMonitorWidget(windows->display,windows,
8621 GetLocaleMonitorMessage(tag),quantum,span);
8626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8630 % X Q u e r y C o l o r D a t a b a s e %
8634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8636 % XQueryColorCompliance() looks up a RGB values for a color given in the target
8639 % The format of the XQueryColorDatabase method is:
8641 % MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
8643 % A description of each parameter follows:
8645 % o target: Specifies the color to lookup in the X color database.
8647 % o color: A pointer to an PixelInfo structure. The RGB value of the target
8648 % color is returned as this value.
8651 MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
8658 *display = (Display *) NULL;
8667 Initialize color return value.
8669 assert(color != (XColor *) NULL);
8673 color->flags=(char) (DoRed | DoGreen | DoBlue);
8674 if ((target == (char *) NULL) || (*target == '\0'))
8675 target="#ffffffffffff";
8677 Let the X server define the color for us.
8679 if (display == (Display *) NULL)
8680 display=XOpenDisplay((char *) NULL);
8681 if (display == (Display *) NULL)
8683 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
8684 return(MagickFalse);
8686 colormap=XDefaultColormap(display,XDefaultScreen(display));
8687 status=XParseColor(display,colormap,(char *) target,&xcolor);
8688 if (status == False)
8689 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
8692 color->red=xcolor.red;
8693 color->green=xcolor.green;
8694 color->blue=xcolor.blue;
8695 color->flags=xcolor.flags;
8697 return(status != False ? MagickTrue : MagickFalse);
8701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8705 % X Q u e r y P o s i t i o n %
8709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8711 % XQueryPosition() gets the pointer coordinates relative to a window.
8713 % The format of the XQueryPosition method is:
8715 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8717 % A description of each parameter follows:
8719 % o display: Specifies a connection to an X server; returned from
8722 % o window: Specifies a pointer to a Window.
8724 % o x: Return the x coordinate of the pointer relative to the origin of the
8727 % o y: Return the y coordinate of the pointer relative to the origin of the
8731 MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,
8744 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8745 assert(display != (Display *) NULL);
8746 assert(window != (Window) NULL);
8747 assert(x != (int *) NULL);
8748 assert(y != (int *) NULL);
8749 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8758 % X R e f r e s h W i n d o w %
8762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8764 % XRefreshWindow() refreshes an image in a X window.
8766 % The format of the XRefreshWindow method is:
8768 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8769 % const XEvent *event)
8771 % A description of each parameter follows:
8773 % o display: Specifies a connection to an X server; returned from
8776 % o window: Specifies a pointer to a XWindowInfo structure.
8778 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8779 % the entire image is refreshed.
8782 MagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
8783 const XEvent *event)
8793 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8794 assert(display != (Display *) NULL);
8795 assert(window != (XWindowInfo *) NULL);
8796 if (window->ximage == (XImage *) NULL)
8798 if (event != (XEvent *) NULL)
8801 Determine geometry from expose event.
8805 width=(unsigned int) event->xexpose.width;
8806 height=(unsigned int) event->xexpose.height;
8814 Refresh entire window; discard outstanding expose events.
8818 width=window->width;
8819 height=window->height;
8820 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8821 if (window->matte_pixmap != (Pixmap) NULL)
8823 #if defined(MAGICKCORE_HAVE_SHAPE)
8824 if (window->shape != MagickFalse)
8825 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8826 window->matte_pixmap,ShapeSet);
8831 Check boundary conditions.
8833 if ((window->ximage->width-(x+window->x)) < (int) width)
8834 width=(unsigned int) (window->ximage->width-(x+window->x));
8835 if ((window->ximage->height-(y+window->y)) < (int) height)
8836 height=(unsigned int) (window->ximage->height-(y+window->y));
8840 if (window->matte_pixmap != (Pixmap) NULL)
8841 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8842 if (window->pixmap != (Pixmap) NULL)
8844 if (window->depth > 1)
8845 (void) XCopyArea(display,window->pixmap,window->id,
8846 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8848 (void) XCopyPlane(display,window->pixmap,window->id,
8849 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8854 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8855 if (window->shared_memory)
8856 (void) XShmPutImage(display,window->id,window->annotate_context,
8857 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8859 if (window->shared_memory == MagickFalse)
8860 (void) XPutImage(display,window->id,window->annotate_context,
8861 window->ximage,x+window->x,y+window->y,x,y,width,height);
8863 if (window->matte_pixmap != (Pixmap) NULL)
8864 (void) XSetClipMask(display,window->annotate_context,None);
8865 (void) XFlush(display);
8869 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8873 % X R e m o t e C o m m a n d %
8877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8879 % XRemoteCommand() forces a remote display(1) to display the specified
8882 % The format of the XRemoteCommand method is:
8884 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8885 % const char *filename)
8887 % A description of each parameter follows:
8889 % o display: Specifies a connection to an X server; returned from
8892 % o window: Specifies the name or id of an X window.
8894 % o filename: the name of the image filename to display.
8897 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8898 const char *window,const char *filename)
8907 assert(filename != (char *) NULL);
8908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8909 if (display == (Display *) NULL)
8910 display=XOpenDisplay((char *) NULL);
8911 if (display == (Display *) NULL)
8913 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8914 return(MagickFalse);
8916 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8917 remote_window=(Window) NULL;
8918 root_window=XRootWindow(display,XDefaultScreen(display));
8919 if (window != (char *) NULL)
8922 Search window hierarchy and identify any clients by name or ID.
8924 if (isdigit((int) ((unsigned char) *window)) != 0)
8925 remote_window=XWindowByID(display,root_window,(Window)
8926 strtol((char *) window,(char **) NULL,0));
8927 if (remote_window == (Window) NULL)
8928 remote_window=XWindowByName(display,root_window,window);
8930 if (remote_window == (Window) NULL)
8931 remote_window=XWindowByProperty(display,root_window,remote_atom);
8932 if (remote_window == (Window) NULL)
8934 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8936 return(MagickFalse);
8939 Send remote command.
8941 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8942 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8943 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8944 (void) XSync(display,MagickFalse);
8949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8953 % X R e n d e r I m a g e %
8957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8959 % XRenderImage() renders text on the image with an X11 font. It also returns
8960 % the bounding box of the text relative to the image.
8962 % The format of the XRenderImage method is:
8964 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
8965 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8967 % A description of each parameter follows:
8969 % o image: the image.
8971 % o draw_info: the draw info.
8973 % o offset: (x,y) location of text relative to image.
8975 % o metrics: bounding box of text.
8977 % o exception: return any errors or warnings in this structure.
8980 MagickPrivate MagickBooleanType XRenderImage(Image *image,
8981 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
8982 ExceptionInfo *exception)
9025 Open X server connection.
9027 display=XOpenDisplay(draw_info->server_name);
9028 if (display == (Display *) NULL)
9030 ThrowXWindowException(XServerError,"UnableToOpenXServer",
9031 draw_info->server_name);
9032 return(MagickFalse);
9035 Get user defaults from X resource database.
9037 (void) XSetErrorHandler(XError);
9038 image_info=AcquireImageInfo();
9039 client_name=GetClientName();
9040 resource_database=XGetResourceDatabase(display,client_name);
9041 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9042 resource_info.close_server=MagickFalse;
9043 resource_info.colormap=PrivateColormap;
9044 resource_info.font=AcquireString(draw_info->font);
9045 resource_info.background_color=AcquireString("#ffffffffffff");
9046 resource_info.foreground_color=AcquireString("#000000000000");
9047 map_info=XAllocStandardColormap();
9048 visual_info=(XVisualInfo *) NULL;
9049 font_info=(XFontStruct *) NULL;
9050 pixel.pixels=(unsigned long *) NULL;
9051 if (map_info == (XStandardColormap *) NULL)
9053 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9055 return(MagickFalse);
9058 Initialize visual info.
9060 visual_info=XBestVisualInfo(display,map_info,&resource_info);
9061 if (visual_info == (XVisualInfo *) NULL)
9063 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9064 &resource_info,(XWindowInfo *) NULL);
9065 ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
9066 return(MagickFalse);
9068 map_info->colormap=(Colormap) NULL;
9070 Initialize Standard Colormap info.
9072 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9074 XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL,
9076 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9078 Initialize font info.
9080 font_info=XBestFont(display,&resource_info,MagickFalse);
9081 if (font_info == (XFontStruct *) NULL)
9083 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9084 &resource_info,(XWindowInfo *) NULL);
9085 ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font);
9086 return(MagickFalse);
9088 cache_info=(*draw_info);
9090 Initialize annotate info.
9092 XGetAnnotateInfo(&annotate_info);
9093 annotate_info.stencil=ForegroundStencil;
9094 if (cache_info.font != draw_info->font)
9097 Type name has changed.
9099 (void) XFreeFont(display,font_info);
9100 (void) CloneString(&resource_info.font,draw_info->font);
9101 font_info=XBestFont(display,&resource_info,MagickFalse);
9102 if (font_info == (XFontStruct *) NULL)
9104 ThrowXWindowException(XServerError,"UnableToLoadFont",
9106 return(MagickFalse);
9109 if (image->debug != MagickFalse)
9110 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9111 "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
9112 draw_info->font : "none",draw_info->pointsize);
9113 cache_info=(*draw_info);
9114 annotate_info.font_info=font_info;
9115 annotate_info.text=(char *) draw_info->text;
9116 annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int)
9117 strlen(draw_info->text));
9118 annotate_info.height=(unsigned int) font_info->ascent+font_info->descent;
9119 metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9120 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9121 metrics->ascent=(double) font_info->ascent+4;
9122 metrics->descent=(double) (-font_info->descent);
9123 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9124 metrics->height=(double) font_info->ascent+font_info->descent;
9125 metrics->max_advance=(double) font_info->max_bounds.width;
9126 metrics->bounds.x1=0.0;
9127 metrics->bounds.y1=metrics->descent;
9128 metrics->bounds.x2=metrics->ascent+metrics->descent;
9129 metrics->bounds.y2=metrics->ascent+metrics->descent;
9130 metrics->underline_position=(-2.0);
9131 metrics->underline_thickness=1.0;
9132 if (draw_info->render == MagickFalse)
9134 if (draw_info->fill.alpha == TransparentAlpha)
9139 width=annotate_info.width;
9140 height=annotate_info.height;
9141 if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9142 (fabs(draw_info->affine.ry) >= MagickEpsilon))
9144 if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9145 (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9146 annotate_info.degrees=(double) (180.0/MagickPI)*
9147 atan2(draw_info->affine.rx,draw_info->affine.sx);
9149 (void) FormatLocaleString(annotate_info.geometry,MagickPathExtent,
9150 "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height,
9151 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9152 draw_info->interline_spacing-0.5));
9153 pixel.pen_color.red=ScaleQuantumToShort(
9154 ClampToQuantum(draw_info->fill.red));
9155 pixel.pen_color.green=ScaleQuantumToShort(
9156 ClampToQuantum(draw_info->fill.green));
9157 pixel.pen_color.blue=ScaleQuantumToShort(
9158 ClampToQuantum(draw_info->fill.blue));
9159 status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9162 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9164 return(MagickFalse);
9170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9174 % X R e t a i n W i n d o w C o l o r s %
9178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9180 % XRetainWindowColors() sets X11 color resources on a window. This preserves
9181 % the colors associated with an image displayed on the window.
9183 % The format of the XRetainWindowColors method is:
9185 % void XRetainWindowColors(Display *display,const Window window)
9187 % A description of each parameter follows:
9189 % o display: Specifies a connection to an X server; returned from
9192 % o window: Specifies a pointer to a XWindowInfo structure.
9195 MagickExport void XRetainWindowColors(Display *display,const Window window)
9204 Put property on the window.
9206 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9207 assert(display != (Display *) NULL);
9208 assert(window != (Window) NULL);
9209 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
9210 if (property == (Atom) NULL)
9212 ThrowXWindowException(XServerError,"UnableToCreateProperty",
9216 pixmap=XCreatePixmap(display,window,1,1,1);
9217 if (pixmap == (Pixmap) NULL)
9219 ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
9222 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9223 (unsigned char *) &pixmap,1);
9224 (void) XSetCloseDownMode(display,RetainPermanent);
9228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9232 % X S e l e c t W i n d o w %
9236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9238 % XSelectWindow() allows a user to select a window using the mouse. If the
9239 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
9240 % is returned in the crop_info structure.
9242 % The format of the XSelectWindow function is:
9244 % target_window=XSelectWindow(display,crop_info)
9246 % A description of each parameter follows:
9248 % o window: XSelectWindow returns the window id.
9250 % o display: Specifies a pointer to the Display structure; returned from
9253 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9254 % contains the extents of any cropping rectangle.
9257 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9259 #define MinimumCropArea (unsigned int) 9
9286 Initialize graphic context.
9288 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9289 assert(display != (Display *) NULL);
9290 assert(crop_info != (RectangleInfo *) NULL);
9291 root_window=XRootWindow(display,XDefaultScreen(display));
9292 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9293 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9294 context_values.function=GXinvert;
9295 context_values.plane_mask=
9296 context_values.background ^ context_values.foreground;
9297 context_values.subwindow_mode=IncludeInferiors;
9298 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9299 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9300 if (annotate_context == (GC) NULL)
9301 return(MagickFalse);
9303 Grab the pointer using target cursor.
9305 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9306 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9307 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9308 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9309 GrabModeAsync,root_window,target_cursor,CurrentTime);
9310 if (status != GrabSuccess)
9312 ThrowXWindowException(XServerError,"UnableToGrabMouse","");
9313 return((Window) NULL);
9319 crop_info->height=0;
9321 target_window=(Window) NULL;
9326 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9327 (void) XDrawRectangle(display,root_window,annotate_context,
9328 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9329 (unsigned int) crop_info->height-1);
9331 Allow another event.
9333 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9334 (void) XWindowEvent(display,root_window,ButtonPressMask |
9335 ButtonReleaseMask | ButtonMotionMask,&event);
9336 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9337 (void) XDrawRectangle(display,root_window,annotate_context,
9338 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9339 (unsigned int) crop_info->height-1);
9344 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9345 event.xbutton.x,event.xbutton.y);
9346 if (target_window == (Window) NULL)
9347 target_window=root_window;
9348 x_offset=event.xbutton.x_root;
9349 y_offset=event.xbutton.y_root;
9350 crop_info->x=(ssize_t) x_offset;
9351 crop_info->y=(ssize_t) y_offset;
9353 crop_info->height=0;
9365 Discard pending button motion events.
9367 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9368 crop_info->x=(ssize_t) event.xmotion.x;
9369 crop_info->y=(ssize_t) event.xmotion.y;
9371 Check boundary conditions.
9373 if ((int) crop_info->x < x_offset)
9374 crop_info->width=(size_t) (x_offset-crop_info->x);
9377 crop_info->width=(size_t) (crop_info->x-x_offset);
9378 crop_info->x=(ssize_t) x_offset;
9380 if ((int) crop_info->y < y_offset)
9381 crop_info->height=(size_t) (y_offset-crop_info->y);
9384 crop_info->height=(size_t) (crop_info->y-y_offset);
9385 crop_info->y=(ssize_t) y_offset;
9391 } while ((target_window == (Window) NULL) || (presses > 0));
9392 (void) XUngrabPointer(display,CurrentTime);
9393 (void) XFreeCursor(display,target_cursor);
9394 (void) XFreeGC(display,annotate_context);
9395 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9398 crop_info->height=0;
9400 if ((crop_info->width != 0) && (crop_info->height != 0))
9401 target_window=root_window;
9402 return(target_window);
9406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9410 % X S e t C u r s o r S t a t e %
9414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9416 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9417 % reset to their default.
9419 % The format of the XXSetCursorState method is:
9421 % XSetCursorState(display,windows,const MagickStatusType state)
9423 % A description of each parameter follows:
9425 % o display: Specifies a connection to an X server; returned from
9428 % o windows: Specifies a pointer to a XWindows structure.
9430 % o state: An unsigned integer greater than 0 sets the cursor state
9431 % to busy, otherwise the cursor are reset to their default.
9434 MagickPrivate void XSetCursorState(Display *display,XWindows *windows,
9435 const MagickStatusType state)
9437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9438 assert(display != (Display *) NULL);
9439 assert(windows != (XWindows *) NULL);
9442 (void) XCheckDefineCursor(display,windows->image.id,
9443 windows->image.busy_cursor);
9444 (void) XCheckDefineCursor(display,windows->pan.id,
9445 windows->pan.busy_cursor);
9446 (void) XCheckDefineCursor(display,windows->magnify.id,
9447 windows->magnify.busy_cursor);
9448 (void) XCheckDefineCursor(display,windows->command.id,
9449 windows->command.busy_cursor);
9453 (void) XCheckDefineCursor(display,windows->image.id,
9454 windows->image.cursor);
9455 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9456 (void) XCheckDefineCursor(display,windows->magnify.id,
9457 windows->magnify.cursor);
9458 (void) XCheckDefineCursor(display,windows->command.id,
9459 windows->command.cursor);
9460 (void) XCheckDefineCursor(display,windows->command.id,
9461 windows->widget.cursor);
9462 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9464 windows->info.mapped=MagickFalse;
9468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9472 % X S e t W i n d o w s %
9476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9478 % XSetWindows() sets the X windows structure if the windows info is specified.
9479 % Otherwise the current windows structure is returned.
9481 % The format of the XSetWindows method is:
9483 % XWindows *XSetWindows(XWindows *windows_info)
9485 % A description of each parameter follows:
9487 % o windows_info: Initialize the Windows structure with this information.
9490 MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9493 *windows = (XWindows *) NULL;
9495 if (windows_info != (XWindows *) ~0)
9497 windows=(XWindows *) RelinquishMagickMemory(windows);
9498 windows=windows_info;
9503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9507 % X U s e r P r e f e r e n c e s %
9511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9513 % XUserPreferences() saves the preferences in a configuration file in the
9514 % users' home directory.
9516 % The format of the XUserPreferences method is:
9518 % void XUserPreferences(XResourceInfo *resource_info)
9520 % A description of each parameter follows:
9522 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9525 MagickPrivate void XUserPreferences(XResourceInfo *resource_info)
9527 #if defined(X11_PREFERENCES_PATH)
9529 cache[MagickPathExtent],
9530 filename[MagickPathExtent],
9531 specifier[MagickPathExtent];
9538 preferences_database;
9541 Save user preferences to the client configuration file.
9543 assert(resource_info != (XResourceInfo *) NULL);
9544 client_name=GetClientName();
9545 preferences_database=XrmGetStringDatabase("");
9546 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.backdrop",client_name);
9547 value=resource_info->backdrop ? "True" : "False";
9548 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9549 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.colormap",client_name);
9550 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9551 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9552 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.confirmExit",
9554 value=resource_info->confirm_exit ? "True" : "False";
9555 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9556 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.confirmEdit",
9558 value=resource_info->confirm_edit ? "True" : "False";
9559 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9560 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.displayWarnings",
9562 value=resource_info->display_warnings ? "True" : "False";
9563 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9564 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.dither",client_name);
9565 value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9567 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9568 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.gammaCorrect",
9570 value=resource_info->gamma_correct ? "True" : "False";
9571 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9572 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.undoCache",client_name);
9573 (void) FormatLocaleString(cache,MagickPathExtent,"%.20g",(double)
9574 resource_info->undo_cache);
9575 XrmPutStringResource(&preferences_database,specifier,cache);
9576 (void) FormatLocaleString(specifier,MagickPathExtent,"%s.usePixmap",client_name);
9577 value=resource_info->use_pixmap ? "True" : "False";
9578 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9579 (void) FormatLocaleString(filename,MagickPathExtent,"%s%src",
9580 X11_PREFERENCES_PATH,client_name);
9581 ExpandFilename(filename);
9582 XrmPutFileDatabase(preferences_database,filename);
9587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9591 % X V i s u a l C l a s s N a m e %
9595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9597 % XVisualClassName() returns the visual class name as a character string.
9599 % The format of the XVisualClassName method is:
9601 % char *XVisualClassName(const int visual_class)
9603 % A description of each parameter follows:
9605 % o visual_type: XVisualClassName returns the visual class as a character
9608 % o class: Specifies the visual class.
9611 static const char *XVisualClassName(const int visual_class)
9613 switch (visual_class)
9615 case StaticGray: return("StaticGray");
9616 case GrayScale: return("GrayScale");
9617 case StaticColor: return("StaticColor");
9618 case PseudoColor: return("PseudoColor");
9619 case TrueColor: return("TrueColor");
9620 case DirectColor: return("DirectColor");
9622 return("unknown visual class");
9626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9636 % XWarning() displays a warning reason in a Notice widget.
9638 % The format of the XWarning method is:
9640 % void XWarning(const unsigned int warning,const char *reason,
9641 % const char *description)
9643 % A description of each parameter follows:
9645 % o warning: Specifies the numeric warning category.
9647 % o reason: Specifies the reason to display before terminating the
9650 % o description: Specifies any description to the reason.
9653 MagickPrivate void XWarning(const ExceptionType magick_unused(warning),
9654 const char *reason,const char *description)
9657 text[MagickPathExtent];
9662 if (reason == (char *) NULL)
9664 (void) CopyMagickString(text,reason,MagickPathExtent);
9665 (void) ConcatenateMagickString(text,":",MagickPathExtent);
9666 windows=XSetWindows((XWindows *) ~0);
9667 XNoticeWidget(windows->display,windows,text,(char *) description);
9671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9675 % X W i n d o w B y I D %
9679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9681 % XWindowByID() locates a child window with a given ID. If not window with
9682 % the given name is found, 0 is returned. Only the window specified and its
9683 % subwindows are searched.
9685 % The format of the XWindowByID function is:
9687 % child=XWindowByID(display,window,id)
9689 % A description of each parameter follows:
9691 % o child: XWindowByID returns the window with the specified
9692 % id. If no windows are found, XWindowByID returns 0.
9694 % o display: Specifies a pointer to the Display structure; returned from
9697 % o id: Specifies the id of the window to locate.
9700 MagickPrivate Window XWindowByID(Display *display,const Window root_window,
9720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9721 assert(display != (Display *) NULL);
9722 assert(root_window != (Window) NULL);
9724 return(XSelectWindow(display,&rectangle_info));
9725 if (root_window == id)
9726 return(root_window);
9727 status=XQueryTree(display,root_window,&child,&child,&children,
9729 if (status == False)
9730 return((Window) NULL);
9731 window=(Window) NULL;
9732 for (i=0; i < (int) number_children; i++)
9735 Search each child and their children.
9737 window=XWindowByID(display,children[i],id);
9738 if (window != (Window) NULL)
9741 if (children != (Window *) NULL)
9742 (void) XFree((void *) children);
9747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9751 % X W i n d o w B y N a m e %
9755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9757 % XWindowByName() locates a window with a given name on a display. If no
9758 % window with the given name is found, 0 is returned. If more than one window
9759 % has the given name, the first one is returned. Only root and its children
9762 % The format of the XWindowByName function is:
9764 % window=XWindowByName(display,root_window,name)
9766 % A description of each parameter follows:
9768 % o window: XWindowByName returns the window id.
9770 % o display: Specifies a pointer to the Display structure; returned from
9773 % o root_window: Specifies the id of the root window.
9775 % o name: Specifies the name of the window to locate.
9778 MagickPrivate Window XWindowByName(Display *display,const Window root_window,
9798 assert(display != (Display *) NULL);
9799 assert(root_window != (Window) NULL);
9800 assert(name != (char *) NULL);
9801 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9802 if (XGetWMName(display,root_window,&window_name) != 0)
9803 if (LocaleCompare((char *) window_name.value,name) == 0)
9804 return(root_window);
9805 status=XQueryTree(display,root_window,&child,&child,&children,
9807 if (status == False)
9808 return((Window) NULL);
9809 window=(Window) NULL;
9810 for (i=0; i < (int) number_children; i++)
9813 Search each child and their children.
9815 window=XWindowByName(display,children[i],name);
9816 if (window != (Window) NULL)
9819 if (children != (Window *) NULL)
9820 (void) XFree((void *) children);
9825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9829 % X W i n d o w B y P r o p e r y %
9833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9835 % XWindowByProperty() locates a child window with a given property. If not
9836 % window with the given name is found, 0 is returned. If more than one window
9837 % has the given property, the first one is returned. Only the window
9838 % specified and its subwindows are searched.
9840 % The format of the XWindowByProperty function is:
9842 % child=XWindowByProperty(display,window,property)
9844 % A description of each parameter follows:
9846 % o child: XWindowByProperty returns the window id with the specified
9847 % property. If no windows are found, XWindowByProperty returns 0.
9849 % o display: Specifies a pointer to the Display structure; returned from
9852 % o property: Specifies the property of the window to locate.
9855 MagickPrivate Window XWindowByProperty(Display *display,const Window window,
9856 const Atom property)
9884 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9885 assert(display != (Display *) NULL);
9886 assert(window != (Window) NULL);
9887 assert(property != (Atom) NULL);
9888 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9889 if (status == False)
9890 return((Window) NULL);
9892 child=(Window) NULL;
9893 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9895 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9896 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9898 (void) XFree((void *) data);
9899 if ((status == Success) && (type != (Atom) NULL))
9902 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9903 child=XWindowByProperty(display,children[i],property);
9904 if (children != (Window *) NULL)
9905 (void) XFree((void *) children);
9911 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9915 % X I m p o r t I m a g e %
9919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9921 % XImportImage() reads an image from an X window.
9923 % The format of the XImportImage method is:
9925 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
9926 % ExceptionInfo *exception)
9928 % A description of each parameter follows:
9930 % o image_info: the image info..
9932 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9934 % o exception: return any errors or warnings in this structure.
9937 MagickExport Image *XImportImage(const ImageInfo *image_info,
9938 XImportInfo *ximage_info,ExceptionInfo *exception)
9940 assert(image_info != (const ImageInfo *) NULL);
9941 assert(image_info->signature == MagickCoreSignature);
9942 if (image_info->debug != MagickFalse)
9943 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9944 image_info->filename);
9945 assert(ximage_info != (XImportInfo *) NULL);
9946 assert(exception != (ExceptionInfo *) NULL);
9947 assert(exception->signature == MagickCoreSignature);
9949 return((Image *) NULL);
9953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9957 % X R e n d e r X 1 1 %
9961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9963 % XRenderImage() renders text on the image with an X11 font. It also returns
9964 % the bounding box of the text relative to the image.
9966 % The format of the XRenderImage method is:
9968 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
9969 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
9971 % A description of each parameter follows:
9973 % o image: the image.
9975 % o draw_info: the draw info.
9977 % o offset: (x,y) location of text relative to image.
9979 % o metrics: bounding box of text.
9981 % o exception: return any errors or warnings in this structure.
9984 MagickPrivate MagickBooleanType XRenderImage(Image *image,
9985 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
9986 ExceptionInfo *exception)
9991 (void) ThrowMagickException(exception,GetMagickModule(),
9992 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)",
9994 return(MagickFalse);
9999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10003 + X C o m p o n e n t G e n e s i s %
10007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10009 % XComponentGenesis() instantiates the X component.
10011 % The format of the XComponentGenesis method is:
10013 % MagickBooleanType XComponentGenesis(void)
10016 MagickPrivate MagickBooleanType XComponentGenesis(void)
10018 return(MagickTrue);
10022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10026 % X G e t I m p o r t I n f o %
10030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10032 % XGetImportInfo() initializes the XImportInfo structure.
10034 % The format of the XGetImportInfo method is:
10036 % void XGetImportInfo(XImportInfo *ximage_info)
10038 % A description of each parameter follows:
10040 % o ximage_info: Specifies a pointer to an ImageInfo structure.
10043 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
10045 assert(ximage_info != (XImportInfo *) NULL);
10046 ximage_info->frame=MagickFalse;
10047 ximage_info->borders=MagickFalse;
10048 ximage_info->screen=MagickFalse;
10049 ximage_info->descend=MagickTrue;
10050 ximage_info->silent=MagickFalse;