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-2013 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/animate.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/client.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colormap.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/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/monitor.h"
67 #include "MagickCore/nt-base-private.h"
68 #include "MagickCore/option.h"
69 #include "MagickCore/pixel-accessor.h"
70 #include "MagickCore/PreRvIcccm.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/token.h"
81 #include "MagickCore/utility.h"
82 #include "MagickCore/utility-private.h"
83 #include "MagickCore/widget.h"
84 #include "MagickCore/widget-private.h"
85 #include "MagickCore/xwindow.h"
86 #include "MagickCore/xwindow-private.h"
87 #include "MagickCore/version.h"
91 #if defined(MAGICKCORE_X11_DELEGATE)
92 #include <X11/Xproto.h>
93 #include <X11/Xlocale.h>
94 #if defined(MAGICK_HAVE_POLL)
95 # include <sys/poll.h>
97 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
98 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
99 # include <machine/param.h>
103 #include <X11/extensions/XShm.h>
105 #if defined(MAGICKCORE_HAVE_SHAPE)
106 #include <X11/extensions/shape.h>
112 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
113 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
115 #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
116 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
118 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
120 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
122 #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
123 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
125 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
127 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
129 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
130 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
132 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
133 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
135 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
136 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
137 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
138 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
140 #define AccentuateModulate ScaleCharToQuantum(80)
141 #define HighlightModulate ScaleCharToQuantum(125)
142 #define ShadowModulate ScaleCharToQuantum(135)
143 #define DepthModulate ScaleCharToQuantum(185)
144 #define TroughModulate ScaleCharToQuantum(110)
146 #define XLIB_ILLEGAL_ACCESS 1
148 #undef NorthWestGravity
150 #undef NorthEastGravity
154 #undef SouthWestGravity
156 #undef SouthEastGravity
163 #define XFD_SET fd_set
167 Enumeration declarations.
181 Typedef declarations.
183 typedef struct _DiversityPacket
198 Constant declaractions.
200 static MagickBooleanType
201 xerror_alert = MagickFalse;
207 *XVisualClassName(const int);
214 static MagickBooleanType
215 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
218 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
219 XImage *,XImage *,ExceptionInfo *),
220 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
221 XImage *,XImage *,ExceptionInfo *);
224 XSelectWindow(Display *,RectangleInfo *);
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 % D e s t r o y X R e s o u r c e s %
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 % DestroyXResources() destroys any X resources.
239 % The format of the DestroyXResources method is:
241 % void DestroyXResources()
243 % A description of each parameter follows:
246 MagickExport void DestroyXResources(void)
255 *magick_windows[MaxXWindows];
261 windows=XSetWindows((XWindows *) ~0);
262 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
265 magick_windows[number_windows++]=(&windows->context);
266 magick_windows[number_windows++]=(&windows->group_leader);
267 magick_windows[number_windows++]=(&windows->backdrop);
268 magick_windows[number_windows++]=(&windows->icon);
269 magick_windows[number_windows++]=(&windows->image);
270 magick_windows[number_windows++]=(&windows->info);
271 magick_windows[number_windows++]=(&windows->magnify);
272 magick_windows[number_windows++]=(&windows->pan);
273 magick_windows[number_windows++]=(&windows->command);
274 magick_windows[number_windows++]=(&windows->widget);
275 magick_windows[number_windows++]=(&windows->popup);
276 magick_windows[number_windows++]=(&windows->context);
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[MaxTextExtent];
629 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%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 == BlendPixelTrait ? 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.
1148 static inline int MagickMax(const int x,const int y)
1155 static inline size_t MagickMin(const unsigned int x,
1156 const unsigned int y)
1163 MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1164 XStandardColormap *map_info,XResourceInfo *resource_info)
1166 #define MaxStandardColormaps 7
1167 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1168 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1169 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1170 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1196 Restrict visual search by screen number.
1198 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1199 assert(display != (Display *) NULL);
1200 assert(map_info != (XStandardColormap *) NULL);
1201 assert(resource_info != (XResourceInfo *) NULL);
1202 map_type=resource_info->map_type;
1203 visual_type=resource_info->visual_type;
1204 visual_mask=VisualScreenMask;
1205 visual_template.screen=XDefaultScreen(display);
1206 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1208 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1209 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1210 visual_mask|=VisualDepthMask;
1211 if (visual_type != (char *) NULL)
1214 Restrict visual search by class or visual id.
1216 if (LocaleCompare("staticgray",visual_type) == 0)
1218 visual_mask|=VisualClassMask;
1219 visual_template.klass=StaticGray;
1222 if (LocaleCompare("grayscale",visual_type) == 0)
1224 visual_mask|=VisualClassMask;
1225 visual_template.klass=GrayScale;
1228 if (LocaleCompare("staticcolor",visual_type) == 0)
1230 visual_mask|=VisualClassMask;
1231 visual_template.klass=StaticColor;
1234 if (LocaleCompare("pseudocolor",visual_type) == 0)
1236 visual_mask|=VisualClassMask;
1237 visual_template.klass=PseudoColor;
1240 if (LocaleCompare("truecolor",visual_type) == 0)
1242 visual_mask|=VisualClassMask;
1243 visual_template.klass=TrueColor;
1246 if (LocaleCompare("directcolor",visual_type) == 0)
1248 visual_mask|=VisualClassMask;
1249 visual_template.klass=DirectColor;
1252 if (LocaleCompare("default",visual_type) == 0)
1254 visual_mask|=VisualIDMask;
1255 visual_template.visualid=XVisualIDFromVisual(
1256 XDefaultVisual(display,XDefaultScreen(display)));
1259 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1261 visual_mask|=VisualIDMask;
1262 visual_template.visualid=
1263 strtol(visual_type,(char **) NULL,0);
1266 ThrowXWindowException(XServerError,
1267 "UnrecognizedVisualSpecifier",visual_type);
1270 Get all visuals that meet our criteria so far.
1273 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1275 visual_mask=VisualScreenMask | VisualIDMask;
1276 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1279 Failed to get visual; try using the default visual.
1281 ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
1282 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1283 XDefaultScreen(display)));
1284 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1286 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1287 return((XVisualInfo *) NULL);
1288 ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
1289 XVisualClassName(visual_list->klass));
1291 resource_info->color_recovery=MagickFalse;
1292 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1298 map_name[MaxTextExtent];
1314 Choose a visual associated with a standard colormap.
1316 root_window=XRootWindow(display,XDefaultScreen(display));
1318 if (LocaleCompare(map_type,"list") != 0)
1321 User specified Standard Colormap.
1323 (void) FormatLocaleString((char *) map_name,MaxTextExtent,
1324 "RGB_%s_MAP",map_type);
1325 LocaleUpper(map_name);
1326 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1327 if (map_property != (Atom) NULL)
1328 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1334 *colormap[MaxStandardColormaps]=
1336 "_HP_RGB_SMOOTH_MAP_LIST",
1346 Choose a standard colormap from a list.
1348 for (i=0; i < MaxStandardColormaps; i++)
1350 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1351 if (map_property == (Atom) NULL)
1353 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1355 if (status != False)
1358 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1360 if (status == False)
1362 ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
1364 return((XVisualInfo *) NULL);
1367 Search all Standard Colormaps and visuals for ids that match.
1369 *map_info=map_list[0];
1370 #if !defined(PRE_R4_ICCCM)
1371 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1372 for (i=0; i < number_maps; i++)
1373 for (j=0; j < number_visuals; j++)
1374 if (map_list[i].visualid ==
1375 XVisualIDFromVisual(visual_list[j].visual))
1377 *map_info=map_list[i];
1378 visual_template.visualid=XVisualIDFromVisual(
1379 visual_list[j].visual);
1382 if (map_info->visualid != visual_template.visualid)
1384 ThrowXWindowException(XServerError,
1385 "UnableToMatchVisualToStandardColormap",map_type);
1386 return((XVisualInfo *) NULL);
1389 if (map_info->colormap == (Colormap) NULL)
1391 ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
1393 return((XVisualInfo *) NULL);
1395 (void) XFree((void *) map_list);
1399 static const unsigned int
1414 Pick one visual that displays the most simultaneous colors.
1416 visual_info=visual_list;
1418 for (i=1; i < number_visuals; i++)
1421 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1424 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1425 if (rank[p->klass] > rank[visual_info->klass])
1428 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1430 (void) XFree((void *) visual_list);
1432 Retrieve only one visual by its screen & id number.
1434 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1436 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1437 return((XVisualInfo *) NULL);
1438 return(visual_info);
1442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1446 % X C h e c k D e f i n e C u r s o r %
1450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1452 % XCheckDefineCursor() prevents cursor changes on the root window.
1454 % The format of the XXCheckDefineCursor method is:
1456 % XCheckDefineCursor(display,window,cursor)
1458 % A description of each parameter follows:
1460 % o display: Specifies a connection to an X server; returned from
1463 % o window: the window.
1465 % o cursor: the cursor.
1468 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1471 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1472 assert(display != (Display *) NULL);
1473 if (window == XRootWindow(display,XDefaultScreen(display)))
1475 return(XDefineCursor(display,window,cursor));
1479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1483 % X C h e c k R e f r e s h W i n d o w s %
1487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489 % XCheckRefreshWindows() checks the X server for exposure events for a
1490 % particular window and updates the areassociated with the exposure event.
1492 % The format of the XCheckRefreshWindows method is:
1494 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1496 % A description of each parameter follows:
1498 % o display: Specifies a connection to an X server; returned from
1501 % o windows: Specifies a pointer to a XWindows structure.
1504 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1513 assert(display != (Display *) NULL);
1514 assert(windows != (XWindows *) NULL);
1515 XDelay(display,SuspendTime);
1516 id=windows->command.id;
1517 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1518 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1519 id=windows->image.id;
1520 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1521 XRefreshWindow(display,&windows->image,&event);
1522 XDelay(display,SuspendTime << 1);
1523 id=windows->command.id;
1524 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1525 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1526 id=windows->image.id;
1527 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1528 XRefreshWindow(display,&windows->image,&event);
1532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1536 % X C l i e n t M e s s a g e %
1540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1542 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1543 % initialized with a particular protocol type and atom.
1545 % The format of the XClientMessage function is:
1547 % XClientMessage(display,window,protocol,reason,timestamp)
1549 % A description of each parameter follows:
1551 % o display: Specifies a pointer to the Display structure; returned from
1554 % o window: Specifies a pointer to a Window structure.
1556 % o protocol: Specifies an atom value.
1558 % o reason: Specifies an atom value which is the reason to send.
1560 % o timestamp: Specifies a value of type Time.
1563 MagickPrivate void XClientMessage(Display *display,const Window window,
1564 const Atom protocol,const Atom reason,const Time timestamp)
1569 assert(display != (Display *) NULL);
1570 client_event.type=ClientMessage;
1571 client_event.window=window;
1572 client_event.message_type=protocol;
1573 client_event.format=32;
1574 client_event.data.l[0]=(long) reason;
1575 client_event.data.l[1]=(long) timestamp;
1576 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 + X C l i e n t W i n d o w %
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 % XClientWindow() finds a window, at or below the specified window, which has
1591 % a WM_STATE property. If such a window is found, it is returned, otherwise
1592 % the argument window is returned.
1594 % The format of the XClientWindow function is:
1596 % client_window=XClientWindow(display,target_window)
1598 % A description of each parameter follows:
1600 % o client_window: XClientWindow returns a window, at or below the specified
1601 % window, which has a WM_STATE property otherwise the argument
1602 % target_window is returned.
1604 % o display: Specifies a pointer to the Display structure; returned from
1607 % o target_window: Specifies the window to find a WM_STATE property.
1610 static Window XClientWindow(Display *display,Window target_window)
1632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1633 assert(display != (Display *) NULL);
1634 state=XInternAtom(display,"WM_STATE",MagickTrue);
1635 if (state == (Atom) NULL)
1636 return(target_window);
1638 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1639 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1640 if ((status == Success) && (type != (Atom) NULL))
1641 return(target_window);
1642 client_window=XWindowByProperty(display,target_window,state);
1643 if (client_window == (Window) NULL)
1644 return(target_window);
1645 return(client_window);
1649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1653 + X C o m p o n e n t T e r m i n u s %
1657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1659 % XComponentTerminus() destroys the module component.
1661 % The format of the XComponentTerminus method is:
1663 % XComponentTerminus(void)
1666 MagickPrivate void XComponentTerminus(void)
1668 DestroyXResources();
1672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1676 % X C o n f i g u r e I m a g e C o l o r m a p %
1680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1682 % XConfigureImageColormap() creates a new X colormap.
1684 % The format of the XConfigureImageColormap method is:
1686 % void XConfigureImageColormap(Display *display,
1687 % XResourceInfo *resource_info,XWindows *windows,Image *image,
1688 % ExceptionInfo *exception)
1690 % A description of each parameter follows:
1692 % o display: Specifies a connection to an X server; returned from
1695 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1697 % o windows: Specifies a pointer to a XWindows structure.
1699 % o image: the image.
1701 % o exception: return any errors or warnings in this structure.
1704 MagickPrivate void XConfigureImageColormap(Display *display,
1705 XResourceInfo *resource_info,XWindows *windows,Image *image,
1706 ExceptionInfo *exception)
1712 Make standard colormap.
1714 XSetCursorState(display,windows,MagickTrue);
1715 XCheckRefreshWindows(display,windows);
1716 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1717 windows->map_info,windows->pixel_info,exception);
1718 colormap=windows->map_info->colormap;
1719 (void) XSetWindowColormap(display,windows->image.id,colormap);
1720 (void) XSetWindowColormap(display,windows->command.id,colormap);
1721 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1722 if (windows->magnify.mapped != MagickFalse)
1723 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1724 if (windows->pan.mapped != MagickFalse)
1725 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1726 XSetCursorState(display,windows,MagickFalse);
1727 XClientMessage(display,windows->image.id,windows->im_protocols,
1728 windows->im_update_colormap,CurrentTime);
1732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 % X C o n s t r a i n W i n d o w P o s i t i o n %
1740 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 % XConstrainWindowPosition() assures a window is positioned within the X
1743 % server boundaries.
1745 % The format of the XConstrainWindowPosition method is:
1747 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1749 % A description of each parameter follows:
1751 % o display: Specifies a pointer to the Display structure; returned from
1754 % o window_info: Specifies a pointer to a XWindowInfo structure.
1757 MagickPrivate void XConstrainWindowPosition(Display *display,
1758 XWindowInfo *window_info)
1763 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1764 assert(display != (Display *) NULL);
1765 assert(window_info != (XWindowInfo *) NULL);
1766 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1767 if (window_info->x < 0)
1770 if (window_info->x > (int) limit)
1771 window_info->x=(int) limit;
1772 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1773 if (window_info->y < 0)
1776 if (window_info->y > limit)
1777 window_info->y=limit;
1781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1791 % XDelay() suspends program execution for the number of milliseconds
1794 % The format of the Delay method is:
1796 % void XDelay(Display *display,const size_t milliseconds)
1798 % A description of each parameter follows:
1800 % o display: Specifies a pointer to the Display structure; returned from
1803 % o milliseconds: Specifies the number of milliseconds to delay before
1807 MagickPrivate void XDelay(Display *display,const size_t milliseconds)
1809 assert(display != (Display *) NULL);
1810 (void) XFlush(display);
1811 MagickDelay(milliseconds);
1815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1819 % X D e s t r o y R e s o u r c e I n f o %
1823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1825 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1828 % The format of the XDestroyResourceInfo method is:
1830 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1832 % A description of each parameter follows:
1834 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1837 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1839 if (resource_info->image_geometry != (char *) NULL)
1840 resource_info->image_geometry=(char *)
1841 RelinquishMagickMemory(resource_info->image_geometry);
1842 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1843 resource_info->quantize_info=DestroyQuantizeInfo(
1844 resource_info->quantize_info);
1845 if (resource_info->client_name != (char *) NULL)
1846 resource_info->client_name=(char *)
1847 RelinquishMagickMemory(resource_info->client_name);
1848 if (resource_info->name != (char *) NULL)
1849 resource_info->name=DestroyString(resource_info->name);
1850 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1858 % X D e s t r o y W i n d o w C o l o r s %
1862 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % XDestroyWindowColors() frees X11 color resources previously saved on a
1865 % window by XRetainWindowColors or programs like xsetroot.
1867 % The format of the XDestroyWindowColors method is:
1869 % void XDestroyWindowColors(Display *display,Window window)
1871 % A description of each parameter follows:
1873 % o display: Specifies a connection to an X server; returned from
1876 % o window: Specifies a pointer to a Window structure.
1879 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1899 If there are previous resources on the root window, destroy them.
1901 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1902 assert(display != (Display *) NULL);
1903 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1904 if (property == (Atom) NULL)
1906 ThrowXWindowException(XServerError,"UnableToCreateProperty",
1910 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1911 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1912 if (status != Success)
1914 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1916 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1917 (void) XDeleteProperty(display,window,property);
1920 (void) XFree((void *) data);
1924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1928 % X D i s p l a y I m a g e I n f o %
1932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934 % XDisplayImageInfo() displays information about an X image.
1936 % The format of the XDisplayImageInfo method is:
1938 % void XDisplayImageInfo(Display *display,
1939 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1940 % Image *image,ExceptionInfo *exception)
1942 % A description of each parameter follows:
1944 % o display: Specifies a connection to an X server; returned from
1947 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1949 % o windows: Specifies a pointer to a XWindows structure.
1951 % o undo_image: the undo image.
1953 % o image: the image.
1955 % o exception: return any errors or warnings in this structure.
1958 MagickPrivate void XDisplayImageInfo(Display *display,
1959 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1960 Image *image,ExceptionInfo *exception)
1963 filename[MaxTextExtent],
1986 Write info about the X server to a file.
1988 assert(display != (Display *) NULL);
1989 assert(resource_info != (XResourceInfo *) NULL);
1990 assert(windows != (XWindows *) NULL);
1991 assert(image != (Image *) NULL);
1993 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1995 unique_file=AcquireUniqueFileResource(filename);
1996 if (unique_file != -1)
1997 file=fdopen(unique_file,"w");
1998 if ((unique_file == -1) || (file == (FILE *) NULL))
2000 XNoticeWidget(display,windows,"Unable to display image info",filename);
2003 if (resource_info->gamma_correct != MagickFalse)
2004 if (resource_info->display_gamma != (char *) NULL)
2005 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
2006 resource_info->display_gamma);
2008 Write info about the X image to a file.
2010 (void) FormatLocaleFile(file,"X\n visual: %s\n",
2011 XVisualClassName((int) windows->image.storage_class));
2012 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
2013 if (windows->visual_info->colormap_size != 0)
2014 (void) FormatLocaleFile(file," colormap size: %d\n",
2015 windows->visual_info->colormap_size);
2016 if (resource_info->colormap== SharedColormap)
2017 (void) FormatLocaleFile(file," colormap type: Shared\n");
2019 (void) FormatLocaleFile(file," colormap type: Private\n");
2020 (void) FormatLocaleFile(file," geometry: %dx%d\n",
2021 windows->image.ximage->width,windows->image.ximage->height);
2022 if (windows->image.crop_geometry != (char *) NULL)
2023 (void) FormatLocaleFile(file," crop geometry: %s\n",
2024 windows->image.crop_geometry);
2025 if (windows->image.pixmap == (Pixmap) NULL)
2026 (void) FormatLocaleFile(file," type: X Image\n");
2028 (void) FormatLocaleFile(file," type: Pixmap\n");
2029 if (windows->image.shape != MagickFalse)
2030 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2032 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2033 if (windows->image.shared_memory != MagickFalse)
2034 (void) FormatLocaleFile(file," shared memory: True\n");
2036 (void) FormatLocaleFile(file," shared memory: False\n");
2037 (void) FormatLocaleFile(file,"\n");
2038 if (resource_info->font != (char *) NULL)
2039 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2040 if (resource_info->text_font != (char *) NULL)
2041 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2043 Write info about the undo cache to a file.
2046 for (levels=0; undo_image != (Image *) NULL; levels++)
2048 number_pixels=undo_image->list->columns*undo_image->list->rows;
2049 bytes+=number_pixels*sizeof(PixelInfo);
2050 undo_image=GetPreviousImageInList(undo_image);
2052 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2053 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2054 ((bytes+(1 << 19)) >> 20));
2055 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2056 resource_info->undo_cache);
2058 Write info about the image to a file.
2060 (void) IdentifyImage(image,file,MagickTrue,exception);
2061 (void) fclose(file);
2062 text=FileToString(filename,~0UL,exception);
2063 (void) RelinquishUniqueFileResource(filename);
2064 if (text == (char *) NULL)
2066 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2067 "UnableToDisplayImageInfo");
2070 textlist=StringToList(text);
2071 if (textlist != (char **) NULL)
2074 title[MaxTextExtent];
2077 Display information about the image in the Text View widget.
2079 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2080 (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
2082 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2083 (char const **) textlist);
2084 for (i=0; textlist[i] != (char *) NULL; i++)
2085 textlist[i]=DestroyString(textlist[i]);
2086 textlist=(char **) RelinquishMagickMemory(textlist);
2088 text=DestroyString(text);
2092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2096 + X D i t h e r I m a g e %
2100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2102 % XDitherImage() dithers the reference image as required by the HP Color
2103 % Recovery algorithm. The color values are quantized to 3 bits of red and
2104 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2105 % standard colormap.
2107 % The format of the XDitherImage method is:
2109 % void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
2111 % A description of each parameter follows:
2113 % o image: the image.
2115 % o ximage: Specifies a pointer to a XImage structure; returned from
2118 % o exception: return any errors or warnings in this structure.
2121 static void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
2123 static const short int
2126 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2127 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2129 dither_green[2][16]=
2131 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2132 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2136 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2137 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2153 register const Quantum
2173 Allocate and initialize dither maps.
2175 for (i=0; i < 2; i++)
2176 for (j=0; j < 16; j++)
2178 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2180 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2181 sizeof(*green_map));
2182 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2184 if ((red_map[i][j] == (unsigned char *) NULL) ||
2185 (green_map[i][j] == (unsigned char *) NULL) ||
2186 (blue_map[i][j] == (unsigned char *) NULL))
2188 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
2194 Initialize dither tables.
2196 for (i=0; i < 2; i++)
2197 for (j=0; j < 16; j++)
2198 for (x=0; x < 256; x++)
2203 value+=dither_red[i][j];
2204 red_map[i][j][x]=(unsigned char)
2205 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2209 value+=dither_green[i][j];
2210 green_map[i][j][x]=(unsigned char)
2211 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2215 value+=((size_t) dither_blue[i][j] << 1);
2216 blue_map[i][j][x]=(unsigned char)
2217 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2222 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2223 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2227 image_view=AcquireVirtualCacheView(image,exception);
2228 for (y=0; y < (int) image->rows; y++)
2230 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2232 if (p == (const Quantum *) NULL)
2234 for (x=0; x < (int) image->columns; x++)
2236 color.red=(double) ClampToQuantum((double) (red_map[i][j][
2237 (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2238 color.green=(double) ClampToQuantum((double) (green_map[i][j][
2239 (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2240 color.blue=(double) ClampToQuantum((double) (blue_map[i][j][
2241 (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2242 pixel=(size_t) (((size_t) color.red & 0xe0) |
2243 (((size_t) color.green & 0xe0) >> 3) |
2244 (((size_t) color.blue & 0xc0) >> 6));
2246 p+=GetPixelChannels(image);
2256 image_view=DestroyCacheView(image_view);
2258 Free allocated memory.
2260 for (i=0; i < 2; i++)
2261 for (j=0; j < 16; j++)
2263 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2264 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2265 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2274 % X D r a w I m a g e %
2278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2280 % XDrawImage() draws a line on the image.
2282 % The format of the XDrawImage method is:
2284 % MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
2285 % XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
2287 % A description of each parameter follows:
2289 % o display: Specifies a connection to an X server; returned from
2292 % o pixel: Specifies a pointer to a XPixelInfo structure.
2294 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2296 % o image: the image.
2298 % o exception: return any errors or warnings in this structure.
2301 MagickPrivate MagickBooleanType XDrawImage(Display *display,
2302 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
2303 ExceptionInfo *exception)
2339 Initialize drawd image.
2341 assert(display != (Display *) NULL);
2342 assert(pixel != (XPixelInfo *) NULL);
2343 assert(draw_info != (XDrawInfo *) NULL);
2344 assert(image != (Image *) NULL);
2345 if (image->debug != MagickFalse)
2346 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2348 Initialize drawd pixmap.
2350 root_window=XRootWindow(display,XDefaultScreen(display));
2351 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2352 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2353 draw_info->height,depth);
2354 if (draw_pixmap == (Pixmap) NULL)
2355 return(MagickFalse);
2357 Initialize graphics info.
2359 context_values.background=(size_t) (~0);
2360 context_values.foreground=0;
2361 context_values.line_width=(int) draw_info->line_width;
2362 draw_context=XCreateGC(display,root_window,(size_t)
2363 (GCBackground | GCForeground | GCLineWidth),&context_values);
2364 if (draw_context == (GC) NULL)
2365 return(MagickFalse);
2369 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2372 Draw line to pixmap.
2374 (void) XSetBackground(display,draw_context,0);
2375 (void) XSetForeground(display,draw_context,(size_t) (~0));
2376 if (draw_info->stipple != (Pixmap) NULL)
2378 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2379 (void) XSetStipple(display,draw_context,draw_info->stipple);
2381 switch (draw_info->element)
2386 (void) XDrawLines(display,draw_pixmap,draw_context,
2387 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2393 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2394 draw_info->line_info.y1,draw_info->line_info.x2,
2395 draw_info->line_info.y2);
2398 case RectangleElement:
2400 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2401 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2402 (unsigned int) draw_info->rectangle_info.width,
2403 (unsigned int) draw_info->rectangle_info.height);
2406 case FillRectangleElement:
2408 (void) XFillRectangle(display,draw_pixmap,draw_context,
2409 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2410 (unsigned int) draw_info->rectangle_info.width,
2411 (unsigned int) draw_info->rectangle_info.height);
2415 case EllipseElement:
2417 (void) XDrawArc(display,draw_pixmap,draw_context,
2418 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2419 (unsigned int) draw_info->rectangle_info.width,
2420 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2423 case FillCircleElement:
2424 case FillEllipseElement:
2426 (void) XFillArc(display,draw_pixmap,draw_context,
2427 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2428 (unsigned int) draw_info->rectangle_info.width,
2429 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2432 case PolygonElement:
2437 coordinate_info=draw_info->coordinate_info;
2438 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2439 (int) draw_info->number_coordinates,CoordModeOrigin);
2440 (void) XDrawLine(display,draw_pixmap,draw_context,
2441 coordinate_info[draw_info->number_coordinates-1].x,
2442 coordinate_info[draw_info->number_coordinates-1].y,
2443 coordinate_info[0].x,coordinate_info[0].y);
2446 case FillPolygonElement:
2448 (void) XFillPolygon(display,draw_pixmap,draw_context,
2449 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2454 (void) XFreeGC(display,draw_context);
2458 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2459 draw_info->height,AllPlanes,ZPixmap);
2460 if (draw_ximage == (XImage *) NULL)
2461 return(MagickFalse);
2462 (void) XFreePixmap(display,draw_pixmap);
2464 Initialize draw image.
2466 draw_image=AcquireImage((ImageInfo *) NULL,exception);
2467 if (draw_image == (Image *) NULL)
2468 return(MagickFalse);
2469 draw_image->columns=draw_info->width;
2470 draw_image->rows=draw_info->height;
2472 Transfer drawn X image to image.
2474 width=(unsigned int) image->columns;
2475 height=(unsigned int) image->rows;
2478 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2479 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
2480 (ssize_t) y,&draw_image->background_color,exception);
2481 if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
2482 return(MagickFalse);
2483 draw_image->alpha_trait=BlendPixelTrait;
2484 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2485 for (y=0; y < (int) draw_image->rows; y++)
2493 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2495 if (q == (Quantum *) NULL)
2497 for (x=0; x < (int) draw_image->columns; x++)
2499 if (XGetPixel(draw_ximage,x,y) == 0)
2502 Set this pixel to the background color.
2504 SetPixelInfoPixel(draw_image,&draw_image->background_color,q);
2505 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2506 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2511 Set this pixel to the pen color.
2513 SetPixelRed(draw_image,ScaleShortToQuantum(
2514 pixel->pen_color.red),q);
2515 SetPixelGreen(draw_image,ScaleShortToQuantum(
2516 pixel->pen_color.green),q);
2517 SetPixelBlue(draw_image,ScaleShortToQuantum(
2518 pixel->pen_color.blue),q);
2519 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2520 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2522 q+=GetPixelChannels(draw_image);
2524 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2527 draw_view=DestroyCacheView(draw_view);
2528 XDestroyImage(draw_ximage);
2530 Determine draw geometry.
2532 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2533 if ((width != (unsigned int) draw_image->columns) ||
2534 (height != (unsigned int) draw_image->rows))
2537 image_geometry[MaxTextExtent];
2542 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
2544 (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2547 if (draw_info->degrees != 0.0)
2561 rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
2562 if (rotate_image == (Image *) NULL)
2563 return(MagickFalse);
2564 draw_image=DestroyImage(draw_image);
2565 draw_image=rotate_image;
2567 Annotation is relative to the degree of rotation.
2569 normalized_degrees=draw_info->degrees;
2570 while (normalized_degrees < -45.0)
2571 normalized_degrees+=360.0;
2572 for (rotations=0; normalized_degrees > 45.0; rotations++)
2573 normalized_degrees-=90.0;
2574 switch (rotations % 4)
2584 x=x-(int) draw_image->columns/2;
2585 y=y+(int) draw_image->columns/2;
2593 x=x-(int) draw_image->columns;
2601 x=x-(int) draw_image->columns/2;
2602 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2608 Composite text onto the image.
2610 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2611 for (y=0; y < (int) draw_image->rows; y++)
2619 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2621 if (q == (Quantum *) NULL)
2623 for (x=0; x < (int) draw_image->columns; x++)
2625 if (GetPixelAlpha(image,q) != TransparentAlpha)
2626 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2627 q+=GetPixelChannels(draw_image);
2629 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2632 draw_view=DestroyCacheView(draw_view);
2633 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2634 if (draw_info->stencil == TransparentStencil)
2635 (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
2636 (ssize_t) x,(ssize_t) y,exception);
2639 alpha_trait=image->alpha_trait;
2640 (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
2641 (ssize_t) x,(ssize_t) y,exception);
2642 image->alpha_trait=alpha_trait;
2644 draw_image=DestroyImage(draw_image);
2649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2659 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2660 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2661 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it
2664 % The format of the XError function is:
2666 % int XError(display,error)
2668 % A description of each parameter follows:
2670 % o display: Specifies a pointer to the Display structure; returned from
2673 % o error: Specifies the error event.
2677 #if defined(__cplusplus) || defined(c_plusplus)
2681 MagickExport int XError(Display *display,XErrorEvent *error)
2683 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2684 assert(display != (Display *) NULL);
2685 assert(error != (XErrorEvent *) NULL);
2686 xerror_alert=MagickTrue;
2687 switch (error->request_code)
2691 if ((int) error->error_code == BadDrawable)
2692 return(MagickFalse);
2695 case X_GetWindowAttributes:
2698 if ((int) error->error_code == BadWindow)
2699 return(MagickFalse);
2704 if ((int) error->error_code == BadValue)
2705 return(MagickFalse);
2712 #if defined(__cplusplus) || defined(c_plusplus)
2717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2721 % X F r e e R e s o u r c e s %
2725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2727 % XFreeResources() frees X11 resources.
2729 % The format of the XFreeResources method is:
2731 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2732 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2733 % XResourceInfo *resource_info,XWindowInfo *window_info)
2734 % resource_info,window_info)
2736 % A description of each parameter follows:
2738 % o display: Specifies a connection to an X server; returned from
2741 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2742 % returned from XGetVisualInfo.
2744 % o map_info: If map_type is specified, this structure is initialized
2745 % with info from the Standard Colormap.
2747 % o pixel: Specifies a pointer to a XPixelInfo structure.
2749 % o font_info: Specifies a pointer to a XFontStruct structure.
2751 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2753 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2756 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2757 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2758 XResourceInfo *resource_info,XWindowInfo *window_info)
2760 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2761 assert(display != (Display *) NULL);
2762 assert(resource_info != (XResourceInfo *) NULL);
2763 if (window_info != (XWindowInfo *) NULL)
2768 if (window_info->ximage != (XImage *) NULL)
2769 XDestroyImage(window_info->ximage);
2770 if (window_info->id != (Window) NULL)
2773 Free destroy window and free cursors.
2775 if (window_info->id != XRootWindow(display,visual_info->screen))
2776 (void) XDestroyWindow(display,window_info->id);
2777 if (window_info->annotate_context != (GC) NULL)
2778 (void) XFreeGC(display,window_info->annotate_context);
2779 if (window_info->highlight_context != (GC) NULL)
2780 (void) XFreeGC(display,window_info->highlight_context);
2781 if (window_info->widget_context != (GC) NULL)
2782 (void) XFreeGC(display,window_info->widget_context);
2783 if (window_info->cursor != (Cursor) NULL)
2784 (void) XFreeCursor(display,window_info->cursor);
2785 window_info->cursor=(Cursor) NULL;
2786 if (window_info->busy_cursor != (Cursor) NULL)
2787 (void) XFreeCursor(display,window_info->busy_cursor);
2788 window_info->busy_cursor=(Cursor) NULL;
2794 if (font_info != (XFontStruct *) NULL)
2796 (void) XFreeFont(display,font_info);
2797 font_info=(XFontStruct *) NULL;
2799 if (map_info != (XStandardColormap *) NULL)
2802 Free X Standard Colormap.
2804 if (resource_info->map_type == (char *) NULL)
2805 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2806 (void) XFree((void *) map_info);
2811 if (visual_info != (XVisualInfo *) NULL)
2812 (void) XFree((void *) visual_info);
2813 if (resource_info->close_server != MagickFalse)
2814 (void) XCloseDisplay(display);
2818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2822 % X F r e e S t a n d a r d C o l o r m a p %
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2828 % XFreeStandardColormap() frees an X11 colormap.
2830 % The format of the XFreeStandardColormap method is:
2832 % void XFreeStandardColormap(Display *display,
2833 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2834 % XPixelInfo *pixel)
2836 % A description of each parameter follows:
2838 % o display: Specifies a connection to an X server; returned from
2841 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2842 % returned from XGetVisualInfo.
2844 % o map_info: If map_type is specified, this structure is initialized
2845 % with info from the Standard Colormap.
2847 % o pixel: Specifies a pointer to a XPixelInfo structure.
2850 MagickPrivate void XFreeStandardColormap(Display *display,
2851 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2856 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2857 assert(display != (Display *) NULL);
2858 assert(visual_info != (XVisualInfo *) NULL);
2859 assert(map_info != (XStandardColormap *) NULL);
2860 (void) XFlush(display);
2861 if (map_info->colormap != (Colormap) NULL)
2863 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2864 (void) XFreeColormap(display,map_info->colormap);
2866 if (pixel != (XPixelInfo *) NULL)
2867 if ((visual_info->klass != TrueColor) &&
2868 (visual_info->klass != DirectColor))
2869 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2870 (int) pixel->colors,0);
2872 map_info->colormap=(Colormap) NULL;
2873 if (pixel != (XPixelInfo *) NULL)
2875 if (pixel->pixels != (unsigned long *) NULL)
2876 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2877 pixel->pixels=(unsigned long *) NULL;
2882 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2886 % X G e t A n n o t a t e I n f o %
2890 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2892 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2894 % The format of the XGetAnnotateInfo method is:
2896 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2898 % A description of each parameter follows:
2900 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2903 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2906 Initialize annotate structure.
2908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2909 assert(annotate_info != (XAnnotateInfo *) NULL);
2912 annotate_info->width=0;
2913 annotate_info->height=0;
2914 annotate_info->stencil=ForegroundStencil;
2915 annotate_info->degrees=0.0;
2916 annotate_info->font_info=(XFontStruct *) NULL;
2917 annotate_info->text=(char *) NULL;
2918 *annotate_info->geometry='\0';
2919 annotate_info->previous=(XAnnotateInfo *) NULL;
2920 annotate_info->next=(XAnnotateInfo *) NULL;
2921 (void) XSupportsLocale();
2922 (void) XSetLocaleModifiers("");
2926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2930 % X G e t M a p I n f o %
2934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2936 % XGetMapInfo() initializes the XStandardColormap structure.
2938 % The format of the XStandardColormap method is:
2940 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2941 % XStandardColormap *map_info)
2943 % A description of each parameter follows:
2945 % o colormap: Specifies the ID of the X server colormap.
2947 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2948 % returned from XGetVisualInfo.
2950 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2953 MagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
2954 const Colormap colormap,XStandardColormap *map_info)
2957 Initialize map info.
2959 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2960 assert(visual_info != (XVisualInfo *) NULL);
2961 assert(map_info != (XStandardColormap *) NULL);
2962 map_info->colormap=colormap;
2963 map_info->red_max=visual_info->red_mask;
2964 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2965 if (map_info->red_max != 0)
2966 while ((map_info->red_max & 0x01) == 0)
2968 map_info->red_max>>=1;
2969 map_info->red_mult<<=1;
2971 map_info->green_max=visual_info->green_mask;
2972 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2973 if (map_info->green_max != 0)
2974 while ((map_info->green_max & 0x01) == 0)
2976 map_info->green_max>>=1;
2977 map_info->green_mult<<=1;
2979 map_info->blue_max=visual_info->blue_mask;
2980 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2981 if (map_info->blue_max != 0)
2982 while ((map_info->blue_max & 0x01) == 0)
2984 map_info->blue_max>>=1;
2985 map_info->blue_mult<<=1;
2987 map_info->base_pixel=0;
2991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2995 % X G e t P i x e l I n f o %
2999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3001 % XGetPixelInfo() initializes the PixelInfo structure.
3003 % The format of the XGetPixelInfo method is:
3005 % void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
3006 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
3007 % Image *image,XPixelInfo *pixel)
3010 % A description of each parameter follows:
3012 % o display: Specifies a connection to an X server; returned from
3015 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
3016 % returned from XGetVisualInfo.
3018 % o map_info: If map_type is specified, this structure is initialized
3019 % with info from the Standard Colormap.
3021 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3023 % o image: the image.
3025 % o pixel: Specifies a pointer to a XPixelInfo structure.
3028 MagickPrivate void XGetPixelInfo(Display *display,
3029 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3030 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3033 *PenColors[MaxNumberPens]=
3035 "#000000000000", /* black */
3036 "#00000000ffff", /* blue */
3037 "#0000ffffffff", /* cyan */
3038 "#0000ffff0000", /* green */
3039 "#bdbdbdbdbdbd", /* gray */
3040 "#ffff00000000", /* red */
3041 "#ffff0000ffff", /* magenta */
3042 "#ffffffff0000", /* yellow */
3043 "#ffffffffffff", /* white */
3044 "#bdbdbdbdbdbd", /* gray */
3045 "#bdbdbdbdbdbd" /* gray */
3065 Initialize pixel info.
3067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3068 assert(display != (Display *) NULL);
3069 assert(visual_info != (XVisualInfo *) NULL);
3070 assert(map_info != (XStandardColormap *) NULL);
3071 assert(resource_info != (XResourceInfo *) NULL);
3072 assert(pixel != (XPixelInfo *) NULL);
3074 if (image != (Image *) NULL)
3075 if (image->storage_class == PseudoClass)
3076 pixel->colors=(ssize_t) image->colors;
3077 packets=(unsigned int)
3078 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3079 if (pixel->pixels != (unsigned long *) NULL)
3080 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3081 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3082 sizeof(pixel->pixels));
3083 if (pixel->pixels == (unsigned long *) NULL)
3084 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3087 Set foreground color.
3089 colormap=map_info->colormap;
3090 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3091 &pixel->foreground_color);
3092 status=XParseColor(display,colormap,resource_info->foreground_color,
3093 &pixel->foreground_color);
3094 if (status == False)
3095 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3096 resource_info->foreground_color);
3097 pixel->foreground_color.pixel=
3098 XStandardPixel(map_info,&pixel->foreground_color);
3099 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3101 Set background color.
3103 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3104 status=XParseColor(display,colormap,resource_info->background_color,
3105 &pixel->background_color);
3106 if (status == False)
3107 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3108 resource_info->background_color);
3109 pixel->background_color.pixel=
3110 XStandardPixel(map_info,&pixel->background_color);
3111 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3115 (void) XParseColor(display,colormap,(char *) BorderColor,
3116 &pixel->border_color);
3117 status=XParseColor(display,colormap,resource_info->border_color,
3118 &pixel->border_color);
3119 if (status == False)
3120 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3121 resource_info->border_color);
3122 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3123 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3127 pixel->matte_color=pixel->background_color;
3128 if (resource_info->matte_color != (char *) NULL)
3131 Matte color is specified as a X resource or command line argument.
3133 status=XParseColor(display,colormap,resource_info->matte_color,
3134 &pixel->matte_color);
3135 if (status == False)
3136 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3137 resource_info->matte_color);
3138 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3139 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3142 Set highlight color.
3144 pixel->highlight_color.red=(unsigned short) ((
3145 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3146 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3147 pixel->highlight_color.green=(unsigned short) ((
3148 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3149 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3150 pixel->highlight_color.blue=(unsigned short) ((
3151 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3152 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3153 pixel->highlight_color.pixel=
3154 XStandardPixel(map_info,&pixel->highlight_color);
3155 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3159 pixel->shadow_color.red=(unsigned short) (((double)
3160 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3161 pixel->shadow_color.green=(unsigned short) (((double)
3162 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3163 pixel->shadow_color.blue=(unsigned short) (((double)
3164 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3165 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3166 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3170 pixel->depth_color.red=(unsigned short) (((double)
3171 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3172 pixel->depth_color.green=(unsigned short) (((double)
3173 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3174 pixel->depth_color.blue=(unsigned short) (((double)
3175 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3176 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3177 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3181 pixel->trough_color.red=(unsigned short) (((double)
3182 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3183 pixel->trough_color.green=(unsigned short) (((double)
3184 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3185 pixel->trough_color.blue=(unsigned short) (((double)
3186 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3187 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3188 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3192 for (i=0; i < MaxNumberPens; i++)
3194 (void) XParseColor(display,colormap,(char *) PenColors[i],
3195 &pixel->pen_colors[i]);
3196 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3197 &pixel->pen_colors[i]);
3198 if (status == False)
3199 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3200 resource_info->pen_colors[i]);
3201 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3202 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3204 pixel->box_color=pixel->background_color;
3205 pixel->pen_color=pixel->foreground_color;
3208 if (image != (Image *) NULL)
3210 if ((resource_info->gamma_correct != MagickFalse) &&
3211 (image->gamma != 0.0))
3220 Initialize map relative to display and image gamma.
3222 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3223 red_gamma=geometry_info.rho;
3224 green_gamma=geometry_info.sigma;
3225 if ((flags & SigmaValue) == 0)
3226 green_gamma=red_gamma;
3227 blue_gamma=geometry_info.xi;
3228 if ((flags & XiValue) == 0)
3229 blue_gamma=red_gamma;
3230 red_gamma*=image->gamma;
3231 green_gamma*=image->gamma;
3232 blue_gamma*=image->gamma;
3234 if (image->storage_class == PseudoClass)
3237 Initialize pixel array for images of type PseudoClass.
3239 for (i=0; i < (ssize_t) image->colors; i++)
3240 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3241 for (i=0; i < MaxNumberPens; i++)
3242 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3243 pixel->colors+=MaxNumberPens;
3249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3253 % X G e t R e s o u r c e C l a s s %
3257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3259 % XGetResourceClass() queries the X server for the specified resource name or
3260 % class. If the resource name or class is not defined in the database, the
3261 % supplied default value is returned.
3263 % The format of the XGetResourceClass method is:
3265 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3266 % const char *keyword,char *resource_default)
3268 % A description of each parameter follows:
3270 % o database: Specifies a resource database; returned from
3271 % XrmGetStringDatabase.
3273 % o client_name: Specifies the application name used to retrieve resource
3274 % info from the X server database.
3276 % o keyword: Specifies the keyword of the value being retrieved.
3278 % o resource_default: Specifies the default value to return if the query
3279 % fails to find the specified keyword/class.
3282 MagickExport char *XGetResourceClass(XrmDatabase database,
3283 const char *client_name,const char *keyword,char *resource_default)
3286 resource_class[MaxTextExtent],
3287 resource_name[MaxTextExtent];
3298 if (database == (XrmDatabase) NULL)
3299 return(resource_default);
3300 *resource_name='\0';
3301 *resource_class='\0';
3302 if (keyword != (char *) NULL)
3309 Initialize resource keyword and class.
3311 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
3312 client_name,keyword);
3313 c=(int) (*client_name);
3314 if ((c >= XK_a) && (c <= XK_z))
3317 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3318 c-=(XK_agrave-XK_Agrave);
3320 if ((c >= XK_oslash) && (c <= XK_thorn))
3321 c-=(XK_oslash-XK_Ooblique);
3323 if ((k >= XK_a) && (k <= XK_z))
3326 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3327 k-=(XK_agrave-XK_Agrave);
3329 if ((k >= XK_oslash) && (k <= XK_thorn))
3330 k-=(XK_oslash-XK_Ooblique);
3331 (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3332 client_name+1,k,keyword+1);
3334 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3336 if (status == False)
3337 return(resource_default);
3338 return(resource_value.addr);
3342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3346 % X G e t R e s o u r c e D a t a b a s e %
3350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3352 % XGetResourceDatabase() creates a new resource database and initializes it.
3354 % The format of the XGetResourceDatabase method is:
3356 % XrmDatabase XGetResourceDatabase(Display *display,
3357 % const char *client_name)
3359 % A description of each parameter follows:
3361 % o database: XGetResourceDatabase() returns the database after it is
3364 % o display: Specifies a connection to an X server; returned from
3367 % o client_name: Specifies the application name used to retrieve resource
3368 % info from the X server database.
3371 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3372 const char *client_name)
3375 filename[MaxTextExtent];
3387 if (display == (Display *) NULL)
3388 return((XrmDatabase) NULL);
3389 assert(client_name != (char *) NULL);
3391 Initialize resource database.
3394 (void) XGetDefault(display,(char *) client_name,"dummy");
3395 resource_database=XrmGetDatabase(display);
3397 Combine application database.
3399 if (client_name != (char *) NULL)
3402 Get basename of client.
3404 p=client_name+(strlen(client_name)-1);
3405 while ((p > client_name) && (*p != '/'))
3410 c=(int) (*client_name);
3411 if ((c >= XK_a) && (c <= XK_z))
3414 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3415 c-=(XK_agrave-XK_Agrave);
3417 if ((c >= XK_oslash) && (c <= XK_thorn))
3418 c-=(XK_oslash-XK_Ooblique);
3419 #if defined(X11_APPLICATION_PATH)
3420 (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
3421 X11_APPLICATION_PATH,c,client_name+1);
3422 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3424 if (XResourceManagerString(display) != (char *) NULL)
3427 Combine server database.
3429 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3430 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3433 Merge user preferences database.
3435 #if defined(X11_PREFERENCES_PATH)
3436 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
3437 X11_PREFERENCES_PATH,client_name);
3438 ExpandFilename(filename);
3439 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3441 return(resource_database);
3445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3449 % X G e t R e s o u r c e I n f o %
3453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3455 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3457 % The format of the XGetResourceInfo method is:
3459 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3460 % const char *client_name,XResourceInfo *resource_info)
3462 % A description of each parameter follows:
3464 % o image_info: the image info.
3466 % o database: Specifies a resource database; returned from
3467 % XrmGetStringDatabase.
3469 % o client_name: Specifies the application name used to retrieve
3470 % resource info from the X server database.
3472 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3475 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3476 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3487 Initialize resource info fields.
3489 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3490 assert(resource_info != (XResourceInfo *) NULL);
3491 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3492 resource_info->resource_database=database;
3493 resource_info->image_info=(ImageInfo *) image_info;
3494 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3495 XMagickProgressMonitor,(void *) NULL);
3496 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3497 resource_info->close_server=MagickTrue;
3498 resource_info->client_name=AcquireString(client_name);
3499 resource_value=XGetResourceClass(database,client_name,"backdrop",
3501 resource_info->backdrop=IsStringTrue(resource_value);
3502 resource_info->background_color=XGetResourceInstance(database,client_name,
3503 "background",(char *) "#d6d6d6d6d6d6");
3504 resource_info->border_color=XGetResourceInstance(database,client_name,
3505 "borderColor",BorderColor);
3506 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3508 resource_info->border_width=(unsigned int) StringToUnsignedLong(
3510 resource_value=XGetResourceClass(database,client_name,"colormap",
3512 resource_info->colormap=UndefinedColormap;
3513 if (LocaleCompare("private",resource_value) == 0)
3514 resource_info->colormap=PrivateColormap;
3515 if (LocaleCompare("shared",resource_value) == 0)
3516 resource_info->colormap=SharedColormap;
3517 if (resource_info->colormap == UndefinedColormap)
3518 ThrowXWindowException(OptionError,"UnrecognizedColormapType",
3520 resource_value=XGetResourceClass(database,client_name,
3521 "colorRecovery",(char *) "False");
3522 resource_info->color_recovery=IsStringTrue(resource_value);
3523 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3525 resource_info->confirm_exit=IsStringTrue(resource_value);
3526 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3528 resource_info->confirm_edit=IsStringTrue(resource_value);
3529 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3530 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3531 resource_info->display_gamma=XGetResourceClass(database,client_name,
3532 "displayGamma",(char *) "2.2");
3533 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3535 resource_info->display_warnings=IsStringTrue(resource_value);
3536 resource_info->font=XGetResourceClass(database,client_name,"font",
3538 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3539 resource_info->font);
3540 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3542 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3543 (char *) "variable");
3544 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3546 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3548 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3549 (char *) "7x13bold");
3550 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3551 (char *) "8x13bold");
3552 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3553 (char *) "9x15bold");
3554 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3556 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3558 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3560 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3562 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3563 "foreground",ForegroundColor);
3564 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3566 resource_info->gamma_correct=IsStringTrue(resource_value);
3567 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3568 client_name,"geometry",(char *) NULL));
3569 resource_value=XGetResourceClass(database,client_name,"gravity",
3571 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3572 MagickFalse,resource_value);
3573 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3575 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3576 "iconGeometry",(char *) NULL);
3577 resource_value=XGetResourceClass(database,client_name,"iconic",
3579 resource_info->iconic=IsStringTrue(resource_value);
3580 resource_value=XGetResourceClass(database,client_name,"immutable",
3581 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3583 resource_info->immutable=IsStringTrue(resource_value);
3584 resource_value=XGetResourceClass(database,client_name,"magnify",
3586 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3587 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3589 resource_info->matte_color=XGetResourceInstance(database,client_name,
3590 "mattecolor",(char *) NULL);
3591 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3592 "name",(char *) NULL));
3593 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3595 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3597 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3599 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3601 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3603 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3605 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3606 (char *) "magenta");
3607 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3609 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3611 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3613 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3615 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3616 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3617 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3618 resource_info->quantum=StringToLong(resource_value);
3619 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3620 "font",(char *) "fixed");
3621 resource_info->text_font=XGetResourceClass(database,client_name,
3622 "textFontList",resource_info->text_font);
3623 resource_info->title=XGetResourceClass(database,client_name,"title",
3625 resource_value=XGetResourceClass(database,client_name,"undoCache",
3627 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3628 resource_value=XGetResourceClass(database,client_name,"update",
3630 resource_info->update=IsStringTrue(resource_value);
3631 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3633 resource_info->use_pixmap=IsStringTrue(resource_value);
3634 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3636 resource_info->use_shared_memory=IsStringTrue(resource_value);
3637 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3639 resource_info->window_group=XGetResourceClass(database,client_name,
3640 "windowGroup",(char *) NULL);
3641 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3643 resource_info->write_filename=XGetResourceClass(database,client_name,
3644 "writeFilename",(char *) NULL);
3648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3652 % X G e t R e s o u r c e I n s t a n c e %
3656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3658 % XGetResourceInstance() queries the X server for the specified resource name.
3659 % If the resource name is not defined in the database, the supplied default
3660 % value is returned.
3662 % The format of the XGetResourceInstance method is:
3664 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3665 % const char *keyword,const char *resource_default)
3667 % A description of each parameter follows:
3669 % o database: Specifies a resource database; returned from
3670 % XrmGetStringDatabase.
3672 % o client_name: Specifies the application name used to retrieve
3673 % resource info from the X server database.
3675 % o keyword: Specifies the keyword of the value being retrieved.
3677 % o resource_default: Specifies the default value to return if the query
3678 % fails to find the specified keyword/class.
3681 MagickExport char *XGetResourceInstance(XrmDatabase database,
3682 const char *client_name,const char *keyword,const char *resource_default)
3686 resource_name[MaxTextExtent];
3694 if (database == (XrmDatabase) NULL)
3695 return((char *) resource_default);
3696 *resource_name='\0';
3697 if (keyword != (char *) NULL)
3698 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",client_name,
3700 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3702 if (status == False)
3703 return((char *) resource_default);
3704 return(resource_value.addr);
3708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3712 % X G e t S c r e e n D e n s i t y %
3716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3718 % XGetScreenDensity() returns the density of the X server screen in
3721 % The format of the XGetScreenDensity method is:
3723 % char *XGetScreenDensity(Display *display)
3725 % A description of each parameter follows:
3727 % o density: XGetScreenDensity() returns the density of the X screen in
3730 % o display: Specifies a connection to an X server; returned from
3734 MagickExport char *XGetScreenDensity(Display *display)
3737 density[MaxTextExtent];
3744 Set density as determined by screen size.
3746 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3747 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3748 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3749 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3750 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",x_density,
3752 return(GetPageGeometry(density));
3756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3760 + X G e t S u b w i n d o w %
3764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3766 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3767 % pointer and a button press.
3769 % The format of the XGetSubwindow method is:
3771 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3773 % A description of each parameter follows:
3775 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3776 % otherwise the subwindow is returned.
3778 % o display: Specifies a connection to an X server; returned from
3781 % o window: Specifies a pointer to a Window.
3783 % o x: the x coordinate of the pointer relative to the origin of the
3786 % o y: the y coordinate of the pointer relative to the origin of the
3790 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3803 assert(display != (Display *) NULL);
3804 source_window=XRootWindow(display,XDefaultScreen(display));
3805 if (window == (Window) NULL)
3806 return(source_window);
3807 target_window=window;
3810 status=XTranslateCoordinates(display,source_window,window,x,y,
3811 &x_offset,&y_offset,&target_window);
3814 if (target_window == (Window) NULL)
3816 source_window=window;
3817 window=target_window;
3821 if (target_window == (Window) NULL)
3822 target_window=window;
3823 return(target_window);
3827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3831 % X G e t W i n d o w C o l o r %
3835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3837 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3840 % The format of the XGetWindowColor method is:
3842 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3843 % char *name,ExceptionInfo *exception)
3845 % A description of each parameter follows:
3847 % o display: Specifies a connection to an X server; returned from
3850 % o windows: Specifies a pointer to a XWindows structure.
3852 % o name: the name of the color if found in the X Color Database is
3853 % returned in this character string.
3855 % o exception: return any errors or warnings in this structure.
3858 MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
3859 XWindows *windows,char *name,ExceptionInfo *exception)
3890 Choose a pixel from the X server.
3892 assert(display != (Display *) NULL);
3893 assert(name != (char *) NULL);
3894 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3896 target_window=XSelectWindow(display,&crop_info);
3897 if (target_window == (Window) NULL)
3898 return(MagickFalse);
3899 root_window=XRootWindow(display,XDefaultScreen(display));
3900 client_window=target_window;
3901 if (target_window != root_window)
3909 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3910 if (status != False)
3912 client_window=XClientWindow(display,target_window);
3913 target_window=client_window;
3917 Verify window is viewable.
3919 status=XGetWindowAttributes(display,target_window,&window_attributes);
3920 if ((status == False) || (window_attributes.map_state != IsViewable))
3921 return(MagickFalse);
3925 (void) XTranslateCoordinates(display,root_window,target_window,
3926 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3927 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3928 if (ximage == (XImage *) NULL)
3929 return(MagickFalse);
3930 color.pixel=XGetPixel(ximage,0,0);
3931 XDestroyImage(ximage);
3933 Match color against the color database.
3935 (void) XQueryColor(display,window_attributes.colormap,&color);
3936 pixel.red=(double) ScaleShortToQuantum(color.red);
3937 pixel.green=(double) ScaleShortToQuantum(color.green);
3938 pixel.blue=(double) ScaleShortToQuantum(color.blue);
3939 pixel.alpha=OpaqueAlpha;
3940 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3946 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3950 + X G e t W i n d o w I m a g e %
3954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3956 % XGetWindowImage() reads an image from the target X window and returns it.
3957 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3958 % target image with each child image in an optimized fashion. Any child
3959 % window that have the same visual, colormap, and are contained by its parent
3962 % The format of the XGetWindowImage method is:
3964 % Image *XGetWindowImage(Display *display,const Window window,
3965 % const unsigned int borders,const unsigned int level,
3966 % ExceptionInfo *exception)
3968 % A description of each parameter follows:
3970 % o display: Specifies a connection to an X server; returned from
3973 % o window: Specifies the window to obtain the image from.
3975 % o borders: Specifies whether borders pixels are to be saved with
3978 % o level: Specifies an unsigned integer representing the level of
3979 % decent in the window hierarchy. This value must be zero or one on
3980 % the initial call to XGetWindowImage. A value of zero returns after
3981 % one call. A value of one causes the function to descend the window
3982 % hierarchy and overlay the target image with each subwindow image.
3984 % o exception: return any errors or warnings in this structure.
3987 static Image *XGetWindowImage(Display *display,const Window window,
3988 const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
3990 typedef struct _ColormapInfo
3998 struct _ColormapInfo
4002 typedef struct _WindowInfo
4038 *colormap_info = (ColormapInfo *) NULL;
4058 Verify window is viewable.
4060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4061 assert(display != (Display *) NULL);
4062 status=XGetWindowAttributes(display,window,&window_attributes);
4063 if ((status == False) || (window_attributes.map_state != IsViewable))
4064 return((Image *) NULL);
4066 Cropping rectangle is relative to root window.
4068 root_window=XRootWindow(display,XDefaultScreen(display));
4069 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4071 crop_info.x=(ssize_t) x_offset;
4072 crop_info.y=(ssize_t) y_offset;
4073 crop_info.width=(size_t) window_attributes.width;
4074 crop_info.height=(size_t) window_attributes.height;
4075 if (borders != MagickFalse)
4078 Include border in image.
4080 crop_info.x-=(ssize_t) window_attributes.border_width;
4081 crop_info.y-=(ssize_t) window_attributes.border_width;
4082 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4083 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4086 Crop to root window.
4088 if (crop_info.x < 0)
4090 crop_info.width+=crop_info.x;
4093 if (crop_info.y < 0)
4095 crop_info.height+=crop_info.y;
4098 display_width=XDisplayWidth(display,XDefaultScreen(display));
4099 if ((int) (crop_info.x+crop_info.width) > display_width)
4100 crop_info.width=(size_t) (display_width-crop_info.x);
4101 display_height=XDisplayHeight(display,XDefaultScreen(display));
4102 if ((int) (crop_info.y+crop_info.height) > display_height)
4103 crop_info.height=(size_t) (display_height-crop_info.y);
4105 Initialize window info attributes.
4107 if (number_windows >= max_windows)
4110 Allocate or resize window info buffer.
4113 if (window_info == (WindowInfo *) NULL)
4114 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4115 sizeof(*window_info));
4117 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4118 max_windows,sizeof(*window_info));
4120 if (window_info == (WindowInfo *) NULL)
4122 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
4123 return((Image *) NULL);
4125 id=number_windows++;
4126 window_info[id].window=window;
4127 window_info[id].visual=window_attributes.visual;
4128 window_info[id].colormap=window_attributes.colormap;
4129 window_info[id].bounds.x1=(short) crop_info.x;
4130 window_info[id].bounds.y1=(short) crop_info.y;
4131 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4132 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4133 crop_info.x-=x_offset;
4134 crop_info.y-=y_offset;
4135 window_info[id].crop_info=crop_info;
4145 Descend the window hierarchy.
4147 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4148 &children,&number_children);
4149 for (i=0; i < id; i++)
4150 if ((window_info[i].window == window_info[id].parent) &&
4151 (window_info[i].visual == window_info[id].visual) &&
4152 (window_info[i].colormap == window_info[id].colormap))
4154 if ((window_info[id].bounds.x1 < window_info[i].bounds.x1) ||
4155 (window_info[id].bounds.x2 > window_info[i].bounds.x2) ||
4156 (window_info[id].bounds.y1 < window_info[i].bounds.y1) ||
4157 (window_info[id].bounds.y2 > window_info[i].bounds.y2))
4160 Eliminate windows not circumscribed by their parent.
4166 if ((status == True) && (number_children != 0))
4168 for (i=0; i < (int) number_children; i++)
4169 (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
4171 (void) XFree((void *) children);
4212 Get X image for each window in the list.
4214 image=NewImageList();
4215 for (id=0; id < number_windows; id++)
4218 Does target window intersect top level window?
4220 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4221 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4222 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4223 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4224 MagickTrue : MagickFalse;
4226 Is target window contained by another window with the same colormap?
4228 for (j=0; j < id; j++)
4229 if ((window_info[id].visual == window_info[j].visual) &&
4230 (window_info[id].colormap == window_info[j].colormap))
4232 if ((window_info[id].bounds.x1 >= window_info[j].bounds.x1) &&
4233 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4234 (window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
4235 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4238 if (import == MagickFalse)
4243 ximage=XGetImage(display,window_info[id].window,(int)
4244 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4245 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4246 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4247 if (ximage == (XImage *) NULL)
4250 Initialize window colormap.
4253 colors=(XColor *) NULL;
4254 if (window_info[id].colormap != (Colormap) NULL)
4260 Search colormap list for window colormap.
4262 number_colors=(unsigned int) window_info[id].visual->map_entries;
4263 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4264 if (p->colormap == window_info[id].colormap)
4266 if (p == (ColormapInfo *) NULL)
4269 Get the window colormap.
4271 colors=(XColor *) AcquireQuantumMemory(number_colors,
4273 if (colors == (XColor *) NULL)
4275 XDestroyImage(ximage);
4276 return((Image *) NULL);
4278 if ((window_info[id].visual->klass != DirectColor) &&
4279 (window_info[id].visual->klass != TrueColor))
4280 for (i=0; i < (int) number_colors; i++)
4282 colors[i].pixel=(size_t) i;
4296 DirectColor or TrueColor visual.
4301 red_bit=window_info[id].visual->red_mask &
4302 (~(window_info[id].visual->red_mask)+1);
4303 green_bit=window_info[id].visual->green_mask &
4304 (~(window_info[id].visual->green_mask)+1);
4305 blue_bit=window_info[id].visual->blue_mask &
4306 (~(window_info[id].visual->blue_mask)+1);
4307 for (i=0; i < (int) number_colors; i++)
4309 colors[i].pixel=(unsigned long) (red | green | blue);
4312 if (red > window_info[id].visual->red_mask)
4315 if (green > window_info[id].visual->green_mask)
4318 if (blue > window_info[id].visual->blue_mask)
4322 (void) XQueryColors(display,window_info[id].colormap,colors,
4323 (int) number_colors);
4325 Append colormap to colormap list.
4327 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4328 if (p == (ColormapInfo *) NULL)
4329 return((Image *) NULL);
4330 p->colormap=window_info[id].colormap;
4332 p->next=colormap_info;
4338 Allocate image structure.
4340 composite_image=AcquireImage((ImageInfo *) NULL,exception);
4341 if (composite_image == (Image *) NULL)
4343 XDestroyImage(ximage);
4344 return((Image *) NULL);
4347 Convert X image to MIFF format.
4349 if ((window_info[id].visual->klass != TrueColor) &&
4350 (window_info[id].visual->klass != DirectColor))
4351 composite_image->storage_class=PseudoClass;
4352 composite_image->columns=(size_t) ximage->width;
4353 composite_image->rows=(size_t) ximage->height;
4354 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4355 switch (composite_image->storage_class)
4373 Determine shift and mask for red, green, and blue.
4375 red_mask=window_info[id].visual->red_mask;
4377 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4382 green_mask=window_info[id].visual->green_mask;
4384 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4389 blue_mask=window_info[id].visual->blue_mask;
4391 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4397 Convert X image to DirectClass packets.
4399 if ((number_colors != 0) &&
4400 (window_info[id].visual->klass == DirectColor))
4401 for (y=0; y < (int) composite_image->rows; y++)
4403 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4404 composite_image->columns,1,exception);
4405 if (q == (Quantum *) NULL)
4407 for (x=0; x < (int) composite_image->columns; x++)
4409 pixel=XGetPixel(ximage,x,y);
4410 index=(pixel >> red_shift) & red_mask;
4411 SetPixelRed(composite_image,
4412 ScaleShortToQuantum(colors[index].red),q);
4413 index=(pixel >> green_shift) & green_mask;
4414 SetPixelGreen(composite_image,
4415 ScaleShortToQuantum(colors[index].green),q);
4416 index=(pixel >> blue_shift) & blue_mask;
4417 SetPixelBlue(composite_image,
4418 ScaleShortToQuantum(colors[index].blue),q);
4419 q+=GetPixelChannels(composite_image);
4421 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4422 if (status == MagickFalse)
4426 for (y=0; y < (int) composite_image->rows; y++)
4428 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4429 composite_image->columns,1,exception);
4430 if (q == (Quantum *) NULL)
4432 for (x=0; x < (int) composite_image->columns; x++)
4434 pixel=XGetPixel(ximage,x,y);
4435 color=(pixel >> red_shift) & red_mask;
4436 color=(65535UL*color)/red_mask;
4437 SetPixelRed(composite_image,
4438 ScaleShortToQuantum((unsigned short) color),q);
4439 color=(pixel >> green_shift) & green_mask;
4440 color=(65535UL*color)/green_mask;
4441 SetPixelGreen(composite_image,
4442 ScaleShortToQuantum((unsigned short) color),q);
4443 color=(pixel >> blue_shift) & blue_mask;
4444 color=(65535UL*color)/blue_mask;
4445 SetPixelBlue(composite_image,
4446 ScaleShortToQuantum((unsigned short) color),q);
4447 q+=GetPixelChannels(composite_image);
4449 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4450 if (status == MagickFalse)
4460 status=AcquireImageColormap(composite_image,number_colors,
4462 if (status == MagickFalse)
4464 XDestroyImage(ximage);
4465 composite_image=DestroyImage(composite_image);
4466 return((Image *) NULL);
4468 for (i=0; i < (int) composite_image->colors; i++)
4470 composite_image->colormap[colors[i].pixel].red=(double)
4471 ScaleShortToQuantum(colors[i].red);
4472 composite_image->colormap[colors[i].pixel].green=(double)
4473 ScaleShortToQuantum(colors[i].green);
4474 composite_image->colormap[colors[i].pixel].blue=(double)
4475 ScaleShortToQuantum(colors[i].blue);
4478 Convert X image to PseudoClass packets.
4480 for (y=0; y < (int) composite_image->rows; y++)
4482 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4483 composite_image->columns,1,exception);
4484 if (q == (Quantum *) NULL)
4486 for (x=0; x < (int) composite_image->columns; x++)
4488 index=(Quantum) XGetPixel(ximage,x,y);
4489 SetPixelIndex(composite_image,index,q);
4490 SetPixelInfoPixel(composite_image,
4491 composite_image->colormap+(ssize_t) index,q);
4492 q+=GetPixelChannels(composite_image);
4494 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4495 if (status == MagickFalse)
4501 composite_view=DestroyCacheView(composite_view);
4502 XDestroyImage(ximage);
4503 if (image == (Image *) NULL)
4505 image=composite_image;
4509 Composite any children in back-to-front order.
4511 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4512 &x_offset,&y_offset,&child);
4513 x_offset-=(int) crop_info.x;
4516 y_offset-=(int) crop_info.y;
4519 (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
4520 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4521 composite_image=DestroyImage(composite_image);
4524 Relinquish resources.
4526 while (colormap_info != (ColormapInfo *) NULL)
4528 next=colormap_info->next;
4529 colormap_info->colors=(XColor *) RelinquishMagickMemory(
4530 colormap_info->colors);
4531 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4535 Relinquish resources and restore initial state.
4537 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4540 colormap_info=(ColormapInfo *) NULL;
4543 return((Image *) NULL);
4547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4551 % X G e t W i n d o w I n f o %
4555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4557 % XGetWindowInfo() initializes the XWindowInfo structure.
4559 % The format of the XGetWindowInfo method is:
4561 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4562 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4563 % XResourceInfo *resource_info,XWindowInfo *window)
4564 % resource_info,window)
4566 % A description of each parameter follows:
4568 % o display: Specifies a connection to an X server; returned from
4571 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4572 % returned from XGetVisualInfo.
4574 % o map_info: If map_type is specified, this structure is initialized
4575 % with info from the Standard Colormap.
4577 % o pixel: Specifies a pointer to a XPixelInfo structure.
4579 % o font_info: Specifies a pointer to a XFontStruct structure.
4581 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4584 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4585 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4586 XResourceInfo *resource_info,XWindowInfo *window)
4589 Initialize window info.
4591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4592 assert(display != (Display *) NULL);
4593 assert(visual_info != (XVisualInfo *) NULL);
4594 assert(map_info != (XStandardColormap *) NULL);
4595 assert(pixel != (XPixelInfo *) NULL);
4596 assert(resource_info != (XResourceInfo *) NULL);
4597 assert(window != (XWindowInfo *) NULL);
4598 if (window->id != (Window) NULL)
4600 if (window->cursor != (Cursor) NULL)
4601 (void) XFreeCursor(display,window->cursor);
4602 if (window->busy_cursor != (Cursor) NULL)
4603 (void) XFreeCursor(display,window->busy_cursor);
4604 if (window->highlight_stipple != (Pixmap) NULL)
4605 (void) XFreePixmap(display,window->highlight_stipple);
4606 if (window->shadow_stipple != (Pixmap) NULL)
4607 (void) XFreePixmap(display,window->shadow_stipple);
4608 if (window->name == (char *) NULL)
4609 window->name=AcquireString("");
4610 if (window->icon_name == (char *) NULL)
4611 window->icon_name=AcquireString("");
4616 Initialize these attributes just once.
4618 window->id=(Window) NULL;
4619 if (window->name == (char *) NULL)
4620 window->name=AcquireString("");
4621 if (window->icon_name == (char *) NULL)
4622 window->icon_name=AcquireString("");
4623 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4624 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4625 window->ximage=(XImage *) NULL;
4626 window->matte_image=(XImage *) NULL;
4627 window->pixmap=(Pixmap) NULL;
4628 window->matte_pixmap=(Pixmap) NULL;
4629 window->mapped=MagickFalse;
4630 window->stasis=MagickFalse;
4631 window->shared_memory=MagickTrue;
4632 window->segment_info=(void *) NULL;
4633 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4638 if (window->segment_info == (void *) NULL)
4639 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4640 segment_info=(XShmSegmentInfo *) window->segment_info;
4641 segment_info[0].shmid=(-1);
4642 segment_info[0].shmaddr=(char *) NULL;
4643 segment_info[1].shmid=(-1);
4644 segment_info[1].shmaddr=(char *) NULL;
4649 Initialize these attributes every time function is called.
4651 window->screen=visual_info->screen;
4652 window->root=XRootWindow(display,visual_info->screen);
4653 window->visual=visual_info->visual;
4654 window->storage_class=(unsigned int) visual_info->klass;
4655 window->depth=(unsigned int) visual_info->depth;
4656 window->visual_info=visual_info;
4657 window->map_info=map_info;
4658 window->pixel_info=pixel;
4659 window->font_info=font_info;
4660 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4661 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4662 window->geometry=(char *) NULL;
4663 window->icon_geometry=(char *) NULL;
4664 if (resource_info->icon_geometry != (char *) NULL)
4665 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4666 window->crop_geometry=(char *) NULL;
4667 window->flags=(size_t) PSize;
4670 window->min_width=1;
4671 window->min_height=1;
4672 window->width_inc=1;
4673 window->height_inc=1;
4674 window->border_width=resource_info->border_width;
4675 window->annotate_context=pixel->annotate_context;
4676 window->highlight_context=pixel->highlight_context;
4677 window->widget_context=pixel->widget_context;
4678 window->shadow_stipple=(Pixmap) NULL;
4679 window->highlight_stipple=(Pixmap) NULL;
4680 window->use_pixmap=MagickTrue;
4681 window->immutable=MagickFalse;
4682 window->shape=MagickFalse;
4684 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4685 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4686 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4687 window->attributes.background_pixel=pixel->background_color.pixel;
4688 window->attributes.background_pixmap=(Pixmap) NULL;
4689 window->attributes.bit_gravity=ForgetGravity;
4690 window->attributes.backing_store=WhenMapped;
4691 window->attributes.save_under=MagickTrue;
4692 window->attributes.border_pixel=pixel->border_color.pixel;
4693 window->attributes.colormap=map_info->colormap;
4694 window->attributes.cursor=window->cursor;
4695 window->attributes.do_not_propagate_mask=NoEventMask;
4696 window->attributes.event_mask=NoEventMask;
4697 window->attributes.override_redirect=MagickFalse;
4698 window->attributes.win_gravity=NorthWestGravity;
4699 window->orphan=MagickFalse;
4703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4707 % X H i g h l i g h t E l l i p s e %
4711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4713 % XHighlightEllipse() puts a border on the X server around a region defined by
4716 % The format of the XHighlightEllipse method is:
4718 % void XHighlightEllipse(Display *display,Window window,
4719 % GC annotate_context,const RectangleInfo *highlight_info)
4721 % A description of each parameter follows:
4723 % o display: Specifies a connection to an X server; returned from
4726 % o window: Specifies a pointer to a Window structure.
4728 % o annotate_context: Specifies a pointer to a GC structure.
4730 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4731 % contains the extents of any highlighting rectangle.
4734 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4735 GC annotate_context,const RectangleInfo *highlight_info)
4737 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4738 assert(display != (Display *) NULL);
4739 assert(window != (Window) NULL);
4740 assert(annotate_context != (GC) NULL);
4741 assert(highlight_info != (RectangleInfo *) NULL);
4742 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4744 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4745 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4746 (unsigned int) highlight_info->height-1,0,360*64);
4747 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4748 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4749 (unsigned int) highlight_info->height-3,0,360*64);
4753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4757 % X H i g h l i g h t L i n e %
4761 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4763 % XHighlightLine() puts a border on the X server around a region defined by
4766 % The format of the XHighlightLine method is:
4768 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4769 % const XSegment *highlight_info)
4771 % A description of each parameter follows:
4773 % o display: Specifies a connection to an X server; returned from
4776 % o window: Specifies a pointer to a Window structure.
4778 % o annotate_context: Specifies a pointer to a GC structure.
4780 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4781 % contains the extents of any highlighting rectangle.
4784 MagickPrivate void XHighlightLine(Display *display,Window window,
4785 GC annotate_context,const XSegment *highlight_info)
4787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4788 assert(display != (Display *) NULL);
4789 assert(window != (Window) NULL);
4790 assert(annotate_context != (GC) NULL);
4791 assert(highlight_info != (XSegment *) NULL);
4792 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4793 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 % X H i g h l i g h t R e c t a n g l e %
4805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4807 % XHighlightRectangle() puts a border on the X server around a region defined
4808 % by highlight_info.
4810 % The format of the XHighlightRectangle method is:
4812 % void XHighlightRectangle(Display *display,Window window,
4813 % GC annotate_context,const RectangleInfo *highlight_info)
4815 % A description of each parameter follows:
4817 % o display: Specifies a connection to an X server; returned from
4820 % o window: Specifies a pointer to a Window structure.
4822 % o annotate_context: Specifies a pointer to a GC structure.
4824 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4825 % contains the extents of any highlighting rectangle.
4828 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4829 GC annotate_context,const RectangleInfo *highlight_info)
4831 assert(display != (Display *) NULL);
4832 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4833 assert(window != (Window) NULL);
4834 assert(annotate_context != (GC) NULL);
4835 assert(highlight_info != (RectangleInfo *) NULL);
4836 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4838 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4839 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4840 (unsigned int) highlight_info->height-1);
4841 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4842 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4843 (unsigned int) highlight_info->height-3);
4847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4851 % X I m p o r t I m a g e %
4855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4857 % XImportImage() reads an image from an X window.
4859 % The format of the XImportImage method is:
4861 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
4862 % ExceptionInfo *exception)
4864 % A description of each parameter follows:
4866 % o image_info: the image info.
4868 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4870 % o exception: return any errors or warnings in this structure.
4873 MagickExport Image *XImportImage(const ImageInfo *image_info,
4874 XImportInfo *ximage_info,ExceptionInfo *exception)
4907 Open X server connection.
4909 assert(image_info != (const ImageInfo *) NULL);
4910 assert(image_info->signature == MagickSignature);
4911 if (image_info->debug != MagickFalse)
4912 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4913 image_info->filename);
4914 assert(ximage_info != (XImportInfo *) NULL);
4915 display=XOpenDisplay(image_info->server_name);
4916 if (display == (Display *) NULL)
4918 ThrowXWindowException(XServerError,"UnableToOpenXServer",
4919 XDisplayName(image_info->server_name));
4920 return((Image *) NULL);
4923 Set our forgiving exception handler.
4925 (void) XSetErrorHandler(XError);
4927 Select target window.
4933 root=XRootWindow(display,XDefaultScreen(display));
4934 target=(Window) NULL;
4935 if ((image_info->filename != (char *) NULL) &&
4936 (*image_info->filename != '\0'))
4938 if (LocaleCompare(image_info->filename,"root") == 0)
4943 Select window by ID or name.
4945 if (isdigit((unsigned char) *image_info->filename) != 0)
4946 target=XWindowByID(display,root,(Window)
4947 strtol(image_info->filename,(char **) NULL,0));
4948 if (target == (Window) NULL)
4949 target=XWindowByName(display,root,image_info->filename);
4950 if (target == (Window) NULL)
4951 ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
4952 image_info->filename);
4956 If target window is not defined, interactively select one.
4958 prior_target=target;
4959 if (target == (Window) NULL)
4960 target=XSelectWindow(display,&crop_info);
4961 if (target == (Window) NULL)
4962 ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
4963 image_info->filename);
4964 client=target; /* obsolete */
4970 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4971 if (status != False)
4979 Find window manager frame.
4981 status=XQueryTree(display,target,&root,&parent,&children,&d);
4982 if ((status != False) && (children != (Window *) NULL))
4983 (void) XFree((char *) children);
4984 if ((status == False) || (parent == (Window) NULL) ||
4992 client=XClientWindow(display,target);
4993 if (ximage_info->frame == MagickFalse)
4995 if ((ximage_info->frame == MagickFalse) &&
4996 (prior_target != MagickFalse))
4997 target=prior_target;
5000 if (ximage_info->screen)
5012 Obtain window image directly from screen.
5014 status=XGetWindowAttributes(display,target,&window_attributes);
5015 if (status == False)
5017 ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
5018 image_info->filename);
5019 (void) XCloseDisplay(display);
5020 return((Image *) NULL);
5022 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5023 crop_info.x=(ssize_t) x;
5024 crop_info.y=(ssize_t) y;
5025 crop_info.width=(size_t) window_attributes.width;
5026 crop_info.height=(size_t) window_attributes.height;
5027 if (ximage_info->borders != 0)
5030 Include border in image.
5032 crop_info.x-=window_attributes.border_width;
5033 crop_info.y-=window_attributes.border_width;
5034 crop_info.width+=window_attributes.border_width << 1;
5035 crop_info.height+=window_attributes.border_width << 1;
5040 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
5043 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5044 if ((status == True) && (number_windows > 0))
5046 ximage_info->descend=MagickTrue;
5047 (void) XFree ((char *) children);
5049 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5050 if (number_colormaps > 0)
5052 if (number_colormaps > 1)
5053 ximage_info->descend=MagickTrue;
5054 (void) XFree((char *) colormaps);
5057 Alert the user not to alter the screen.
5059 if (ximage_info->silent == MagickFalse)
5060 (void) XBell(display,0);
5062 Get image by window id.
5064 (void) XGrabServer(display);
5065 image=XGetWindowImage(display,target,ximage_info->borders,
5066 ximage_info->descend ? 1U : 0U,exception);
5067 (void) XUngrabServer(display);
5068 if (image == (Image *) NULL)
5069 ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
5070 image_info->filename)
5073 (void) CopyMagickString(image->filename,image_info->filename,
5075 if ((crop_info.width != 0) && (crop_info.height != 0))
5082 Crop image as defined by the cropping rectangle.
5084 clone_image=CloneImage(image,0,0,MagickTrue,exception);
5085 if (clone_image != (Image *) NULL)
5087 crop_image=CropImage(clone_image,&crop_info,exception);
5088 if (crop_image != (Image *) NULL)
5090 image=DestroyImage(image);
5095 status=XGetWMName(display,target,&window_name);
5098 if ((image_info->filename != (char *) NULL) &&
5099 (*image_info->filename == '\0'))
5100 (void) CopyMagickString(image->filename,(char *) window_name.value,
5101 (size_t) window_name.nitems+1);
5102 (void) XFree((void *) window_name.value);
5105 if (ximage_info->silent == MagickFalse)
5108 Alert the user we're done.
5110 (void) XBell(display,0);
5111 (void) XBell(display,0);
5113 (void) XCloseDisplay(display);
5118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5122 % X I n i t i a l i z e W i n d o w s %
5126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5128 % XInitializeWindows() initializes the XWindows structure.
5130 % The format of the XInitializeWindows method is:
5132 % XWindows *XInitializeWindows(Display *display,
5133 % XResourceInfo *resource_info)
5135 % A description of each parameter follows:
5137 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5139 % o display: Specifies a connection to an X server; returned from
5142 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5145 MagickPrivate XWindows *XInitializeWindows(Display *display,
5146 XResourceInfo *resource_info)
5155 Allocate windows structure.
5157 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5158 if (windows == (XWindows *) NULL)
5160 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5162 return((XWindows *) NULL);
5164 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5165 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5166 sizeof(*windows->pixel_info));
5167 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5168 sizeof(*windows->icon_pixel));
5169 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5170 sizeof(*windows->icon_resources));
5171 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5172 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5173 (windows->icon_resources == (XResourceInfo *) NULL))
5175 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5177 return((XWindows *) NULL);
5180 Initialize windows structure.
5182 windows->display=display;
5183 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5184 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5185 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5186 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5187 windows->im_remote_command=
5188 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5189 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5190 windows->im_update_colormap=
5191 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5192 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5193 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5194 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5195 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5196 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5197 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5198 (void) XSynchronize(display,IsWindows95());
5200 if (IsEventLogging())
5202 (void) XSynchronize(display,MagickTrue);
5203 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5204 GetMagickVersion((size_t *) NULL));
5205 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5206 (void) LogMagickEvent(X11Event,GetMagickModule(),
5207 " Window Manager: 0x%lx",windows->wm_protocols);
5208 (void) LogMagickEvent(X11Event,GetMagickModule(),
5209 " delete window: 0x%lx",windows->wm_delete_window);
5210 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5211 windows->wm_take_focus);
5212 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5213 windows->im_protocols);
5214 (void) LogMagickEvent(X11Event,GetMagickModule(),
5215 " remote command: 0x%lx",windows->im_remote_command);
5216 (void) LogMagickEvent(X11Event,GetMagickModule(),
5217 " update widget: 0x%lx",windows->im_update_widget);
5218 (void) LogMagickEvent(X11Event,GetMagickModule(),
5219 " update colormap: 0x%lx",windows->im_update_colormap);
5220 (void) LogMagickEvent(X11Event,GetMagickModule(),
5221 " former image: 0x%lx",windows->im_former_image);
5222 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5223 windows->im_next_image);
5224 (void) LogMagickEvent(X11Event,GetMagickModule(),
5225 " retain colors: 0x%lx",windows->im_retain_colors);
5226 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5228 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5229 windows->dnd_protocols);
5232 Allocate standard colormap.
5234 windows->map_info=XAllocStandardColormap();
5235 windows->icon_map=XAllocStandardColormap();
5236 if ((windows->map_info == (XStandardColormap *) NULL) ||
5237 (windows->icon_map == (XStandardColormap *) NULL))
5238 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5240 windows->map_info->colormap=(Colormap) NULL;
5241 windows->icon_map->colormap=(Colormap) NULL;
5242 windows->pixel_info->pixels=(unsigned long *) NULL;
5243 windows->pixel_info->annotate_context=(GC) NULL;
5244 windows->pixel_info->highlight_context=(GC) NULL;
5245 windows->pixel_info->widget_context=(GC) NULL;
5246 windows->font_info=(XFontStruct *) NULL;
5247 windows->icon_pixel->annotate_context=(GC) NULL;
5248 windows->icon_pixel->pixels=(unsigned long *) NULL;
5252 *windows->icon_resources=(*resource_info);
5253 windows->icon_resources->visual_type=(char *) "default";
5254 windows->icon_resources->colormap=SharedColormap;
5255 windows->visual_info=
5256 XBestVisualInfo(display,windows->map_info,resource_info);
5257 windows->icon_visual=
5258 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5259 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5260 (windows->icon_visual == (XVisualInfo *) NULL))
5261 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5262 resource_info->visual_type);
5263 if (IsEventLogging())
5265 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5266 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5267 windows->visual_info->visualid);
5268 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5269 XVisualClassName(windows->visual_info->klass));
5270 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5271 windows->visual_info->depth);
5272 (void) LogMagickEvent(X11Event,GetMagickModule(),
5273 " size of colormap: %d entries",windows->visual_info->colormap_size);
5274 (void) LogMagickEvent(X11Event,GetMagickModule(),
5275 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5276 windows->visual_info->red_mask,windows->visual_info->green_mask,
5277 windows->visual_info->blue_mask);
5278 (void) LogMagickEvent(X11Event,GetMagickModule(),
5279 " significant bits in color: %d bits",
5280 windows->visual_info->bits_per_rgb);
5283 Allocate class and manager hints.
5285 windows->class_hints=XAllocClassHint();
5286 windows->manager_hints=XAllocWMHints();
5287 if ((windows->class_hints == (XClassHint *) NULL) ||
5288 (windows->manager_hints == (XWMHints *) NULL))
5289 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5292 Determine group leader if we have one.
5294 root_window=XRootWindow(display,windows->visual_info->screen);
5295 windows->group_leader.id=(Window) NULL;
5296 if (resource_info->window_group != (char *) NULL)
5298 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5299 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5300 strtol((char *) resource_info->window_group,(char **) NULL,0));
5301 if (windows->group_leader.id == (Window) NULL)
5302 windows->group_leader.id=
5303 XWindowByName(display,root_window,resource_info->window_group);
5309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5313 % X M a k e C u r s o r %
5317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5319 % XMakeCursor() creates a crosshairs X11 cursor.
5321 % The format of the XMakeCursor method is:
5323 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5324 % char *background_color,char *foreground_color)
5326 % A description of each parameter follows:
5328 % o display: Specifies a connection to an X server; returned from
5331 % o window: Specifies the ID of the window for which the cursor is
5334 % o colormap: Specifies the ID of the colormap from which the background
5335 % and foreground color will be retrieved.
5337 % o background_color: Specifies the color to use for the cursor background.
5339 % o foreground_color: Specifies the color to use for the cursor foreground.
5342 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5343 Colormap colormap,char *background_color,char *foreground_color)
5345 #define scope_height 17
5346 #define scope_x_hot 8
5347 #define scope_y_hot 8
5348 #define scope_width 17
5350 static const unsigned char
5353 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5354 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5355 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5356 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5357 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5361 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5362 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5363 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5364 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5365 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5379 assert(display != (Display *) NULL);
5380 assert(window != (Window) NULL);
5381 assert(colormap != (Colormap) NULL);
5382 assert(background_color != (char *) NULL);
5383 assert(foreground_color != (char *) NULL);
5384 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5385 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5387 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5388 scope_width,scope_height);
5389 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5391 ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
5392 return((Cursor) NULL);
5394 (void) XParseColor(display,colormap,background_color,&background);
5395 (void) XParseColor(display,colormap,foreground_color,&foreground);
5396 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5397 scope_x_hot,scope_y_hot);
5398 (void) XFreePixmap(display,source);
5399 (void) XFreePixmap(display,mask);
5404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5408 % X M a k e I m a g e %
5412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5414 % XMakeImage() creates an X11 image. If the image size differs from the X11
5415 % image size, the image is first resized.
5417 % The format of the XMakeImage method is:
5419 % MagickBooleanType XMakeImage(Display *display,
5420 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5421 % unsigned int width,unsigned int height,ExceptionInfo *exception)
5423 % A description of each parameter follows:
5425 % o display: Specifies a connection to an X server; returned from
5428 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5430 % o window: Specifies a pointer to a XWindowInfo structure.
5432 % o image: the image.
5434 % o width: Specifies the width in pixels of the rectangular area to
5437 % o height: Specifies the height in pixels of the rectangular area to
5440 % o exception: return any errors or warnings in this structure.
5443 MagickPrivate MagickBooleanType XMakeImage(Display *display,
5444 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5445 unsigned int width,unsigned int height,ExceptionInfo *exception)
5447 #define CheckOverflowException(length,width,height) \
5448 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5461 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5462 assert(display != (Display *) NULL);
5463 assert(resource_info != (XResourceInfo *) NULL);
5464 assert(window != (XWindowInfo *) NULL);
5466 assert(height != 0);
5467 if ((window->width == 0) || (window->height == 0))
5468 return(MagickFalse);
5470 Apply user transforms to the image.
5472 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5473 (void) XFlush(display);
5474 depth=(int) window->depth;
5475 if (window->destroy)
5476 window->image=DestroyImage(window->image);
5477 window->image=image;
5478 window->destroy=MagickFalse;
5479 if (window->image != (Image *) NULL)
5481 if (window->crop_geometry != (char *) NULL)
5492 window->image->page.x=0;
5493 window->image->page.y=0;
5494 (void) ParsePageGeometry(window->image,window->crop_geometry,
5495 &crop_info,exception);
5496 crop_image=CropImage(window->image,&crop_info,exception);
5497 if (crop_image != (Image *) NULL)
5499 if (window->image != image)
5500 window->image=DestroyImage(window->image);
5501 window->image=crop_image;
5502 window->destroy=MagickTrue;
5505 if ((width != (unsigned int) window->image->columns) ||
5506 (height != (unsigned int) window->image->rows))
5514 resize_image=NewImageList();
5515 if ((window->pixel_info->colors == 0) &&
5516 (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
5517 (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
5518 resize_image=ResizeImage(window->image,width,height,
5519 image->filter,exception);
5522 if (window->image->storage_class == PseudoClass)
5523 resize_image=SampleImage(window->image,width,height,
5526 resize_image=ThumbnailImage(window->image,width,height,
5529 if (resize_image != (Image *) NULL)
5531 if (window->image != image)
5532 window->image=DestroyImage(window->image);
5533 window->image=resize_image;
5534 window->destroy=MagickTrue;
5537 width=(unsigned int) window->image->columns;
5538 assert((size_t) width == window->image->columns);
5539 height=(unsigned int) window->image->rows;
5540 assert((size_t) height == window->image->rows);
5545 ximage=(XImage *) NULL;
5546 format=(depth == 1) ? XYBitmap : ZPixmap;
5547 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5548 if (window->shared_memory != MagickFalse)
5553 segment_info=(XShmSegmentInfo *) window->segment_info;
5554 segment_info[1].shmid=(-1);
5555 segment_info[1].shmaddr=(char *) NULL;
5556 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5557 (char *) NULL,&segment_info[1],width,height);
5558 if (ximage == (XImage *) NULL)
5559 window->shared_memory=MagickFalse;
5560 length=(size_t) ximage->bytes_per_line*ximage->height;
5561 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5562 window->shared_memory=MagickFalse;
5563 if (window->shared_memory != MagickFalse)
5564 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5565 if (window->shared_memory != MagickFalse)
5566 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5567 if (segment_info[1].shmid < 0)
5568 window->shared_memory=MagickFalse;
5569 if (window->shared_memory != MagickFalse)
5570 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5573 if (ximage != (XImage *) NULL)
5574 XDestroyImage(ximage);
5575 ximage=(XImage *) NULL;
5576 if (segment_info[1].shmaddr)
5578 (void) shmdt(segment_info[1].shmaddr);
5579 segment_info[1].shmaddr=(char *) NULL;
5581 if (segment_info[1].shmid >= 0)
5583 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5584 segment_info[1].shmid=(-1);
5590 Allocate X image pixel data.
5592 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5593 if (window->shared_memory)
5601 (void) XSync(display,MagickFalse);
5602 xerror_alert=MagickFalse;
5603 segment_info=(XShmSegmentInfo *) window->segment_info;
5604 ximage->data=segment_info[1].shmaddr;
5605 segment_info[1].readOnly=MagickFalse;
5606 status=XShmAttach(display,&segment_info[1]);
5607 if (status != False)
5608 (void) XSync(display,MagickFalse);
5609 if ((status == False) || (xerror_alert != MagickFalse))
5611 window->shared_memory=MagickFalse;
5612 if (status != False)
5613 XShmDetach(display,&segment_info[1]);
5614 if (ximage != (XImage *) NULL)
5617 XDestroyImage(ximage);
5618 ximage=(XImage *) NULL;
5620 if (segment_info[1].shmid >= 0)
5622 if (segment_info[1].shmaddr != NULL)
5623 (void) shmdt(segment_info[1].shmaddr);
5624 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5625 segment_info[1].shmid=(-1);
5626 segment_info[1].shmaddr=(char *) NULL;
5631 if (window->shared_memory == MagickFalse)
5632 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5633 (char *) NULL,width,height,XBitmapPad(display),0);
5634 if (ximage == (XImage *) NULL)
5637 Unable to create X image.
5639 (void) XCheckDefineCursor(display,window->id,window->cursor);
5640 return(MagickFalse);
5642 length=(size_t) ximage->bytes_per_line*ximage->height;
5643 if (IsEventLogging())
5645 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5646 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5647 ximage->width,ximage->height);
5648 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5650 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5651 ximage->byte_order);
5652 (void) LogMagickEvent(X11Event,GetMagickModule(),
5653 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5654 ximage->bitmap_bit_order,ximage->bitmap_pad);
5655 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5657 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5658 ximage->bytes_per_line);
5659 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5660 ximage->bits_per_pixel);
5661 (void) LogMagickEvent(X11Event,GetMagickModule(),
5662 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5663 ximage->green_mask,ximage->blue_mask);
5665 if (window->shared_memory == MagickFalse)
5667 if (ximage->format != XYBitmap)
5668 ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
5671 ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
5672 ximage->depth*ximage->height);
5674 if (ximage->data == (char *) NULL)
5677 Unable to allocate pixel data.
5679 XDestroyImage(ximage);
5680 ximage=(XImage *) NULL;
5681 (void) XCheckDefineCursor(display,window->id,window->cursor);
5682 return(MagickFalse);
5684 if (window->ximage != (XImage *) NULL)
5687 Destroy previous X image.
5689 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5690 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5691 if (window->segment_info != (XShmSegmentInfo *) NULL)
5696 segment_info=(XShmSegmentInfo *) window->segment_info;
5697 if (segment_info[0].shmid >= 0)
5699 (void) XSync(display,MagickFalse);
5700 (void) XShmDetach(display,&segment_info[0]);
5701 (void) XSync(display,MagickFalse);
5702 if (segment_info[0].shmaddr != (char *) NULL)
5703 (void) shmdt(segment_info[0].shmaddr);
5704 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5705 segment_info[0].shmid=(-1);
5706 segment_info[0].shmaddr=(char *) NULL;
5707 window->ximage->data=(char *) NULL;
5711 if (window->ximage->data != (char *) NULL)
5712 free(window->ximage->data);
5713 window->ximage->data=(char *) NULL;
5714 XDestroyImage(window->ximage);
5715 window->ximage=(XImage *) NULL;
5717 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5718 if (window->segment_info != (XShmSegmentInfo *) NULL)
5723 segment_info=(XShmSegmentInfo *) window->segment_info;
5724 segment_info[0]=segment_info[1];
5727 window->ximage=ximage;
5728 matte_image=(XImage *) NULL;
5729 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5730 if ((window->image->alpha_trait == BlendPixelTrait) &&
5731 ((int) width <= XDisplayWidth(display,window->screen)) &&
5732 ((int) height <= XDisplayHeight(display,window->screen)))
5737 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5738 (char *) NULL,width,height,XBitmapPad(display),0);
5739 if (IsEventLogging())
5741 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5742 (void) LogMagickEvent(X11Event,GetMagickModule(),
5743 " width, height: %dx%d",matte_image->width,matte_image->height);
5745 if (matte_image != (XImage *) NULL)
5748 Allocate matte image pixel data.
5750 matte_image->data=(char *) malloc((size_t)
5751 matte_image->bytes_per_line*matte_image->depth*
5752 matte_image->height);
5753 if (matte_image->data == (char *) NULL)
5755 XDestroyImage(matte_image);
5756 matte_image=(XImage *) NULL;
5760 if (window->matte_image != (XImage *) NULL)
5765 if (window->matte_image->data != (char *) NULL)
5766 free(window->matte_image->data);
5767 window->matte_image->data=(char *) NULL;
5768 XDestroyImage(window->matte_image);
5769 window->matte_image=(XImage *) NULL;
5771 window->matte_image=matte_image;
5772 if (window->matte_pixmap != (Pixmap) NULL)
5774 (void) XFreePixmap(display,window->matte_pixmap);
5775 window->matte_pixmap=(Pixmap) NULL;
5776 #if defined(MAGICKCORE_HAVE_SHAPE)
5777 if (window->shape != MagickFalse)
5778 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5781 window->stasis=MagickFalse;
5783 Convert pixels to X image data.
5785 if (window->image != (Image *) NULL)
5787 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5788 (ximage->bitmap_bit_order == LSBFirst)))
5789 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5790 matte_image,exception);
5792 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5793 matte_image,exception);
5795 if (window->matte_image != (XImage *) NULL)
5798 Create matte pixmap.
5800 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5801 if (window->matte_pixmap != (Pixmap) NULL)
5810 Copy matte image to matte pixmap.
5812 context_values.background=0;
5813 context_values.foreground=1;
5814 graphics_context=XCreateGC(display,window->matte_pixmap,
5815 (size_t) (GCBackground | GCForeground),&context_values);
5816 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5817 window->matte_image,0,0,0,0,width,height);
5818 (void) XFreeGC(display,graphics_context);
5819 #if defined(MAGICKCORE_HAVE_SHAPE)
5820 if (window->shape != MagickFalse)
5821 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5822 window->matte_pixmap,ShapeSet);
5826 (void) XMakePixmap(display,resource_info,window);
5830 (void) XCheckDefineCursor(display,window->id,window->cursor);
5835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5839 + X M a k e I m a g e L S B F i r s t %
5843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5845 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5846 % pixels are copied in least-significant bit and byte first order. The
5847 % server's scanline pad is respected. Rather than using one or two general
5848 % cases, many special cases are found here to help speed up the image
5851 % The format of the XMakeImageLSBFirst method is:
5853 % void XMakeImageLSBFirst(Display *display,XWindows *windows,
5854 % ExceptionInfo *exception)
5856 % A description of each parameter follows:
5858 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5860 % o window: Specifies a pointer to a XWindowInfo structure.
5862 % o image: the image.
5864 % o ximage: Specifies a pointer to a XImage structure; returned from
5867 % o matte_image: Specifies a pointer to a XImage structure; returned from
5870 % o exception: return any errors or warnings in this structure.
5873 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5874 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5875 ExceptionInfo *exception)
5886 register const Quantum
5892 register unsigned char
5909 assert(resource_info != (XResourceInfo *) NULL);
5910 assert(window != (XWindowInfo *) NULL);
5911 assert(image != (Image *) NULL);
5912 if (image->debug != MagickFalse)
5913 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5915 if ((window->immutable == MagickFalse) &&
5916 (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
5919 size[MaxTextExtent];
5927 image_info=AcquireImageInfo();
5928 (void) CopyMagickString(image_info->filename,
5929 resource_info->image_info->texture != (char *) NULL ?
5930 resource_info->image_info->texture : "pattern:checkerboard",
5932 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5933 image->columns,(double) image->rows);
5934 image_info->size=ConstantString(size);
5935 pattern=ReadImage(image_info,exception);
5936 image_info=DestroyImageInfo(image_info);
5937 if (pattern != (Image *) NULL)
5939 canvas=CloneImage(image,0,0,MagickTrue,exception);
5940 if (canvas != (Image *) NULL)
5941 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5943 pattern=DestroyImage(pattern);
5946 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5947 ximage->bits_per_pixel) >> 3));
5948 map_info=window->map_info;
5949 pixels=window->pixel_info->pixels;
5950 q=(unsigned char *) ximage->data;
5952 canvas_view=AcquireVirtualCacheView(canvas,exception);
5953 if (ximage->format == XYBitmap)
5955 register unsigned short
5963 Convert canvas to big-endian bitmap.
5965 background=(unsigned char)
5966 (XPixelIntensity(&window->pixel_info->foreground_color) <
5967 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5968 foreground=(unsigned char)
5969 (XPixelIntensity(&window->pixel_info->background_color) <
5970 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5971 polarity=(unsigned short) ((GetPixelInfoIntensity(
5972 &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
5973 if (canvas->colors == 2)
5974 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
5975 GetPixelInfoIntensity(&canvas->colormap[1]);
5976 for (y=0; y < (int) canvas->rows; y++)
5978 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5980 if (p == (const Quantum *) NULL)
5984 for (x=0; x < (int) canvas->columns; x++)
5987 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
5998 p+=GetPixelChannels(canvas);
6006 if (window->pixel_info->colors != 0)
6007 switch (ximage->bits_per_pixel)
6011 register unsigned int
6015 Convert to 2 bit color-mapped X canvas.
6017 for (y=0; y < (int) canvas->rows; y++)
6019 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6020 canvas->columns,1,exception);
6021 if (p == (const Quantum *) NULL)
6024 for (x=0; x < (int) canvas->columns; x++)
6026 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6031 *q=(unsigned char) pixel;
6037 *q|=(unsigned char) (pixel << 2);
6043 *q|=(unsigned char) (pixel << 4);
6049 *q|=(unsigned char) (pixel << 6);
6055 p+=GetPixelChannels(canvas);
6063 register unsigned int
6067 Convert to 4 bit color-mapped X canvas.
6069 for (y=0; y < (int) canvas->rows; y++)
6071 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6072 canvas->columns,1,exception);
6073 if (p == (const Quantum *) NULL)
6076 for (x=0; x < (int) canvas->columns; x++)
6078 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6083 *q=(unsigned char) pixel;
6089 *q|=(unsigned char) (pixel << 4);
6095 p+=GetPixelChannels(canvas);
6105 Convert to 8 bit color-mapped X canvas.
6107 if (resource_info->color_recovery &&
6108 resource_info->quantize_info->dither_method != NoDitherMethod)
6110 XDitherImage(canvas,ximage,exception);
6113 for (y=0; y < (int) canvas->rows; y++)
6115 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6116 canvas->columns,1,exception);
6117 if (p == (const Quantum *) NULL)
6119 for (x=0; x < (int) canvas->columns; x++)
6121 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6122 *q++=(unsigned char) pixel;
6123 p+=GetPixelChannels(canvas);
6134 register unsigned int
6138 Convert to multi-byte color-mapped X canvas.
6140 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6141 for (y=0; y < (int) canvas->rows; y++)
6143 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6144 canvas->columns,1,exception);
6145 if (p == (const Quantum *) NULL)
6147 for (x=0; x < (int) canvas->columns; x++)
6149 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6150 for (k=0; k < (int) bytes_per_pixel; k++)
6152 *q++=(unsigned char) (pixel & 0xff);
6155 p+=GetPixelChannels(canvas);
6163 switch (ximage->bits_per_pixel)
6167 register unsigned int
6171 Convert to contiguous 2 bit continuous-tone X canvas.
6173 for (y=0; y < (int) canvas->rows; y++)
6176 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6177 canvas->columns,1,exception);
6178 if (p == (const Quantum *) NULL)
6180 for (x=0; x < (int) canvas->columns; x++)
6182 pixel=XGammaPixel(canvas,map_info,p);
6188 *q=(unsigned char) pixel;
6194 *q|=(unsigned char) (pixel << 2);
6200 *q|=(unsigned char) (pixel << 4);
6206 *q|=(unsigned char) (pixel << 6);
6212 p+=GetPixelChannels(canvas);
6220 register unsigned int
6224 Convert to contiguous 4 bit continuous-tone X canvas.
6226 for (y=0; y < (int) canvas->rows; y++)
6228 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6229 canvas->columns,1,exception);
6230 if (p == (const Quantum *) NULL)
6233 for (x=0; x < (int) canvas->columns; x++)
6235 pixel=XGammaPixel(canvas,map_info,p);
6241 *q=(unsigned char) pixel;
6247 *q|=(unsigned char) (pixel << 4);
6253 p+=GetPixelChannels(canvas);
6263 Convert to contiguous 8 bit continuous-tone X canvas.
6265 if (resource_info->color_recovery &&
6266 resource_info->quantize_info->dither_method != NoDitherMethod)
6268 XDitherImage(canvas,ximage,exception);
6271 for (y=0; y < (int) canvas->rows; y++)
6273 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6274 canvas->columns,1,exception);
6275 if (p == (const Quantum *) NULL)
6277 for (x=0; x < (int) canvas->columns; x++)
6279 pixel=XGammaPixel(canvas,map_info,p);
6280 *q++=(unsigned char) pixel;
6281 p+=GetPixelChannels(canvas);
6289 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6290 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6291 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6292 (map_info->blue_mult == 1))
6295 Convert to 32 bit continuous-tone X canvas.
6297 for (y=0; y < (int) canvas->rows; y++)
6299 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6300 canvas->columns,1,exception);
6301 if (p == (const Quantum *) NULL)
6303 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6304 (blue_gamma != 1.0))
6307 Gamma correct canvas.
6309 for (x=(int) canvas->columns-1; x >= 0; x--)
6311 *q++=ScaleQuantumToChar(XBlueGamma(
6312 GetPixelBlue(canvas,p)));
6313 *q++=ScaleQuantumToChar(XGreenGamma(
6314 GetPixelGreen(canvas,p)));
6315 *q++=ScaleQuantumToChar(XRedGamma(
6316 GetPixelRed(canvas,p)));
6318 p+=GetPixelChannels(canvas);
6322 for (x=(int) canvas->columns-1; x >= 0; x--)
6324 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6325 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6326 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6328 p+=GetPixelChannels(canvas);
6333 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6334 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6335 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6336 (map_info->blue_mult == 65536L))
6339 Convert to 32 bit continuous-tone X canvas.
6341 for (y=0; y < (int) canvas->rows; y++)
6343 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6344 canvas->columns,1,exception);
6345 if (p == (const Quantum *) NULL)
6347 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6348 (blue_gamma != 1.0))
6351 Gamma correct canvas.
6353 for (x=(int) canvas->columns-1; x >= 0; x--)
6355 *q++=ScaleQuantumToChar(XRedGamma(
6356 GetPixelRed(canvas,p)));
6357 *q++=ScaleQuantumToChar(XGreenGamma(
6358 GetPixelGreen(canvas,p)));
6359 *q++=ScaleQuantumToChar(XBlueGamma(
6360 GetPixelBlue(canvas,p)));
6362 p+=GetPixelChannels(canvas);
6366 for (x=(int) canvas->columns-1; x >= 0; x--)
6368 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6369 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6370 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6372 p+=GetPixelChannels(canvas);
6381 register unsigned int
6385 Convert to multi-byte continuous-tone X canvas.
6387 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6388 for (y=0; y < (int) canvas->rows; y++)
6390 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6391 canvas->columns,1,exception);
6392 if (p == (const Quantum *) NULL)
6394 for (x=0; x < (int) canvas->columns; x++)
6396 pixel=XGammaPixel(canvas,map_info,p);
6397 for (k=0; k < (int) bytes_per_pixel; k++)
6399 *q++=(unsigned char) (pixel & 0xff);
6402 p+=GetPixelChannels(canvas);
6410 if (matte_image != (XImage *) NULL)
6413 Initialize matte canvas.
6415 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6416 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6417 q=(unsigned char *) matte_image->data;
6418 for (y=0; y < (int) canvas->rows; y++)
6420 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6422 if (p == (const Quantum *) NULL)
6426 for (x=(int) canvas->columns-1; x >= 0; x--)
6429 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6438 p+=GetPixelChannels(canvas);
6445 canvas_view=DestroyCacheView(canvas_view);
6446 if (canvas != image)
6447 canvas=DestroyImage(canvas);
6451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6455 + X M a k e I m a g e M S B F i r s t %
6459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6461 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6462 % image pixels are copied in most-significant bit and byte first order. The
6463 % server's scanline pad is also respected. Rather than using one or two
6464 % general cases, many special cases are found here to help speed up the image
6467 % The format of the XMakeImageMSBFirst method is:
6469 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6470 % ExceptionInfo *exception)
6472 % A description of each parameter follows:
6474 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6476 % o window: Specifies a pointer to a XWindowInfo structure.
6478 % o image: the image.
6480 % o ximage: Specifies a pointer to a XImage structure; returned from
6483 % o matte_image: Specifies a pointer to a XImage structure; returned from
6486 % o exception: return any errors or warnings in this structure.
6489 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6490 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6491 ExceptionInfo *exception)
6505 register const Quantum
6508 register unsigned char
6525 assert(resource_info != (XResourceInfo *) NULL);
6526 assert(window != (XWindowInfo *) NULL);
6527 assert(image != (Image *) NULL);
6528 if (image->debug != MagickFalse)
6529 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6531 if ((window->immutable != MagickFalse) &&
6532 (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
6535 size[MaxTextExtent];
6543 image_info=AcquireImageInfo();
6544 (void) CopyMagickString(image_info->filename,
6545 resource_info->image_info->texture != (char *) NULL ?
6546 resource_info->image_info->texture : "pattern:checkerboard",
6548 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6549 image->columns,(double) image->rows);
6550 image_info->size=ConstantString(size);
6551 pattern=ReadImage(image_info,exception);
6552 image_info=DestroyImageInfo(image_info);
6553 if (pattern != (Image *) NULL)
6555 canvas=CloneImage(image,0,0,MagickTrue,exception);
6556 if (canvas != (Image *) NULL)
6557 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6559 pattern=DestroyImage(pattern);
6562 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
6563 ximage->bits_per_pixel) >> 3));
6564 map_info=window->map_info;
6565 pixels=window->pixel_info->pixels;
6566 q=(unsigned char *) ximage->data;
6568 canvas_view=AcquireVirtualCacheView(canvas,exception);
6569 if (ximage->format == XYBitmap)
6571 register unsigned short
6579 Convert canvas to big-endian bitmap.
6581 background=(unsigned char)
6582 (XPixelIntensity(&window->pixel_info->foreground_color) <
6583 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6584 foreground=(unsigned char)
6585 (XPixelIntensity(&window->pixel_info->background_color) <
6586 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6587 polarity=(unsigned short) ((GetPixelInfoIntensity(
6588 &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
6589 if (canvas->colors == 2)
6590 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
6591 GetPixelInfoIntensity(&canvas->colormap[1]);
6592 for (y=0; y < (int) canvas->rows; y++)
6594 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6596 if (p == (const Quantum *) NULL)
6600 for (x=(int) canvas->columns-1; x >= 0; x--)
6603 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6614 p+=GetPixelChannels(canvas);
6622 if (window->pixel_info->colors != 0)
6623 switch (ximage->bits_per_pixel)
6627 register unsigned int
6631 Convert to 2 bit color-mapped X canvas.
6633 for (y=0; y < (int) canvas->rows; y++)
6635 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6636 canvas->columns,1,exception);
6637 if (p == (const Quantum *) NULL)
6640 for (x=0; x < (int) canvas->columns; x++)
6642 pixel=pixels[(ssize_t)
6643 GetPixelIndex(canvas,p)] & 0xf;
6648 *q=(unsigned char) (pixel << 6);
6654 *q|=(unsigned char) (pixel << 4);
6660 *q|=(unsigned char) (pixel << 2);
6666 *q|=(unsigned char) pixel;
6672 p+=GetPixelChannels(canvas);
6680 register unsigned int
6684 Convert to 4 bit color-mapped X canvas.
6686 for (y=0; y < (int) canvas->rows; y++)
6688 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6689 canvas->columns,1,exception);
6690 if (p == (const Quantum *) NULL)
6693 for (x=0; x < (int) canvas->columns; x++)
6695 pixel=pixels[(ssize_t)
6696 GetPixelIndex(canvas,p)] & 0xf;
6701 *q=(unsigned char) (pixel << 4);
6707 *q|=(unsigned char) pixel;
6713 p+=GetPixelChannels(canvas);
6723 Convert to 8 bit color-mapped X canvas.
6725 if (resource_info->color_recovery &&
6726 resource_info->quantize_info->dither_method != NoDitherMethod)
6728 XDitherImage(canvas,ximage,exception);
6731 for (y=0; y < (int) canvas->rows; y++)
6733 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6734 canvas->columns,1,exception);
6735 if (p == (const Quantum *) NULL)
6737 for (x=0; x < (int) canvas->columns; x++)
6739 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6740 *q++=(unsigned char) pixel;
6741 p+=GetPixelChannels(canvas);
6752 register unsigned int
6756 channel[sizeof(size_t)];
6759 Convert to 8 bit color-mapped X canvas.
6761 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6762 for (y=0; y < (int) canvas->rows; y++)
6764 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6765 canvas->columns,1,exception);
6766 if (p == (const Quantum *) NULL)
6768 for (x=0; x < (int) canvas->columns; x++)
6770 pixel=pixels[(ssize_t)
6771 GetPixelIndex(canvas,p)];
6772 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6774 channel[k]=(unsigned char) pixel;
6777 for (k=0; k < (int) bytes_per_pixel; k++)
6779 p+=GetPixelChannels(canvas);
6787 switch (ximage->bits_per_pixel)
6791 register unsigned int
6795 Convert to 4 bit continuous-tone X canvas.
6797 for (y=0; y < (int) canvas->rows; y++)
6799 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6800 canvas->columns,1,exception);
6801 if (p == (const Quantum *) NULL)
6804 for (x=(int) canvas->columns-1; x >= 0; x--)
6806 pixel=XGammaPixel(canvas,map_info,p);
6812 *q=(unsigned char) (pixel << 6);
6818 *q|=(unsigned char) (pixel << 4);
6824 *q|=(unsigned char) (pixel << 2);
6830 *q|=(unsigned char) pixel;
6836 p+=GetPixelChannels(canvas);
6844 register unsigned int
6848 Convert to 4 bit continuous-tone X canvas.
6850 for (y=0; y < (int) canvas->rows; y++)
6852 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6853 canvas->columns,1,exception);
6854 if (p == (const Quantum *) NULL)
6857 for (x=(int) canvas->columns-1; x >= 0; x--)
6859 pixel=XGammaPixel(canvas,map_info,p);
6865 *q=(unsigned char) (pixel << 4);
6871 *q|=(unsigned char) pixel;
6877 p+=GetPixelChannels(canvas);
6887 Convert to 8 bit continuous-tone X canvas.
6889 if (resource_info->color_recovery &&
6890 resource_info->quantize_info->dither_method != NoDitherMethod)
6892 XDitherImage(canvas,ximage,exception);
6895 for (y=0; y < (int) canvas->rows; y++)
6897 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6898 canvas->columns,1,exception);
6899 if (p == (const Quantum *) NULL)
6901 for (x=(int) canvas->columns-1; x >= 0; x--)
6903 pixel=XGammaPixel(canvas,map_info,p);
6904 *q++=(unsigned char) pixel;
6905 p+=GetPixelChannels(canvas);
6913 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6914 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6915 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6916 (map_info->blue_mult == 1))
6919 Convert to 32 bit continuous-tone X canvas.
6921 for (y=0; y < (int) canvas->rows; y++)
6923 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6924 canvas->columns,1,exception);
6925 if (p == (const Quantum *) NULL)
6927 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6928 (blue_gamma != 1.0))
6931 Gamma correct canvas.
6933 for (x=(int) canvas->columns-1; x >= 0; x--)
6936 *q++=ScaleQuantumToChar(XRedGamma(
6937 GetPixelRed(canvas,p)));
6938 *q++=ScaleQuantumToChar(XGreenGamma(
6939 GetPixelGreen(canvas,p)));
6940 *q++=ScaleQuantumToChar(XBlueGamma(
6941 GetPixelBlue(canvas,p)));
6942 p+=GetPixelChannels(canvas);
6946 for (x=(int) canvas->columns-1; x >= 0; x--)
6949 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6950 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6951 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6952 p+=GetPixelChannels(canvas);
6957 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6958 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6959 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6960 (map_info->blue_mult == 65536L))
6963 Convert to 32 bit continuous-tone X canvas.
6965 for (y=0; y < (int) canvas->rows; y++)
6967 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6968 canvas->columns,1,exception);
6969 if (p == (const Quantum *) NULL)
6971 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6972 (blue_gamma != 1.0))
6975 Gamma correct canvas.
6977 for (x=(int) canvas->columns-1; x >= 0; x--)
6980 *q++=ScaleQuantumToChar(XBlueGamma(
6981 GetPixelBlue(canvas,p)));
6982 *q++=ScaleQuantumToChar(XGreenGamma(
6983 GetPixelGreen(canvas,p)));
6984 *q++=ScaleQuantumToChar(XRedGamma(
6985 GetPixelRed(canvas,p)));
6986 p+=GetPixelChannels(canvas);
6990 for (x=(int) canvas->columns-1; x >= 0; x--)
6993 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6994 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6995 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6996 p+=GetPixelChannels(canvas);
7005 register unsigned int
7009 channel[sizeof(size_t)];
7012 Convert to multi-byte continuous-tone X canvas.
7014 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
7015 for (y=0; y < (int) canvas->rows; y++)
7017 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7018 canvas->columns,1,exception);
7019 if (p == (const Quantum *) NULL)
7021 for (x=(int) canvas->columns-1; x >= 0; x--)
7023 pixel=XGammaPixel(canvas,map_info,p);
7024 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
7026 channel[k]=(unsigned char) pixel;
7029 for (k=0; k < (int) bytes_per_pixel; k++)
7031 p+=GetPixelChannels(canvas);
7039 if (matte_image != (XImage *) NULL)
7042 Initialize matte canvas.
7044 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7045 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7046 q=(unsigned char *) matte_image->data;
7047 for (y=0; y < (int) canvas->rows; y++)
7049 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7051 if (p == (const Quantum *) NULL)
7055 for (x=(int) canvas->columns-1; x >= 0; x--)
7058 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7067 p+=GetPixelChannels(canvas);
7074 canvas_view=DestroyCacheView(canvas_view);
7075 if (canvas != image)
7076 canvas=DestroyImage(canvas);
7080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7084 % X M a k e M a g n i f y I m a g e %
7088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7090 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7092 % The format of the XMakeMagnifyImage method is:
7094 % void XMakeMagnifyImage(Display *display,XWindows *windows,
7095 % ExceptionInfo *exception)
7097 % A description of each parameter follows:
7099 % o display: Specifies a connection to an X server; returned from
7102 % o windows: Specifies a pointer to a XWindows structure.
7104 % o exception: return any errors or warnings in this structure.
7107 MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
7108 ExceptionInfo *exception)
7111 tuple[MaxTextExtent];
7125 register unsigned char
7133 previous_magnify = 0;
7151 Check boundary conditions.
7153 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7154 assert(display != (Display *) NULL);
7155 assert(windows != (XWindows *) NULL);
7157 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7159 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7161 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7163 while (magnify > windows->magnify.width)
7165 while (magnify > windows->magnify.height)
7167 if (magnify != previous_magnify)
7176 New magnify factor: update magnify window name.
7179 while ((1 << i) <= (int) magnify)
7181 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7182 "Magnify %.20gX",(double) i);
7183 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7184 if (status != False)
7186 XSetWMName(display,windows->magnify.id,&window_name);
7187 XSetWMIconName(display,windows->magnify.id,&window_name);
7188 (void) XFree((void *) window_name.value);
7191 previous_magnify=magnify;
7192 ximage=windows->image.ximage;
7193 width=(unsigned int) windows->magnify.ximage->width;
7194 height=(unsigned int) windows->magnify.ximage->height;
7195 if ((windows->magnify.x < 0) ||
7196 (windows->magnify.x >= windows->image.ximage->width))
7197 windows->magnify.x=windows->image.ximage->width >> 1;
7198 x=windows->magnify.x-((width/magnify) >> 1);
7202 if (x > (int) (ximage->width-(width/magnify)))
7203 x=ximage->width-width/magnify;
7204 if ((windows->magnify.y < 0) ||
7205 (windows->magnify.y >= windows->image.ximage->height))
7206 windows->magnify.y=windows->image.ximage->height >> 1;
7207 y=windows->magnify.y-((height/magnify) >> 1);
7211 if (y > (int) (ximage->height-(height/magnify)))
7212 y=ximage->height-height/magnify;
7213 q=(unsigned char *) windows->magnify.ximage->data;
7214 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7215 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7216 if (ximage->bits_per_pixel < 8)
7218 register unsigned char
7225 register unsigned int
7231 pixel_info=windows->magnify.pixel_info;
7232 switch (ximage->bitmap_bit_order)
7237 Magnify little-endian bitmap.
7241 if (ximage->format == XYBitmap)
7243 background=(unsigned char)
7244 (XPixelIntensity(&pixel_info->foreground_color) <
7245 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7246 foreground=(unsigned char)
7247 (XPixelIntensity(&pixel_info->background_color) <
7248 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7249 if (windows->magnify.depth > 1)
7250 Swap(background,foreground);
7252 for (i=0; i < (ssize_t) height; i+=magnify)
7255 Propogate pixel magnify rows.
7257 for (j=0; j < magnify; j++)
7259 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7260 ((x*ximage->bits_per_pixel) >> 3);
7261 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7264 for (k=0; k < width; k+=magnify)
7267 Propogate pixel magnify columns.
7269 for (l=0; l < magnify; l++)
7272 Propogate each bit plane.
7274 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7277 if (*p & (0x01 << (p_bit+plane)))
7290 p_bit+=ximage->bits_per_pixel;
7297 *q=byte >> (8-q_bit);
7309 Magnify big-endian bitmap.
7313 if (ximage->format == XYBitmap)
7315 background=(unsigned char)
7316 (XPixelIntensity(&pixel_info->foreground_color) <
7317 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7318 foreground=(unsigned char)
7319 (XPixelIntensity(&pixel_info->background_color) <
7320 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7321 if (windows->magnify.depth > 1)
7322 Swap(background,foreground);
7324 for (i=0; i < (ssize_t) height; i+=magnify)
7327 Propogate pixel magnify rows.
7329 for (j=0; j < magnify; j++)
7331 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7332 ((x*ximage->bits_per_pixel) >> 3);
7333 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7336 for (k=0; k < width; k+=magnify)
7339 Propogate pixel magnify columns.
7341 for (l=0; l < magnify; l++)
7344 Propogate each bit plane.
7346 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7349 if (*p & (0x80 >> (p_bit+plane)))
7362 p_bit+=ximage->bits_per_pixel;
7369 *q=byte << (8-q_bit);
7380 switch (ximage->bits_per_pixel)
7386 Magnify 8 bit X image.
7388 for (i=0; i < (ssize_t) height; i+=magnify)
7391 Propogate pixel magnify rows.
7393 for (j=0; j < magnify; j++)
7395 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7396 ((x*ximage->bits_per_pixel) >> 3);
7397 for (k=0; k < width; k+=magnify)
7400 Propogate pixel magnify columns.
7402 for (l=0; l < magnify; l++)
7414 register unsigned int
7419 Magnify multi-byte X image.
7421 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7422 for (i=0; i < (ssize_t) height; i+=magnify)
7425 Propogate pixel magnify rows.
7427 for (j=0; j < magnify; j++)
7429 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7430 ((x*ximage->bits_per_pixel) >> 3);
7431 for (k=0; k < width; k+=magnify)
7434 Propogate pixel magnify columns.
7436 for (l=0; l < magnify; l++)
7437 for (m=0; m < bytes_per_pixel; m++)
7449 Copy X image to magnify pixmap.
7451 x=windows->magnify.x-((width/magnify) >> 1);
7453 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7455 if (x > (int) (ximage->width-(width/magnify)))
7456 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7459 y=windows->magnify.y-((height/magnify) >> 1);
7461 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7463 if (y > (int) (ximage->height-(height/magnify)))
7464 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7467 if ((x != 0) || (y != 0))
7468 (void) XFillRectangle(display,windows->magnify.pixmap,
7469 windows->magnify.annotate_context,0,0,width,height);
7470 (void) XPutImage(display,windows->magnify.pixmap,
7471 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7473 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7474 (magnify <= (height >> 1))))
7480 Highlight center pixel.
7482 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7483 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7484 highlight_info.width=magnify;
7485 highlight_info.height=magnify;
7486 (void) XDrawRectangle(display,windows->magnify.pixmap,
7487 windows->magnify.highlight_context,(int) highlight_info.x,
7488 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7489 (unsigned int) highlight_info.height-1);
7491 (void) XDrawRectangle(display,windows->magnify.pixmap,
7492 windows->magnify.annotate_context,(int) highlight_info.x+1,
7493 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7494 (unsigned int) highlight_info.height-3);
7497 Show center pixel color.
7499 (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
7500 (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7501 (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
7502 windows->magnify.x,windows->magnify.y);
7503 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7504 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7505 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7506 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7507 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7508 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7509 if (pixel.colorspace == CMYKColorspace)
7511 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7512 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7514 if (pixel.alpha_trait == BlendPixelTrait)
7516 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7517 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7519 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7520 height=(unsigned int) windows->magnify.font_info->ascent+
7521 windows->magnify.font_info->descent;
7522 x=windows->magnify.font_info->max_bounds.width >> 1;
7523 y=windows->magnify.font_info->ascent+(height >> 2);
7524 (void) XDrawImageString(display,windows->magnify.pixmap,
7525 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7526 GetColorTuple(&pixel,MagickTrue,tuple);
7528 (void) XDrawImageString(display,windows->magnify.pixmap,
7529 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7530 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7533 (void) XDrawImageString(display,windows->magnify.pixmap,
7534 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7536 Refresh magnify window.
7538 magnify_window=windows->magnify;
7541 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7545 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7549 % X M a k e P i x m a p %
7553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7555 % XMakePixmap() creates an X11 pixmap.
7557 % The format of the XMakePixmap method is:
7559 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7560 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7561 % XPixelInfo *pixel)
7563 % A description of each parameter follows:
7565 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7567 % o display: Specifies a connection to an X server; returned from
7570 % o window: Specifies a pointer to a XWindowInfo structure.
7573 static MagickBooleanType XMakePixmap(Display *display,
7574 const XResourceInfo *resource_info,XWindowInfo *window)
7580 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7581 assert(display != (Display *) NULL);
7582 assert(resource_info != (XResourceInfo *) NULL);
7583 assert(window != (XWindowInfo *) NULL);
7584 if (window->pixmap != (Pixmap) NULL)
7587 Destroy previous X pixmap.
7589 (void) XFreePixmap(display,window->pixmap);
7590 window->pixmap=(Pixmap) NULL;
7592 if (window->use_pixmap == MagickFalse)
7593 return(MagickFalse);
7594 if (window->ximage == (XImage *) NULL)
7595 return(MagickFalse);
7597 Display busy cursor.
7599 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7600 (void) XFlush(display);
7604 width=(unsigned int) window->ximage->width;
7605 height=(unsigned int) window->ximage->height;
7606 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7607 if (window->pixmap == (Pixmap) NULL)
7610 Unable to allocate pixmap.
7612 (void) XCheckDefineCursor(display,window->id,window->cursor);
7613 return(MagickFalse);
7616 Copy X image to pixmap.
7618 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7619 if (window->shared_memory)
7620 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7621 window->ximage,0,0,0,0,width,height,MagickTrue);
7623 if (window->shared_memory == MagickFalse)
7624 (void) XPutImage(display,window->pixmap,window->annotate_context,
7625 window->ximage,0,0,0,0,width,height);
7626 if (IsEventLogging())
7628 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7629 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7635 (void) XCheckDefineCursor(display,window->id,window->cursor);
7640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7644 % X M a k e S t a n d a r d C o l o r m a p %
7648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7650 % XMakeStandardColormap() creates an X11 Standard Colormap.
7652 % The format of the XMakeStandardColormap method is:
7654 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7655 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7656 % XPixelInfo *pixel,ExceptionInfo *exception)
7658 % A description of each parameter follows:
7660 % o display: Specifies a connection to an X server; returned from
7663 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7664 % returned from XGetVisualInfo.
7666 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7668 % o image: the image.
7670 % o map_info: If a Standard Colormap type is specified, this structure is
7671 % initialized with info from the Standard Colormap.
7673 % o pixel: Specifies a pointer to a XPixelInfo structure.
7675 % o exception: return any errors or warnings in this structure.
7679 #if defined(__cplusplus) || defined(c_plusplus)
7683 static inline double DiversityPixelIntensity(
7684 const DiversityPacket *pixel)
7689 intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
7693 static int IntensityCompare(const void *x,const void *y)
7702 color_1=(DiversityPacket *) x;
7703 color_2=(DiversityPacket *) y;
7704 diversity=(int) (DiversityPixelIntensity(color_2)-
7705 DiversityPixelIntensity(color_1));
7709 static int PopularityCompare(const void *x,const void *y)
7715 color_1=(DiversityPacket *) x;
7716 color_2=(DiversityPacket *) y;
7717 return((int) color_2->count-(int) color_1->count);
7720 #if defined(__cplusplus) || defined(c_plusplus)
7724 static inline Quantum ScaleXToQuantum(const size_t x,
7727 return((Quantum) (((double) QuantumRange*x)/scale+0.5));
7730 MagickPrivate void XMakeStandardColormap(Display *display,
7731 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7732 XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
7755 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7756 assert(display != (Display *) NULL);
7757 assert(visual_info != (XVisualInfo *) NULL);
7758 assert(map_info != (XStandardColormap *) NULL);
7759 assert(resource_info != (XResourceInfo *) NULL);
7760 assert(pixel != (XPixelInfo *) NULL);
7761 if (resource_info->map_type != (char *) NULL)
7764 Standard Colormap is already defined (i.e. xstdcmap).
7766 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7768 number_colors=(unsigned int) (map_info->base_pixel+
7769 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7770 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7771 if ((image->alpha_trait != BlendPixelTrait) &&
7772 (resource_info->color_recovery == MagickFalse) &&
7773 (resource_info->quantize_info->dither_method != NoDitherMethod) &&
7774 (number_colors < MaxColormapSize))
7783 Improve image appearance with error diffusion.
7785 affinity_image=AcquireImage((ImageInfo *) NULL,exception);
7786 if (affinity_image == (Image *) NULL)
7787 ThrowXWindowFatalException(ResourceLimitFatalError,
7788 "UnableToDitherImage",image->filename);
7789 affinity_image->columns=number_colors;
7790 affinity_image->rows=1;
7792 Initialize colormap image.
7794 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7796 if (q != (Quantum *) NULL)
7798 for (i=0; i < (ssize_t) number_colors; i++)
7800 SetPixelRed(affinity_image,0,q);
7801 if (map_info->red_max != 0)
7802 SetPixelRed(affinity_image,ScaleXToQuantum((size_t)
7803 (i/map_info->red_mult),map_info->red_max),q);
7804 SetPixelGreen(affinity_image,0,q);
7805 if (map_info->green_max != 0)
7806 SetPixelGreen(affinity_image,ScaleXToQuantum((size_t)
7807 ((i/map_info->green_mult) % (map_info->green_max+1)),
7808 map_info->green_max),q);
7809 SetPixelBlue(affinity_image,0,q);
7810 if (map_info->blue_max != 0)
7811 SetPixelBlue(affinity_image,ScaleXToQuantum((size_t)
7812 (i % map_info->green_mult),map_info->blue_max),q);
7813 SetPixelAlpha(affinity_image,
7814 TransparentAlpha,q);
7815 q+=GetPixelChannels(affinity_image);
7817 (void) SyncAuthenticPixels(affinity_image,exception);
7818 (void) RemapImage(resource_info->quantize_info,image,
7819 affinity_image,exception);
7821 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7823 (void) SetImageStorageClass(image,DirectClass,exception);
7824 affinity_image=DestroyImage(affinity_image);
7826 if (IsEventLogging())
7828 (void) LogMagickEvent(X11Event,GetMagickModule(),
7829 "Standard Colormap:");
7830 (void) LogMagickEvent(X11Event,GetMagickModule(),
7831 " colormap id: 0x%lx",map_info->colormap);
7832 (void) LogMagickEvent(X11Event,GetMagickModule(),
7833 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7834 map_info->green_max,map_info->blue_max);
7835 (void) LogMagickEvent(X11Event,GetMagickModule(),
7836 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7837 map_info->green_mult,map_info->blue_mult);
7841 if ((visual_info->klass != DirectColor) &&
7842 (visual_info->klass != TrueColor))
7843 if ((image->storage_class == DirectClass) ||
7844 ((int) image->colors > visual_info->colormap_size))
7850 Image has more colors than the visual supports.
7852 quantize_info=(*resource_info->quantize_info);
7853 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7854 (void) QuantizeImage(&quantize_info,image,exception);
7857 Free previous and create new colormap.
7859 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7860 colormap=XDefaultColormap(display,visual_info->screen);
7861 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7862 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7863 visual_info->visual,visual_info->klass == DirectColor ?
7864 AllocAll : AllocNone);
7865 if (colormap == (Colormap) NULL)
7866 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7869 Initialize the map and pixel info structures.
7871 XGetMapInfo(visual_info,colormap,map_info);
7872 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7874 Allocating colors in server colormap is based on visual class.
7876 switch (visual_info->klass)
7882 Define Standard Colormap for StaticGray or StaticColor visual.
7884 number_colors=image->colors;
7885 colors=(XColor *) AcquireQuantumMemory((size_t)
7886 visual_info->colormap_size,sizeof(*colors));
7887 if (colors == (XColor *) NULL)
7888 ThrowXWindowFatalException(ResourceLimitFatalError,
7889 "UnableToCreateColormap",image->filename);
7891 color.flags=(char) (DoRed | DoGreen | DoBlue);
7892 for (i=0; i < (ssize_t) image->colors; i++)
7894 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7895 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7896 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7897 if (visual_info->klass != StaticColor)
7899 gray_value=(unsigned short) XPixelIntensity(&color);
7900 color.red=gray_value;
7901 color.green=gray_value;
7902 color.blue=gray_value;
7904 status=XAllocColor(display,colormap,&color);
7905 if (status == False)
7907 colormap=XCopyColormapAndFree(display,colormap);
7908 (void) XAllocColor(display,colormap,&color);
7910 pixel->pixels[i]=color.pixel;
7922 Define Standard Colormap for GrayScale or PseudoColor visual.
7924 number_colors=image->colors;
7925 colors=(XColor *) AcquireQuantumMemory((size_t)
7926 visual_info->colormap_size,sizeof(*colors));
7927 if (colors == (XColor *) NULL)
7928 ThrowXWindowFatalException(ResourceLimitFatalError,
7929 "UnableToCreateColormap",image->filename);
7931 Preallocate our GUI colors.
7933 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7934 (void) XAllocColor(display,colormap,&pixel->background_color);
7935 (void) XAllocColor(display,colormap,&pixel->border_color);
7936 (void) XAllocColor(display,colormap,&pixel->matte_color);
7937 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7938 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7939 (void) XAllocColor(display,colormap,&pixel->depth_color);
7940 (void) XAllocColor(display,colormap,&pixel->trough_color);
7941 for (i=0; i < MaxNumberPens; i++)
7942 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7944 Determine if image colors will "fit" into X server colormap.
7946 colormap_type=resource_info->colormap;
7947 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7948 NULL,0,pixel->pixels,(unsigned int) image->colors);
7949 if (status != False)
7950 colormap_type=PrivateColormap;
7951 if (colormap_type == SharedColormap)
7972 Define Standard colormap for shared GrayScale or PseudoColor visual.
7974 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7975 sizeof(*diversity));
7976 if (diversity == (DiversityPacket *) NULL)
7977 ThrowXWindowFatalException(ResourceLimitFatalError,
7978 "UnableToCreateColormap",image->filename);
7979 for (i=0; i < (ssize_t) image->colors; i++)
7981 diversity[i].red=ClampToQuantum(image->colormap[i].red);
7982 diversity[i].green=ClampToQuantum(image->colormap[i].green);
7983 diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
7984 diversity[i].index=(unsigned short) i;
7985 diversity[i].count=0;
7987 image_view=AcquireAuthenticCacheView(image,exception);
7988 for (y=0; y < (int) image->rows; y++)
7993 register const Quantum
7996 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7997 image->columns,1,exception);
7998 if (p == (const Quantum *) NULL)
8000 for (x=(int) image->columns-1; x >= 0; x--)
8002 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8003 p+=GetPixelChannels(image);
8006 image_view=DestroyCacheView(image_view);
8008 Sort colors by decreasing intensity.
8010 qsort((void *) diversity,image->colors,sizeof(*diversity),
8012 for (i=0; i < (ssize_t) image->colors; )
8014 diversity[i].count<<=4; /* increase this colors popularity */
8015 i+=MagickMax((int) (image->colors >> 4),2);
8017 diversity[image->colors-1].count<<=4;
8018 qsort((void *) diversity,image->colors,sizeof(*diversity),
8024 color.flags=(char) (DoRed | DoGreen | DoBlue);
8025 for (i=0; i < (ssize_t) image->colors; i++)
8027 index=diversity[i].index;
8029 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8031 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8033 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8034 if (visual_info->klass != PseudoColor)
8036 gray_value=(unsigned short) XPixelIntensity(&color);
8037 color.red=gray_value;
8038 color.green=gray_value;
8039 color.blue=gray_value;
8041 status=XAllocColor(display,colormap,&color);
8042 if (status == False)
8044 pixel->pixels[index]=color.pixel;
8048 Read X server colormap.
8050 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8051 visual_info->colormap_size,sizeof(*server_colors));
8052 if (server_colors == (XColor *) NULL)
8053 ThrowXWindowFatalException(ResourceLimitFatalError,
8054 "UnableToCreateColormap",image->filename);
8055 for (x=visual_info->colormap_size-1; x >= 0; x--)
8056 server_colors[x].pixel=(size_t) x;
8057 (void) XQueryColors(display,colormap,server_colors,
8058 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8060 Select remaining colors from X server colormap.
8062 for (; i < (ssize_t) image->colors; i++)
8064 index=diversity[i].index;
8065 color.red=ScaleQuantumToShort(
8066 XRedGamma(image->colormap[index].red));
8067 color.green=ScaleQuantumToShort(
8068 XGreenGamma(image->colormap[index].green));
8069 color.blue=ScaleQuantumToShort(
8070 XBlueGamma(image->colormap[index].blue));
8071 if (visual_info->klass != PseudoColor)
8073 gray_value=(unsigned short) XPixelIntensity(&color);
8074 color.red=gray_value;
8075 color.green=gray_value;
8076 color.blue=gray_value;
8078 XBestPixel(display,colormap,server_colors,(unsigned int)
8079 visual_info->colormap_size,&color);
8080 pixel->pixels[index]=color.pixel;
8083 if ((int) image->colors < visual_info->colormap_size)
8086 Fill up colors array-- more choices for pen colors.
8088 retain_colors=MagickMin((unsigned int)
8089 (visual_info->colormap_size-image->colors),256);
8090 for (i=0; i < (ssize_t) retain_colors; i++)
8091 *p++=server_colors[i];
8092 number_colors+=retain_colors;
8094 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8095 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8099 Define Standard colormap for private GrayScale or PseudoColor visual.
8101 if (status == False)
8104 Not enough colormap entries in the colormap-- Create a new colormap.
8106 colormap=XCreateColormap(display,
8107 XRootWindow(display,visual_info->screen),visual_info->visual,
8109 if (colormap == (Colormap) NULL)
8110 ThrowXWindowFatalException(ResourceLimitFatalError,
8111 "UnableToCreateColormap",image->filename);
8112 map_info->colormap=colormap;
8113 if ((int) image->colors < visual_info->colormap_size)
8116 Retain colors from the default colormap to help lessens the
8117 effects of colormap flashing.
8119 retain_colors=MagickMin((unsigned int)
8120 (visual_info->colormap_size-image->colors),256);
8121 p=colors+image->colors;
8122 for (i=0; i < (ssize_t) retain_colors; i++)
8124 p->pixel=(unsigned long) i;
8127 (void) XQueryColors(display,
8128 XDefaultColormap(display,visual_info->screen),
8129 colors+image->colors,(int) retain_colors);
8131 Transfer colors from default to private colormap.
8133 (void) XAllocColorCells(display,colormap,MagickFalse,
8134 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8136 p=colors+image->colors;
8137 for (i=0; i < (ssize_t) retain_colors; i++)
8139 p->pixel=pixel->pixels[i];
8142 (void) XStoreColors(display,colormap,colors+image->colors,
8143 (int) retain_colors);
8144 number_colors+=retain_colors;
8146 (void) XAllocColorCells(display,colormap,MagickFalse,
8147 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8151 Store the image colormap.
8154 color.flags=(char) (DoRed | DoGreen | DoBlue);
8155 for (i=0; i < (ssize_t) image->colors; i++)
8157 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8158 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8159 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8160 if (visual_info->klass != PseudoColor)
8162 gray_value=(unsigned short) XPixelIntensity(&color);
8163 color.red=gray_value;
8164 color.green=gray_value;
8165 color.blue=gray_value;
8167 color.pixel=pixel->pixels[i];
8170 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8181 Define Standard Colormap for TrueColor or DirectColor visual.
8183 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8184 (map_info->green_max*map_info->green_mult)+
8185 (map_info->blue_max*map_info->blue_mult)+1);
8186 linear_colormap=(number_colors > 4096) ||
8187 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8188 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8189 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8190 MagickTrue : MagickFalse;
8191 if (linear_colormap != MagickFalse)
8192 number_colors=(size_t) visual_info->colormap_size;
8194 Allocate color array.
8196 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8197 if (colors == (XColor *) NULL)
8198 ThrowXWindowFatalException(ResourceLimitFatalError,
8199 "UnableToCreateColormap",image->filename);
8201 Initialize linear color ramp.
8204 color.flags=(char) (DoRed | DoGreen | DoBlue);
8205 if (linear_colormap != MagickFalse)
8206 for (i=0; i < (ssize_t) number_colors; i++)
8208 color.blue=(unsigned short) 0;
8209 if (map_info->blue_max != 0)
8210 color.blue=(unsigned short) ((size_t)
8211 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8212 color.green=color.blue;
8213 color.red=color.blue;
8214 color.pixel=XStandardPixel(map_info,&color);
8218 for (i=0; i < (ssize_t) number_colors; i++)
8220 color.red=(unsigned short) 0;
8221 if (map_info->red_max != 0)
8222 color.red=(unsigned short) ((size_t)
8223 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8224 color.green=(unsigned int) 0;
8225 if (map_info->green_max != 0)
8226 color.green=(unsigned short) ((size_t)
8227 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8228 map_info->green_max));
8229 color.blue=(unsigned short) 0;
8230 if (map_info->blue_max != 0)
8231 color.blue=(unsigned short) ((size_t)
8232 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8233 color.pixel=XStandardPixel(map_info,&color);
8236 if ((visual_info->klass == DirectColor) &&
8237 (colormap != XDefaultColormap(display,visual_info->screen)))
8238 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8240 for (i=0; i < (ssize_t) number_colors; i++)
8241 (void) XAllocColor(display,colormap,&colors[i]);
8245 if ((visual_info->klass != DirectColor) &&
8246 (visual_info->klass != TrueColor))
8249 Set foreground, background, border, etc. pixels.
8251 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8252 &pixel->foreground_color);
8253 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8254 &pixel->background_color);
8255 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8258 Foreground and background colors must differ.
8260 pixel->background_color.red=(~pixel->foreground_color.red);
8261 pixel->background_color.green=
8262 (~pixel->foreground_color.green);
8263 pixel->background_color.blue=
8264 (~pixel->foreground_color.blue);
8265 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8266 &pixel->background_color);
8268 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8269 &pixel->border_color);
8270 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8271 &pixel->matte_color);
8272 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8273 &pixel->highlight_color);
8274 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8275 &pixel->shadow_color);
8276 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8277 &pixel->depth_color);
8278 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8279 &pixel->trough_color);
8280 for (i=0; i < MaxNumberPens; i++)
8282 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8283 &pixel->pen_colors[i]);
8284 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8286 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8288 colors=(XColor *) RelinquishMagickMemory(colors);
8289 if (IsEventLogging())
8291 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8292 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8293 map_info->colormap);
8294 (void) LogMagickEvent(X11Event,GetMagickModule(),
8295 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8296 map_info->green_max,map_info->blue_max);
8297 (void) LogMagickEvent(X11Event,GetMagickModule(),
8298 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8299 map_info->green_mult,map_info->blue_mult);
8304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8308 % X M a k e W i n d o w %
8312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8314 % XMakeWindow() creates an X11 window.
8316 % The format of the XMakeWindow method is:
8318 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8319 % XClassHint *class_hint,XWMHints *manager_hints,
8320 % XWindowInfo *window_info)
8322 % A description of each parameter follows:
8324 % o display: Specifies a connection to an X server; returned from
8327 % o parent: Specifies the parent window_info.
8329 % o argv: Specifies the application's argument list.
8331 % o argc: Specifies the number of arguments.
8333 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8335 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8337 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8340 MagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
8341 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8342 XWindowInfo *window_info)
8344 #define MinWindowSize 64
8352 static XTextProperty
8363 Set window info hints.
8365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8366 assert(display != (Display *) NULL);
8367 assert(window_info != (XWindowInfo *) NULL);
8368 size_hints=XAllocSizeHints();
8369 if (size_hints == (XSizeHints *) NULL)
8370 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8371 size_hints->flags=(int) window_info->flags;
8372 size_hints->x=window_info->x;
8373 size_hints->y=window_info->y;
8374 size_hints->width=(int) window_info->width;
8375 size_hints->height=(int) window_info->height;
8376 if (window_info->immutable != MagickFalse)
8379 Window size cannot be changed.
8381 size_hints->min_width=size_hints->width;
8382 size_hints->min_height=size_hints->height;
8383 size_hints->max_width=size_hints->width;
8384 size_hints->max_height=size_hints->height;
8385 size_hints->flags|=PMinSize;
8386 size_hints->flags|=PMaxSize;
8391 Window size can be changed.
8393 size_hints->min_width=(int) window_info->min_width;
8394 size_hints->min_height=(int) window_info->min_height;
8395 size_hints->flags|=PResizeInc;
8396 size_hints->width_inc=(int) window_info->width_inc;
8397 size_hints->height_inc=(int) window_info->height_inc;
8398 #if !defined(PRE_R4_ICCCM)
8399 size_hints->flags|=PBaseSize;
8400 size_hints->base_width=size_hints->width_inc;
8401 size_hints->base_height=size_hints->height_inc;
8404 gravity=NorthWestGravity;
8405 if (window_info->geometry != (char *) NULL)
8408 default_geometry[MaxTextExtent],
8409 geometry[MaxTextExtent];
8418 User specified geometry.
8420 (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
8421 size_hints->width,size_hints->height);
8422 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8424 while (strlen(p) != 0)
8426 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8429 (void) CopyMagickString(p,p+1,MaxTextExtent);
8431 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8432 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8433 &size_hints->width,&size_hints->height,&gravity);
8434 if ((flags & WidthValue) && (flags & HeightValue))
8435 size_hints->flags|=USSize;
8436 if ((flags & XValue) && (flags & YValue))
8438 size_hints->flags|=USPosition;
8439 window_info->x=size_hints->x;
8440 window_info->y=size_hints->y;
8443 #if !defined(PRE_R4_ICCCM)
8444 size_hints->win_gravity=gravity;
8445 size_hints->flags|=PWinGravity;
8447 if (window_info->id == (Window) NULL)
8448 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8449 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8450 window_info->border_width,(int) window_info->depth,InputOutput,
8451 window_info->visual,(unsigned long) window_info->mask,
8452 &window_info->attributes);
8465 Window already exists; change relevant attributes.
8467 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8468 window_info->mask,&window_info->attributes);
8469 mask=ConfigureNotify;
8470 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8471 window_changes.x=window_info->x;
8472 window_changes.y=window_info->y;
8473 window_changes.width=(int) window_info->width;
8474 window_changes.height=(int) window_info->height;
8475 mask=(MagickStatusType) (CWWidth | CWHeight);
8476 if (window_info->flags & USPosition)
8478 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8479 mask,&window_changes);
8481 if (window_info->id == (Window) NULL)
8482 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8484 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8485 if (status == False)
8486 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8488 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8489 if (status == False)
8490 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8491 window_info->icon_name);
8492 if (window_info->icon_geometry != (char *) NULL)
8500 User specified icon geometry.
8502 size_hints->flags|=USPosition;
8503 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8504 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8505 &manager_hints->icon_y,&width,&height,&gravity);
8506 if ((flags & XValue) && (flags & YValue))
8507 manager_hints->flags|=IconPositionHint;
8509 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8510 size_hints,manager_hints,class_hint);
8511 if (window_name.value != (void *) NULL)
8513 (void) XFree((void *) window_name.value);
8514 window_name.value=(unsigned char *) NULL;
8515 window_name.nitems=0;
8517 if (icon_name.value != (void *) NULL)
8519 (void) XFree((void *) icon_name.value);
8520 icon_name.value=(unsigned char *) NULL;
8523 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8524 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8525 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8526 (void) XFree((void *) size_hints);
8527 if (window_info->shape != MagickFalse)
8529 #if defined(MAGICKCORE_HAVE_SHAPE)
8535 Can we apply a non-rectangular shaping mask?
8539 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8540 window_info->shape=MagickFalse;
8542 window_info->shape=MagickFalse;
8545 if (window_info->shared_memory)
8547 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8549 Can we use shared memory with this window?
8551 if (XShmQueryExtension(display) == 0)
8552 window_info->shared_memory=MagickFalse;
8554 window_info->shared_memory=MagickFalse;
8557 window_info->image=NewImageList();
8558 window_info->destroy=MagickFalse;
8562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8566 % X M a g i c k P r o g r e s s M o n i t o r %
8570 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8572 % XMagickProgressMonitor() displays the progress a task is making in
8573 % completing a task.
8575 % The format of the XMagickProgressMonitor method is:
8577 % void XMagickProgressMonitor(const char *task,
8578 % const MagickOffsetType quantum,const MagickSizeType span,
8579 % void *client_data)
8581 % A description of each parameter follows:
8583 % o task: Identifies the task in progress.
8585 % o quantum: Specifies the quantum position within the span which represents
8586 % how much progress has been made in completing a task.
8588 % o span: Specifies the span relative to completing a task.
8590 % o client_data: Pointer to any client data.
8594 static const char *GetLocaleMonitorMessage(const char *text)
8597 message[MaxTextExtent],
8606 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8608 if (p != (char *) NULL)
8610 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
8611 locale_message=GetLocaleMessage(message);
8612 if (locale_message == message)
8614 return(locale_message);
8617 MagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
8618 const MagickOffsetType quantum,const MagickSizeType span,
8619 void *magick_unused(client_data))
8624 windows=XSetWindows((XWindows *) ~0);
8625 if (windows == (XWindows *) NULL)
8627 if (windows->info.mapped != MagickFalse)
8628 XProgressMonitorWidget(windows->display,windows,
8629 GetLocaleMonitorMessage(tag),quantum,span);
8634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8638 % X Q u e r y C o l o r D a t a b a s e %
8642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8644 % XQueryColorCompliance() looks up a RGB values for a color given in the target
8647 % The format of the XQueryColorDatabase method is:
8649 % MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
8651 % A description of each parameter follows:
8653 % o target: Specifies the color to lookup in the X color database.
8655 % o color: A pointer to an PixelInfo structure. The RGB value of the target
8656 % color is returned as this value.
8659 MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
8666 *display = (Display *) NULL;
8675 Initialize color return value.
8677 assert(color != (XColor *) NULL);
8681 color->flags=(char) (DoRed | DoGreen | DoBlue);
8682 if ((target == (char *) NULL) || (*target == '\0'))
8683 target="#ffffffffffff";
8685 Let the X server define the color for us.
8687 if (display == (Display *) NULL)
8688 display=XOpenDisplay((char *) NULL);
8689 if (display == (Display *) NULL)
8691 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
8692 return(MagickFalse);
8694 colormap=XDefaultColormap(display,XDefaultScreen(display));
8695 status=XParseColor(display,colormap,(char *) target,&xcolor);
8696 if (status == False)
8697 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
8700 color->red=xcolor.red;
8701 color->green=xcolor.green;
8702 color->blue=xcolor.blue;
8703 color->flags=xcolor.flags;
8705 return(status != False ? MagickTrue : MagickFalse);
8709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8713 % X Q u e r y P o s i t i o n %
8717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8719 % XQueryPosition() gets the pointer coordinates relative to a window.
8721 % The format of the XQueryPosition method is:
8723 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8725 % A description of each parameter follows:
8727 % o display: Specifies a connection to an X server; returned from
8730 % o window: Specifies a pointer to a Window.
8732 % o x: Return the x coordinate of the pointer relative to the origin of the
8735 % o y: Return the y coordinate of the pointer relative to the origin of the
8739 MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,
8752 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8753 assert(display != (Display *) NULL);
8754 assert(window != (Window) NULL);
8755 assert(x != (int *) NULL);
8756 assert(y != (int *) NULL);
8757 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8766 % X R e f r e s h W i n d o w %
8770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8772 % XRefreshWindow() refreshes an image in a X window.
8774 % The format of the XRefreshWindow method is:
8776 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8777 % const XEvent *event)
8779 % A description of each parameter follows:
8781 % o display: Specifies a connection to an X server; returned from
8784 % o window: Specifies a pointer to a XWindowInfo structure.
8786 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8787 % the entire image is refreshed.
8790 MagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
8791 const XEvent *event)
8801 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8802 assert(display != (Display *) NULL);
8803 assert(window != (XWindowInfo *) NULL);
8804 if (window->ximage == (XImage *) NULL)
8806 if (event != (XEvent *) NULL)
8809 Determine geometry from expose event.
8813 width=(unsigned int) event->xexpose.width;
8814 height=(unsigned int) event->xexpose.height;
8822 Refresh entire window; discard outstanding expose events.
8826 width=window->width;
8827 height=window->height;
8828 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8829 if (window->matte_pixmap != (Pixmap) NULL)
8831 #if defined(MAGICKCORE_HAVE_SHAPE)
8832 if (window->shape != MagickFalse)
8833 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8834 window->matte_pixmap,ShapeSet);
8839 Check boundary conditions.
8841 if ((window->ximage->width-(x+window->x)) < (int) width)
8842 width=(unsigned int) (window->ximage->width-(x+window->x));
8843 if ((window->ximage->height-(y+window->y)) < (int) height)
8844 height=(unsigned int) (window->ximage->height-(y+window->y));
8848 if (window->matte_pixmap != (Pixmap) NULL)
8849 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8850 if (window->pixmap != (Pixmap) NULL)
8852 if (window->depth > 1)
8853 (void) XCopyArea(display,window->pixmap,window->id,
8854 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8856 (void) XCopyPlane(display,window->pixmap,window->id,
8857 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8862 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8863 if (window->shared_memory)
8864 (void) XShmPutImage(display,window->id,window->annotate_context,
8865 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8867 if (window->shared_memory == MagickFalse)
8868 (void) XPutImage(display,window->id,window->annotate_context,
8869 window->ximage,x+window->x,y+window->y,x,y,width,height);
8871 if (window->matte_pixmap != (Pixmap) NULL)
8872 (void) XSetClipMask(display,window->annotate_context,None);
8873 (void) XFlush(display);
8877 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8881 % X R e m o t e C o m m a n d %
8885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8887 % XRemoteCommand() forces a remote display(1) to display the specified
8890 % The format of the XRemoteCommand method is:
8892 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8893 % const char *filename)
8895 % A description of each parameter follows:
8897 % o display: Specifies a connection to an X server; returned from
8900 % o window: Specifies the name or id of an X window.
8902 % o filename: the name of the image filename to display.
8905 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8906 const char *window,const char *filename)
8915 assert(filename != (char *) NULL);
8916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8917 if (display == (Display *) NULL)
8918 display=XOpenDisplay((char *) NULL);
8919 if (display == (Display *) NULL)
8921 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8922 return(MagickFalse);
8924 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8925 remote_window=(Window) NULL;
8926 root_window=XRootWindow(display,XDefaultScreen(display));
8927 if (window != (char *) NULL)
8930 Search window hierarchy and identify any clients by name or ID.
8932 if (isdigit((unsigned char) *window) != 0)
8933 remote_window=XWindowByID(display,root_window,(Window)
8934 strtol((char *) window,(char **) NULL,0));
8935 if (remote_window == (Window) NULL)
8936 remote_window=XWindowByName(display,root_window,window);
8938 if (remote_window == (Window) NULL)
8939 remote_window=XWindowByProperty(display,root_window,remote_atom);
8940 if (remote_window == (Window) NULL)
8942 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8944 return(MagickFalse);
8947 Send remote command.
8949 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8950 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8951 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8952 (void) XSync(display,MagickFalse);
8957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8961 % X R e n d e r I m a g e %
8965 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8967 % XRenderImage() renders text on the image with an X11 font. It also returns
8968 % the bounding box of the text relative to the image.
8970 % The format of the XRenderImage method is:
8972 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
8973 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8975 % A description of each parameter follows:
8977 % o image: the image.
8979 % o draw_info: the draw info.
8981 % o offset: (x,y) location of text relative to image.
8983 % o metrics: bounding box of text.
8985 % o exception: return any errors or warnings in this structure.
8988 MagickPrivate MagickBooleanType XRenderImage(Image *image,
8989 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
8990 ExceptionInfo *exception)
9033 Open X server connection.
9035 display=XOpenDisplay(draw_info->server_name);
9036 if (display == (Display *) NULL)
9038 ThrowXWindowException(XServerError,"UnableToOpenXServer",
9039 draw_info->server_name);
9040 return(MagickFalse);
9043 Get user defaults from X resource database.
9045 (void) XSetErrorHandler(XError);
9046 image_info=AcquireImageInfo();
9047 client_name=GetClientName();
9048 resource_database=XGetResourceDatabase(display,client_name);
9049 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9050 resource_info.close_server=MagickFalse;
9051 resource_info.colormap=PrivateColormap;
9052 resource_info.font=AcquireString(draw_info->font);
9053 resource_info.background_color=AcquireString("#ffffffffffff");
9054 resource_info.foreground_color=AcquireString("#000000000000");
9055 map_info=XAllocStandardColormap();
9056 if (map_info == (XStandardColormap *) NULL)
9058 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9060 return(MagickFalse);
9063 Initialize visual info.
9065 visual_info=XBestVisualInfo(display,map_info,&resource_info);
9066 if (visual_info == (XVisualInfo *) NULL)
9068 ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
9069 return(MagickFalse);
9071 map_info->colormap=(Colormap) NULL;
9072 pixel.pixels=(unsigned long *) NULL;
9074 Initialize Standard Colormap info.
9076 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9078 XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL,
9080 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9082 Initialize font info.
9084 font_info=XBestFont(display,&resource_info,MagickFalse);
9085 if (font_info == (XFontStruct *) NULL)
9087 ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font);
9088 return(MagickFalse);
9090 if ((map_info == (XStandardColormap *) NULL) ||
9091 (visual_info == (XVisualInfo *) NULL) ||
9092 (font_info == (XFontStruct *) NULL))
9094 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9095 &resource_info,(XWindowInfo *) NULL);
9096 ThrowXWindowException(XServerError,"UnableToLoadFont",image->filename);
9097 return(MagickFalse);
9099 cache_info=(*draw_info);
9101 Initialize annotate info.
9103 XGetAnnotateInfo(&annotate_info);
9104 annotate_info.stencil=ForegroundStencil;
9105 if (cache_info.font != draw_info->font)
9108 Type name has changed.
9110 (void) XFreeFont(display,font_info);
9111 (void) CloneString(&resource_info.font,draw_info->font);
9112 font_info=XBestFont(display,&resource_info,MagickFalse);
9113 if (font_info == (XFontStruct *) NULL)
9115 ThrowXWindowException(XServerError,"UnableToLoadFont",
9117 return(MagickFalse);
9120 if (image->debug != MagickFalse)
9121 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9122 "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
9123 draw_info->font : "none",draw_info->pointsize);
9124 cache_info=(*draw_info);
9125 annotate_info.font_info=font_info;
9126 annotate_info.text=(char *) draw_info->text;
9127 annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int)
9128 strlen(draw_info->text));
9129 annotate_info.height=(unsigned int) font_info->ascent+font_info->descent;
9130 metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9131 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9132 metrics->ascent=(double) font_info->ascent+4;
9133 metrics->descent=(double) (-font_info->descent);
9134 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9135 metrics->height=font_info->ascent+font_info->descent;
9136 metrics->max_advance=(double) font_info->max_bounds.width;
9137 metrics->bounds.x1=0.0;
9138 metrics->bounds.y1=metrics->descent;
9139 metrics->bounds.x2=metrics->ascent+metrics->descent;
9140 metrics->bounds.y2=metrics->ascent+metrics->descent;
9141 metrics->underline_position=(-2.0);
9142 metrics->underline_thickness=1.0;
9143 if (draw_info->render == MagickFalse)
9145 if (draw_info->fill.alpha == TransparentAlpha)
9150 width=annotate_info.width;
9151 height=annotate_info.height;
9152 if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9153 (fabs(draw_info->affine.ry) >= MagickEpsilon))
9155 if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9156 (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9157 annotate_info.degrees=(double) (180.0/MagickPI)*
9158 atan2(draw_info->affine.rx,draw_info->affine.sx);
9160 (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent,
9161 "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height,
9162 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9163 draw_info->interline_spacing-0.5));
9164 pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
9165 pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
9166 pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
9167 status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9170 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9172 return(MagickFalse);
9178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9182 % X R e t a i n W i n d o w C o l o r s %
9186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9188 % XRetainWindowColors() sets X11 color resources on a window. This preserves
9189 % the colors associated with an image displayed on the window.
9191 % The format of the XRetainWindowColors method is:
9193 % void XRetainWindowColors(Display *display,const Window window)
9195 % A description of each parameter follows:
9197 % o display: Specifies a connection to an X server; returned from
9200 % o window: Specifies a pointer to a XWindowInfo structure.
9203 MagickExport void XRetainWindowColors(Display *display,const Window window)
9212 Put property on the window.
9214 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9215 assert(display != (Display *) NULL);
9216 assert(window != (Window) NULL);
9217 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
9218 if (property == (Atom) NULL)
9220 ThrowXWindowException(XServerError,"UnableToCreateProperty",
9224 pixmap=XCreatePixmap(display,window,1,1,1);
9225 if (pixmap == (Pixmap) NULL)
9227 ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
9230 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9231 (unsigned char *) &pixmap,1);
9232 (void) XSetCloseDownMode(display,RetainPermanent);
9236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9240 % X S e l e c t W i n d o w %
9244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9246 % XSelectWindow() allows a user to select a window using the mouse. If the
9247 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
9248 % is returned in the crop_info structure.
9250 % The format of the XSelectWindow function is:
9252 % target_window=XSelectWindow(display,crop_info)
9254 % A description of each parameter follows:
9256 % o window: XSelectWindow returns the window id.
9258 % o display: Specifies a pointer to the Display structure; returned from
9261 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9262 % contains the extents of any cropping rectangle.
9265 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9267 #define MinimumCropArea (unsigned int) 9
9294 Initialize graphic context.
9296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9297 assert(display != (Display *) NULL);
9298 assert(crop_info != (RectangleInfo *) NULL);
9299 root_window=XRootWindow(display,XDefaultScreen(display));
9300 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9301 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9302 context_values.function=GXinvert;
9303 context_values.plane_mask=
9304 context_values.background ^ context_values.foreground;
9305 context_values.subwindow_mode=IncludeInferiors;
9306 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9307 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9308 if (annotate_context == (GC) NULL)
9309 return(MagickFalse);
9311 Grab the pointer using target cursor.
9313 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9314 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9315 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9316 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9317 GrabModeAsync,root_window,target_cursor,CurrentTime);
9318 if (status != GrabSuccess)
9320 ThrowXWindowException(XServerError,"UnableToGrabMouse","");
9321 return((Window) NULL);
9327 crop_info->height=0;
9329 target_window=(Window) NULL;
9334 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9335 (void) XDrawRectangle(display,root_window,annotate_context,
9336 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9337 (unsigned int) crop_info->height-1);
9339 Allow another event.
9341 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9342 (void) XWindowEvent(display,root_window,ButtonPressMask |
9343 ButtonReleaseMask | ButtonMotionMask,&event);
9344 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9345 (void) XDrawRectangle(display,root_window,annotate_context,
9346 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9347 (unsigned int) crop_info->height-1);
9352 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9353 event.xbutton.x,event.xbutton.y);
9354 if (target_window == (Window) NULL)
9355 target_window=root_window;
9356 x_offset=event.xbutton.x_root;
9357 y_offset=event.xbutton.y_root;
9358 crop_info->x=(ssize_t) x_offset;
9359 crop_info->y=(ssize_t) y_offset;
9361 crop_info->height=0;
9373 Discard pending button motion events.
9375 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9376 crop_info->x=(ssize_t) event.xmotion.x;
9377 crop_info->y=(ssize_t) event.xmotion.y;
9379 Check boundary conditions.
9381 if ((int) crop_info->x < x_offset)
9382 crop_info->width=(size_t) (x_offset-crop_info->x);
9385 crop_info->width=(size_t) (crop_info->x-x_offset);
9386 crop_info->x=(ssize_t) x_offset;
9388 if ((int) crop_info->y < y_offset)
9389 crop_info->height=(size_t) (y_offset-crop_info->y);
9392 crop_info->height=(size_t) (crop_info->y-y_offset);
9393 crop_info->y=(ssize_t) y_offset;
9399 } while ((target_window == (Window) NULL) || (presses > 0));
9400 (void) XUngrabPointer(display,CurrentTime);
9401 (void) XFreeCursor(display,target_cursor);
9402 (void) XFreeGC(display,annotate_context);
9403 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9406 crop_info->height=0;
9408 if ((crop_info->width != 0) && (crop_info->height != 0))
9409 target_window=root_window;
9410 return(target_window);
9414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9418 % X S e t C u r s o r S t a t e %
9422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9424 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9425 % reset to their default.
9427 % The format of the XXSetCursorState method is:
9429 % XSetCursorState(display,windows,const MagickStatusType state)
9431 % A description of each parameter follows:
9433 % o display: Specifies a connection to an X server; returned from
9436 % o windows: Specifies a pointer to a XWindows structure.
9438 % o state: An unsigned integer greater than 0 sets the cursor state
9439 % to busy, otherwise the cursor are reset to their default.
9442 MagickPrivate void XSetCursorState(Display *display,XWindows *windows,
9443 const MagickStatusType state)
9445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9446 assert(display != (Display *) NULL);
9447 assert(windows != (XWindows *) NULL);
9450 (void) XCheckDefineCursor(display,windows->image.id,
9451 windows->image.busy_cursor);
9452 (void) XCheckDefineCursor(display,windows->pan.id,
9453 windows->pan.busy_cursor);
9454 (void) XCheckDefineCursor(display,windows->magnify.id,
9455 windows->magnify.busy_cursor);
9456 (void) XCheckDefineCursor(display,windows->command.id,
9457 windows->command.busy_cursor);
9461 (void) XCheckDefineCursor(display,windows->image.id,
9462 windows->image.cursor);
9463 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9464 (void) XCheckDefineCursor(display,windows->magnify.id,
9465 windows->magnify.cursor);
9466 (void) XCheckDefineCursor(display,windows->command.id,
9467 windows->command.cursor);
9468 (void) XCheckDefineCursor(display,windows->command.id,
9469 windows->widget.cursor);
9470 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9472 windows->info.mapped=MagickFalse;
9476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9480 % X S e t W i n d o w s %
9484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9486 % XSetWindows() sets the X windows structure if the windows info is specified.
9487 % Otherwise the current windows structure is returned.
9489 % The format of the XSetWindows method is:
9491 % XWindows *XSetWindows(XWindows *windows_info)
9493 % A description of each parameter follows:
9495 % o windows_info: Initialize the Windows structure with this information.
9498 MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9501 *windows = (XWindows *) NULL;
9503 if (windows_info != (XWindows *) ~0)
9505 windows=(XWindows *) RelinquishMagickMemory(windows);
9506 windows=windows_info;
9511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9515 % X U s e r P r e f e r e n c e s %
9519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9521 % XUserPreferences() saves the preferences in a configuration file in the
9522 % users' home directory.
9524 % The format of the XUserPreferences method is:
9526 % void XUserPreferences(XResourceInfo *resource_info)
9528 % A description of each parameter follows:
9530 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9533 MagickPrivate void XUserPreferences(XResourceInfo *resource_info)
9535 #if defined(X11_PREFERENCES_PATH)
9537 cache[MaxTextExtent],
9538 filename[MaxTextExtent],
9539 specifier[MaxTextExtent];
9546 preferences_database;
9549 Save user preferences to the client configuration file.
9551 assert(resource_info != (XResourceInfo *) NULL);
9552 client_name=GetClientName();
9553 preferences_database=XrmGetStringDatabase("");
9554 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9555 value=resource_info->backdrop ? "True" : "False";
9556 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9557 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
9558 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9559 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9560 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9562 value=resource_info->confirm_exit ? "True" : "False";
9563 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9564 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9566 value=resource_info->confirm_edit ? "True" : "False";
9567 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9568 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9570 value=resource_info->display_warnings ? "True" : "False";
9571 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9572 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
9573 value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9575 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9576 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9578 value=resource_info->gamma_correct ? "True" : "False";
9579 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9580 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9581 (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
9582 resource_info->undo_cache);
9583 XrmPutStringResource(&preferences_database,specifier,cache);
9584 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9585 value=resource_info->use_pixmap ? "True" : "False";
9586 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9587 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9588 X11_PREFERENCES_PATH,client_name);
9589 ExpandFilename(filename);
9590 XrmPutFileDatabase(preferences_database,filename);
9595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9599 % X V i s u a l C l a s s N a m e %
9603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9605 % XVisualClassName() returns the visual class name as a character string.
9607 % The format of the XVisualClassName method is:
9609 % char *XVisualClassName(const int visual_class)
9611 % A description of each parameter follows:
9613 % o visual_type: XVisualClassName returns the visual class as a character
9616 % o class: Specifies the visual class.
9619 static const char *XVisualClassName(const int visual_class)
9621 switch (visual_class)
9623 case StaticGray: return("StaticGray");
9624 case GrayScale: return("GrayScale");
9625 case StaticColor: return("StaticColor");
9626 case PseudoColor: return("PseudoColor");
9627 case TrueColor: return("TrueColor");
9628 case DirectColor: return("DirectColor");
9630 return("unknown visual class");
9634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9644 % XWarning() displays a warning reason in a Notice widget.
9646 % The format of the XWarning method is:
9648 % void XWarning(const unsigned int warning,const char *reason,
9649 % const char *description)
9651 % A description of each parameter follows:
9653 % o warning: Specifies the numeric warning category.
9655 % o reason: Specifies the reason to display before terminating the
9658 % o description: Specifies any description to the reason.
9661 MagickPrivate void XWarning(const ExceptionType magick_unused(warning),
9662 const char *reason,const char *description)
9665 text[MaxTextExtent];
9670 if (reason == (char *) NULL)
9672 (void) CopyMagickString(text,reason,MaxTextExtent);
9673 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9674 windows=XSetWindows((XWindows *) ~0);
9675 XNoticeWidget(windows->display,windows,text,(char *) description);
9679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9683 % X W i n d o w B y I D %
9687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9689 % XWindowByID() locates a child window with a given ID. If not window with
9690 % the given name is found, 0 is returned. Only the window specified and its
9691 % subwindows are searched.
9693 % The format of the XWindowByID function is:
9695 % child=XWindowByID(display,window,id)
9697 % A description of each parameter follows:
9699 % o child: XWindowByID returns the window with the specified
9700 % id. If no windows are found, XWindowByID returns 0.
9702 % o display: Specifies a pointer to the Display structure; returned from
9705 % o id: Specifies the id of the window to locate.
9708 MagickPrivate Window XWindowByID(Display *display,const Window root_window,
9728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9729 assert(display != (Display *) NULL);
9730 assert(root_window != (Window) NULL);
9732 return(XSelectWindow(display,&rectangle_info));
9733 if (root_window == id)
9734 return(root_window);
9735 status=XQueryTree(display,root_window,&child,&child,&children,
9737 if (status == False)
9738 return((Window) NULL);
9739 window=(Window) NULL;
9740 for (i=0; i < (int) number_children; i++)
9743 Search each child and their children.
9745 window=XWindowByID(display,children[i],id);
9746 if (window != (Window) NULL)
9749 if (children != (Window *) NULL)
9750 (void) XFree((void *) children);
9755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9759 % X W i n d o w B y N a m e %
9763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9765 % XWindowByName() locates a window with a given name on a display. If no
9766 % window with the given name is found, 0 is returned. If more than one window
9767 % has the given name, the first one is returned. Only root and its children
9770 % The format of the XWindowByName function is:
9772 % window=XWindowByName(display,root_window,name)
9774 % A description of each parameter follows:
9776 % o window: XWindowByName returns the window id.
9778 % o display: Specifies a pointer to the Display structure; returned from
9781 % o root_window: Specifies the id of the root window.
9783 % o name: Specifies the name of the window to locate.
9786 MagickPrivate Window XWindowByName(Display *display,const Window root_window,
9806 assert(display != (Display *) NULL);
9807 assert(root_window != (Window) NULL);
9808 assert(name != (char *) NULL);
9809 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9810 if (XGetWMName(display,root_window,&window_name) != 0)
9811 if (LocaleCompare((char *) window_name.value,name) == 0)
9812 return(root_window);
9813 status=XQueryTree(display,root_window,&child,&child,&children,
9815 if (status == False)
9816 return((Window) NULL);
9817 window=(Window) NULL;
9818 for (i=0; i < (int) number_children; i++)
9821 Search each child and their children.
9823 window=XWindowByName(display,children[i],name);
9824 if (window != (Window) NULL)
9827 if (children != (Window *) NULL)
9828 (void) XFree((void *) children);
9833 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9837 % X W i n d o w B y P r o p e r y %
9841 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9843 % XWindowByProperty() locates a child window with a given property. If not
9844 % window with the given name is found, 0 is returned. If more than one window
9845 % has the given property, the first one is returned. Only the window
9846 % specified and its subwindows are searched.
9848 % The format of the XWindowByProperty function is:
9850 % child=XWindowByProperty(display,window,property)
9852 % A description of each parameter follows:
9854 % o child: XWindowByProperty returns the window id with the specified
9855 % property. If no windows are found, XWindowByProperty returns 0.
9857 % o display: Specifies a pointer to the Display structure; returned from
9860 % o property: Specifies the property of the window to locate.
9863 MagickPrivate Window XWindowByProperty(Display *display,const Window window,
9864 const Atom property)
9892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9893 assert(display != (Display *) NULL);
9894 assert(window != (Window) NULL);
9895 assert(property != (Atom) NULL);
9896 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9897 if (status == False)
9898 return((Window) NULL);
9900 child=(Window) NULL;
9901 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9903 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9904 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9906 (void) XFree((void *) data);
9907 if ((status == Success) && (type != (Atom) NULL))
9910 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9911 child=XWindowByProperty(display,children[i],property);
9912 if (children != (Window *) NULL)
9913 (void) XFree((void *) children);
9919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9923 % X I m p o r t I m a g e %
9927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9929 % XImportImage() reads an image from an X window.
9931 % The format of the XImportImage method is:
9933 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
9934 % ExceptionInfo *exception)
9936 % A description of each parameter follows:
9938 % o image_info: the image info..
9940 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9942 % o exception: return any errors or warnings in this structure.
9945 MagickExport Image *XImportImage(const ImageInfo *image_info,
9946 XImportInfo *ximage_info,ExceptionInfo *exception)
9948 assert(image_info != (const ImageInfo *) NULL);
9949 assert(image_info->signature == MagickSignature);
9950 if (image_info->debug != MagickFalse)
9951 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9952 image_info->filename);
9953 assert(ximage_info != (XImportInfo *) NULL);
9954 assert(exception != (ExceptionInfo *) NULL);
9955 assert(exception->signature == MagickSignature);
9956 return((Image *) NULL);
9960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9964 % X R e n d e r X 1 1 %
9968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9970 % XRenderImage() renders text on the image with an X11 font. It also returns
9971 % the bounding box of the text relative to the image.
9973 % The format of the XRenderImage method is:
9975 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
9976 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
9978 % A description of each parameter follows:
9980 % o image: the image.
9982 % o draw_info: the draw info.
9984 % o offset: (x,y) location of text relative to image.
9986 % o metrics: bounding box of text.
9988 % o exception: return any errors or warnings in this structure.
9991 MagickPrivate MagickBooleanType XRenderImage(Image *image,
9992 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
9993 ExceptionInfo *exception)
9998 (void) ThrowMagickException(exception,GetMagickModule(),
9999 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)",
10001 return(MagickFalse);
10006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10010 + X C o m p o n e n t G e n e s i s %
10014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10016 % XComponentGenesis() instantiates the X component.
10018 % The format of the XComponentGenesis method is:
10020 % MagickBooleanType XComponentGenesis(void)
10023 MagickPrivate MagickBooleanType XComponentGenesis(void)
10025 return(MagickTrue);
10029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10033 % X G e t I m p o r t I n f o %
10037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10039 % XGetImportInfo() initializes the XImportInfo structure.
10041 % The format of the XGetImportInfo method is:
10043 % void XGetImportInfo(XImportInfo *ximage_info)
10045 % A description of each parameter follows:
10047 % o ximage_info: Specifies a pointer to an ImageInfo structure.
10050 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
10052 assert(ximage_info != (XImportInfo *) NULL);
10053 ximage_info->frame=MagickFalse;
10054 ximage_info->borders=MagickFalse;
10055 ximage_info->screen=MagickFalse;
10056 ximage_info->descend=MagickTrue;
10057 ximage_info->silent=MagickFalse;