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-2014 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));
1319 if (LocaleCompare(map_type,"list") != 0)
1322 User specified Standard Colormap.
1324 (void) FormatLocaleString((char *) map_name,MaxTextExtent,
1325 "RGB_%s_MAP",map_type);
1326 LocaleUpper(map_name);
1327 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1328 if (map_property != (Atom) NULL)
1329 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1335 *colormap[MaxStandardColormaps]=
1337 "_HP_RGB_SMOOTH_MAP_LIST",
1347 Choose a standard colormap from a list.
1349 for (i=0; i < MaxStandardColormaps; i++)
1351 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1352 if (map_property == (Atom) NULL)
1354 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1356 if (status != False)
1359 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1361 if (status == False)
1363 ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
1365 return((XVisualInfo *) NULL);
1368 Search all Standard Colormaps and visuals for ids that match.
1370 *map_info=map_list[0];
1371 #if !defined(PRE_R4_ICCCM)
1372 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1373 for (i=0; i < number_maps; i++)
1374 for (j=0; j < number_visuals; j++)
1375 if (map_list[i].visualid ==
1376 XVisualIDFromVisual(visual_list[j].visual))
1378 *map_info=map_list[i];
1379 visual_template.visualid=XVisualIDFromVisual(
1380 visual_list[j].visual);
1383 if (map_info->visualid != visual_template.visualid)
1385 ThrowXWindowException(XServerError,
1386 "UnableToMatchVisualToStandardColormap",map_type);
1387 return((XVisualInfo *) NULL);
1390 if (map_info->colormap == (Colormap) NULL)
1392 ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
1394 return((XVisualInfo *) NULL);
1396 (void) XFree((void *) map_list);
1400 static const unsigned int
1415 Pick one visual that displays the most simultaneous colors.
1417 visual_info=visual_list;
1419 for (i=1; i < number_visuals; i++)
1422 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1425 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1426 if (rank[p->klass] > rank[visual_info->klass])
1429 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1431 (void) XFree((void *) visual_list);
1433 Retrieve only one visual by its screen & id number.
1435 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1437 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1438 return((XVisualInfo *) NULL);
1439 return(visual_info);
1443 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1447 % X C h e c k D e f i n e C u r s o r %
1451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1453 % XCheckDefineCursor() prevents cursor changes on the root window.
1455 % The format of the XXCheckDefineCursor method is:
1457 % XCheckDefineCursor(display,window,cursor)
1459 % A description of each parameter follows:
1461 % o display: Specifies a connection to an X server; returned from
1464 % o window: the window.
1466 % o cursor: the cursor.
1469 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1472 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1473 assert(display != (Display *) NULL);
1474 if (window == XRootWindow(display,XDefaultScreen(display)))
1476 return(XDefineCursor(display,window,cursor));
1480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1484 % X C h e c k R e f r e s h W i n d o w s %
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490 % XCheckRefreshWindows() checks the X server for exposure events for a
1491 % particular window and updates the areassociated with the exposure event.
1493 % The format of the XCheckRefreshWindows method is:
1495 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1497 % A description of each parameter follows:
1499 % o display: Specifies a connection to an X server; returned from
1502 % o windows: Specifies a pointer to a XWindows structure.
1505 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1513 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1514 assert(display != (Display *) NULL);
1515 assert(windows != (XWindows *) NULL);
1516 XDelay(display,SuspendTime);
1517 id=windows->command.id;
1518 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1519 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1520 id=windows->image.id;
1521 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1522 XRefreshWindow(display,&windows->image,&event);
1523 XDelay(display,SuspendTime << 1);
1524 id=windows->command.id;
1525 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1526 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1527 id=windows->image.id;
1528 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1529 XRefreshWindow(display,&windows->image,&event);
1533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % X C l i e n t M e s s a g e %
1541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1544 % initialized with a particular protocol type and atom.
1546 % The format of the XClientMessage function is:
1548 % XClientMessage(display,window,protocol,reason,timestamp)
1550 % A description of each parameter follows:
1552 % o display: Specifies a pointer to the Display structure; returned from
1555 % o window: Specifies a pointer to a Window structure.
1557 % o protocol: Specifies an atom value.
1559 % o reason: Specifies an atom value which is the reason to send.
1561 % o timestamp: Specifies a value of type Time.
1564 MagickPrivate void XClientMessage(Display *display,const Window window,
1565 const Atom protocol,const Atom reason,const Time timestamp)
1570 assert(display != (Display *) NULL);
1571 client_event.type=ClientMessage;
1572 client_event.window=window;
1573 client_event.message_type=protocol;
1574 client_event.format=32;
1575 client_event.data.l[0]=(long) reason;
1576 client_event.data.l[1]=(long) timestamp;
1577 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1585 + X C l i e n t W i n d o w %
1589 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1591 % XClientWindow() finds a window, at or below the specified window, which has
1592 % a WM_STATE property. If such a window is found, it is returned, otherwise
1593 % the argument window is returned.
1595 % The format of the XClientWindow function is:
1597 % client_window=XClientWindow(display,target_window)
1599 % A description of each parameter follows:
1601 % o client_window: XClientWindow returns a window, at or below the specified
1602 % window, which has a WM_STATE property otherwise the argument
1603 % target_window is returned.
1605 % o display: Specifies a pointer to the Display structure; returned from
1608 % o target_window: Specifies the window to find a WM_STATE property.
1611 static Window XClientWindow(Display *display,Window target_window)
1633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1634 assert(display != (Display *) NULL);
1635 state=XInternAtom(display,"WM_STATE",MagickTrue);
1636 if (state == (Atom) NULL)
1637 return(target_window);
1639 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1640 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1641 if ((status == Success) && (type != (Atom) NULL))
1642 return(target_window);
1643 client_window=XWindowByProperty(display,target_window,state);
1644 if (client_window == (Window) NULL)
1645 return(target_window);
1646 return(client_window);
1650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654 + X C o m p o n e n t T e r m i n u s %
1658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1660 % XComponentTerminus() destroys the module component.
1662 % The format of the XComponentTerminus method is:
1664 % XComponentTerminus(void)
1667 MagickPrivate void XComponentTerminus(void)
1669 DestroyXResources();
1673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1677 % X C o n f i g u r e I m a g e C o l o r m a p %
1681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1683 % XConfigureImageColormap() creates a new X colormap.
1685 % The format of the XConfigureImageColormap method is:
1687 % void XConfigureImageColormap(Display *display,
1688 % XResourceInfo *resource_info,XWindows *windows,Image *image,
1689 % ExceptionInfo *exception)
1691 % A description of each parameter follows:
1693 % o display: Specifies a connection to an X server; returned from
1696 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1698 % o windows: Specifies a pointer to a XWindows structure.
1700 % o image: the image.
1702 % o exception: return any errors or warnings in this structure.
1705 MagickPrivate void XConfigureImageColormap(Display *display,
1706 XResourceInfo *resource_info,XWindows *windows,Image *image,
1707 ExceptionInfo *exception)
1713 Make standard colormap.
1715 XSetCursorState(display,windows,MagickTrue);
1716 XCheckRefreshWindows(display,windows);
1717 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1718 windows->map_info,windows->pixel_info,exception);
1719 colormap=windows->map_info->colormap;
1720 (void) XSetWindowColormap(display,windows->image.id,colormap);
1721 (void) XSetWindowColormap(display,windows->command.id,colormap);
1722 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1723 if (windows->magnify.mapped != MagickFalse)
1724 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1725 if (windows->pan.mapped != MagickFalse)
1726 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1727 XSetCursorState(display,windows,MagickFalse);
1728 XClientMessage(display,windows->image.id,windows->im_protocols,
1729 windows->im_update_colormap,CurrentTime);
1733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1737 % X C o n s t r a i n W i n d o w P o s i t i o n %
1741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1743 % XConstrainWindowPosition() assures a window is positioned within the X
1744 % server boundaries.
1746 % The format of the XConstrainWindowPosition method is:
1748 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1750 % A description of each parameter follows:
1752 % o display: Specifies a pointer to the Display structure; returned from
1755 % o window_info: Specifies a pointer to a XWindowInfo structure.
1758 MagickPrivate void XConstrainWindowPosition(Display *display,
1759 XWindowInfo *window_info)
1764 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1765 assert(display != (Display *) NULL);
1766 assert(window_info != (XWindowInfo *) NULL);
1767 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1768 if (window_info->x < 0)
1771 if (window_info->x > (int) limit)
1772 window_info->x=(int) limit;
1773 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1774 if (window_info->y < 0)
1777 if (window_info->y > limit)
1778 window_info->y=limit;
1782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1792 % XDelay() suspends program execution for the number of milliseconds
1795 % The format of the Delay method is:
1797 % void XDelay(Display *display,const size_t milliseconds)
1799 % A description of each parameter follows:
1801 % o display: Specifies a pointer to the Display structure; returned from
1804 % o milliseconds: Specifies the number of milliseconds to delay before
1808 MagickPrivate void XDelay(Display *display,const size_t milliseconds)
1810 assert(display != (Display *) NULL);
1811 (void) XFlush(display);
1812 MagickDelay(milliseconds);
1816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1820 % X D e s t r o y R e s o u r c e I n f o %
1824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1826 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1829 % The format of the XDestroyResourceInfo method is:
1831 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1833 % A description of each parameter follows:
1835 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1838 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1840 if (resource_info->image_geometry != (char *) NULL)
1841 resource_info->image_geometry=(char *)
1842 RelinquishMagickMemory(resource_info->image_geometry);
1843 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1844 resource_info->quantize_info=DestroyQuantizeInfo(
1845 resource_info->quantize_info);
1846 if (resource_info->client_name != (char *) NULL)
1847 resource_info->client_name=(char *)
1848 RelinquishMagickMemory(resource_info->client_name);
1849 if (resource_info->name != (char *) NULL)
1850 resource_info->name=DestroyString(resource_info->name);
1851 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1859 % X D e s t r o y W i n d o w C o l o r s %
1863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1865 % XDestroyWindowColors() frees X11 color resources previously saved on a
1866 % window by XRetainWindowColors or programs like xsetroot.
1868 % The format of the XDestroyWindowColors method is:
1870 % void XDestroyWindowColors(Display *display,Window window)
1872 % A description of each parameter follows:
1874 % o display: Specifies a connection to an X server; returned from
1877 % o window: Specifies a pointer to a Window structure.
1880 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1900 If there are previous resources on the root window, destroy them.
1902 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1903 assert(display != (Display *) NULL);
1904 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1905 if (property == (Atom) NULL)
1907 ThrowXWindowException(XServerError,"UnableToCreateProperty",
1911 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1912 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1913 if (status != Success)
1915 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1917 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1918 (void) XDeleteProperty(display,window,property);
1921 (void) XFree((void *) data);
1925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1929 % X D i s p l a y I m a g e I n f o %
1933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935 % XDisplayImageInfo() displays information about an X image.
1937 % The format of the XDisplayImageInfo method is:
1939 % void XDisplayImageInfo(Display *display,
1940 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1941 % Image *image,ExceptionInfo *exception)
1943 % A description of each parameter follows:
1945 % o display: Specifies a connection to an X server; returned from
1948 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1950 % o windows: Specifies a pointer to a XWindows structure.
1952 % o undo_image: the undo image.
1954 % o image: the image.
1956 % o exception: return any errors or warnings in this structure.
1959 MagickPrivate void XDisplayImageInfo(Display *display,
1960 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1961 Image *image,ExceptionInfo *exception)
1964 filename[MaxTextExtent],
1987 Write info about the X server to a file.
1989 assert(display != (Display *) NULL);
1990 assert(resource_info != (XResourceInfo *) NULL);
1991 assert(windows != (XWindows *) NULL);
1992 assert(image != (Image *) NULL);
1994 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1996 unique_file=AcquireUniqueFileResource(filename);
1997 if (unique_file != -1)
1998 file=fdopen(unique_file,"w");
1999 if ((unique_file == -1) || (file == (FILE *) NULL))
2001 XNoticeWidget(display,windows,"Unable to display image info",filename);
2004 if (resource_info->gamma_correct != MagickFalse)
2005 if (resource_info->display_gamma != (char *) NULL)
2006 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
2007 resource_info->display_gamma);
2009 Write info about the X image to a file.
2011 (void) FormatLocaleFile(file,"X\n visual: %s\n",
2012 XVisualClassName((int) windows->image.storage_class));
2013 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
2014 if (windows->visual_info->colormap_size != 0)
2015 (void) FormatLocaleFile(file," colormap size: %d\n",
2016 windows->visual_info->colormap_size);
2017 if (resource_info->colormap== SharedColormap)
2018 (void) FormatLocaleFile(file," colormap type: Shared\n");
2020 (void) FormatLocaleFile(file," colormap type: Private\n");
2021 (void) FormatLocaleFile(file," geometry: %dx%d\n",
2022 windows->image.ximage->width,windows->image.ximage->height);
2023 if (windows->image.crop_geometry != (char *) NULL)
2024 (void) FormatLocaleFile(file," crop geometry: %s\n",
2025 windows->image.crop_geometry);
2026 if (windows->image.pixmap == (Pixmap) NULL)
2027 (void) FormatLocaleFile(file," type: X Image\n");
2029 (void) FormatLocaleFile(file," type: Pixmap\n");
2030 if (windows->image.shape != MagickFalse)
2031 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2033 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2034 if (windows->image.shared_memory != MagickFalse)
2035 (void) FormatLocaleFile(file," shared memory: True\n");
2037 (void) FormatLocaleFile(file," shared memory: False\n");
2038 (void) FormatLocaleFile(file,"\n");
2039 if (resource_info->font != (char *) NULL)
2040 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2041 if (resource_info->text_font != (char *) NULL)
2042 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2044 Write info about the undo cache to a file.
2047 for (levels=0; undo_image != (Image *) NULL; levels++)
2049 number_pixels=undo_image->list->columns*undo_image->list->rows;
2050 bytes+=number_pixels*sizeof(PixelInfo);
2051 undo_image=GetPreviousImageInList(undo_image);
2053 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2054 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2055 ((bytes+(1 << 19)) >> 20));
2056 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2057 resource_info->undo_cache);
2059 Write info about the image to a file.
2061 (void) IdentifyImage(image,file,MagickTrue,exception);
2062 (void) fclose(file);
2063 text=FileToString(filename,~0UL,exception);
2064 (void) RelinquishUniqueFileResource(filename);
2065 if (text == (char *) NULL)
2067 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2068 "UnableToDisplayImageInfo");
2071 textlist=StringToList(text);
2072 if (textlist != (char **) NULL)
2075 title[MaxTextExtent];
2078 Display information about the image in the Text View widget.
2080 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2081 (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
2083 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2084 (char const **) textlist);
2085 for (i=0; textlist[i] != (char *) NULL; i++)
2086 textlist[i]=DestroyString(textlist[i]);
2087 textlist=(char **) RelinquishMagickMemory(textlist);
2089 text=DestroyString(text);
2093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2097 + X D i t h e r I m a g e %
2101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2103 % XDitherImage() dithers the reference image as required by the HP Color
2104 % Recovery algorithm. The color values are quantized to 3 bits of red and
2105 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2106 % standard colormap.
2108 % The format of the XDitherImage method is:
2110 % void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
2112 % A description of each parameter follows:
2114 % o image: the image.
2116 % o ximage: Specifies a pointer to a XImage structure; returned from
2119 % o exception: return any errors or warnings in this structure.
2122 static void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
2124 static const short int
2127 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2128 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2130 dither_green[2][16]=
2132 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2133 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2137 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2138 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2154 register const Quantum
2174 Allocate and initialize dither maps.
2176 for (i=0; i < 2; i++)
2177 for (j=0; j < 16; j++)
2179 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2181 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2182 sizeof(*green_map));
2183 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2185 if ((red_map[i][j] == (unsigned char *) NULL) ||
2186 (green_map[i][j] == (unsigned char *) NULL) ||
2187 (blue_map[i][j] == (unsigned char *) NULL))
2189 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
2195 Initialize dither tables.
2197 for (i=0; i < 2; i++)
2198 for (j=0; j < 16; j++)
2199 for (x=0; x < 256; x++)
2204 value+=dither_red[i][j];
2205 red_map[i][j][x]=(unsigned char)
2206 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2210 value+=dither_green[i][j];
2211 green_map[i][j][x]=(unsigned char)
2212 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2216 value+=((size_t) dither_blue[i][j] << 1);
2217 blue_map[i][j][x]=(unsigned char)
2218 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2223 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2224 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2228 image_view=AcquireVirtualCacheView(image,exception);
2229 for (y=0; y < (int) image->rows; y++)
2231 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2233 if (p == (const Quantum *) NULL)
2235 for (x=0; x < (int) image->columns; x++)
2237 color.red=(double) ClampToQuantum((double) (red_map[i][j][
2238 (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2239 color.green=(double) ClampToQuantum((double) (green_map[i][j][
2240 (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2241 color.blue=(double) ClampToQuantum((double) (blue_map[i][j][
2242 (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2243 pixel=(size_t) (((size_t) color.red & 0xe0) |
2244 (((size_t) color.green & 0xe0) >> 3) |
2245 (((size_t) color.blue & 0xc0) >> 6));
2247 p+=GetPixelChannels(image);
2257 image_view=DestroyCacheView(image_view);
2259 Free allocated memory.
2261 for (i=0; i < 2; i++)
2262 for (j=0; j < 16; j++)
2264 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2265 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2266 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2275 % X D r a w I m a g e %
2279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2281 % XDrawImage() draws a line on the image.
2283 % The format of the XDrawImage method is:
2285 % MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
2286 % XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
2288 % A description of each parameter follows:
2290 % o display: Specifies a connection to an X server; returned from
2293 % o pixel: Specifies a pointer to a XPixelInfo structure.
2295 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2297 % o image: the image.
2299 % o exception: return any errors or warnings in this structure.
2302 MagickPrivate MagickBooleanType XDrawImage(Display *display,
2303 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
2304 ExceptionInfo *exception)
2340 Initialize drawd image.
2342 assert(display != (Display *) NULL);
2343 assert(pixel != (XPixelInfo *) NULL);
2344 assert(draw_info != (XDrawInfo *) NULL);
2345 assert(image != (Image *) NULL);
2346 if (image->debug != MagickFalse)
2347 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2349 Initialize drawd pixmap.
2351 root_window=XRootWindow(display,XDefaultScreen(display));
2352 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2353 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2354 draw_info->height,depth);
2355 if (draw_pixmap == (Pixmap) NULL)
2356 return(MagickFalse);
2358 Initialize graphics info.
2360 context_values.background=(size_t) (~0);
2361 context_values.foreground=0;
2362 context_values.line_width=(int) draw_info->line_width;
2363 draw_context=XCreateGC(display,root_window,(size_t)
2364 (GCBackground | GCForeground | GCLineWidth),&context_values);
2365 if (draw_context == (GC) NULL)
2366 return(MagickFalse);
2370 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2373 Draw line to pixmap.
2375 (void) XSetBackground(display,draw_context,0);
2376 (void) XSetForeground(display,draw_context,(size_t) (~0));
2377 if (draw_info->stipple != (Pixmap) NULL)
2379 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2380 (void) XSetStipple(display,draw_context,draw_info->stipple);
2382 switch (draw_info->element)
2387 (void) XDrawLines(display,draw_pixmap,draw_context,
2388 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2394 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2395 draw_info->line_info.y1,draw_info->line_info.x2,
2396 draw_info->line_info.y2);
2399 case RectangleElement:
2401 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2402 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2403 (unsigned int) draw_info->rectangle_info.width,
2404 (unsigned int) draw_info->rectangle_info.height);
2407 case FillRectangleElement:
2409 (void) XFillRectangle(display,draw_pixmap,draw_context,
2410 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2411 (unsigned int) draw_info->rectangle_info.width,
2412 (unsigned int) draw_info->rectangle_info.height);
2416 case EllipseElement:
2418 (void) XDrawArc(display,draw_pixmap,draw_context,
2419 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2420 (unsigned int) draw_info->rectangle_info.width,
2421 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2424 case FillCircleElement:
2425 case FillEllipseElement:
2427 (void) XFillArc(display,draw_pixmap,draw_context,
2428 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2429 (unsigned int) draw_info->rectangle_info.width,
2430 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2433 case PolygonElement:
2438 coordinate_info=draw_info->coordinate_info;
2439 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2440 (int) draw_info->number_coordinates,CoordModeOrigin);
2441 (void) XDrawLine(display,draw_pixmap,draw_context,
2442 coordinate_info[draw_info->number_coordinates-1].x,
2443 coordinate_info[draw_info->number_coordinates-1].y,
2444 coordinate_info[0].x,coordinate_info[0].y);
2447 case FillPolygonElement:
2449 (void) XFillPolygon(display,draw_pixmap,draw_context,
2450 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2455 (void) XFreeGC(display,draw_context);
2459 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2460 draw_info->height,AllPlanes,ZPixmap);
2461 if (draw_ximage == (XImage *) NULL)
2462 return(MagickFalse);
2463 (void) XFreePixmap(display,draw_pixmap);
2465 Initialize draw image.
2467 draw_image=AcquireImage((ImageInfo *) NULL,exception);
2468 if (draw_image == (Image *) NULL)
2469 return(MagickFalse);
2470 draw_image->columns=draw_info->width;
2471 draw_image->rows=draw_info->height;
2473 Transfer drawn X image to image.
2475 width=(unsigned int) image->columns;
2476 height=(unsigned int) image->rows;
2479 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2480 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
2481 (ssize_t) y,&draw_image->background_color,exception);
2482 if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
2483 return(MagickFalse);
2484 draw_image->alpha_trait=BlendPixelTrait;
2485 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2486 for (y=0; y < (int) draw_image->rows; y++)
2494 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2496 if (q == (Quantum *) NULL)
2498 for (x=0; x < (int) draw_image->columns; x++)
2500 if (XGetPixel(draw_ximage,x,y) == 0)
2503 Set this pixel to the background color.
2505 SetPixelInfoPixel(draw_image,&draw_image->background_color,q);
2506 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2507 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2512 Set this pixel to the pen color.
2514 SetPixelRed(draw_image,ScaleShortToQuantum(
2515 pixel->pen_color.red),q);
2516 SetPixelGreen(draw_image,ScaleShortToQuantum(
2517 pixel->pen_color.green),q);
2518 SetPixelBlue(draw_image,ScaleShortToQuantum(
2519 pixel->pen_color.blue),q);
2520 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2521 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2523 q+=GetPixelChannels(draw_image);
2525 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2528 draw_view=DestroyCacheView(draw_view);
2529 XDestroyImage(draw_ximage);
2531 Determine draw geometry.
2533 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2534 if ((width != (unsigned int) draw_image->columns) ||
2535 (height != (unsigned int) draw_image->rows))
2538 image_geometry[MaxTextExtent];
2543 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
2545 (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2548 if (draw_info->degrees != 0.0)
2562 rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
2563 if (rotate_image == (Image *) NULL)
2564 return(MagickFalse);
2565 draw_image=DestroyImage(draw_image);
2566 draw_image=rotate_image;
2568 Annotation is relative to the degree of rotation.
2570 normalized_degrees=draw_info->degrees;
2571 while (normalized_degrees < -45.0)
2572 normalized_degrees+=360.0;
2573 for (rotations=0; normalized_degrees > 45.0; rotations++)
2574 normalized_degrees-=90.0;
2575 switch (rotations % 4)
2585 x=x-(int) draw_image->columns/2;
2586 y=y+(int) draw_image->columns/2;
2594 x=x-(int) draw_image->columns;
2602 x=x-(int) draw_image->columns/2;
2603 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2609 Composite text onto the image.
2611 draw_view=AcquireAuthenticCacheView(draw_image,exception);
2612 for (y=0; y < (int) draw_image->rows; y++)
2620 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2622 if (q == (Quantum *) NULL)
2624 for (x=0; x < (int) draw_image->columns; x++)
2626 if (GetPixelAlpha(image,q) != TransparentAlpha)
2627 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2628 q+=GetPixelChannels(draw_image);
2630 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2633 draw_view=DestroyCacheView(draw_view);
2634 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2635 if (draw_info->stencil == TransparentStencil)
2636 (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
2637 (ssize_t) x,(ssize_t) y,exception);
2640 alpha_trait=image->alpha_trait;
2641 (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
2642 (ssize_t) x,(ssize_t) y,exception);
2643 image->alpha_trait=alpha_trait;
2645 draw_image=DestroyImage(draw_image);
2650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2660 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2661 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2662 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it
2665 % The format of the XError function is:
2667 % int XError(display,error)
2669 % A description of each parameter follows:
2671 % o display: Specifies a pointer to the Display structure; returned from
2674 % o error: Specifies the error event.
2678 #if defined(__cplusplus) || defined(c_plusplus)
2682 MagickExport int XError(Display *display,XErrorEvent *error)
2684 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2685 assert(display != (Display *) NULL);
2686 assert(error != (XErrorEvent *) NULL);
2687 xerror_alert=MagickTrue;
2688 switch (error->request_code)
2692 if ((int) error->error_code == BadDrawable)
2693 return(MagickFalse);
2696 case X_GetWindowAttributes:
2699 if ((int) error->error_code == BadWindow)
2700 return(MagickFalse);
2705 if ((int) error->error_code == BadValue)
2706 return(MagickFalse);
2713 #if defined(__cplusplus) || defined(c_plusplus)
2718 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2722 % X F r e e R e s o u r c e s %
2726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2728 % XFreeResources() frees X11 resources.
2730 % The format of the XFreeResources method is:
2732 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2733 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2734 % XResourceInfo *resource_info,XWindowInfo *window_info)
2735 % resource_info,window_info)
2737 % A description of each parameter follows:
2739 % o display: Specifies a connection to an X server; returned from
2742 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2743 % returned from XGetVisualInfo.
2745 % o map_info: If map_type is specified, this structure is initialized
2746 % with info from the Standard Colormap.
2748 % o pixel: Specifies a pointer to a XPixelInfo structure.
2750 % o font_info: Specifies a pointer to a XFontStruct structure.
2752 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2754 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2757 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2758 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2759 XResourceInfo *resource_info,XWindowInfo *window_info)
2761 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2762 assert(display != (Display *) NULL);
2763 assert(resource_info != (XResourceInfo *) NULL);
2764 if (window_info != (XWindowInfo *) NULL)
2769 if (window_info->ximage != (XImage *) NULL)
2770 XDestroyImage(window_info->ximage);
2771 if (window_info->id != (Window) NULL)
2774 Free destroy window and free cursors.
2776 if (window_info->id != XRootWindow(display,visual_info->screen))
2777 (void) XDestroyWindow(display,window_info->id);
2778 if (window_info->annotate_context != (GC) NULL)
2779 (void) XFreeGC(display,window_info->annotate_context);
2780 if (window_info->highlight_context != (GC) NULL)
2781 (void) XFreeGC(display,window_info->highlight_context);
2782 if (window_info->widget_context != (GC) NULL)
2783 (void) XFreeGC(display,window_info->widget_context);
2784 if (window_info->cursor != (Cursor) NULL)
2785 (void) XFreeCursor(display,window_info->cursor);
2786 window_info->cursor=(Cursor) NULL;
2787 if (window_info->busy_cursor != (Cursor) NULL)
2788 (void) XFreeCursor(display,window_info->busy_cursor);
2789 window_info->busy_cursor=(Cursor) NULL;
2795 if (font_info != (XFontStruct *) NULL)
2797 (void) XFreeFont(display,font_info);
2798 font_info=(XFontStruct *) NULL;
2800 if (map_info != (XStandardColormap *) NULL)
2803 Free X Standard Colormap.
2805 if (resource_info->map_type == (char *) NULL)
2806 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2807 (void) XFree((void *) map_info);
2812 if (visual_info != (XVisualInfo *) NULL)
2813 (void) XFree((void *) visual_info);
2814 if (resource_info->close_server != MagickFalse)
2815 (void) XCloseDisplay(display);
2819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2823 % X F r e e S t a n d a r d C o l o r m a p %
2827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2829 % XFreeStandardColormap() frees an X11 colormap.
2831 % The format of the XFreeStandardColormap method is:
2833 % void XFreeStandardColormap(Display *display,
2834 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2835 % XPixelInfo *pixel)
2837 % A description of each parameter follows:
2839 % o display: Specifies a connection to an X server; returned from
2842 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2843 % returned from XGetVisualInfo.
2845 % o map_info: If map_type is specified, this structure is initialized
2846 % with info from the Standard Colormap.
2848 % o pixel: Specifies a pointer to a XPixelInfo structure.
2851 MagickPrivate void XFreeStandardColormap(Display *display,
2852 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2857 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2858 assert(display != (Display *) NULL);
2859 assert(visual_info != (XVisualInfo *) NULL);
2860 assert(map_info != (XStandardColormap *) NULL);
2861 (void) XFlush(display);
2862 if (map_info->colormap != (Colormap) NULL)
2864 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2865 (void) XFreeColormap(display,map_info->colormap);
2867 if (pixel != (XPixelInfo *) NULL)
2868 if ((visual_info->klass != TrueColor) &&
2869 (visual_info->klass != DirectColor))
2870 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2871 (int) pixel->colors,0);
2873 map_info->colormap=(Colormap) NULL;
2874 if (pixel != (XPixelInfo *) NULL)
2876 if (pixel->pixels != (unsigned long *) NULL)
2877 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2878 pixel->pixels=(unsigned long *) NULL;
2883 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2887 % X G e t A n n o t a t e I n f o %
2891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2893 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2895 % The format of the XGetAnnotateInfo method is:
2897 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2899 % A description of each parameter follows:
2901 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2904 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2907 Initialize annotate structure.
2909 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2910 assert(annotate_info != (XAnnotateInfo *) NULL);
2913 annotate_info->width=0;
2914 annotate_info->height=0;
2915 annotate_info->stencil=ForegroundStencil;
2916 annotate_info->degrees=0.0;
2917 annotate_info->font_info=(XFontStruct *) NULL;
2918 annotate_info->text=(char *) NULL;
2919 *annotate_info->geometry='\0';
2920 annotate_info->previous=(XAnnotateInfo *) NULL;
2921 annotate_info->next=(XAnnotateInfo *) NULL;
2922 (void) XSupportsLocale();
2923 (void) XSetLocaleModifiers("");
2927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2931 % X G e t M a p I n f o %
2935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2937 % XGetMapInfo() initializes the XStandardColormap structure.
2939 % The format of the XStandardColormap method is:
2941 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2942 % XStandardColormap *map_info)
2944 % A description of each parameter follows:
2946 % o colormap: Specifies the ID of the X server colormap.
2948 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2949 % returned from XGetVisualInfo.
2951 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2954 MagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
2955 const Colormap colormap,XStandardColormap *map_info)
2958 Initialize map info.
2960 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2961 assert(visual_info != (XVisualInfo *) NULL);
2962 assert(map_info != (XStandardColormap *) NULL);
2963 map_info->colormap=colormap;
2964 map_info->red_max=visual_info->red_mask;
2965 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2966 if (map_info->red_max != 0)
2967 while ((map_info->red_max & 0x01) == 0)
2969 map_info->red_max>>=1;
2970 map_info->red_mult<<=1;
2972 map_info->green_max=visual_info->green_mask;
2973 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2974 if (map_info->green_max != 0)
2975 while ((map_info->green_max & 0x01) == 0)
2977 map_info->green_max>>=1;
2978 map_info->green_mult<<=1;
2980 map_info->blue_max=visual_info->blue_mask;
2981 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2982 if (map_info->blue_max != 0)
2983 while ((map_info->blue_max & 0x01) == 0)
2985 map_info->blue_max>>=1;
2986 map_info->blue_mult<<=1;
2988 map_info->base_pixel=0;
2992 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2996 % X G e t P i x e l I n f o %
3000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3002 % XGetPixelInfo() initializes the PixelInfo structure.
3004 % The format of the XGetPixelInfo method is:
3006 % void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
3007 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
3008 % Image *image,XPixelInfo *pixel)
3011 % A description of each parameter follows:
3013 % o display: Specifies a connection to an X server; returned from
3016 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
3017 % returned from XGetVisualInfo.
3019 % o map_info: If map_type is specified, this structure is initialized
3020 % with info from the Standard Colormap.
3022 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3024 % o image: the image.
3026 % o pixel: Specifies a pointer to a XPixelInfo structure.
3029 MagickPrivate void XGetPixelInfo(Display *display,
3030 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3031 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3034 *PenColors[MaxNumberPens]=
3036 "#000000000000", /* black */
3037 "#00000000ffff", /* blue */
3038 "#0000ffffffff", /* cyan */
3039 "#0000ffff0000", /* green */
3040 "#bdbdbdbdbdbd", /* gray */
3041 "#ffff00000000", /* red */
3042 "#ffff0000ffff", /* magenta */
3043 "#ffffffff0000", /* yellow */
3044 "#ffffffffffff", /* white */
3045 "#bdbdbdbdbdbd", /* gray */
3046 "#bdbdbdbdbdbd" /* gray */
3066 Initialize pixel info.
3068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3069 assert(display != (Display *) NULL);
3070 assert(visual_info != (XVisualInfo *) NULL);
3071 assert(map_info != (XStandardColormap *) NULL);
3072 assert(resource_info != (XResourceInfo *) NULL);
3073 assert(pixel != (XPixelInfo *) NULL);
3075 if (image != (Image *) NULL)
3076 if (image->storage_class == PseudoClass)
3077 pixel->colors=(ssize_t) image->colors;
3078 packets=(unsigned int)
3079 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3080 if (pixel->pixels != (unsigned long *) NULL)
3081 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3082 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3083 sizeof(pixel->pixels));
3084 if (pixel->pixels == (unsigned long *) NULL)
3085 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3088 Set foreground color.
3090 colormap=map_info->colormap;
3091 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3092 &pixel->foreground_color);
3093 status=XParseColor(display,colormap,resource_info->foreground_color,
3094 &pixel->foreground_color);
3095 if (status == False)
3096 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3097 resource_info->foreground_color);
3098 pixel->foreground_color.pixel=
3099 XStandardPixel(map_info,&pixel->foreground_color);
3100 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3102 Set background color.
3104 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3105 status=XParseColor(display,colormap,resource_info->background_color,
3106 &pixel->background_color);
3107 if (status == False)
3108 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3109 resource_info->background_color);
3110 pixel->background_color.pixel=
3111 XStandardPixel(map_info,&pixel->background_color);
3112 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3116 (void) XParseColor(display,colormap,(char *) BorderColor,
3117 &pixel->border_color);
3118 status=XParseColor(display,colormap,resource_info->border_color,
3119 &pixel->border_color);
3120 if (status == False)
3121 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3122 resource_info->border_color);
3123 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3124 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3128 pixel->matte_color=pixel->background_color;
3129 if (resource_info->matte_color != (char *) NULL)
3132 Matte color is specified as a X resource or command line argument.
3134 status=XParseColor(display,colormap,resource_info->matte_color,
3135 &pixel->matte_color);
3136 if (status == False)
3137 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3138 resource_info->matte_color);
3139 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3140 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3143 Set highlight color.
3145 pixel->highlight_color.red=(unsigned short) ((
3146 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3147 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3148 pixel->highlight_color.green=(unsigned short) ((
3149 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3150 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3151 pixel->highlight_color.blue=(unsigned short) ((
3152 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3153 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3154 pixel->highlight_color.pixel=
3155 XStandardPixel(map_info,&pixel->highlight_color);
3156 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3160 pixel->shadow_color.red=(unsigned short) (((double)
3161 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3162 pixel->shadow_color.green=(unsigned short) (((double)
3163 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3164 pixel->shadow_color.blue=(unsigned short) (((double)
3165 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3166 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3167 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3171 pixel->depth_color.red=(unsigned short) (((double)
3172 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3173 pixel->depth_color.green=(unsigned short) (((double)
3174 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3175 pixel->depth_color.blue=(unsigned short) (((double)
3176 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3177 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3178 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3182 pixel->trough_color.red=(unsigned short) (((double)
3183 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3184 pixel->trough_color.green=(unsigned short) (((double)
3185 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3186 pixel->trough_color.blue=(unsigned short) (((double)
3187 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3188 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3189 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3193 for (i=0; i < MaxNumberPens; i++)
3195 (void) XParseColor(display,colormap,(char *) PenColors[i],
3196 &pixel->pen_colors[i]);
3197 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3198 &pixel->pen_colors[i]);
3199 if (status == False)
3200 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3201 resource_info->pen_colors[i]);
3202 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3203 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3205 pixel->box_color=pixel->background_color;
3206 pixel->pen_color=pixel->foreground_color;
3209 if (image != (Image *) NULL)
3211 if ((resource_info->gamma_correct != MagickFalse) &&
3212 (image->gamma != 0.0))
3221 Initialize map relative to display and image gamma.
3223 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3224 red_gamma=geometry_info.rho;
3225 green_gamma=geometry_info.sigma;
3226 if ((flags & SigmaValue) == 0)
3227 green_gamma=red_gamma;
3228 blue_gamma=geometry_info.xi;
3229 if ((flags & XiValue) == 0)
3230 blue_gamma=red_gamma;
3231 red_gamma*=image->gamma;
3232 green_gamma*=image->gamma;
3233 blue_gamma*=image->gamma;
3235 if (image->storage_class == PseudoClass)
3238 Initialize pixel array for images of type PseudoClass.
3240 for (i=0; i < (ssize_t) image->colors; i++)
3241 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3242 for (i=0; i < MaxNumberPens; i++)
3243 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3244 pixel->colors+=MaxNumberPens;
3250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3254 % X G e t R e s o u r c e C l a s s %
3258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3260 % XGetResourceClass() queries the X server for the specified resource name or
3261 % class. If the resource name or class is not defined in the database, the
3262 % supplied default value is returned.
3264 % The format of the XGetResourceClass method is:
3266 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3267 % const char *keyword,char *resource_default)
3269 % A description of each parameter follows:
3271 % o database: Specifies a resource database; returned from
3272 % XrmGetStringDatabase.
3274 % o client_name: Specifies the application name used to retrieve resource
3275 % info from the X server database.
3277 % o keyword: Specifies the keyword of the value being retrieved.
3279 % o resource_default: Specifies the default value to return if the query
3280 % fails to find the specified keyword/class.
3283 MagickExport char *XGetResourceClass(XrmDatabase database,
3284 const char *client_name,const char *keyword,char *resource_default)
3287 resource_class[MaxTextExtent],
3288 resource_name[MaxTextExtent];
3299 if (database == (XrmDatabase) NULL)
3300 return(resource_default);
3301 *resource_name='\0';
3302 *resource_class='\0';
3303 if (keyword != (char *) NULL)
3310 Initialize resource keyword and class.
3312 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
3313 client_name,keyword);
3314 c=(int) (*client_name);
3315 if ((c >= XK_a) && (c <= XK_z))
3318 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3319 c-=(XK_agrave-XK_Agrave);
3321 if ((c >= XK_oslash) && (c <= XK_thorn))
3322 c-=(XK_oslash-XK_Ooblique);
3324 if ((k >= XK_a) && (k <= XK_z))
3327 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3328 k-=(XK_agrave-XK_Agrave);
3330 if ((k >= XK_oslash) && (k <= XK_thorn))
3331 k-=(XK_oslash-XK_Ooblique);
3332 (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3333 client_name+1,k,keyword+1);
3335 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3337 if (status == False)
3338 return(resource_default);
3339 return(resource_value.addr);
3343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3347 % X G e t R e s o u r c e D a t a b a s e %
3351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3353 % XGetResourceDatabase() creates a new resource database and initializes it.
3355 % The format of the XGetResourceDatabase method is:
3357 % XrmDatabase XGetResourceDatabase(Display *display,
3358 % const char *client_name)
3360 % A description of each parameter follows:
3362 % o database: XGetResourceDatabase() returns the database after it is
3365 % o display: Specifies a connection to an X server; returned from
3368 % o client_name: Specifies the application name used to retrieve resource
3369 % info from the X server database.
3372 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3373 const char *client_name)
3376 filename[MaxTextExtent];
3388 if (display == (Display *) NULL)
3389 return((XrmDatabase) NULL);
3390 assert(client_name != (char *) NULL);
3392 Initialize resource database.
3395 (void) XGetDefault(display,(char *) client_name,"dummy");
3396 resource_database=XrmGetDatabase(display);
3398 Combine application database.
3400 if (client_name != (char *) NULL)
3403 Get basename of client.
3405 p=client_name+(strlen(client_name)-1);
3406 while ((p > client_name) && (*p != '/'))
3411 c=(int) (*client_name);
3412 if ((c >= XK_a) && (c <= XK_z))
3415 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3416 c-=(XK_agrave-XK_Agrave);
3418 if ((c >= XK_oslash) && (c <= XK_thorn))
3419 c-=(XK_oslash-XK_Ooblique);
3420 #if defined(X11_APPLICATION_PATH)
3421 (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
3422 X11_APPLICATION_PATH,c,client_name+1);
3423 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3425 if (XResourceManagerString(display) != (char *) NULL)
3428 Combine server database.
3430 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3431 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3434 Merge user preferences database.
3436 #if defined(X11_PREFERENCES_PATH)
3437 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
3438 X11_PREFERENCES_PATH,client_name);
3439 ExpandFilename(filename);
3440 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3442 return(resource_database);
3446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3450 % X G e t R e s o u r c e I n f o %
3454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3456 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3458 % The format of the XGetResourceInfo method is:
3460 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3461 % const char *client_name,XResourceInfo *resource_info)
3463 % A description of each parameter follows:
3465 % o image_info: the image info.
3467 % o database: Specifies a resource database; returned from
3468 % XrmGetStringDatabase.
3470 % o client_name: Specifies the application name used to retrieve
3471 % resource info from the X server database.
3473 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3476 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3477 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3488 Initialize resource info fields.
3490 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3491 assert(resource_info != (XResourceInfo *) NULL);
3492 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3493 resource_info->resource_database=database;
3494 resource_info->image_info=(ImageInfo *) image_info;
3495 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3496 XMagickProgressMonitor,(void *) NULL);
3497 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3498 resource_info->close_server=MagickTrue;
3499 resource_info->client_name=AcquireString(client_name);
3500 resource_value=XGetResourceClass(database,client_name,"backdrop",
3502 resource_info->backdrop=IsStringTrue(resource_value);
3503 resource_info->background_color=XGetResourceInstance(database,client_name,
3504 "background",(char *) "#d6d6d6d6d6d6");
3505 resource_info->border_color=XGetResourceInstance(database,client_name,
3506 "borderColor",BorderColor);
3507 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3509 resource_info->border_width=(unsigned int) StringToUnsignedLong(
3511 resource_value=XGetResourceClass(database,client_name,"colormap",
3513 resource_info->colormap=UndefinedColormap;
3514 if (LocaleCompare("private",resource_value) == 0)
3515 resource_info->colormap=PrivateColormap;
3516 if (LocaleCompare("shared",resource_value) == 0)
3517 resource_info->colormap=SharedColormap;
3518 if (resource_info->colormap == UndefinedColormap)
3519 ThrowXWindowException(OptionError,"UnrecognizedColormapType",
3521 resource_value=XGetResourceClass(database,client_name,
3522 "colorRecovery",(char *) "False");
3523 resource_info->color_recovery=IsStringTrue(resource_value);
3524 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3526 resource_info->confirm_exit=IsStringTrue(resource_value);
3527 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3529 resource_info->confirm_edit=IsStringTrue(resource_value);
3530 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3531 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3532 resource_info->display_gamma=XGetResourceClass(database,client_name,
3533 "displayGamma",(char *) "2.2");
3534 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3536 resource_info->display_warnings=IsStringTrue(resource_value);
3537 resource_info->font=XGetResourceClass(database,client_name,"font",
3539 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3540 resource_info->font);
3541 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3543 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3544 (char *) "variable");
3545 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3547 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3549 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3550 (char *) "7x13bold");
3551 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3552 (char *) "8x13bold");
3553 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3554 (char *) "9x15bold");
3555 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3557 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3559 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3561 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3563 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3564 "foreground",ForegroundColor);
3565 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3567 resource_info->gamma_correct=IsStringTrue(resource_value);
3568 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3569 client_name,"geometry",(char *) NULL));
3570 resource_value=XGetResourceClass(database,client_name,"gravity",
3572 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3573 MagickFalse,resource_value);
3574 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3576 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3577 "iconGeometry",(char *) NULL);
3578 resource_value=XGetResourceClass(database,client_name,"iconic",
3580 resource_info->iconic=IsStringTrue(resource_value);
3581 resource_value=XGetResourceClass(database,client_name,"immutable",
3582 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3584 resource_info->immutable=IsStringTrue(resource_value);
3585 resource_value=XGetResourceClass(database,client_name,"magnify",
3587 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3588 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3590 resource_info->matte_color=XGetResourceInstance(database,client_name,
3591 "mattecolor",(char *) NULL);
3592 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3593 "name",(char *) NULL));
3594 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3596 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3598 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3600 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3602 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3604 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3606 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3607 (char *) "magenta");
3608 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3610 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3612 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3614 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3616 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3617 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3618 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3619 resource_info->quantum=StringToLong(resource_value);
3620 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3621 "font",(char *) "fixed");
3622 resource_info->text_font=XGetResourceClass(database,client_name,
3623 "textFontList",resource_info->text_font);
3624 resource_info->title=XGetResourceClass(database,client_name,"title",
3626 resource_value=XGetResourceClass(database,client_name,"undoCache",
3628 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3629 resource_value=XGetResourceClass(database,client_name,"update",
3631 resource_info->update=IsStringTrue(resource_value);
3632 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3634 resource_info->use_pixmap=IsStringTrue(resource_value);
3635 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3637 resource_info->use_shared_memory=IsStringTrue(resource_value);
3638 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3640 resource_info->window_group=XGetResourceClass(database,client_name,
3641 "windowGroup",(char *) NULL);
3642 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3644 resource_info->write_filename=XGetResourceClass(database,client_name,
3645 "writeFilename",(char *) NULL);
3649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3653 % X G e t R e s o u r c e I n s t a n c e %
3657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3659 % XGetResourceInstance() queries the X server for the specified resource name.
3660 % If the resource name is not defined in the database, the supplied default
3661 % value is returned.
3663 % The format of the XGetResourceInstance method is:
3665 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3666 % const char *keyword,const char *resource_default)
3668 % A description of each parameter follows:
3670 % o database: Specifies a resource database; returned from
3671 % XrmGetStringDatabase.
3673 % o client_name: Specifies the application name used to retrieve
3674 % resource info from the X server database.
3676 % o keyword: Specifies the keyword of the value being retrieved.
3678 % o resource_default: Specifies the default value to return if the query
3679 % fails to find the specified keyword/class.
3682 MagickExport char *XGetResourceInstance(XrmDatabase database,
3683 const char *client_name,const char *keyword,const char *resource_default)
3687 resource_name[MaxTextExtent];
3695 if (database == (XrmDatabase) NULL)
3696 return((char *) resource_default);
3697 *resource_name='\0';
3698 if (keyword != (char *) NULL)
3699 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",client_name,
3701 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3703 if (status == False)
3704 return((char *) resource_default);
3705 return(resource_value.addr);
3709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3713 % X G e t S c r e e n D e n s i t y %
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3719 % XGetScreenDensity() returns the density of the X server screen in
3722 % The format of the XGetScreenDensity method is:
3724 % char *XGetScreenDensity(Display *display)
3726 % A description of each parameter follows:
3728 % o density: XGetScreenDensity() returns the density of the X screen in
3731 % o display: Specifies a connection to an X server; returned from
3735 MagickExport char *XGetScreenDensity(Display *display)
3738 density[MaxTextExtent];
3745 Set density as determined by screen size.
3747 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3748 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3749 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3750 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3751 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",x_density,
3753 return(GetPageGeometry(density));
3757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3761 + X G e t S u b w i n d o w %
3765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3767 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3768 % pointer and a button press.
3770 % The format of the XGetSubwindow method is:
3772 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3774 % A description of each parameter follows:
3776 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3777 % otherwise the subwindow is returned.
3779 % o display: Specifies a connection to an X server; returned from
3782 % o window: Specifies a pointer to a Window.
3784 % o x: the x coordinate of the pointer relative to the origin of the
3787 % o y: the y coordinate of the pointer relative to the origin of the
3791 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3804 assert(display != (Display *) NULL);
3805 source_window=XRootWindow(display,XDefaultScreen(display));
3806 if (window == (Window) NULL)
3807 return(source_window);
3808 target_window=window;
3811 status=XTranslateCoordinates(display,source_window,window,x,y,
3812 &x_offset,&y_offset,&target_window);
3815 if (target_window == (Window) NULL)
3817 source_window=window;
3818 window=target_window;
3822 if (target_window == (Window) NULL)
3823 target_window=window;
3824 return(target_window);
3828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3832 % X G e t W i n d o w C o l o r %
3836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3838 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3841 % The format of the XGetWindowColor method is:
3843 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3844 % char *name,ExceptionInfo *exception)
3846 % A description of each parameter follows:
3848 % o display: Specifies a connection to an X server; returned from
3851 % o windows: Specifies a pointer to a XWindows structure.
3853 % o name: the name of the color if found in the X Color Database is
3854 % returned in this character string.
3856 % o exception: return any errors or warnings in this structure.
3859 MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
3860 XWindows *windows,char *name,ExceptionInfo *exception)
3891 Choose a pixel from the X server.
3893 assert(display != (Display *) NULL);
3894 assert(name != (char *) NULL);
3895 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3897 target_window=XSelectWindow(display,&crop_info);
3898 if (target_window == (Window) NULL)
3899 return(MagickFalse);
3900 root_window=XRootWindow(display,XDefaultScreen(display));
3901 client_window=target_window;
3902 if (target_window != root_window)
3910 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3911 if (status != False)
3913 client_window=XClientWindow(display,target_window);
3914 target_window=client_window;
3918 Verify window is viewable.
3920 status=XGetWindowAttributes(display,target_window,&window_attributes);
3921 if ((status == False) || (window_attributes.map_state != IsViewable))
3922 return(MagickFalse);
3926 (void) XTranslateCoordinates(display,root_window,target_window,
3927 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3928 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3929 if (ximage == (XImage *) NULL)
3930 return(MagickFalse);
3931 color.pixel=XGetPixel(ximage,0,0);
3932 XDestroyImage(ximage);
3934 Match color against the color database.
3936 (void) XQueryColor(display,window_attributes.colormap,&color);
3937 pixel.red=(double) ScaleShortToQuantum(color.red);
3938 pixel.green=(double) ScaleShortToQuantum(color.green);
3939 pixel.blue=(double) ScaleShortToQuantum(color.blue);
3940 pixel.alpha=OpaqueAlpha;
3941 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3947 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3951 + X G e t W i n d o w I m a g e %
3955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3957 % XGetWindowImage() reads an image from the target X window and returns it.
3958 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3959 % target image with each child image in an optimized fashion. Any child
3960 % window that have the same visual, colormap, and are contained by its parent
3963 % The format of the XGetWindowImage method is:
3965 % Image *XGetWindowImage(Display *display,const Window window,
3966 % const unsigned int borders,const unsigned int level,
3967 % ExceptionInfo *exception)
3969 % A description of each parameter follows:
3971 % o display: Specifies a connection to an X server; returned from
3974 % o window: Specifies the window to obtain the image from.
3976 % o borders: Specifies whether borders pixels are to be saved with
3979 % o level: Specifies an unsigned integer representing the level of
3980 % decent in the window hierarchy. This value must be zero or one on
3981 % the initial call to XGetWindowImage. A value of zero returns after
3982 % one call. A value of one causes the function to descend the window
3983 % hierarchy and overlay the target image with each subwindow image.
3985 % o exception: return any errors or warnings in this structure.
3988 static Image *XGetWindowImage(Display *display,const Window window,
3989 const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
3991 typedef struct _ColormapInfo
3999 struct _ColormapInfo
4003 typedef struct _WindowInfo
4039 *colormap_info = (ColormapInfo *) NULL;
4059 Verify window is viewable.
4061 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4062 assert(display != (Display *) NULL);
4063 status=XGetWindowAttributes(display,window,&window_attributes);
4064 if ((status == False) || (window_attributes.map_state != IsViewable))
4065 return((Image *) NULL);
4067 Cropping rectangle is relative to root window.
4069 root_window=XRootWindow(display,XDefaultScreen(display));
4070 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4072 crop_info.x=(ssize_t) x_offset;
4073 crop_info.y=(ssize_t) y_offset;
4074 crop_info.width=(size_t) window_attributes.width;
4075 crop_info.height=(size_t) window_attributes.height;
4076 if (borders != MagickFalse)
4079 Include border in image.
4081 crop_info.x-=(ssize_t) window_attributes.border_width;
4082 crop_info.y-=(ssize_t) window_attributes.border_width;
4083 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4084 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4087 Crop to root window.
4089 if (crop_info.x < 0)
4091 crop_info.width+=crop_info.x;
4094 if (crop_info.y < 0)
4096 crop_info.height+=crop_info.y;
4099 display_width=XDisplayWidth(display,XDefaultScreen(display));
4100 if ((int) (crop_info.x+crop_info.width) > display_width)
4101 crop_info.width=(size_t) (display_width-crop_info.x);
4102 display_height=XDisplayHeight(display,XDefaultScreen(display));
4103 if ((int) (crop_info.y+crop_info.height) > display_height)
4104 crop_info.height=(size_t) (display_height-crop_info.y);
4106 Initialize window info attributes.
4108 if (number_windows >= max_windows)
4111 Allocate or resize window info buffer.
4114 if (window_info == (WindowInfo *) NULL)
4115 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4116 sizeof(*window_info));
4118 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4119 max_windows,sizeof(*window_info));
4121 if (window_info == (WindowInfo *) NULL)
4123 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
4124 return((Image *) NULL);
4126 id=number_windows++;
4127 window_info[id].window=window;
4128 window_info[id].visual=window_attributes.visual;
4129 window_info[id].colormap=window_attributes.colormap;
4130 window_info[id].bounds.x1=(short) crop_info.x;
4131 window_info[id].bounds.y1=(short) crop_info.y;
4132 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4133 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4134 crop_info.x-=x_offset;
4135 crop_info.y-=y_offset;
4136 window_info[id].crop_info=crop_info;
4146 Descend the window hierarchy.
4148 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4149 &children,&number_children);
4150 for (i=0; i < id; i++)
4151 if ((window_info[i].window == window_info[id].parent) &&
4152 (window_info[i].visual == window_info[id].visual) &&
4153 (window_info[i].colormap == window_info[id].colormap))
4155 if ((window_info[id].bounds.x1 < window_info[i].bounds.x1) ||
4156 (window_info[id].bounds.x2 > window_info[i].bounds.x2) ||
4157 (window_info[id].bounds.y1 < window_info[i].bounds.y1) ||
4158 (window_info[id].bounds.y2 > window_info[i].bounds.y2))
4161 Eliminate windows not circumscribed by their parent.
4167 if ((status == True) && (number_children != 0))
4169 for (i=0; i < (int) number_children; i++)
4170 (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
4172 (void) XFree((void *) children);
4213 Get X image for each window in the list.
4215 image=NewImageList();
4216 for (id=0; id < number_windows; id++)
4219 Does target window intersect top level window?
4221 import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4222 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4223 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4224 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4225 MagickTrue : MagickFalse;
4227 Is target window contained by another window with the same colormap?
4229 for (j=0; j < id; j++)
4230 if ((window_info[id].visual == window_info[j].visual) &&
4231 (window_info[id].colormap == window_info[j].colormap))
4233 if ((window_info[id].bounds.x1 >= window_info[j].bounds.x1) &&
4234 (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
4235 (window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
4236 (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4239 if (import == MagickFalse)
4244 ximage=XGetImage(display,window_info[id].window,(int)
4245 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4246 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4247 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4248 if (ximage == (XImage *) NULL)
4251 Initialize window colormap.
4254 colors=(XColor *) NULL;
4255 if (window_info[id].colormap != (Colormap) NULL)
4261 Search colormap list for window colormap.
4263 number_colors=(unsigned int) window_info[id].visual->map_entries;
4264 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4265 if (p->colormap == window_info[id].colormap)
4267 if (p == (ColormapInfo *) NULL)
4270 Get the window colormap.
4272 colors=(XColor *) AcquireQuantumMemory(number_colors,
4274 if (colors == (XColor *) NULL)
4276 XDestroyImage(ximage);
4277 return((Image *) NULL);
4279 if ((window_info[id].visual->klass != DirectColor) &&
4280 (window_info[id].visual->klass != TrueColor))
4281 for (i=0; i < (int) number_colors; i++)
4283 colors[i].pixel=(size_t) i;
4297 DirectColor or TrueColor visual.
4302 red_bit=window_info[id].visual->red_mask &
4303 (~(window_info[id].visual->red_mask)+1);
4304 green_bit=window_info[id].visual->green_mask &
4305 (~(window_info[id].visual->green_mask)+1);
4306 blue_bit=window_info[id].visual->blue_mask &
4307 (~(window_info[id].visual->blue_mask)+1);
4308 for (i=0; i < (int) number_colors; i++)
4310 colors[i].pixel=(unsigned long) (red | green | blue);
4313 if (red > window_info[id].visual->red_mask)
4316 if (green > window_info[id].visual->green_mask)
4319 if (blue > window_info[id].visual->blue_mask)
4323 (void) XQueryColors(display,window_info[id].colormap,colors,
4324 (int) number_colors);
4326 Append colormap to colormap list.
4328 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4329 if (p == (ColormapInfo *) NULL)
4330 return((Image *) NULL);
4331 p->colormap=window_info[id].colormap;
4333 p->next=colormap_info;
4339 Allocate image structure.
4341 composite_image=AcquireImage((ImageInfo *) NULL,exception);
4342 if (composite_image == (Image *) NULL)
4344 XDestroyImage(ximage);
4345 return((Image *) NULL);
4348 Convert X image to MIFF format.
4350 if ((window_info[id].visual->klass != TrueColor) &&
4351 (window_info[id].visual->klass != DirectColor))
4352 composite_image->storage_class=PseudoClass;
4353 composite_image->columns=(size_t) ximage->width;
4354 composite_image->rows=(size_t) ximage->height;
4355 composite_view=AcquireAuthenticCacheView(composite_image,exception);
4356 switch (composite_image->storage_class)
4374 Determine shift and mask for red, green, and blue.
4376 red_mask=window_info[id].visual->red_mask;
4378 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4383 green_mask=window_info[id].visual->green_mask;
4385 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4390 blue_mask=window_info[id].visual->blue_mask;
4392 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4398 Convert X image to DirectClass packets.
4400 if ((number_colors != 0) &&
4401 (window_info[id].visual->klass == DirectColor))
4402 for (y=0; y < (int) composite_image->rows; y++)
4404 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4405 composite_image->columns,1,exception);
4406 if (q == (Quantum *) NULL)
4408 for (x=0; x < (int) composite_image->columns; x++)
4410 pixel=XGetPixel(ximage,x,y);
4411 index=(pixel >> red_shift) & red_mask;
4412 SetPixelRed(composite_image,
4413 ScaleShortToQuantum(colors[index].red),q);
4414 index=(pixel >> green_shift) & green_mask;
4415 SetPixelGreen(composite_image,
4416 ScaleShortToQuantum(colors[index].green),q);
4417 index=(pixel >> blue_shift) & blue_mask;
4418 SetPixelBlue(composite_image,
4419 ScaleShortToQuantum(colors[index].blue),q);
4420 q+=GetPixelChannels(composite_image);
4422 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4423 if (status == MagickFalse)
4427 for (y=0; y < (int) composite_image->rows; y++)
4429 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4430 composite_image->columns,1,exception);
4431 if (q == (Quantum *) NULL)
4433 for (x=0; x < (int) composite_image->columns; x++)
4435 pixel=XGetPixel(ximage,x,y);
4436 color=(pixel >> red_shift) & red_mask;
4438 color=(65535UL*color)/red_mask;
4439 SetPixelRed(composite_image,ScaleShortToQuantum(
4440 (unsigned short) color),q);
4441 color=(pixel >> green_shift) & green_mask;
4442 if (green_mask != 0)
4443 color=(65535UL*color)/green_mask;
4444 SetPixelGreen(composite_image,ScaleShortToQuantum(
4445 (unsigned short) color),q);
4446 color=(pixel >> blue_shift) & blue_mask;
4448 color=(65535UL*color)/blue_mask;
4449 SetPixelBlue(composite_image,ScaleShortToQuantum(
4450 (unsigned short) color),q);
4451 q+=GetPixelChannels(composite_image);
4453 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4454 if (status == MagickFalse)
4464 status=AcquireImageColormap(composite_image,number_colors,
4466 if (status == MagickFalse)
4468 XDestroyImage(ximage);
4469 composite_image=DestroyImage(composite_image);
4470 return((Image *) NULL);
4472 for (i=0; i < (int) composite_image->colors; i++)
4474 composite_image->colormap[colors[i].pixel].red=(double)
4475 ScaleShortToQuantum(colors[i].red);
4476 composite_image->colormap[colors[i].pixel].green=(double)
4477 ScaleShortToQuantum(colors[i].green);
4478 composite_image->colormap[colors[i].pixel].blue=(double)
4479 ScaleShortToQuantum(colors[i].blue);
4482 Convert X image to PseudoClass packets.
4484 for (y=0; y < (int) composite_image->rows; y++)
4486 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4487 composite_image->columns,1,exception);
4488 if (q == (Quantum *) NULL)
4490 for (x=0; x < (int) composite_image->columns; x++)
4492 index=(Quantum) XGetPixel(ximage,x,y);
4493 SetPixelIndex(composite_image,index,q);
4494 SetPixelInfoPixel(composite_image,
4495 composite_image->colormap+(ssize_t) index,q);
4496 q+=GetPixelChannels(composite_image);
4498 status=SyncCacheViewAuthenticPixels(composite_view,exception);
4499 if (status == MagickFalse)
4505 composite_view=DestroyCacheView(composite_view);
4506 XDestroyImage(ximage);
4507 if (image == (Image *) NULL)
4509 image=composite_image;
4513 Composite any children in back-to-front order.
4515 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4516 &x_offset,&y_offset,&child);
4517 x_offset-=(int) crop_info.x;
4520 y_offset-=(int) crop_info.y;
4523 (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
4524 (ssize_t) x_offset,(ssize_t) y_offset,exception);
4525 composite_image=DestroyImage(composite_image);
4528 Relinquish resources.
4530 while (colormap_info != (ColormapInfo *) NULL)
4532 next=colormap_info->next;
4533 colormap_info->colors=(XColor *) RelinquishMagickMemory(
4534 colormap_info->colors);
4535 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4539 Relinquish resources and restore initial state.
4541 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4544 colormap_info=(ColormapInfo *) NULL;
4547 return((Image *) NULL);
4551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4555 % X G e t W i n d o w I n f o %
4559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4561 % XGetWindowInfo() initializes the XWindowInfo structure.
4563 % The format of the XGetWindowInfo method is:
4565 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4566 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4567 % XResourceInfo *resource_info,XWindowInfo *window)
4568 % resource_info,window)
4570 % A description of each parameter follows:
4572 % o display: Specifies a connection to an X server; returned from
4575 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4576 % returned from XGetVisualInfo.
4578 % o map_info: If map_type is specified, this structure is initialized
4579 % with info from the Standard Colormap.
4581 % o pixel: Specifies a pointer to a XPixelInfo structure.
4583 % o font_info: Specifies a pointer to a XFontStruct structure.
4585 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4588 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4589 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4590 XResourceInfo *resource_info,XWindowInfo *window)
4593 Initialize window info.
4595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4596 assert(display != (Display *) NULL);
4597 assert(visual_info != (XVisualInfo *) NULL);
4598 assert(map_info != (XStandardColormap *) NULL);
4599 assert(pixel != (XPixelInfo *) NULL);
4600 assert(resource_info != (XResourceInfo *) NULL);
4601 assert(window != (XWindowInfo *) NULL);
4602 if (window->id != (Window) NULL)
4604 if (window->cursor != (Cursor) NULL)
4605 (void) XFreeCursor(display,window->cursor);
4606 if (window->busy_cursor != (Cursor) NULL)
4607 (void) XFreeCursor(display,window->busy_cursor);
4608 if (window->highlight_stipple != (Pixmap) NULL)
4609 (void) XFreePixmap(display,window->highlight_stipple);
4610 if (window->shadow_stipple != (Pixmap) NULL)
4611 (void) XFreePixmap(display,window->shadow_stipple);
4612 if (window->name == (char *) NULL)
4613 window->name=AcquireString("");
4614 if (window->icon_name == (char *) NULL)
4615 window->icon_name=AcquireString("");
4620 Initialize these attributes just once.
4622 window->id=(Window) NULL;
4623 if (window->name == (char *) NULL)
4624 window->name=AcquireString("");
4625 if (window->icon_name == (char *) NULL)
4626 window->icon_name=AcquireString("");
4627 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4628 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4629 window->ximage=(XImage *) NULL;
4630 window->matte_image=(XImage *) NULL;
4631 window->pixmap=(Pixmap) NULL;
4632 window->matte_pixmap=(Pixmap) NULL;
4633 window->mapped=MagickFalse;
4634 window->stasis=MagickFalse;
4635 window->shared_memory=MagickTrue;
4636 window->segment_info=(void *) NULL;
4637 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4642 if (window->segment_info == (void *) NULL)
4643 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4644 segment_info=(XShmSegmentInfo *) window->segment_info;
4645 segment_info[0].shmid=(-1);
4646 segment_info[0].shmaddr=(char *) NULL;
4647 segment_info[1].shmid=(-1);
4648 segment_info[1].shmaddr=(char *) NULL;
4653 Initialize these attributes every time function is called.
4655 window->screen=visual_info->screen;
4656 window->root=XRootWindow(display,visual_info->screen);
4657 window->visual=visual_info->visual;
4658 window->storage_class=(unsigned int) visual_info->klass;
4659 window->depth=(unsigned int) visual_info->depth;
4660 window->visual_info=visual_info;
4661 window->map_info=map_info;
4662 window->pixel_info=pixel;
4663 window->font_info=font_info;
4664 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4665 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4666 window->geometry=(char *) NULL;
4667 window->icon_geometry=(char *) NULL;
4668 if (resource_info->icon_geometry != (char *) NULL)
4669 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4670 window->crop_geometry=(char *) NULL;
4671 window->flags=(size_t) PSize;
4674 window->min_width=1;
4675 window->min_height=1;
4676 window->width_inc=1;
4677 window->height_inc=1;
4678 window->border_width=resource_info->border_width;
4679 window->annotate_context=pixel->annotate_context;
4680 window->highlight_context=pixel->highlight_context;
4681 window->widget_context=pixel->widget_context;
4682 window->shadow_stipple=(Pixmap) NULL;
4683 window->highlight_stipple=(Pixmap) NULL;
4684 window->use_pixmap=MagickTrue;
4685 window->immutable=MagickFalse;
4686 window->shape=MagickFalse;
4688 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4689 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4690 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4691 window->attributes.background_pixel=pixel->background_color.pixel;
4692 window->attributes.background_pixmap=(Pixmap) NULL;
4693 window->attributes.bit_gravity=ForgetGravity;
4694 window->attributes.backing_store=WhenMapped;
4695 window->attributes.save_under=MagickTrue;
4696 window->attributes.border_pixel=pixel->border_color.pixel;
4697 window->attributes.colormap=map_info->colormap;
4698 window->attributes.cursor=window->cursor;
4699 window->attributes.do_not_propagate_mask=NoEventMask;
4700 window->attributes.event_mask=NoEventMask;
4701 window->attributes.override_redirect=MagickFalse;
4702 window->attributes.win_gravity=NorthWestGravity;
4703 window->orphan=MagickFalse;
4707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4711 % X H i g h l i g h t E l l i p s e %
4715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4717 % XHighlightEllipse() puts a border on the X server around a region defined by
4720 % The format of the XHighlightEllipse method is:
4722 % void XHighlightEllipse(Display *display,Window window,
4723 % GC annotate_context,const RectangleInfo *highlight_info)
4725 % A description of each parameter follows:
4727 % o display: Specifies a connection to an X server; returned from
4730 % o window: Specifies a pointer to a Window structure.
4732 % o annotate_context: Specifies a pointer to a GC structure.
4734 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4735 % contains the extents of any highlighting rectangle.
4738 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4739 GC annotate_context,const RectangleInfo *highlight_info)
4741 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4742 assert(display != (Display *) NULL);
4743 assert(window != (Window) NULL);
4744 assert(annotate_context != (GC) NULL);
4745 assert(highlight_info != (RectangleInfo *) NULL);
4746 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4748 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4749 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4750 (unsigned int) highlight_info->height-1,0,360*64);
4751 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4752 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4753 (unsigned int) highlight_info->height-3,0,360*64);
4757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4761 % X H i g h l i g h t L i n e %
4765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4767 % XHighlightLine() puts a border on the X server around a region defined by
4770 % The format of the XHighlightLine method is:
4772 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4773 % const XSegment *highlight_info)
4775 % A description of each parameter follows:
4777 % o display: Specifies a connection to an X server; returned from
4780 % o window: Specifies a pointer to a Window structure.
4782 % o annotate_context: Specifies a pointer to a GC structure.
4784 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4785 % contains the extents of any highlighting rectangle.
4788 MagickPrivate void XHighlightLine(Display *display,Window window,
4789 GC annotate_context,const XSegment *highlight_info)
4791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4792 assert(display != (Display *) NULL);
4793 assert(window != (Window) NULL);
4794 assert(annotate_context != (GC) NULL);
4795 assert(highlight_info != (XSegment *) NULL);
4796 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4797 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4801 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4805 % X H i g h l i g h t R e c t a n g l e %
4809 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4811 % XHighlightRectangle() puts a border on the X server around a region defined
4812 % by highlight_info.
4814 % The format of the XHighlightRectangle method is:
4816 % void XHighlightRectangle(Display *display,Window window,
4817 % GC annotate_context,const RectangleInfo *highlight_info)
4819 % A description of each parameter follows:
4821 % o display: Specifies a connection to an X server; returned from
4824 % o window: Specifies a pointer to a Window structure.
4826 % o annotate_context: Specifies a pointer to a GC structure.
4828 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4829 % contains the extents of any highlighting rectangle.
4832 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4833 GC annotate_context,const RectangleInfo *highlight_info)
4835 assert(display != (Display *) NULL);
4836 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4837 assert(window != (Window) NULL);
4838 assert(annotate_context != (GC) NULL);
4839 assert(highlight_info != (RectangleInfo *) NULL);
4840 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4842 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4843 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4844 (unsigned int) highlight_info->height-1);
4845 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4846 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4847 (unsigned int) highlight_info->height-3);
4851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4855 % X I m p o r t I m a g e %
4859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4861 % XImportImage() reads an image from an X window.
4863 % The format of the XImportImage method is:
4865 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
4866 % ExceptionInfo *exception)
4868 % A description of each parameter follows:
4870 % o image_info: the image info.
4872 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4874 % o exception: return any errors or warnings in this structure.
4877 MagickExport Image *XImportImage(const ImageInfo *image_info,
4878 XImportInfo *ximage_info,ExceptionInfo *exception)
4911 Open X server connection.
4913 assert(image_info != (const ImageInfo *) NULL);
4914 assert(image_info->signature == MagickSignature);
4915 if (image_info->debug != MagickFalse)
4916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4917 image_info->filename);
4918 assert(ximage_info != (XImportInfo *) NULL);
4919 display=XOpenDisplay(image_info->server_name);
4920 if (display == (Display *) NULL)
4922 ThrowXWindowException(XServerError,"UnableToOpenXServer",
4923 XDisplayName(image_info->server_name));
4924 return((Image *) NULL);
4927 Set our forgiving exception handler.
4929 (void) XSetErrorHandler(XError);
4931 Select target window.
4937 root=XRootWindow(display,XDefaultScreen(display));
4938 target=(Window) NULL;
4939 if ((image_info->filename != (char *) NULL) &&
4940 (*image_info->filename != '\0'))
4942 if (LocaleCompare(image_info->filename,"root") == 0)
4947 Select window by ID or name.
4949 if (isdigit((int) ((unsigned char) *image_info->filename)) != 0)
4950 target=XWindowByID(display,root,(Window)
4951 strtol(image_info->filename,(char **) NULL,0));
4952 if (target == (Window) NULL)
4953 target=XWindowByName(display,root,image_info->filename);
4954 if (target == (Window) NULL)
4955 ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
4956 image_info->filename);
4960 If target window is not defined, interactively select one.
4962 prior_target=target;
4963 if (target == (Window) NULL)
4964 target=XSelectWindow(display,&crop_info);
4965 if (target == (Window) NULL)
4966 ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
4967 image_info->filename);
4968 client=target; /* obsolete */
4974 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4975 if (status != False)
4983 Find window manager frame.
4985 status=XQueryTree(display,target,&root,&parent,&children,&d);
4986 if ((status != False) && (children != (Window *) NULL))
4987 (void) XFree((char *) children);
4988 if ((status == False) || (parent == (Window) NULL) ||
4996 client=XClientWindow(display,target);
4997 if (ximage_info->frame == MagickFalse)
4999 if ((ximage_info->frame == MagickFalse) &&
5000 (prior_target != MagickFalse))
5001 target=prior_target;
5004 if (ximage_info->screen)
5016 Obtain window image directly from screen.
5018 status=XGetWindowAttributes(display,target,&window_attributes);
5019 if (status == False)
5021 ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
5022 image_info->filename);
5023 (void) XCloseDisplay(display);
5024 return((Image *) NULL);
5026 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5027 crop_info.x=(ssize_t) x;
5028 crop_info.y=(ssize_t) y;
5029 crop_info.width=(size_t) window_attributes.width;
5030 crop_info.height=(size_t) window_attributes.height;
5031 if (ximage_info->borders != 0)
5034 Include border in image.
5036 crop_info.x-=window_attributes.border_width;
5037 crop_info.y-=window_attributes.border_width;
5038 crop_info.width+=window_attributes.border_width << 1;
5039 crop_info.height+=window_attributes.border_width << 1;
5044 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
5047 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5048 if ((status == True) && (number_windows > 0))
5050 ximage_info->descend=MagickTrue;
5051 (void) XFree ((char *) children);
5053 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5054 if (number_colormaps > 0)
5056 if (number_colormaps > 1)
5057 ximage_info->descend=MagickTrue;
5058 (void) XFree((char *) colormaps);
5061 Alert the user not to alter the screen.
5063 if (ximage_info->silent == MagickFalse)
5064 (void) XBell(display,0);
5066 Get image by window id.
5068 (void) XGrabServer(display);
5069 image=XGetWindowImage(display,target,ximage_info->borders,
5070 ximage_info->descend ? 1U : 0U,exception);
5071 (void) XUngrabServer(display);
5072 if (image == (Image *) NULL)
5073 ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
5074 image_info->filename)
5077 (void) CopyMagickString(image->filename,image_info->filename,
5079 if ((crop_info.width != 0) && (crop_info.height != 0))
5086 Crop image as defined by the cropping rectangle.
5088 clone_image=CloneImage(image,0,0,MagickTrue,exception);
5089 if (clone_image != (Image *) NULL)
5091 crop_image=CropImage(clone_image,&crop_info,exception);
5092 if (crop_image != (Image *) NULL)
5094 image=DestroyImage(image);
5099 status=XGetWMName(display,target,&window_name);
5102 if ((image_info->filename != (char *) NULL) &&
5103 (*image_info->filename == '\0'))
5104 (void) CopyMagickString(image->filename,(char *) window_name.value,
5105 (size_t) window_name.nitems+1);
5106 (void) XFree((void *) window_name.value);
5109 if (ximage_info->silent == MagickFalse)
5112 Alert the user we're done.
5114 (void) XBell(display,0);
5115 (void) XBell(display,0);
5117 (void) XCloseDisplay(display);
5122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5126 % X I n i t i a l i z e W i n d o w s %
5130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5132 % XInitializeWindows() initializes the XWindows structure.
5134 % The format of the XInitializeWindows method is:
5136 % XWindows *XInitializeWindows(Display *display,
5137 % XResourceInfo *resource_info)
5139 % A description of each parameter follows:
5141 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5143 % o display: Specifies a connection to an X server; returned from
5146 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5149 MagickPrivate XWindows *XInitializeWindows(Display *display,
5150 XResourceInfo *resource_info)
5159 Allocate windows structure.
5161 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5162 if (windows == (XWindows *) NULL)
5164 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5166 return((XWindows *) NULL);
5168 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5169 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5170 sizeof(*windows->pixel_info));
5171 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5172 sizeof(*windows->icon_pixel));
5173 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5174 sizeof(*windows->icon_resources));
5175 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5176 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5177 (windows->icon_resources == (XResourceInfo *) NULL))
5179 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5181 return((XWindows *) NULL);
5184 Initialize windows structure.
5186 windows->display=display;
5187 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5188 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5189 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5190 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5191 windows->im_remote_command=
5192 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5193 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5194 windows->im_update_colormap=
5195 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5196 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5197 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5198 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5199 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5200 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5201 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5202 (void) XSynchronize(display,IsWindows95());
5204 if (IsEventLogging())
5206 (void) XSynchronize(display,MagickTrue);
5207 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5208 GetMagickVersion((size_t *) NULL));
5209 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5210 (void) LogMagickEvent(X11Event,GetMagickModule(),
5211 " Window Manager: 0x%lx",windows->wm_protocols);
5212 (void) LogMagickEvent(X11Event,GetMagickModule(),
5213 " delete window: 0x%lx",windows->wm_delete_window);
5214 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5215 windows->wm_take_focus);
5216 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5217 windows->im_protocols);
5218 (void) LogMagickEvent(X11Event,GetMagickModule(),
5219 " remote command: 0x%lx",windows->im_remote_command);
5220 (void) LogMagickEvent(X11Event,GetMagickModule(),
5221 " update widget: 0x%lx",windows->im_update_widget);
5222 (void) LogMagickEvent(X11Event,GetMagickModule(),
5223 " update colormap: 0x%lx",windows->im_update_colormap);
5224 (void) LogMagickEvent(X11Event,GetMagickModule(),
5225 " former image: 0x%lx",windows->im_former_image);
5226 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5227 windows->im_next_image);
5228 (void) LogMagickEvent(X11Event,GetMagickModule(),
5229 " retain colors: 0x%lx",windows->im_retain_colors);
5230 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5232 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5233 windows->dnd_protocols);
5236 Allocate standard colormap.
5238 windows->map_info=XAllocStandardColormap();
5239 windows->icon_map=XAllocStandardColormap();
5240 if ((windows->map_info == (XStandardColormap *) NULL) ||
5241 (windows->icon_map == (XStandardColormap *) NULL))
5242 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5244 windows->map_info->colormap=(Colormap) NULL;
5245 windows->icon_map->colormap=(Colormap) NULL;
5246 windows->pixel_info->pixels=(unsigned long *) NULL;
5247 windows->pixel_info->annotate_context=(GC) NULL;
5248 windows->pixel_info->highlight_context=(GC) NULL;
5249 windows->pixel_info->widget_context=(GC) NULL;
5250 windows->font_info=(XFontStruct *) NULL;
5251 windows->icon_pixel->annotate_context=(GC) NULL;
5252 windows->icon_pixel->pixels=(unsigned long *) NULL;
5256 *windows->icon_resources=(*resource_info);
5257 windows->icon_resources->visual_type=(char *) "default";
5258 windows->icon_resources->colormap=SharedColormap;
5259 windows->visual_info=
5260 XBestVisualInfo(display,windows->map_info,resource_info);
5261 windows->icon_visual=
5262 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5263 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5264 (windows->icon_visual == (XVisualInfo *) NULL))
5265 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5266 resource_info->visual_type);
5267 if (IsEventLogging())
5269 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5270 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5271 windows->visual_info->visualid);
5272 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5273 XVisualClassName(windows->visual_info->klass));
5274 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5275 windows->visual_info->depth);
5276 (void) LogMagickEvent(X11Event,GetMagickModule(),
5277 " size of colormap: %d entries",windows->visual_info->colormap_size);
5278 (void) LogMagickEvent(X11Event,GetMagickModule(),
5279 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5280 windows->visual_info->red_mask,windows->visual_info->green_mask,
5281 windows->visual_info->blue_mask);
5282 (void) LogMagickEvent(X11Event,GetMagickModule(),
5283 " significant bits in color: %d bits",
5284 windows->visual_info->bits_per_rgb);
5287 Allocate class and manager hints.
5289 windows->class_hints=XAllocClassHint();
5290 windows->manager_hints=XAllocWMHints();
5291 if ((windows->class_hints == (XClassHint *) NULL) ||
5292 (windows->manager_hints == (XWMHints *) NULL))
5293 ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5296 Determine group leader if we have one.
5298 root_window=XRootWindow(display,windows->visual_info->screen);
5299 windows->group_leader.id=(Window) NULL;
5300 if (resource_info->window_group != (char *) NULL)
5302 if (isdigit((int) ((unsigned char) *resource_info->window_group)) != 0)
5303 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5304 strtol((char *) resource_info->window_group,(char **) NULL,0));
5305 if (windows->group_leader.id == (Window) NULL)
5306 windows->group_leader.id=
5307 XWindowByName(display,root_window,resource_info->window_group);
5313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5317 % X M a k e C u r s o r %
5321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5323 % XMakeCursor() creates a crosshairs X11 cursor.
5325 % The format of the XMakeCursor method is:
5327 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5328 % char *background_color,char *foreground_color)
5330 % A description of each parameter follows:
5332 % o display: Specifies a connection to an X server; returned from
5335 % o window: Specifies the ID of the window for which the cursor is
5338 % o colormap: Specifies the ID of the colormap from which the background
5339 % and foreground color will be retrieved.
5341 % o background_color: Specifies the color to use for the cursor background.
5343 % o foreground_color: Specifies the color to use for the cursor foreground.
5346 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5347 Colormap colormap,char *background_color,char *foreground_color)
5349 #define scope_height 17
5350 #define scope_x_hot 8
5351 #define scope_y_hot 8
5352 #define scope_width 17
5354 static const unsigned char
5357 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5358 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5359 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5360 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5361 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5365 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5366 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5367 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5368 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5369 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5383 assert(display != (Display *) NULL);
5384 assert(window != (Window) NULL);
5385 assert(colormap != (Colormap) NULL);
5386 assert(background_color != (char *) NULL);
5387 assert(foreground_color != (char *) NULL);
5388 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5389 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5391 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5392 scope_width,scope_height);
5393 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5395 ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
5396 return((Cursor) NULL);
5398 (void) XParseColor(display,colormap,background_color,&background);
5399 (void) XParseColor(display,colormap,foreground_color,&foreground);
5400 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5401 scope_x_hot,scope_y_hot);
5402 (void) XFreePixmap(display,source);
5403 (void) XFreePixmap(display,mask);
5408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5412 % X M a k e I m a g e %
5416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5418 % XMakeImage() creates an X11 image. If the image size differs from the X11
5419 % image size, the image is first resized.
5421 % The format of the XMakeImage method is:
5423 % MagickBooleanType XMakeImage(Display *display,
5424 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5425 % unsigned int width,unsigned int height,ExceptionInfo *exception)
5427 % A description of each parameter follows:
5429 % o display: Specifies a connection to an X server; returned from
5432 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5434 % o window: Specifies a pointer to a XWindowInfo structure.
5436 % o image: the image.
5438 % o width: Specifies the width in pixels of the rectangular area to
5441 % o height: Specifies the height in pixels of the rectangular area to
5444 % o exception: return any errors or warnings in this structure.
5447 MagickPrivate MagickBooleanType XMakeImage(Display *display,
5448 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5449 unsigned int width,unsigned int height,ExceptionInfo *exception)
5451 #define CheckOverflowException(length,width,height) \
5452 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5466 assert(display != (Display *) NULL);
5467 assert(resource_info != (XResourceInfo *) NULL);
5468 assert(window != (XWindowInfo *) NULL);
5470 assert(height != 0);
5471 if ((window->width == 0) || (window->height == 0))
5472 return(MagickFalse);
5474 Apply user transforms to the image.
5476 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5477 (void) XFlush(display);
5478 depth=(int) window->depth;
5479 if (window->destroy)
5480 window->image=DestroyImage(window->image);
5481 window->image=image;
5482 window->destroy=MagickFalse;
5483 if (window->image != (Image *) NULL)
5485 if (window->crop_geometry != (char *) NULL)
5496 window->image->page.x=0;
5497 window->image->page.y=0;
5498 (void) ParsePageGeometry(window->image,window->crop_geometry,
5499 &crop_info,exception);
5500 crop_image=CropImage(window->image,&crop_info,exception);
5501 if (crop_image != (Image *) NULL)
5503 if (window->image != image)
5504 window->image=DestroyImage(window->image);
5505 window->image=crop_image;
5506 window->destroy=MagickTrue;
5509 if ((width != (unsigned int) window->image->columns) ||
5510 (height != (unsigned int) window->image->rows))
5518 resize_image=NewImageList();
5519 if ((window->pixel_info->colors == 0) &&
5520 (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
5521 (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
5522 resize_image=ResizeImage(window->image,width,height,
5523 image->filter,exception);
5526 if (window->image->storage_class == PseudoClass)
5527 resize_image=SampleImage(window->image,width,height,
5530 resize_image=ThumbnailImage(window->image,width,height,
5533 if (resize_image != (Image *) NULL)
5535 if (window->image != image)
5536 window->image=DestroyImage(window->image);
5537 window->image=resize_image;
5538 window->destroy=MagickTrue;
5541 width=(unsigned int) window->image->columns;
5542 assert((size_t) width == window->image->columns);
5543 height=(unsigned int) window->image->rows;
5544 assert((size_t) height == window->image->rows);
5549 ximage=(XImage *) NULL;
5550 format=(depth == 1) ? XYBitmap : ZPixmap;
5551 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5552 if (window->shared_memory != MagickFalse)
5557 segment_info=(XShmSegmentInfo *) window->segment_info;
5558 segment_info[1].shmid=(-1);
5559 segment_info[1].shmaddr=(char *) NULL;
5560 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5561 (char *) NULL,&segment_info[1],width,height);
5562 if (ximage == (XImage *) NULL)
5563 window->shared_memory=MagickFalse;
5564 length=(size_t) ximage->bytes_per_line*ximage->height;
5565 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5566 window->shared_memory=MagickFalse;
5567 if (window->shared_memory != MagickFalse)
5568 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5569 if (window->shared_memory != MagickFalse)
5570 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5571 if (segment_info[1].shmid < 0)
5572 window->shared_memory=MagickFalse;
5573 if (window->shared_memory != MagickFalse)
5574 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5577 if (ximage != (XImage *) NULL)
5578 XDestroyImage(ximage);
5579 ximage=(XImage *) NULL;
5580 if (segment_info[1].shmaddr)
5582 (void) shmdt(segment_info[1].shmaddr);
5583 segment_info[1].shmaddr=(char *) NULL;
5585 if (segment_info[1].shmid >= 0)
5587 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5588 segment_info[1].shmid=(-1);
5594 Allocate X image pixel data.
5596 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5597 if (window->shared_memory)
5605 (void) XSync(display,MagickFalse);
5606 xerror_alert=MagickFalse;
5607 segment_info=(XShmSegmentInfo *) window->segment_info;
5608 ximage->data=segment_info[1].shmaddr;
5609 segment_info[1].readOnly=MagickFalse;
5610 status=XShmAttach(display,&segment_info[1]);
5611 if (status != False)
5612 (void) XSync(display,MagickFalse);
5613 if ((status == False) || (xerror_alert != MagickFalse))
5615 window->shared_memory=MagickFalse;
5616 if (status != False)
5617 XShmDetach(display,&segment_info[1]);
5618 if (ximage != (XImage *) NULL)
5621 XDestroyImage(ximage);
5622 ximage=(XImage *) NULL;
5624 if (segment_info[1].shmid >= 0)
5626 if (segment_info[1].shmaddr != NULL)
5627 (void) shmdt(segment_info[1].shmaddr);
5628 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5629 segment_info[1].shmid=(-1);
5630 segment_info[1].shmaddr=(char *) NULL;
5635 if (window->shared_memory == MagickFalse)
5636 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5637 (char *) NULL,width,height,XBitmapPad(display),0);
5638 if (ximage == (XImage *) NULL)
5641 Unable to create X image.
5643 (void) XCheckDefineCursor(display,window->id,window->cursor);
5644 return(MagickFalse);
5646 length=(size_t) ximage->bytes_per_line*ximage->height;
5647 if (IsEventLogging())
5649 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5650 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5651 ximage->width,ximage->height);
5652 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5654 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5655 ximage->byte_order);
5656 (void) LogMagickEvent(X11Event,GetMagickModule(),
5657 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5658 ximage->bitmap_bit_order,ximage->bitmap_pad);
5659 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5661 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5662 ximage->bytes_per_line);
5663 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5664 ximage->bits_per_pixel);
5665 (void) LogMagickEvent(X11Event,GetMagickModule(),
5666 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5667 ximage->green_mask,ximage->blue_mask);
5669 if (window->shared_memory == MagickFalse)
5671 if (ximage->format != XYBitmap)
5672 ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
5675 ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
5676 ximage->depth*ximage->height);
5678 if (ximage->data == (char *) NULL)
5681 Unable to allocate pixel data.
5683 XDestroyImage(ximage);
5684 ximage=(XImage *) NULL;
5685 (void) XCheckDefineCursor(display,window->id,window->cursor);
5686 return(MagickFalse);
5688 if (window->ximage != (XImage *) NULL)
5691 Destroy previous X image.
5693 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5694 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5695 if (window->segment_info != (XShmSegmentInfo *) NULL)
5700 segment_info=(XShmSegmentInfo *) window->segment_info;
5701 if (segment_info[0].shmid >= 0)
5703 (void) XSync(display,MagickFalse);
5704 (void) XShmDetach(display,&segment_info[0]);
5705 (void) XSync(display,MagickFalse);
5706 if (segment_info[0].shmaddr != (char *) NULL)
5707 (void) shmdt(segment_info[0].shmaddr);
5708 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5709 segment_info[0].shmid=(-1);
5710 segment_info[0].shmaddr=(char *) NULL;
5711 window->ximage->data=(char *) NULL;
5715 if (window->ximage->data != (char *) NULL)
5716 free(window->ximage->data);
5717 window->ximage->data=(char *) NULL;
5718 XDestroyImage(window->ximage);
5719 window->ximage=(XImage *) NULL;
5721 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5722 if (window->segment_info != (XShmSegmentInfo *) NULL)
5727 segment_info=(XShmSegmentInfo *) window->segment_info;
5728 segment_info[0]=segment_info[1];
5731 window->ximage=ximage;
5732 matte_image=(XImage *) NULL;
5733 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5734 if ((window->image->alpha_trait == BlendPixelTrait) &&
5735 ((int) width <= XDisplayWidth(display,window->screen)) &&
5736 ((int) height <= XDisplayHeight(display,window->screen)))
5741 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5742 (char *) NULL,width,height,XBitmapPad(display),0);
5743 if (IsEventLogging())
5745 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5746 (void) LogMagickEvent(X11Event,GetMagickModule(),
5747 " width, height: %dx%d",matte_image->width,matte_image->height);
5749 if (matte_image != (XImage *) NULL)
5752 Allocate matte image pixel data.
5754 matte_image->data=(char *) malloc((size_t)
5755 matte_image->bytes_per_line*matte_image->depth*
5756 matte_image->height);
5757 if (matte_image->data == (char *) NULL)
5759 XDestroyImage(matte_image);
5760 matte_image=(XImage *) NULL;
5764 if (window->matte_image != (XImage *) NULL)
5769 if (window->matte_image->data != (char *) NULL)
5770 free(window->matte_image->data);
5771 window->matte_image->data=(char *) NULL;
5772 XDestroyImage(window->matte_image);
5773 window->matte_image=(XImage *) NULL;
5775 window->matte_image=matte_image;
5776 if (window->matte_pixmap != (Pixmap) NULL)
5778 (void) XFreePixmap(display,window->matte_pixmap);
5779 window->matte_pixmap=(Pixmap) NULL;
5780 #if defined(MAGICKCORE_HAVE_SHAPE)
5781 if (window->shape != MagickFalse)
5782 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5785 window->stasis=MagickFalse;
5787 Convert pixels to X image data.
5789 if (window->image != (Image *) NULL)
5791 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5792 (ximage->bitmap_bit_order == LSBFirst)))
5793 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5794 matte_image,exception);
5796 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5797 matte_image,exception);
5799 if (window->matte_image != (XImage *) NULL)
5802 Create matte pixmap.
5804 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5805 if (window->matte_pixmap != (Pixmap) NULL)
5814 Copy matte image to matte pixmap.
5816 context_values.background=0;
5817 context_values.foreground=1;
5818 graphics_context=XCreateGC(display,window->matte_pixmap,
5819 (size_t) (GCBackground | GCForeground),&context_values);
5820 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5821 window->matte_image,0,0,0,0,width,height);
5822 (void) XFreeGC(display,graphics_context);
5823 #if defined(MAGICKCORE_HAVE_SHAPE)
5824 if (window->shape != MagickFalse)
5825 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5826 window->matte_pixmap,ShapeSet);
5830 (void) XMakePixmap(display,resource_info,window);
5834 (void) XCheckDefineCursor(display,window->id,window->cursor);
5839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5843 + X M a k e I m a g e L S B F i r s t %
5847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5849 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5850 % pixels are copied in least-significant bit and byte first order. The
5851 % server's scanline pad is respected. Rather than using one or two general
5852 % cases, many special cases are found here to help speed up the image
5855 % The format of the XMakeImageLSBFirst method is:
5857 % void XMakeImageLSBFirst(Display *display,XWindows *windows,
5858 % ExceptionInfo *exception)
5860 % A description of each parameter follows:
5862 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5864 % o window: Specifies a pointer to a XWindowInfo structure.
5866 % o image: the image.
5868 % o ximage: Specifies a pointer to a XImage structure; returned from
5871 % o matte_image: Specifies a pointer to a XImage structure; returned from
5874 % o exception: return any errors or warnings in this structure.
5877 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5878 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5879 ExceptionInfo *exception)
5890 register const Quantum
5896 register unsigned char
5913 assert(resource_info != (XResourceInfo *) NULL);
5914 assert(window != (XWindowInfo *) NULL);
5915 assert(image != (Image *) NULL);
5916 if (image->debug != MagickFalse)
5917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5919 if ((window->immutable == MagickFalse) &&
5920 (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
5923 size[MaxTextExtent];
5931 image_info=AcquireImageInfo();
5932 (void) CopyMagickString(image_info->filename,
5933 resource_info->image_info->texture != (char *) NULL ?
5934 resource_info->image_info->texture : "pattern:checkerboard",
5936 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5937 image->columns,(double) image->rows);
5938 image_info->size=ConstantString(size);
5939 pattern=ReadImage(image_info,exception);
5940 image_info=DestroyImageInfo(image_info);
5941 if (pattern != (Image *) NULL)
5943 canvas=CloneImage(image,0,0,MagickTrue,exception);
5944 if (canvas != (Image *) NULL)
5945 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5947 pattern=DestroyImage(pattern);
5950 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5951 ximage->bits_per_pixel) >> 3));
5952 map_info=window->map_info;
5953 pixels=window->pixel_info->pixels;
5954 q=(unsigned char *) ximage->data;
5956 canvas_view=AcquireVirtualCacheView(canvas,exception);
5957 if (ximage->format == XYBitmap)
5959 register unsigned short
5967 Convert canvas to big-endian bitmap.
5969 background=(unsigned char)
5970 (XPixelIntensity(&window->pixel_info->foreground_color) <
5971 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5972 foreground=(unsigned char)
5973 (XPixelIntensity(&window->pixel_info->background_color) <
5974 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5975 polarity=(unsigned short) ((GetPixelInfoIntensity(
5976 &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
5977 if (canvas->colors == 2)
5978 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
5979 GetPixelInfoIntensity(&canvas->colormap[1]);
5980 for (y=0; y < (int) canvas->rows; y++)
5982 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5984 if (p == (const Quantum *) NULL)
5988 for (x=0; x < (int) canvas->columns; x++)
5991 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6002 p+=GetPixelChannels(canvas);
6010 if (window->pixel_info->colors != 0)
6011 switch (ximage->bits_per_pixel)
6015 register unsigned int
6019 Convert to 2 bit color-mapped X canvas.
6021 for (y=0; y < (int) canvas->rows; y++)
6023 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6024 canvas->columns,1,exception);
6025 if (p == (const Quantum *) NULL)
6028 for (x=0; x < (int) canvas->columns; x++)
6030 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6035 *q=(unsigned char) pixel;
6041 *q|=(unsigned char) (pixel << 2);
6047 *q|=(unsigned char) (pixel << 4);
6053 *q|=(unsigned char) (pixel << 6);
6059 p+=GetPixelChannels(canvas);
6067 register unsigned int
6071 Convert to 4 bit color-mapped X canvas.
6073 for (y=0; y < (int) canvas->rows; y++)
6075 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6076 canvas->columns,1,exception);
6077 if (p == (const Quantum *) NULL)
6080 for (x=0; x < (int) canvas->columns; x++)
6082 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6087 *q=(unsigned char) pixel;
6093 *q|=(unsigned char) (pixel << 4);
6099 p+=GetPixelChannels(canvas);
6109 Convert to 8 bit color-mapped X canvas.
6111 if (resource_info->color_recovery &&
6112 resource_info->quantize_info->dither_method != NoDitherMethod)
6114 XDitherImage(canvas,ximage,exception);
6117 for (y=0; y < (int) canvas->rows; y++)
6119 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6120 canvas->columns,1,exception);
6121 if (p == (const Quantum *) NULL)
6123 for (x=0; x < (int) canvas->columns; x++)
6125 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6126 *q++=(unsigned char) pixel;
6127 p+=GetPixelChannels(canvas);
6138 register unsigned int
6142 Convert to multi-byte color-mapped X canvas.
6144 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6145 for (y=0; y < (int) canvas->rows; y++)
6147 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6148 canvas->columns,1,exception);
6149 if (p == (const Quantum *) NULL)
6151 for (x=0; x < (int) canvas->columns; x++)
6153 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6154 for (k=0; k < (int) bytes_per_pixel; k++)
6156 *q++=(unsigned char) (pixel & 0xff);
6159 p+=GetPixelChannels(canvas);
6167 switch (ximage->bits_per_pixel)
6171 register unsigned int
6175 Convert to contiguous 2 bit continuous-tone X canvas.
6177 for (y=0; y < (int) canvas->rows; y++)
6180 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6181 canvas->columns,1,exception);
6182 if (p == (const Quantum *) NULL)
6184 for (x=0; x < (int) canvas->columns; x++)
6186 pixel=XGammaPixel(canvas,map_info,p);
6192 *q=(unsigned char) pixel;
6198 *q|=(unsigned char) (pixel << 2);
6204 *q|=(unsigned char) (pixel << 4);
6210 *q|=(unsigned char) (pixel << 6);
6216 p+=GetPixelChannels(canvas);
6224 register unsigned int
6228 Convert to contiguous 4 bit continuous-tone X canvas.
6230 for (y=0; y < (int) canvas->rows; y++)
6232 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6233 canvas->columns,1,exception);
6234 if (p == (const Quantum *) NULL)
6237 for (x=0; x < (int) canvas->columns; x++)
6239 pixel=XGammaPixel(canvas,map_info,p);
6245 *q=(unsigned char) pixel;
6251 *q|=(unsigned char) (pixel << 4);
6257 p+=GetPixelChannels(canvas);
6267 Convert to contiguous 8 bit continuous-tone X canvas.
6269 if (resource_info->color_recovery &&
6270 resource_info->quantize_info->dither_method != NoDitherMethod)
6272 XDitherImage(canvas,ximage,exception);
6275 for (y=0; y < (int) canvas->rows; y++)
6277 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6278 canvas->columns,1,exception);
6279 if (p == (const Quantum *) NULL)
6281 for (x=0; x < (int) canvas->columns; x++)
6283 pixel=XGammaPixel(canvas,map_info,p);
6284 *q++=(unsigned char) pixel;
6285 p+=GetPixelChannels(canvas);
6293 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6294 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6295 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6296 (map_info->blue_mult == 1))
6299 Convert to 32 bit continuous-tone X canvas.
6301 for (y=0; y < (int) canvas->rows; y++)
6303 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6304 canvas->columns,1,exception);
6305 if (p == (const Quantum *) NULL)
6307 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6308 (blue_gamma != 1.0))
6311 Gamma correct canvas.
6313 for (x=(int) canvas->columns-1; x >= 0; x--)
6315 *q++=ScaleQuantumToChar(XBlueGamma(
6316 GetPixelBlue(canvas,p)));
6317 *q++=ScaleQuantumToChar(XGreenGamma(
6318 GetPixelGreen(canvas,p)));
6319 *q++=ScaleQuantumToChar(XRedGamma(
6320 GetPixelRed(canvas,p)));
6322 p+=GetPixelChannels(canvas);
6326 for (x=(int) canvas->columns-1; x >= 0; x--)
6328 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6329 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6330 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6332 p+=GetPixelChannels(canvas);
6337 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6338 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6339 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6340 (map_info->blue_mult == 65536L))
6343 Convert to 32 bit continuous-tone X canvas.
6345 for (y=0; y < (int) canvas->rows; y++)
6347 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6348 canvas->columns,1,exception);
6349 if (p == (const Quantum *) NULL)
6351 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6352 (blue_gamma != 1.0))
6355 Gamma correct canvas.
6357 for (x=(int) canvas->columns-1; x >= 0; x--)
6359 *q++=ScaleQuantumToChar(XRedGamma(
6360 GetPixelRed(canvas,p)));
6361 *q++=ScaleQuantumToChar(XGreenGamma(
6362 GetPixelGreen(canvas,p)));
6363 *q++=ScaleQuantumToChar(XBlueGamma(
6364 GetPixelBlue(canvas,p)));
6366 p+=GetPixelChannels(canvas);
6370 for (x=(int) canvas->columns-1; x >= 0; x--)
6372 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6373 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6374 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6376 p+=GetPixelChannels(canvas);
6385 register unsigned int
6389 Convert to multi-byte continuous-tone X canvas.
6391 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6392 for (y=0; y < (int) canvas->rows; y++)
6394 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6395 canvas->columns,1,exception);
6396 if (p == (const Quantum *) NULL)
6398 for (x=0; x < (int) canvas->columns; x++)
6400 pixel=XGammaPixel(canvas,map_info,p);
6401 for (k=0; k < (int) bytes_per_pixel; k++)
6403 *q++=(unsigned char) (pixel & 0xff);
6406 p+=GetPixelChannels(canvas);
6414 if (matte_image != (XImage *) NULL)
6417 Initialize matte canvas.
6419 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6420 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6421 q=(unsigned char *) matte_image->data;
6422 for (y=0; y < (int) canvas->rows; y++)
6424 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6426 if (p == (const Quantum *) NULL)
6430 for (x=(int) canvas->columns-1; x >= 0; x--)
6433 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6442 p+=GetPixelChannels(canvas);
6449 canvas_view=DestroyCacheView(canvas_view);
6450 if (canvas != image)
6451 canvas=DestroyImage(canvas);
6455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6459 + X M a k e I m a g e M S B F i r s t %
6463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6465 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6466 % image pixels are copied in most-significant bit and byte first order. The
6467 % server's scanline pad is also respected. Rather than using one or two
6468 % general cases, many special cases are found here to help speed up the image
6471 % The format of the XMakeImageMSBFirst method is:
6473 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6474 % ExceptionInfo *exception)
6476 % A description of each parameter follows:
6478 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6480 % o window: Specifies a pointer to a XWindowInfo structure.
6482 % o image: the image.
6484 % o ximage: Specifies a pointer to a XImage structure; returned from
6487 % o matte_image: Specifies a pointer to a XImage structure; returned from
6490 % o exception: return any errors or warnings in this structure.
6493 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6494 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6495 ExceptionInfo *exception)
6509 register const Quantum
6512 register unsigned char
6529 assert(resource_info != (XResourceInfo *) NULL);
6530 assert(window != (XWindowInfo *) NULL);
6531 assert(image != (Image *) NULL);
6532 if (image->debug != MagickFalse)
6533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6535 if ((window->immutable != MagickFalse) &&
6536 (image->storage_class == DirectClass) && (image->alpha_trait == BlendPixelTrait))
6539 size[MaxTextExtent];
6547 image_info=AcquireImageInfo();
6548 (void) CopyMagickString(image_info->filename,
6549 resource_info->image_info->texture != (char *) NULL ?
6550 resource_info->image_info->texture : "pattern:checkerboard",
6552 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6553 image->columns,(double) image->rows);
6554 image_info->size=ConstantString(size);
6555 pattern=ReadImage(image_info,exception);
6556 image_info=DestroyImageInfo(image_info);
6557 if (pattern != (Image *) NULL)
6559 canvas=CloneImage(image,0,0,MagickTrue,exception);
6560 if (canvas != (Image *) NULL)
6561 (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6563 pattern=DestroyImage(pattern);
6566 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
6567 ximage->bits_per_pixel) >> 3));
6568 map_info=window->map_info;
6569 pixels=window->pixel_info->pixels;
6570 q=(unsigned char *) ximage->data;
6572 canvas_view=AcquireVirtualCacheView(canvas,exception);
6573 if (ximage->format == XYBitmap)
6575 register unsigned short
6583 Convert canvas to big-endian bitmap.
6585 background=(unsigned char)
6586 (XPixelIntensity(&window->pixel_info->foreground_color) <
6587 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6588 foreground=(unsigned char)
6589 (XPixelIntensity(&window->pixel_info->background_color) <
6590 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6591 polarity=(unsigned short) ((GetPixelInfoIntensity(
6592 &canvas->colormap[0])) < (QuantumRange/2) ? 1 : 0);
6593 if (canvas->colors == 2)
6594 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
6595 GetPixelInfoIntensity(&canvas->colormap[1]);
6596 for (y=0; y < (int) canvas->rows; y++)
6598 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6600 if (p == (const Quantum *) NULL)
6604 for (x=(int) canvas->columns-1; x >= 0; x--)
6607 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6618 p+=GetPixelChannels(canvas);
6626 if (window->pixel_info->colors != 0)
6627 switch (ximage->bits_per_pixel)
6631 register unsigned int
6635 Convert to 2 bit color-mapped X canvas.
6637 for (y=0; y < (int) canvas->rows; y++)
6639 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6640 canvas->columns,1,exception);
6641 if (p == (const Quantum *) NULL)
6644 for (x=0; x < (int) canvas->columns; x++)
6646 pixel=pixels[(ssize_t)
6647 GetPixelIndex(canvas,p)] & 0xf;
6652 *q=(unsigned char) (pixel << 6);
6658 *q|=(unsigned char) (pixel << 4);
6664 *q|=(unsigned char) (pixel << 2);
6670 *q|=(unsigned char) pixel;
6676 p+=GetPixelChannels(canvas);
6684 register unsigned int
6688 Convert to 4 bit color-mapped X canvas.
6690 for (y=0; y < (int) canvas->rows; y++)
6692 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6693 canvas->columns,1,exception);
6694 if (p == (const Quantum *) NULL)
6697 for (x=0; x < (int) canvas->columns; x++)
6699 pixel=pixels[(ssize_t)
6700 GetPixelIndex(canvas,p)] & 0xf;
6705 *q=(unsigned char) (pixel << 4);
6711 *q|=(unsigned char) pixel;
6717 p+=GetPixelChannels(canvas);
6727 Convert to 8 bit color-mapped X canvas.
6729 if (resource_info->color_recovery &&
6730 resource_info->quantize_info->dither_method != NoDitherMethod)
6732 XDitherImage(canvas,ximage,exception);
6735 for (y=0; y < (int) canvas->rows; y++)
6737 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6738 canvas->columns,1,exception);
6739 if (p == (const Quantum *) NULL)
6741 for (x=0; x < (int) canvas->columns; x++)
6743 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6744 *q++=(unsigned char) pixel;
6745 p+=GetPixelChannels(canvas);
6756 register unsigned int
6760 channel[sizeof(size_t)];
6763 Convert to 8 bit color-mapped X canvas.
6765 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6766 for (y=0; y < (int) canvas->rows; y++)
6768 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6769 canvas->columns,1,exception);
6770 if (p == (const Quantum *) NULL)
6772 for (x=0; x < (int) canvas->columns; x++)
6774 pixel=pixels[(ssize_t)
6775 GetPixelIndex(canvas,p)];
6776 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6778 channel[k]=(unsigned char) pixel;
6781 for (k=0; k < (int) bytes_per_pixel; k++)
6783 p+=GetPixelChannels(canvas);
6791 switch (ximage->bits_per_pixel)
6795 register unsigned int
6799 Convert to 4 bit continuous-tone X canvas.
6801 for (y=0; y < (int) canvas->rows; y++)
6803 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6804 canvas->columns,1,exception);
6805 if (p == (const Quantum *) NULL)
6808 for (x=(int) canvas->columns-1; x >= 0; x--)
6810 pixel=XGammaPixel(canvas,map_info,p);
6816 *q=(unsigned char) (pixel << 6);
6822 *q|=(unsigned char) (pixel << 4);
6828 *q|=(unsigned char) (pixel << 2);
6834 *q|=(unsigned char) pixel;
6840 p+=GetPixelChannels(canvas);
6848 register unsigned int
6852 Convert to 4 bit continuous-tone X canvas.
6854 for (y=0; y < (int) canvas->rows; y++)
6856 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6857 canvas->columns,1,exception);
6858 if (p == (const Quantum *) NULL)
6861 for (x=(int) canvas->columns-1; x >= 0; x--)
6863 pixel=XGammaPixel(canvas,map_info,p);
6869 *q=(unsigned char) (pixel << 4);
6875 *q|=(unsigned char) pixel;
6881 p+=GetPixelChannels(canvas);
6891 Convert to 8 bit continuous-tone X canvas.
6893 if (resource_info->color_recovery &&
6894 resource_info->quantize_info->dither_method != NoDitherMethod)
6896 XDitherImage(canvas,ximage,exception);
6899 for (y=0; y < (int) canvas->rows; y++)
6901 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6902 canvas->columns,1,exception);
6903 if (p == (const Quantum *) NULL)
6905 for (x=(int) canvas->columns-1; x >= 0; x--)
6907 pixel=XGammaPixel(canvas,map_info,p);
6908 *q++=(unsigned char) pixel;
6909 p+=GetPixelChannels(canvas);
6917 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6918 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6919 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6920 (map_info->blue_mult == 1))
6923 Convert to 32 bit continuous-tone X canvas.
6925 for (y=0; y < (int) canvas->rows; y++)
6927 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6928 canvas->columns,1,exception);
6929 if (p == (const Quantum *) NULL)
6931 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6932 (blue_gamma != 1.0))
6935 Gamma correct canvas.
6937 for (x=(int) canvas->columns-1; x >= 0; x--)
6940 *q++=ScaleQuantumToChar(XRedGamma(
6941 GetPixelRed(canvas,p)));
6942 *q++=ScaleQuantumToChar(XGreenGamma(
6943 GetPixelGreen(canvas,p)));
6944 *q++=ScaleQuantumToChar(XBlueGamma(
6945 GetPixelBlue(canvas,p)));
6946 p+=GetPixelChannels(canvas);
6950 for (x=(int) canvas->columns-1; x >= 0; x--)
6953 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6954 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6955 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6956 p+=GetPixelChannels(canvas);
6961 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6962 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6963 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6964 (map_info->blue_mult == 65536L))
6967 Convert to 32 bit continuous-tone X canvas.
6969 for (y=0; y < (int) canvas->rows; y++)
6971 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6972 canvas->columns,1,exception);
6973 if (p == (const Quantum *) NULL)
6975 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6976 (blue_gamma != 1.0))
6979 Gamma correct canvas.
6981 for (x=(int) canvas->columns-1; x >= 0; x--)
6984 *q++=ScaleQuantumToChar(XBlueGamma(
6985 GetPixelBlue(canvas,p)));
6986 *q++=ScaleQuantumToChar(XGreenGamma(
6987 GetPixelGreen(canvas,p)));
6988 *q++=ScaleQuantumToChar(XRedGamma(
6989 GetPixelRed(canvas,p)));
6990 p+=GetPixelChannels(canvas);
6994 for (x=(int) canvas->columns-1; x >= 0; x--)
6997 *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6998 *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
6999 *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
7000 p+=GetPixelChannels(canvas);
7009 register unsigned int
7013 channel[sizeof(size_t)];
7016 Convert to multi-byte continuous-tone X canvas.
7018 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
7019 for (y=0; y < (int) canvas->rows; y++)
7021 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7022 canvas->columns,1,exception);
7023 if (p == (const Quantum *) NULL)
7025 for (x=(int) canvas->columns-1; x >= 0; x--)
7027 pixel=XGammaPixel(canvas,map_info,p);
7028 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
7030 channel[k]=(unsigned char) pixel;
7033 for (k=0; k < (int) bytes_per_pixel; k++)
7035 p+=GetPixelChannels(canvas);
7043 if (matte_image != (XImage *) NULL)
7046 Initialize matte canvas.
7048 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7049 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7050 q=(unsigned char *) matte_image->data;
7051 for (y=0; y < (int) canvas->rows; y++)
7053 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7055 if (p == (const Quantum *) NULL)
7059 for (x=(int) canvas->columns-1; x >= 0; x--)
7062 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7071 p+=GetPixelChannels(canvas);
7078 canvas_view=DestroyCacheView(canvas_view);
7079 if (canvas != image)
7080 canvas=DestroyImage(canvas);
7084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7088 % X M a k e M a g n i f y I m a g e %
7092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7094 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7096 % The format of the XMakeMagnifyImage method is:
7098 % void XMakeMagnifyImage(Display *display,XWindows *windows,
7099 % ExceptionInfo *exception)
7101 % A description of each parameter follows:
7103 % o display: Specifies a connection to an X server; returned from
7106 % o windows: Specifies a pointer to a XWindows structure.
7108 % o exception: return any errors or warnings in this structure.
7111 MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
7112 ExceptionInfo *exception)
7115 tuple[MaxTextExtent];
7129 register unsigned char
7137 previous_magnify = 0;
7155 Check boundary conditions.
7157 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7158 assert(display != (Display *) NULL);
7159 assert(windows != (XWindows *) NULL);
7161 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7163 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7165 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7167 while (magnify > windows->magnify.width)
7169 while (magnify > windows->magnify.height)
7171 if (magnify != previous_magnify)
7180 New magnify factor: update magnify window name.
7183 while ((1 << i) <= (int) magnify)
7185 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7186 "Magnify %.20gX",(double) i);
7187 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7188 if (status != False)
7190 XSetWMName(display,windows->magnify.id,&window_name);
7191 XSetWMIconName(display,windows->magnify.id,&window_name);
7192 (void) XFree((void *) window_name.value);
7195 previous_magnify=magnify;
7196 ximage=windows->image.ximage;
7197 width=(unsigned int) windows->magnify.ximage->width;
7198 height=(unsigned int) windows->magnify.ximage->height;
7199 if ((windows->magnify.x < 0) ||
7200 (windows->magnify.x >= windows->image.ximage->width))
7201 windows->magnify.x=windows->image.ximage->width >> 1;
7202 x=windows->magnify.x-((width/magnify) >> 1);
7206 if (x > (int) (ximage->width-(width/magnify)))
7207 x=ximage->width-width/magnify;
7208 if ((windows->magnify.y < 0) ||
7209 (windows->magnify.y >= windows->image.ximage->height))
7210 windows->magnify.y=windows->image.ximage->height >> 1;
7211 y=windows->magnify.y-((height/magnify) >> 1);
7215 if (y > (int) (ximage->height-(height/magnify)))
7216 y=ximage->height-height/magnify;
7217 q=(unsigned char *) windows->magnify.ximage->data;
7218 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7219 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7220 if (ximage->bits_per_pixel < 8)
7222 register unsigned char
7229 register unsigned int
7235 pixel_info=windows->magnify.pixel_info;
7236 switch (ximage->bitmap_bit_order)
7241 Magnify little-endian bitmap.
7245 if (ximage->format == XYBitmap)
7247 background=(unsigned char)
7248 (XPixelIntensity(&pixel_info->foreground_color) <
7249 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7250 foreground=(unsigned char)
7251 (XPixelIntensity(&pixel_info->background_color) <
7252 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7253 if (windows->magnify.depth > 1)
7254 Swap(background,foreground);
7256 for (i=0; i < (ssize_t) height; i+=magnify)
7259 Propogate pixel magnify rows.
7261 for (j=0; j < magnify; j++)
7263 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7264 ((x*ximage->bits_per_pixel) >> 3);
7265 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7268 for (k=0; k < width; k+=magnify)
7271 Propogate pixel magnify columns.
7273 for (l=0; l < magnify; l++)
7276 Propogate each bit plane.
7278 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7281 if (*p & (0x01 << (p_bit+plane)))
7294 p_bit+=ximage->bits_per_pixel;
7301 *q=byte >> (8-q_bit);
7313 Magnify big-endian bitmap.
7317 if (ximage->format == XYBitmap)
7319 background=(unsigned char)
7320 (XPixelIntensity(&pixel_info->foreground_color) <
7321 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7322 foreground=(unsigned char)
7323 (XPixelIntensity(&pixel_info->background_color) <
7324 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7325 if (windows->magnify.depth > 1)
7326 Swap(background,foreground);
7328 for (i=0; i < (ssize_t) height; i+=magnify)
7331 Propogate pixel magnify rows.
7333 for (j=0; j < magnify; j++)
7335 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7336 ((x*ximage->bits_per_pixel) >> 3);
7337 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7340 for (k=0; k < width; k+=magnify)
7343 Propogate pixel magnify columns.
7345 for (l=0; l < magnify; l++)
7348 Propogate each bit plane.
7350 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7353 if (*p & (0x80 >> (p_bit+plane)))
7366 p_bit+=ximage->bits_per_pixel;
7373 *q=byte << (8-q_bit);
7384 switch (ximage->bits_per_pixel)
7390 Magnify 8 bit X image.
7392 for (i=0; i < (ssize_t) height; i+=magnify)
7395 Propogate pixel magnify rows.
7397 for (j=0; j < magnify; j++)
7399 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7400 ((x*ximage->bits_per_pixel) >> 3);
7401 for (k=0; k < width; k+=magnify)
7404 Propogate pixel magnify columns.
7406 for (l=0; l < magnify; l++)
7418 register unsigned int
7423 Magnify multi-byte X image.
7425 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7426 for (i=0; i < (ssize_t) height; i+=magnify)
7429 Propogate pixel magnify rows.
7431 for (j=0; j < magnify; j++)
7433 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7434 ((x*ximage->bits_per_pixel) >> 3);
7435 for (k=0; k < width; k+=magnify)
7438 Propogate pixel magnify columns.
7440 for (l=0; l < magnify; l++)
7441 for (m=0; m < bytes_per_pixel; m++)
7453 Copy X image to magnify pixmap.
7455 x=windows->magnify.x-((width/magnify) >> 1);
7457 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7459 if (x > (int) (ximage->width-(width/magnify)))
7460 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7463 y=windows->magnify.y-((height/magnify) >> 1);
7465 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7467 if (y > (int) (ximage->height-(height/magnify)))
7468 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7471 if ((x != 0) || (y != 0))
7472 (void) XFillRectangle(display,windows->magnify.pixmap,
7473 windows->magnify.annotate_context,0,0,width,height);
7474 (void) XPutImage(display,windows->magnify.pixmap,
7475 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7477 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7478 (magnify <= (height >> 1))))
7484 Highlight center pixel.
7486 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7487 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7488 highlight_info.width=magnify;
7489 highlight_info.height=magnify;
7490 (void) XDrawRectangle(display,windows->magnify.pixmap,
7491 windows->magnify.highlight_context,(int) highlight_info.x,
7492 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7493 (unsigned int) highlight_info.height-1);
7495 (void) XDrawRectangle(display,windows->magnify.pixmap,
7496 windows->magnify.annotate_context,(int) highlight_info.x+1,
7497 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7498 (unsigned int) highlight_info.height-3);
7501 Show center pixel color.
7503 (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
7504 (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7505 (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
7506 windows->magnify.x,windows->magnify.y);
7507 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7508 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7509 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7510 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7511 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7512 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7513 if (pixel.colorspace == CMYKColorspace)
7515 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7516 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7518 if (pixel.alpha_trait == BlendPixelTrait)
7520 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7521 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7523 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7524 height=(unsigned int) windows->magnify.font_info->ascent+
7525 windows->magnify.font_info->descent;
7526 x=windows->magnify.font_info->max_bounds.width >> 1;
7527 y=windows->magnify.font_info->ascent+(height >> 2);
7528 (void) XDrawImageString(display,windows->magnify.pixmap,
7529 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7530 GetColorTuple(&pixel,MagickTrue,tuple);
7532 (void) XDrawImageString(display,windows->magnify.pixmap,
7533 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7534 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7537 (void) XDrawImageString(display,windows->magnify.pixmap,
7538 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7540 Refresh magnify window.
7542 magnify_window=windows->magnify;
7545 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7553 % X M a k e P i x m a p %
7557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7559 % XMakePixmap() creates an X11 pixmap.
7561 % The format of the XMakePixmap method is:
7563 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7564 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7565 % XPixelInfo *pixel)
7567 % A description of each parameter follows:
7569 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7571 % o display: Specifies a connection to an X server; returned from
7574 % o window: Specifies a pointer to a XWindowInfo structure.
7577 static MagickBooleanType XMakePixmap(Display *display,
7578 const XResourceInfo *resource_info,XWindowInfo *window)
7584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7585 assert(display != (Display *) NULL);
7586 assert(resource_info != (XResourceInfo *) NULL);
7587 assert(window != (XWindowInfo *) NULL);
7588 if (window->pixmap != (Pixmap) NULL)
7591 Destroy previous X pixmap.
7593 (void) XFreePixmap(display,window->pixmap);
7594 window->pixmap=(Pixmap) NULL;
7596 if (window->use_pixmap == MagickFalse)
7597 return(MagickFalse);
7598 if (window->ximage == (XImage *) NULL)
7599 return(MagickFalse);
7601 Display busy cursor.
7603 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7604 (void) XFlush(display);
7608 width=(unsigned int) window->ximage->width;
7609 height=(unsigned int) window->ximage->height;
7610 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7611 if (window->pixmap == (Pixmap) NULL)
7614 Unable to allocate pixmap.
7616 (void) XCheckDefineCursor(display,window->id,window->cursor);
7617 return(MagickFalse);
7620 Copy X image to pixmap.
7622 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7623 if (window->shared_memory)
7624 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7625 window->ximage,0,0,0,0,width,height,MagickTrue);
7627 if (window->shared_memory == MagickFalse)
7628 (void) XPutImage(display,window->pixmap,window->annotate_context,
7629 window->ximage,0,0,0,0,width,height);
7630 if (IsEventLogging())
7632 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7633 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7639 (void) XCheckDefineCursor(display,window->id,window->cursor);
7644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7648 % X M a k e S t a n d a r d C o l o r m a p %
7652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7654 % XMakeStandardColormap() creates an X11 Standard Colormap.
7656 % The format of the XMakeStandardColormap method is:
7658 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7659 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7660 % XPixelInfo *pixel,ExceptionInfo *exception)
7662 % A description of each parameter follows:
7664 % o display: Specifies a connection to an X server; returned from
7667 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7668 % returned from XGetVisualInfo.
7670 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7672 % o image: the image.
7674 % o map_info: If a Standard Colormap type is specified, this structure is
7675 % initialized with info from the Standard Colormap.
7677 % o pixel: Specifies a pointer to a XPixelInfo structure.
7679 % o exception: return any errors or warnings in this structure.
7683 #if defined(__cplusplus) || defined(c_plusplus)
7687 static inline double DiversityPixelIntensity(
7688 const DiversityPacket *pixel)
7693 intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
7697 static int IntensityCompare(const void *x,const void *y)
7706 color_1=(DiversityPacket *) x;
7707 color_2=(DiversityPacket *) y;
7708 diversity=(int) (DiversityPixelIntensity(color_2)-
7709 DiversityPixelIntensity(color_1));
7713 static int PopularityCompare(const void *x,const void *y)
7719 color_1=(DiversityPacket *) x;
7720 color_2=(DiversityPacket *) y;
7721 return((int) color_2->count-(int) color_1->count);
7724 #if defined(__cplusplus) || defined(c_plusplus)
7728 static inline Quantum ScaleXToQuantum(const size_t x,
7731 return((Quantum) (((double) QuantumRange*x)/scale+0.5));
7734 MagickPrivate void XMakeStandardColormap(Display *display,
7735 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7736 XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
7759 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7760 assert(display != (Display *) NULL);
7761 assert(visual_info != (XVisualInfo *) NULL);
7762 assert(map_info != (XStandardColormap *) NULL);
7763 assert(resource_info != (XResourceInfo *) NULL);
7764 assert(pixel != (XPixelInfo *) NULL);
7765 if (resource_info->map_type != (char *) NULL)
7768 Standard Colormap is already defined (i.e. xstdcmap).
7770 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7772 number_colors=(unsigned int) (map_info->base_pixel+
7773 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7774 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7775 if ((image->alpha_trait != BlendPixelTrait) &&
7776 (resource_info->color_recovery == MagickFalse) &&
7777 (resource_info->quantize_info->dither_method != NoDitherMethod) &&
7778 (number_colors < MaxColormapSize))
7787 Improve image appearance with error diffusion.
7789 affinity_image=AcquireImage((ImageInfo *) NULL,exception);
7790 if (affinity_image == (Image *) NULL)
7791 ThrowXWindowFatalException(ResourceLimitFatalError,
7792 "UnableToDitherImage",image->filename);
7793 affinity_image->columns=number_colors;
7794 affinity_image->rows=1;
7796 Initialize colormap image.
7798 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7800 if (q != (Quantum *) NULL)
7802 for (i=0; i < (ssize_t) number_colors; i++)
7804 SetPixelRed(affinity_image,0,q);
7805 if (map_info->red_max != 0)
7806 SetPixelRed(affinity_image,ScaleXToQuantum((size_t)
7807 (i/map_info->red_mult),map_info->red_max),q);
7808 SetPixelGreen(affinity_image,0,q);
7809 if (map_info->green_max != 0)
7810 SetPixelGreen(affinity_image,ScaleXToQuantum((size_t)
7811 ((i/map_info->green_mult) % (map_info->green_max+1)),
7812 map_info->green_max),q);
7813 SetPixelBlue(affinity_image,0,q);
7814 if (map_info->blue_max != 0)
7815 SetPixelBlue(affinity_image,ScaleXToQuantum((size_t)
7816 (i % map_info->green_mult),map_info->blue_max),q);
7817 SetPixelAlpha(affinity_image,
7818 TransparentAlpha,q);
7819 q+=GetPixelChannels(affinity_image);
7821 (void) SyncAuthenticPixels(affinity_image,exception);
7822 (void) RemapImage(resource_info->quantize_info,image,
7823 affinity_image,exception);
7825 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7827 (void) SetImageStorageClass(image,DirectClass,exception);
7828 affinity_image=DestroyImage(affinity_image);
7830 if (IsEventLogging())
7832 (void) LogMagickEvent(X11Event,GetMagickModule(),
7833 "Standard Colormap:");
7834 (void) LogMagickEvent(X11Event,GetMagickModule(),
7835 " colormap id: 0x%lx",map_info->colormap);
7836 (void) LogMagickEvent(X11Event,GetMagickModule(),
7837 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7838 map_info->green_max,map_info->blue_max);
7839 (void) LogMagickEvent(X11Event,GetMagickModule(),
7840 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7841 map_info->green_mult,map_info->blue_mult);
7845 if ((visual_info->klass != DirectColor) &&
7846 (visual_info->klass != TrueColor))
7847 if ((image->storage_class == DirectClass) ||
7848 ((int) image->colors > visual_info->colormap_size))
7854 Image has more colors than the visual supports.
7856 quantize_info=(*resource_info->quantize_info);
7857 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7858 (void) QuantizeImage(&quantize_info,image,exception);
7861 Free previous and create new colormap.
7863 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7864 colormap=XDefaultColormap(display,visual_info->screen);
7865 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7866 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7867 visual_info->visual,visual_info->klass == DirectColor ?
7868 AllocAll : AllocNone);
7869 if (colormap == (Colormap) NULL)
7870 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7873 Initialize the map and pixel info structures.
7875 XGetMapInfo(visual_info,colormap,map_info);
7876 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7878 Allocating colors in server colormap is based on visual class.
7880 switch (visual_info->klass)
7886 Define Standard Colormap for StaticGray or StaticColor visual.
7888 number_colors=image->colors;
7889 colors=(XColor *) AcquireQuantumMemory((size_t)
7890 visual_info->colormap_size,sizeof(*colors));
7891 if (colors == (XColor *) NULL)
7892 ThrowXWindowFatalException(ResourceLimitFatalError,
7893 "UnableToCreateColormap",image->filename);
7895 color.flags=(char) (DoRed | DoGreen | DoBlue);
7896 for (i=0; i < (ssize_t) image->colors; i++)
7898 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7899 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7900 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7901 if (visual_info->klass != StaticColor)
7903 gray_value=(unsigned short) XPixelIntensity(&color);
7904 color.red=gray_value;
7905 color.green=gray_value;
7906 color.blue=gray_value;
7908 status=XAllocColor(display,colormap,&color);
7909 if (status == False)
7911 colormap=XCopyColormapAndFree(display,colormap);
7912 (void) XAllocColor(display,colormap,&color);
7914 pixel->pixels[i]=color.pixel;
7926 Define Standard Colormap for GrayScale or PseudoColor visual.
7928 number_colors=image->colors;
7929 colors=(XColor *) AcquireQuantumMemory((size_t)
7930 visual_info->colormap_size,sizeof(*colors));
7931 if (colors == (XColor *) NULL)
7932 ThrowXWindowFatalException(ResourceLimitFatalError,
7933 "UnableToCreateColormap",image->filename);
7935 Preallocate our GUI colors.
7937 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7938 (void) XAllocColor(display,colormap,&pixel->background_color);
7939 (void) XAllocColor(display,colormap,&pixel->border_color);
7940 (void) XAllocColor(display,colormap,&pixel->matte_color);
7941 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7942 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7943 (void) XAllocColor(display,colormap,&pixel->depth_color);
7944 (void) XAllocColor(display,colormap,&pixel->trough_color);
7945 for (i=0; i < MaxNumberPens; i++)
7946 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7948 Determine if image colors will "fit" into X server colormap.
7950 colormap_type=resource_info->colormap;
7951 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7952 NULL,0,pixel->pixels,(unsigned int) image->colors);
7953 if (status != False)
7954 colormap_type=PrivateColormap;
7955 if (colormap_type == SharedColormap)
7976 Define Standard colormap for shared GrayScale or PseudoColor visual.
7978 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7979 sizeof(*diversity));
7980 if (diversity == (DiversityPacket *) NULL)
7981 ThrowXWindowFatalException(ResourceLimitFatalError,
7982 "UnableToCreateColormap",image->filename);
7983 for (i=0; i < (ssize_t) image->colors; i++)
7985 diversity[i].red=ClampToQuantum(image->colormap[i].red);
7986 diversity[i].green=ClampToQuantum(image->colormap[i].green);
7987 diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
7988 diversity[i].index=(unsigned short) i;
7989 diversity[i].count=0;
7991 image_view=AcquireAuthenticCacheView(image,exception);
7992 for (y=0; y < (int) image->rows; y++)
7997 register const Quantum
8000 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
8001 image->columns,1,exception);
8002 if (p == (const Quantum *) NULL)
8004 for (x=(int) image->columns-1; x >= 0; x--)
8006 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8007 p+=GetPixelChannels(image);
8010 image_view=DestroyCacheView(image_view);
8012 Sort colors by decreasing intensity.
8014 qsort((void *) diversity,image->colors,sizeof(*diversity),
8016 for (i=0; i < (ssize_t) image->colors; )
8018 diversity[i].count<<=4; /* increase this colors popularity */
8019 i+=MagickMax((int) (image->colors >> 4),2);
8021 diversity[image->colors-1].count<<=4;
8022 qsort((void *) diversity,image->colors,sizeof(*diversity),
8028 color.flags=(char) (DoRed | DoGreen | DoBlue);
8029 for (i=0; i < (ssize_t) image->colors; i++)
8031 index=diversity[i].index;
8033 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8035 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8037 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8038 if (visual_info->klass != PseudoColor)
8040 gray_value=(unsigned short) XPixelIntensity(&color);
8041 color.red=gray_value;
8042 color.green=gray_value;
8043 color.blue=gray_value;
8045 status=XAllocColor(display,colormap,&color);
8046 if (status == False)
8048 pixel->pixels[index]=color.pixel;
8052 Read X server colormap.
8054 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8055 visual_info->colormap_size,sizeof(*server_colors));
8056 if (server_colors == (XColor *) NULL)
8057 ThrowXWindowFatalException(ResourceLimitFatalError,
8058 "UnableToCreateColormap",image->filename);
8059 for (x=visual_info->colormap_size-1; x >= 0; x--)
8060 server_colors[x].pixel=(size_t) x;
8061 (void) XQueryColors(display,colormap,server_colors,
8062 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8064 Select remaining colors from X server colormap.
8066 for (; i < (ssize_t) image->colors; i++)
8068 index=diversity[i].index;
8069 color.red=ScaleQuantumToShort(
8070 XRedGamma(image->colormap[index].red));
8071 color.green=ScaleQuantumToShort(
8072 XGreenGamma(image->colormap[index].green));
8073 color.blue=ScaleQuantumToShort(
8074 XBlueGamma(image->colormap[index].blue));
8075 if (visual_info->klass != PseudoColor)
8077 gray_value=(unsigned short) XPixelIntensity(&color);
8078 color.red=gray_value;
8079 color.green=gray_value;
8080 color.blue=gray_value;
8082 XBestPixel(display,colormap,server_colors,(unsigned int)
8083 visual_info->colormap_size,&color);
8084 pixel->pixels[index]=color.pixel;
8087 if ((int) image->colors < visual_info->colormap_size)
8090 Fill up colors array-- more choices for pen colors.
8092 retain_colors=MagickMin((unsigned int)
8093 (visual_info->colormap_size-image->colors),256);
8094 for (i=0; i < (ssize_t) retain_colors; i++)
8095 *p++=server_colors[i];
8096 number_colors+=retain_colors;
8098 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8099 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8103 Define Standard colormap for private GrayScale or PseudoColor visual.
8105 if (status == False)
8108 Not enough colormap entries in the colormap-- Create a new colormap.
8110 colormap=XCreateColormap(display,
8111 XRootWindow(display,visual_info->screen),visual_info->visual,
8113 if (colormap == (Colormap) NULL)
8114 ThrowXWindowFatalException(ResourceLimitFatalError,
8115 "UnableToCreateColormap",image->filename);
8116 map_info->colormap=colormap;
8117 if ((int) image->colors < visual_info->colormap_size)
8120 Retain colors from the default colormap to help lessens the
8121 effects of colormap flashing.
8123 retain_colors=MagickMin((unsigned int)
8124 (visual_info->colormap_size-image->colors),256);
8125 p=colors+image->colors;
8126 for (i=0; i < (ssize_t) retain_colors; i++)
8128 p->pixel=(unsigned long) i;
8131 (void) XQueryColors(display,
8132 XDefaultColormap(display,visual_info->screen),
8133 colors+image->colors,(int) retain_colors);
8135 Transfer colors from default to private colormap.
8137 (void) XAllocColorCells(display,colormap,MagickFalse,
8138 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8140 p=colors+image->colors;
8141 for (i=0; i < (ssize_t) retain_colors; i++)
8143 p->pixel=pixel->pixels[i];
8146 (void) XStoreColors(display,colormap,colors+image->colors,
8147 (int) retain_colors);
8148 number_colors+=retain_colors;
8150 (void) XAllocColorCells(display,colormap,MagickFalse,
8151 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8155 Store the image colormap.
8158 color.flags=(char) (DoRed | DoGreen | DoBlue);
8159 for (i=0; i < (ssize_t) image->colors; i++)
8161 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8162 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8163 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8164 if (visual_info->klass != PseudoColor)
8166 gray_value=(unsigned short) XPixelIntensity(&color);
8167 color.red=gray_value;
8168 color.green=gray_value;
8169 color.blue=gray_value;
8171 color.pixel=pixel->pixels[i];
8174 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8185 Define Standard Colormap for TrueColor or DirectColor visual.
8187 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8188 (map_info->green_max*map_info->green_mult)+
8189 (map_info->blue_max*map_info->blue_mult)+1);
8190 linear_colormap=(number_colors > 4096) ||
8191 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8192 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8193 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8194 MagickTrue : MagickFalse;
8195 if (linear_colormap != MagickFalse)
8196 number_colors=(size_t) visual_info->colormap_size;
8198 Allocate color array.
8200 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8201 if (colors == (XColor *) NULL)
8202 ThrowXWindowFatalException(ResourceLimitFatalError,
8203 "UnableToCreateColormap",image->filename);
8205 Initialize linear color ramp.
8208 color.flags=(char) (DoRed | DoGreen | DoBlue);
8209 if (linear_colormap != MagickFalse)
8210 for (i=0; i < (ssize_t) number_colors; i++)
8212 color.blue=(unsigned short) 0;
8213 if (map_info->blue_max != 0)
8214 color.blue=(unsigned short) ((size_t)
8215 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8216 color.green=color.blue;
8217 color.red=color.blue;
8218 color.pixel=XStandardPixel(map_info,&color);
8222 for (i=0; i < (ssize_t) number_colors; i++)
8224 color.red=(unsigned short) 0;
8225 if (map_info->red_max != 0)
8226 color.red=(unsigned short) ((size_t)
8227 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8228 color.green=(unsigned int) 0;
8229 if (map_info->green_max != 0)
8230 color.green=(unsigned short) ((size_t)
8231 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8232 map_info->green_max));
8233 color.blue=(unsigned short) 0;
8234 if (map_info->blue_max != 0)
8235 color.blue=(unsigned short) ((size_t)
8236 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8237 color.pixel=XStandardPixel(map_info,&color);
8240 if ((visual_info->klass == DirectColor) &&
8241 (colormap != XDefaultColormap(display,visual_info->screen)))
8242 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8244 for (i=0; i < (ssize_t) number_colors; i++)
8245 (void) XAllocColor(display,colormap,&colors[i]);
8249 if ((visual_info->klass != DirectColor) &&
8250 (visual_info->klass != TrueColor))
8253 Set foreground, background, border, etc. pixels.
8255 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8256 &pixel->foreground_color);
8257 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8258 &pixel->background_color);
8259 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8262 Foreground and background colors must differ.
8264 pixel->background_color.red=(~pixel->foreground_color.red);
8265 pixel->background_color.green=
8266 (~pixel->foreground_color.green);
8267 pixel->background_color.blue=
8268 (~pixel->foreground_color.blue);
8269 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8270 &pixel->background_color);
8272 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8273 &pixel->border_color);
8274 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8275 &pixel->matte_color);
8276 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8277 &pixel->highlight_color);
8278 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8279 &pixel->shadow_color);
8280 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8281 &pixel->depth_color);
8282 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8283 &pixel->trough_color);
8284 for (i=0; i < MaxNumberPens; i++)
8286 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8287 &pixel->pen_colors[i]);
8288 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8290 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8292 colors=(XColor *) RelinquishMagickMemory(colors);
8293 if (IsEventLogging())
8295 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8296 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8297 map_info->colormap);
8298 (void) LogMagickEvent(X11Event,GetMagickModule(),
8299 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8300 map_info->green_max,map_info->blue_max);
8301 (void) LogMagickEvent(X11Event,GetMagickModule(),
8302 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8303 map_info->green_mult,map_info->blue_mult);
8308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8312 % X M a k e W i n d o w %
8316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8318 % XMakeWindow() creates an X11 window.
8320 % The format of the XMakeWindow method is:
8322 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8323 % XClassHint *class_hint,XWMHints *manager_hints,
8324 % XWindowInfo *window_info)
8326 % A description of each parameter follows:
8328 % o display: Specifies a connection to an X server; returned from
8331 % o parent: Specifies the parent window_info.
8333 % o argv: Specifies the application's argument list.
8335 % o argc: Specifies the number of arguments.
8337 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8339 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8341 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8344 MagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
8345 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8346 XWindowInfo *window_info)
8348 #define MinWindowSize 64
8356 static XTextProperty
8367 Set window info hints.
8369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8370 assert(display != (Display *) NULL);
8371 assert(window_info != (XWindowInfo *) NULL);
8372 size_hints=XAllocSizeHints();
8373 if (size_hints == (XSizeHints *) NULL)
8374 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8375 size_hints->flags=(int) window_info->flags;
8376 size_hints->x=window_info->x;
8377 size_hints->y=window_info->y;
8378 size_hints->width=(int) window_info->width;
8379 size_hints->height=(int) window_info->height;
8380 if (window_info->immutable != MagickFalse)
8383 Window size cannot be changed.
8385 size_hints->min_width=size_hints->width;
8386 size_hints->min_height=size_hints->height;
8387 size_hints->max_width=size_hints->width;
8388 size_hints->max_height=size_hints->height;
8389 size_hints->flags|=PMinSize;
8390 size_hints->flags|=PMaxSize;
8395 Window size can be changed.
8397 size_hints->min_width=(int) window_info->min_width;
8398 size_hints->min_height=(int) window_info->min_height;
8399 size_hints->flags|=PResizeInc;
8400 size_hints->width_inc=(int) window_info->width_inc;
8401 size_hints->height_inc=(int) window_info->height_inc;
8402 #if !defined(PRE_R4_ICCCM)
8403 size_hints->flags|=PBaseSize;
8404 size_hints->base_width=size_hints->width_inc;
8405 size_hints->base_height=size_hints->height_inc;
8408 gravity=NorthWestGravity;
8409 if (window_info->geometry != (char *) NULL)
8412 default_geometry[MaxTextExtent],
8413 geometry[MaxTextExtent];
8422 User specified geometry.
8424 (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
8425 size_hints->width,size_hints->height);
8426 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8428 while (strlen(p) != 0)
8430 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8433 (void) CopyMagickString(p,p+1,MaxTextExtent);
8435 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8436 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8437 &size_hints->width,&size_hints->height,&gravity);
8438 if ((flags & WidthValue) && (flags & HeightValue))
8439 size_hints->flags|=USSize;
8440 if ((flags & XValue) && (flags & YValue))
8442 size_hints->flags|=USPosition;
8443 window_info->x=size_hints->x;
8444 window_info->y=size_hints->y;
8447 #if !defined(PRE_R4_ICCCM)
8448 size_hints->win_gravity=gravity;
8449 size_hints->flags|=PWinGravity;
8451 if (window_info->id == (Window) NULL)
8452 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8453 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8454 window_info->border_width,(int) window_info->depth,InputOutput,
8455 window_info->visual,(unsigned long) window_info->mask,
8456 &window_info->attributes);
8469 Window already exists; change relevant attributes.
8471 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8472 window_info->mask,&window_info->attributes);
8473 mask=ConfigureNotify;
8474 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8475 window_changes.x=window_info->x;
8476 window_changes.y=window_info->y;
8477 window_changes.width=(int) window_info->width;
8478 window_changes.height=(int) window_info->height;
8479 mask=(MagickStatusType) (CWWidth | CWHeight);
8480 if (window_info->flags & USPosition)
8482 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8483 mask,&window_changes);
8485 if (window_info->id == (Window) NULL)
8486 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8488 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8489 if (status == False)
8490 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8492 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8493 if (status == False)
8494 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8495 window_info->icon_name);
8496 if (window_info->icon_geometry != (char *) NULL)
8504 User specified icon geometry.
8506 size_hints->flags|=USPosition;
8507 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8508 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8509 &manager_hints->icon_y,&width,&height,&gravity);
8510 if ((flags & XValue) && (flags & YValue))
8511 manager_hints->flags|=IconPositionHint;
8513 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8514 size_hints,manager_hints,class_hint);
8515 if (window_name.value != (void *) NULL)
8517 (void) XFree((void *) window_name.value);
8518 window_name.value=(unsigned char *) NULL;
8519 window_name.nitems=0;
8521 if (icon_name.value != (void *) NULL)
8523 (void) XFree((void *) icon_name.value);
8524 icon_name.value=(unsigned char *) NULL;
8527 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8528 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8529 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8530 (void) XFree((void *) size_hints);
8531 if (window_info->shape != MagickFalse)
8533 #if defined(MAGICKCORE_HAVE_SHAPE)
8539 Can we apply a non-rectangular shaping mask?
8543 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8544 window_info->shape=MagickFalse;
8546 window_info->shape=MagickFalse;
8549 if (window_info->shared_memory)
8551 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8553 Can we use shared memory with this window?
8555 if (XShmQueryExtension(display) == 0)
8556 window_info->shared_memory=MagickFalse;
8558 window_info->shared_memory=MagickFalse;
8561 window_info->image=NewImageList();
8562 window_info->destroy=MagickFalse;
8566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8570 % X M a g i c k P r o g r e s s M o n i t o r %
8574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8576 % XMagickProgressMonitor() displays the progress a task is making in
8577 % completing a task.
8579 % The format of the XMagickProgressMonitor method is:
8581 % void XMagickProgressMonitor(const char *task,
8582 % const MagickOffsetType quantum,const MagickSizeType span,
8583 % void *client_data)
8585 % A description of each parameter follows:
8587 % o task: Identifies the task in progress.
8589 % o quantum: Specifies the quantum position within the span which represents
8590 % how much progress has been made in completing a task.
8592 % o span: Specifies the span relative to completing a task.
8594 % o client_data: Pointer to any client data.
8598 static const char *GetLocaleMonitorMessage(const char *text)
8601 message[MaxTextExtent],
8610 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8612 if (p != (char *) NULL)
8614 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
8615 locale_message=GetLocaleMessage(message);
8616 if (locale_message == message)
8618 return(locale_message);
8621 MagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
8622 const MagickOffsetType quantum,const MagickSizeType span,
8623 void *magick_unused(client_data))
8628 windows=XSetWindows((XWindows *) ~0);
8629 if (windows == (XWindows *) NULL)
8631 if (windows->info.mapped != MagickFalse)
8632 XProgressMonitorWidget(windows->display,windows,
8633 GetLocaleMonitorMessage(tag),quantum,span);
8638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8642 % X Q u e r y C o l o r D a t a b a s e %
8646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8648 % XQueryColorCompliance() looks up a RGB values for a color given in the target
8651 % The format of the XQueryColorDatabase method is:
8653 % MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
8655 % A description of each parameter follows:
8657 % o target: Specifies the color to lookup in the X color database.
8659 % o color: A pointer to an PixelInfo structure. The RGB value of the target
8660 % color is returned as this value.
8663 MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
8670 *display = (Display *) NULL;
8679 Initialize color return value.
8681 assert(color != (XColor *) NULL);
8685 color->flags=(char) (DoRed | DoGreen | DoBlue);
8686 if ((target == (char *) NULL) || (*target == '\0'))
8687 target="#ffffffffffff";
8689 Let the X server define the color for us.
8691 if (display == (Display *) NULL)
8692 display=XOpenDisplay((char *) NULL);
8693 if (display == (Display *) NULL)
8695 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
8696 return(MagickFalse);
8698 colormap=XDefaultColormap(display,XDefaultScreen(display));
8699 status=XParseColor(display,colormap,(char *) target,&xcolor);
8700 if (status == False)
8701 ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
8704 color->red=xcolor.red;
8705 color->green=xcolor.green;
8706 color->blue=xcolor.blue;
8707 color->flags=xcolor.flags;
8709 return(status != False ? MagickTrue : MagickFalse);
8713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8717 % X Q u e r y P o s i t i o n %
8721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8723 % XQueryPosition() gets the pointer coordinates relative to a window.
8725 % The format of the XQueryPosition method is:
8727 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8729 % A description of each parameter follows:
8731 % o display: Specifies a connection to an X server; returned from
8734 % o window: Specifies a pointer to a Window.
8736 % o x: Return the x coordinate of the pointer relative to the origin of the
8739 % o y: Return the y coordinate of the pointer relative to the origin of the
8743 MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,
8756 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8757 assert(display != (Display *) NULL);
8758 assert(window != (Window) NULL);
8759 assert(x != (int *) NULL);
8760 assert(y != (int *) NULL);
8761 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8770 % X R e f r e s h W i n d o w %
8774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8776 % XRefreshWindow() refreshes an image in a X window.
8778 % The format of the XRefreshWindow method is:
8780 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8781 % const XEvent *event)
8783 % A description of each parameter follows:
8785 % o display: Specifies a connection to an X server; returned from
8788 % o window: Specifies a pointer to a XWindowInfo structure.
8790 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8791 % the entire image is refreshed.
8794 MagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
8795 const XEvent *event)
8805 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8806 assert(display != (Display *) NULL);
8807 assert(window != (XWindowInfo *) NULL);
8808 if (window->ximage == (XImage *) NULL)
8810 if (event != (XEvent *) NULL)
8813 Determine geometry from expose event.
8817 width=(unsigned int) event->xexpose.width;
8818 height=(unsigned int) event->xexpose.height;
8826 Refresh entire window; discard outstanding expose events.
8830 width=window->width;
8831 height=window->height;
8832 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8833 if (window->matte_pixmap != (Pixmap) NULL)
8835 #if defined(MAGICKCORE_HAVE_SHAPE)
8836 if (window->shape != MagickFalse)
8837 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8838 window->matte_pixmap,ShapeSet);
8843 Check boundary conditions.
8845 if ((window->ximage->width-(x+window->x)) < (int) width)
8846 width=(unsigned int) (window->ximage->width-(x+window->x));
8847 if ((window->ximage->height-(y+window->y)) < (int) height)
8848 height=(unsigned int) (window->ximage->height-(y+window->y));
8852 if (window->matte_pixmap != (Pixmap) NULL)
8853 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8854 if (window->pixmap != (Pixmap) NULL)
8856 if (window->depth > 1)
8857 (void) XCopyArea(display,window->pixmap,window->id,
8858 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8860 (void) XCopyPlane(display,window->pixmap,window->id,
8861 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8866 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8867 if (window->shared_memory)
8868 (void) XShmPutImage(display,window->id,window->annotate_context,
8869 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8871 if (window->shared_memory == MagickFalse)
8872 (void) XPutImage(display,window->id,window->annotate_context,
8873 window->ximage,x+window->x,y+window->y,x,y,width,height);
8875 if (window->matte_pixmap != (Pixmap) NULL)
8876 (void) XSetClipMask(display,window->annotate_context,None);
8877 (void) XFlush(display);
8881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8885 % X R e m o t e C o m m a n d %
8889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8891 % XRemoteCommand() forces a remote display(1) to display the specified
8894 % The format of the XRemoteCommand method is:
8896 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8897 % const char *filename)
8899 % A description of each parameter follows:
8901 % o display: Specifies a connection to an X server; returned from
8904 % o window: Specifies the name or id of an X window.
8906 % o filename: the name of the image filename to display.
8909 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8910 const char *window,const char *filename)
8919 assert(filename != (char *) NULL);
8920 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8921 if (display == (Display *) NULL)
8922 display=XOpenDisplay((char *) NULL);
8923 if (display == (Display *) NULL)
8925 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8926 return(MagickFalse);
8928 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8929 remote_window=(Window) NULL;
8930 root_window=XRootWindow(display,XDefaultScreen(display));
8931 if (window != (char *) NULL)
8934 Search window hierarchy and identify any clients by name or ID.
8936 if (isdigit((int) ((unsigned char) *window)) != 0)
8937 remote_window=XWindowByID(display,root_window,(Window)
8938 strtol((char *) window,(char **) NULL,0));
8939 if (remote_window == (Window) NULL)
8940 remote_window=XWindowByName(display,root_window,window);
8942 if (remote_window == (Window) NULL)
8943 remote_window=XWindowByProperty(display,root_window,remote_atom);
8944 if (remote_window == (Window) NULL)
8946 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8948 return(MagickFalse);
8951 Send remote command.
8953 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8954 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8955 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8956 (void) XSync(display,MagickFalse);
8961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8965 % X R e n d e r I m a g e %
8969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8971 % XRenderImage() renders text on the image with an X11 font. It also returns
8972 % the bounding box of the text relative to the image.
8974 % The format of the XRenderImage method is:
8976 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
8977 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8979 % A description of each parameter follows:
8981 % o image: the image.
8983 % o draw_info: the draw info.
8985 % o offset: (x,y) location of text relative to image.
8987 % o metrics: bounding box of text.
8989 % o exception: return any errors or warnings in this structure.
8992 MagickPrivate MagickBooleanType XRenderImage(Image *image,
8993 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
8994 ExceptionInfo *exception)
9037 Open X server connection.
9039 display=XOpenDisplay(draw_info->server_name);
9040 if (display == (Display *) NULL)
9042 ThrowXWindowException(XServerError,"UnableToOpenXServer",
9043 draw_info->server_name);
9044 return(MagickFalse);
9047 Get user defaults from X resource database.
9049 (void) XSetErrorHandler(XError);
9050 image_info=AcquireImageInfo();
9051 client_name=GetClientName();
9052 resource_database=XGetResourceDatabase(display,client_name);
9053 XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9054 resource_info.close_server=MagickFalse;
9055 resource_info.colormap=PrivateColormap;
9056 resource_info.font=AcquireString(draw_info->font);
9057 resource_info.background_color=AcquireString("#ffffffffffff");
9058 resource_info.foreground_color=AcquireString("#000000000000");
9059 map_info=XAllocStandardColormap();
9060 if (map_info == (XStandardColormap *) NULL)
9062 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9064 return(MagickFalse);
9067 Initialize visual info.
9069 visual_info=XBestVisualInfo(display,map_info,&resource_info);
9070 if (visual_info == (XVisualInfo *) NULL)
9072 ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
9073 return(MagickFalse);
9075 map_info->colormap=(Colormap) NULL;
9076 pixel.pixels=(unsigned long *) NULL;
9078 Initialize Standard Colormap info.
9080 XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9082 XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL,
9084 pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9086 Initialize font info.
9088 font_info=XBestFont(display,&resource_info,MagickFalse);
9089 if (font_info == (XFontStruct *) NULL)
9091 ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font);
9092 return(MagickFalse);
9094 if ((map_info == (XStandardColormap *) NULL) ||
9095 (visual_info == (XVisualInfo *) NULL) ||
9096 (font_info == (XFontStruct *) NULL))
9098 XFreeResources(display,visual_info,map_info,&pixel,font_info,
9099 &resource_info,(XWindowInfo *) NULL);
9100 ThrowXWindowException(XServerError,"UnableToLoadFont",image->filename);
9101 return(MagickFalse);
9103 cache_info=(*draw_info);
9105 Initialize annotate info.
9107 XGetAnnotateInfo(&annotate_info);
9108 annotate_info.stencil=ForegroundStencil;
9109 if (cache_info.font != draw_info->font)
9112 Type name has changed.
9114 (void) XFreeFont(display,font_info);
9115 (void) CloneString(&resource_info.font,draw_info->font);
9116 font_info=XBestFont(display,&resource_info,MagickFalse);
9117 if (font_info == (XFontStruct *) NULL)
9119 ThrowXWindowException(XServerError,"UnableToLoadFont",
9121 return(MagickFalse);
9124 if (image->debug != MagickFalse)
9125 (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9126 "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
9127 draw_info->font : "none",draw_info->pointsize);
9128 cache_info=(*draw_info);
9129 annotate_info.font_info=font_info;
9130 annotate_info.text=(char *) draw_info->text;
9131 annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int)
9132 strlen(draw_info->text));
9133 annotate_info.height=(unsigned int) font_info->ascent+font_info->descent;
9134 metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9135 metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9136 metrics->ascent=(double) font_info->ascent+4;
9137 metrics->descent=(double) (-font_info->descent);
9138 metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9139 metrics->height=font_info->ascent+font_info->descent;
9140 metrics->max_advance=(double) font_info->max_bounds.width;
9141 metrics->bounds.x1=0.0;
9142 metrics->bounds.y1=metrics->descent;
9143 metrics->bounds.x2=metrics->ascent+metrics->descent;
9144 metrics->bounds.y2=metrics->ascent+metrics->descent;
9145 metrics->underline_position=(-2.0);
9146 metrics->underline_thickness=1.0;
9147 if (draw_info->render == MagickFalse)
9149 if (draw_info->fill.alpha == TransparentAlpha)
9154 width=annotate_info.width;
9155 height=annotate_info.height;
9156 if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9157 (fabs(draw_info->affine.ry) >= MagickEpsilon))
9159 if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9160 (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9161 annotate_info.degrees=(double) (180.0/MagickPI)*
9162 atan2(draw_info->affine.rx,draw_info->affine.sx);
9164 (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent,
9165 "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height,
9166 ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9167 draw_info->interline_spacing-0.5));
9168 pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
9169 pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
9170 pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
9171 status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9174 ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9176 return(MagickFalse);
9182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9186 % X R e t a i n W i n d o w C o l o r s %
9190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9192 % XRetainWindowColors() sets X11 color resources on a window. This preserves
9193 % the colors associated with an image displayed on the window.
9195 % The format of the XRetainWindowColors method is:
9197 % void XRetainWindowColors(Display *display,const Window window)
9199 % A description of each parameter follows:
9201 % o display: Specifies a connection to an X server; returned from
9204 % o window: Specifies a pointer to a XWindowInfo structure.
9207 MagickExport void XRetainWindowColors(Display *display,const Window window)
9216 Put property on the window.
9218 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9219 assert(display != (Display *) NULL);
9220 assert(window != (Window) NULL);
9221 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
9222 if (property == (Atom) NULL)
9224 ThrowXWindowException(XServerError,"UnableToCreateProperty",
9228 pixmap=XCreatePixmap(display,window,1,1,1);
9229 if (pixmap == (Pixmap) NULL)
9231 ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
9234 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9235 (unsigned char *) &pixmap,1);
9236 (void) XSetCloseDownMode(display,RetainPermanent);
9240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9244 % X S e l e c t W i n d o w %
9248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9250 % XSelectWindow() allows a user to select a window using the mouse. If the
9251 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
9252 % is returned in the crop_info structure.
9254 % The format of the XSelectWindow function is:
9256 % target_window=XSelectWindow(display,crop_info)
9258 % A description of each parameter follows:
9260 % o window: XSelectWindow returns the window id.
9262 % o display: Specifies a pointer to the Display structure; returned from
9265 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9266 % contains the extents of any cropping rectangle.
9269 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9271 #define MinimumCropArea (unsigned int) 9
9298 Initialize graphic context.
9300 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9301 assert(display != (Display *) NULL);
9302 assert(crop_info != (RectangleInfo *) NULL);
9303 root_window=XRootWindow(display,XDefaultScreen(display));
9304 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9305 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9306 context_values.function=GXinvert;
9307 context_values.plane_mask=
9308 context_values.background ^ context_values.foreground;
9309 context_values.subwindow_mode=IncludeInferiors;
9310 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9311 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9312 if (annotate_context == (GC) NULL)
9313 return(MagickFalse);
9315 Grab the pointer using target cursor.
9317 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9318 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9319 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9320 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9321 GrabModeAsync,root_window,target_cursor,CurrentTime);
9322 if (status != GrabSuccess)
9324 ThrowXWindowException(XServerError,"UnableToGrabMouse","");
9325 return((Window) NULL);
9331 crop_info->height=0;
9333 target_window=(Window) NULL;
9338 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9339 (void) XDrawRectangle(display,root_window,annotate_context,
9340 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9341 (unsigned int) crop_info->height-1);
9343 Allow another event.
9345 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9346 (void) XWindowEvent(display,root_window,ButtonPressMask |
9347 ButtonReleaseMask | ButtonMotionMask,&event);
9348 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9349 (void) XDrawRectangle(display,root_window,annotate_context,
9350 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9351 (unsigned int) crop_info->height-1);
9356 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9357 event.xbutton.x,event.xbutton.y);
9358 if (target_window == (Window) NULL)
9359 target_window=root_window;
9360 x_offset=event.xbutton.x_root;
9361 y_offset=event.xbutton.y_root;
9362 crop_info->x=(ssize_t) x_offset;
9363 crop_info->y=(ssize_t) y_offset;
9365 crop_info->height=0;
9377 Discard pending button motion events.
9379 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9380 crop_info->x=(ssize_t) event.xmotion.x;
9381 crop_info->y=(ssize_t) event.xmotion.y;
9383 Check boundary conditions.
9385 if ((int) crop_info->x < x_offset)
9386 crop_info->width=(size_t) (x_offset-crop_info->x);
9389 crop_info->width=(size_t) (crop_info->x-x_offset);
9390 crop_info->x=(ssize_t) x_offset;
9392 if ((int) crop_info->y < y_offset)
9393 crop_info->height=(size_t) (y_offset-crop_info->y);
9396 crop_info->height=(size_t) (crop_info->y-y_offset);
9397 crop_info->y=(ssize_t) y_offset;
9403 } while ((target_window == (Window) NULL) || (presses > 0));
9404 (void) XUngrabPointer(display,CurrentTime);
9405 (void) XFreeCursor(display,target_cursor);
9406 (void) XFreeGC(display,annotate_context);
9407 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9410 crop_info->height=0;
9412 if ((crop_info->width != 0) && (crop_info->height != 0))
9413 target_window=root_window;
9414 return(target_window);
9418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9422 % X S e t C u r s o r S t a t e %
9426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9428 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9429 % reset to their default.
9431 % The format of the XXSetCursorState method is:
9433 % XSetCursorState(display,windows,const MagickStatusType state)
9435 % A description of each parameter follows:
9437 % o display: Specifies a connection to an X server; returned from
9440 % o windows: Specifies a pointer to a XWindows structure.
9442 % o state: An unsigned integer greater than 0 sets the cursor state
9443 % to busy, otherwise the cursor are reset to their default.
9446 MagickPrivate void XSetCursorState(Display *display,XWindows *windows,
9447 const MagickStatusType state)
9449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9450 assert(display != (Display *) NULL);
9451 assert(windows != (XWindows *) NULL);
9454 (void) XCheckDefineCursor(display,windows->image.id,
9455 windows->image.busy_cursor);
9456 (void) XCheckDefineCursor(display,windows->pan.id,
9457 windows->pan.busy_cursor);
9458 (void) XCheckDefineCursor(display,windows->magnify.id,
9459 windows->magnify.busy_cursor);
9460 (void) XCheckDefineCursor(display,windows->command.id,
9461 windows->command.busy_cursor);
9465 (void) XCheckDefineCursor(display,windows->image.id,
9466 windows->image.cursor);
9467 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9468 (void) XCheckDefineCursor(display,windows->magnify.id,
9469 windows->magnify.cursor);
9470 (void) XCheckDefineCursor(display,windows->command.id,
9471 windows->command.cursor);
9472 (void) XCheckDefineCursor(display,windows->command.id,
9473 windows->widget.cursor);
9474 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9476 windows->info.mapped=MagickFalse;
9480 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9484 % X S e t W i n d o w s %
9488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9490 % XSetWindows() sets the X windows structure if the windows info is specified.
9491 % Otherwise the current windows structure is returned.
9493 % The format of the XSetWindows method is:
9495 % XWindows *XSetWindows(XWindows *windows_info)
9497 % A description of each parameter follows:
9499 % o windows_info: Initialize the Windows structure with this information.
9502 MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9505 *windows = (XWindows *) NULL;
9507 if (windows_info != (XWindows *) ~0)
9509 windows=(XWindows *) RelinquishMagickMemory(windows);
9510 windows=windows_info;
9515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9519 % X U s e r P r e f e r e n c e s %
9523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9525 % XUserPreferences() saves the preferences in a configuration file in the
9526 % users' home directory.
9528 % The format of the XUserPreferences method is:
9530 % void XUserPreferences(XResourceInfo *resource_info)
9532 % A description of each parameter follows:
9534 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9537 MagickPrivate void XUserPreferences(XResourceInfo *resource_info)
9539 #if defined(X11_PREFERENCES_PATH)
9541 cache[MaxTextExtent],
9542 filename[MaxTextExtent],
9543 specifier[MaxTextExtent];
9550 preferences_database;
9553 Save user preferences to the client configuration file.
9555 assert(resource_info != (XResourceInfo *) NULL);
9556 client_name=GetClientName();
9557 preferences_database=XrmGetStringDatabase("");
9558 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9559 value=resource_info->backdrop ? "True" : "False";
9560 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9561 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
9562 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9563 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9564 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9566 value=resource_info->confirm_exit ? "True" : "False";
9567 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9568 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9570 value=resource_info->confirm_edit ? "True" : "False";
9571 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9572 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9574 value=resource_info->display_warnings ? "True" : "False";
9575 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9576 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
9577 value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9579 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9580 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9582 value=resource_info->gamma_correct ? "True" : "False";
9583 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9584 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9585 (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
9586 resource_info->undo_cache);
9587 XrmPutStringResource(&preferences_database,specifier,cache);
9588 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9589 value=resource_info->use_pixmap ? "True" : "False";
9590 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9591 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9592 X11_PREFERENCES_PATH,client_name);
9593 ExpandFilename(filename);
9594 XrmPutFileDatabase(preferences_database,filename);
9599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9603 % X V i s u a l C l a s s N a m e %
9607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9609 % XVisualClassName() returns the visual class name as a character string.
9611 % The format of the XVisualClassName method is:
9613 % char *XVisualClassName(const int visual_class)
9615 % A description of each parameter follows:
9617 % o visual_type: XVisualClassName returns the visual class as a character
9620 % o class: Specifies the visual class.
9623 static const char *XVisualClassName(const int visual_class)
9625 switch (visual_class)
9627 case StaticGray: return("StaticGray");
9628 case GrayScale: return("GrayScale");
9629 case StaticColor: return("StaticColor");
9630 case PseudoColor: return("PseudoColor");
9631 case TrueColor: return("TrueColor");
9632 case DirectColor: return("DirectColor");
9634 return("unknown visual class");
9638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9648 % XWarning() displays a warning reason in a Notice widget.
9650 % The format of the XWarning method is:
9652 % void XWarning(const unsigned int warning,const char *reason,
9653 % const char *description)
9655 % A description of each parameter follows:
9657 % o warning: Specifies the numeric warning category.
9659 % o reason: Specifies the reason to display before terminating the
9662 % o description: Specifies any description to the reason.
9665 MagickPrivate void XWarning(const ExceptionType magick_unused(warning),
9666 const char *reason,const char *description)
9669 text[MaxTextExtent];
9674 if (reason == (char *) NULL)
9676 (void) CopyMagickString(text,reason,MaxTextExtent);
9677 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9678 windows=XSetWindows((XWindows *) ~0);
9679 XNoticeWidget(windows->display,windows,text,(char *) description);
9683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9687 % X W i n d o w B y I D %
9691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9693 % XWindowByID() locates a child window with a given ID. If not window with
9694 % the given name is found, 0 is returned. Only the window specified and its
9695 % subwindows are searched.
9697 % The format of the XWindowByID function is:
9699 % child=XWindowByID(display,window,id)
9701 % A description of each parameter follows:
9703 % o child: XWindowByID returns the window with the specified
9704 % id. If no windows are found, XWindowByID returns 0.
9706 % o display: Specifies a pointer to the Display structure; returned from
9709 % o id: Specifies the id of the window to locate.
9712 MagickPrivate Window XWindowByID(Display *display,const Window root_window,
9732 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9733 assert(display != (Display *) NULL);
9734 assert(root_window != (Window) NULL);
9736 return(XSelectWindow(display,&rectangle_info));
9737 if (root_window == id)
9738 return(root_window);
9739 status=XQueryTree(display,root_window,&child,&child,&children,
9741 if (status == False)
9742 return((Window) NULL);
9743 window=(Window) NULL;
9744 for (i=0; i < (int) number_children; i++)
9747 Search each child and their children.
9749 window=XWindowByID(display,children[i],id);
9750 if (window != (Window) NULL)
9753 if (children != (Window *) NULL)
9754 (void) XFree((void *) children);
9759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9763 % X W i n d o w B y N a m e %
9767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9769 % XWindowByName() locates a window with a given name on a display. If no
9770 % window with the given name is found, 0 is returned. If more than one window
9771 % has the given name, the first one is returned. Only root and its children
9774 % The format of the XWindowByName function is:
9776 % window=XWindowByName(display,root_window,name)
9778 % A description of each parameter follows:
9780 % o window: XWindowByName returns the window id.
9782 % o display: Specifies a pointer to the Display structure; returned from
9785 % o root_window: Specifies the id of the root window.
9787 % o name: Specifies the name of the window to locate.
9790 MagickPrivate Window XWindowByName(Display *display,const Window root_window,
9810 assert(display != (Display *) NULL);
9811 assert(root_window != (Window) NULL);
9812 assert(name != (char *) NULL);
9813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9814 if (XGetWMName(display,root_window,&window_name) != 0)
9815 if (LocaleCompare((char *) window_name.value,name) == 0)
9816 return(root_window);
9817 status=XQueryTree(display,root_window,&child,&child,&children,
9819 if (status == False)
9820 return((Window) NULL);
9821 window=(Window) NULL;
9822 for (i=0; i < (int) number_children; i++)
9825 Search each child and their children.
9827 window=XWindowByName(display,children[i],name);
9828 if (window != (Window) NULL)
9831 if (children != (Window *) NULL)
9832 (void) XFree((void *) children);
9837 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9841 % X W i n d o w B y P r o p e r y %
9845 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9847 % XWindowByProperty() locates a child window with a given property. If not
9848 % window with the given name is found, 0 is returned. If more than one window
9849 % has the given property, the first one is returned. Only the window
9850 % specified and its subwindows are searched.
9852 % The format of the XWindowByProperty function is:
9854 % child=XWindowByProperty(display,window,property)
9856 % A description of each parameter follows:
9858 % o child: XWindowByProperty returns the window id with the specified
9859 % property. If no windows are found, XWindowByProperty returns 0.
9861 % o display: Specifies a pointer to the Display structure; returned from
9864 % o property: Specifies the property of the window to locate.
9867 MagickPrivate Window XWindowByProperty(Display *display,const Window window,
9868 const Atom property)
9896 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9897 assert(display != (Display *) NULL);
9898 assert(window != (Window) NULL);
9899 assert(property != (Atom) NULL);
9900 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9901 if (status == False)
9902 return((Window) NULL);
9904 child=(Window) NULL;
9905 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9907 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9908 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9910 (void) XFree((void *) data);
9911 if ((status == Success) && (type != (Atom) NULL))
9914 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9915 child=XWindowByProperty(display,children[i],property);
9916 if (children != (Window *) NULL)
9917 (void) XFree((void *) children);
9923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9927 % X I m p o r t I m a g e %
9931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9933 % XImportImage() reads an image from an X window.
9935 % The format of the XImportImage method is:
9937 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
9938 % ExceptionInfo *exception)
9940 % A description of each parameter follows:
9942 % o image_info: the image info..
9944 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9946 % o exception: return any errors or warnings in this structure.
9949 MagickExport Image *XImportImage(const ImageInfo *image_info,
9950 XImportInfo *ximage_info,ExceptionInfo *exception)
9952 assert(image_info != (const ImageInfo *) NULL);
9953 assert(image_info->signature == MagickSignature);
9954 if (image_info->debug != MagickFalse)
9955 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9956 image_info->filename);
9957 assert(ximage_info != (XImportInfo *) NULL);
9958 assert(exception != (ExceptionInfo *) NULL);
9959 assert(exception->signature == MagickSignature);
9960 return((Image *) NULL);
9964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9968 % X R e n d e r X 1 1 %
9972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9974 % XRenderImage() renders text on the image with an X11 font. It also returns
9975 % the bounding box of the text relative to the image.
9977 % The format of the XRenderImage method is:
9979 % MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
9980 % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
9982 % A description of each parameter follows:
9984 % o image: the image.
9986 % o draw_info: the draw info.
9988 % o offset: (x,y) location of text relative to image.
9990 % o metrics: bounding box of text.
9992 % o exception: return any errors or warnings in this structure.
9995 MagickPrivate MagickBooleanType XRenderImage(Image *image,
9996 const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
9997 ExceptionInfo *exception)
10002 (void) ThrowMagickException(exception,GetMagickModule(),
10003 MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)",
10005 return(MagickFalse);
10010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10014 + X C o m p o n e n t G e n e s i s %
10018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10020 % XComponentGenesis() instantiates the X component.
10022 % The format of the XComponentGenesis method is:
10024 % MagickBooleanType XComponentGenesis(void)
10027 MagickPrivate MagickBooleanType XComponentGenesis(void)
10029 return(MagickTrue);
10033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10037 % X G e t I m p o r t I n f o %
10041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10043 % XGetImportInfo() initializes the XImportInfo structure.
10045 % The format of the XGetImportInfo method is:
10047 % void XGetImportInfo(XImportInfo *ximage_info)
10049 % A description of each parameter follows:
10051 % o ximage_info: Specifies a pointer to an ImageInfo structure.
10054 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
10056 assert(ximage_info != (XImportInfo *) NULL);
10057 ximage_info->frame=MagickFalse;
10058 ximage_info->borders=MagickFalse;
10059 ximage_info->screen=MagickFalse;
10060 ximage_info->descend=MagickTrue;
10061 ximage_info->silent=MagickFalse;