2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % X X W W IIIII N N DDDD OOO W W %
7 % X X W W I NN N D D O O W W %
8 % X W W I N N N D D O O W W %
9 % X X W W W I N NN D D O O W W W %
10 % X X W W IIIII N N DDDD OOO W W %
13 % MagickCore X11 Utility Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/animate.h"
44 #include "MagickCore/artifact.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/client.h"
48 #include "MagickCore/color.h"
49 #include "MagickCore/color-private.h"
50 #include "MagickCore/colormap.h"
51 #include "MagickCore/composite.h"
52 #include "MagickCore/display.h"
53 #include "MagickCore/exception.h"
54 #include "MagickCore/exception-private.h"
55 #include "MagickCore/geometry.h"
56 #include "MagickCore/identify.h"
57 #include "MagickCore/image.h"
58 #include "MagickCore/image-private.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/locale_.h"
61 #include "MagickCore/log.h"
62 #include "MagickCore/magick.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/monitor.h"
65 #include "MagickCore/nt-base-private.h"
66 #include "MagickCore/option.h"
67 #include "MagickCore/pixel-accessor.h"
68 #include "MagickCore/PreRvIcccm.h"
69 #include "MagickCore/quantize.h"
70 #include "MagickCore/quantum.h"
71 #include "MagickCore/quantum-private.h"
72 #include "MagickCore/resource_.h"
73 #include "MagickCore/resize.h"
74 #include "MagickCore/shear.h"
75 #include "MagickCore/statistic.h"
76 #include "MagickCore/string_.h"
77 #include "MagickCore/string-private.h"
78 #include "MagickCore/transform.h"
79 #include "MagickCore/utility.h"
80 #include "MagickCore/utility-private.h"
81 #include "MagickCore/widget.h"
82 #include "MagickCore/widget-private.h"
83 #include "MagickCore/xwindow.h"
84 #include "MagickCore/xwindow-private.h"
85 #include "MagickCore/version.h"
89 #if defined(MAGICKCORE_X11_DELEGATE)
90 #include <X11/Xproto.h>
91 #include <X11/Xlocale.h>
92 #if defined(MAGICK_HAVE_POLL)
93 # include <sys/poll.h>
95 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
96 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
97 # include <machine/param.h>
101 #include <X11/extensions/XShm.h>
103 #if defined(MAGICKCORE_HAVE_SHAPE)
104 #include <X11/extensions/shape.h>
110 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
111 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
113 #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
114 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
116 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
118 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
120 #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
121 ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
123 ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
125 ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
127 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
128 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
130 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
131 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
133 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
134 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
135 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
136 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
138 #define AccentuateModulate ScaleCharToQuantum(80)
139 #define HighlightModulate ScaleCharToQuantum(125)
140 #define ShadowModulate ScaleCharToQuantum(135)
141 #define DepthModulate ScaleCharToQuantum(185)
142 #define TroughModulate ScaleCharToQuantum(110)
144 #define XLIB_ILLEGAL_ACCESS 1
146 #undef NorthWestGravity
148 #undef NorthEastGravity
152 #undef SouthWestGravity
154 #undef SouthEastGravity
161 #define XFD_SET fd_set
165 Enumeration declarations.
179 Typedef declarations.
181 typedef struct _DiversityPacket
196 Constant declaractions.
198 static MagickBooleanType
199 xerror_alert = MagickFalse;
205 *XVisualClassName(const int);
207 static MagickRealType
212 static MagickBooleanType
213 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
216 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
217 XImage *,XImage *,ExceptionInfo *),
218 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
219 XImage *,XImage *,ExceptionInfo *);
222 XSelectWindow(Display *,RectangleInfo *);
225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % D e s t r o y X R e s o u r c e s %
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 % DestroyXResources() destroys any X resources.
237 % The format of the DestroyXResources method is:
239 % void DestroyXResources()
241 % A description of each parameter follows:
244 MagickExport void DestroyXResources(void)
253 *magick_windows[MaxXWindows];
259 windows=XSetWindows((XWindows *) ~0);
260 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
263 magick_windows[number_windows++]=(&windows->context);
264 magick_windows[number_windows++]=(&windows->group_leader);
265 magick_windows[number_windows++]=(&windows->backdrop);
266 magick_windows[number_windows++]=(&windows->icon);
267 magick_windows[number_windows++]=(&windows->image);
268 magick_windows[number_windows++]=(&windows->info);
269 magick_windows[number_windows++]=(&windows->magnify);
270 magick_windows[number_windows++]=(&windows->pan);
271 magick_windows[number_windows++]=(&windows->command);
272 magick_windows[number_windows++]=(&windows->widget);
273 magick_windows[number_windows++]=(&windows->popup);
274 magick_windows[number_windows++]=(&windows->context);
275 for (i=0; i < (int) number_windows; i++)
277 if (magick_windows[i]->mapped != MagickFalse)
279 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
280 magick_windows[i]->screen);
281 magick_windows[i]->mapped=MagickFalse;
283 if (magick_windows[i]->name != (char *) NULL)
284 magick_windows[i]->name=(char *)
285 RelinquishMagickMemory(magick_windows[i]->name);
286 if (magick_windows[i]->icon_name != (char *) NULL)
287 magick_windows[i]->icon_name=(char *)
288 RelinquishMagickMemory(magick_windows[i]->icon_name);
289 if (magick_windows[i]->cursor != (Cursor) NULL)
291 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
292 magick_windows[i]->cursor=(Cursor) NULL;
294 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
296 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
297 magick_windows[i]->busy_cursor=(Cursor) NULL;
299 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
301 (void) XFreePixmap(windows->display,
302 magick_windows[i]->highlight_stipple);
303 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
305 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
307 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
308 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
310 if (magick_windows[i]->ximage != (XImage *) NULL)
312 XDestroyImage(magick_windows[i]->ximage);
313 magick_windows[i]->ximage=(XImage *) NULL;
315 if (magick_windows[i]->pixmap != (Pixmap) NULL)
317 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
318 magick_windows[i]->pixmap=(Pixmap) NULL;
320 if (magick_windows[i]->id != (Window) NULL)
322 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
323 magick_windows[i]->id=(Window) NULL;
325 if (magick_windows[i]->destroy != MagickFalse)
327 if (magick_windows[i]->image != (Image *) NULL)
329 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
330 magick_windows[i]->image=NewImageList();
332 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
334 (void) XFreePixmap(windows->display,
335 magick_windows[i]->matte_pixmap);
336 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
339 if (magick_windows[i]->segment_info != (void *) NULL)
341 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
345 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
346 if (segment_info != (XShmSegmentInfo *) NULL)
347 if (segment_info[0].shmid >= 0)
349 if (segment_info[0].shmaddr != NULL)
350 (void) shmdt(segment_info[0].shmaddr);
351 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
352 segment_info[0].shmaddr=NULL;
353 segment_info[0].shmid=(-1);
356 magick_windows[i]->segment_info=(void *)
357 RelinquishMagickMemory(magick_windows[i]->segment_info);
360 windows->icon_resources=(XResourceInfo *)
361 RelinquishMagickMemory(windows->icon_resources);
362 if (windows->icon_pixel != (XPixelInfo *) NULL)
364 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
365 windows->icon_pixel->pixels=(unsigned long *)
366 RelinquishMagickMemory(windows->icon_pixel->pixels);
367 if (windows->icon_pixel->annotate_context != (GC) NULL)
368 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
369 windows->icon_pixel=(XPixelInfo *)
370 RelinquishMagickMemory(windows->icon_pixel);
372 if (windows->pixel_info != (XPixelInfo *) NULL)
374 if (windows->pixel_info->pixels != (unsigned long *) NULL)
375 windows->pixel_info->pixels=(unsigned long *)
376 RelinquishMagickMemory(windows->pixel_info->pixels);
377 if (windows->pixel_info->annotate_context != (GC) NULL)
378 XFreeGC(windows->display,windows->pixel_info->annotate_context);
379 if (windows->pixel_info->widget_context != (GC) NULL)
380 XFreeGC(windows->display,windows->pixel_info->widget_context);
381 if (windows->pixel_info->highlight_context != (GC) NULL)
382 XFreeGC(windows->display,windows->pixel_info->highlight_context);
383 windows->pixel_info=(XPixelInfo *)
384 RelinquishMagickMemory(windows->pixel_info);
386 if (windows->font_info != (XFontStruct *) NULL)
388 XFreeFont(windows->display,windows->font_info);
389 windows->font_info=(XFontStruct *) NULL;
391 if (windows->class_hints != (XClassHint *) NULL)
393 if (windows->class_hints->res_name != (char *) NULL)
394 windows->class_hints->res_name=DestroyString(
395 windows->class_hints->res_name);
396 if (windows->class_hints->res_class != (char *) NULL)
397 windows->class_hints->res_class=DestroyString(
398 windows->class_hints->res_class);
399 XFree(windows->class_hints);
400 windows->class_hints=(XClassHint *) NULL;
402 if (windows->manager_hints != (XWMHints *) NULL)
404 XFree(windows->manager_hints);
405 windows->manager_hints=(XWMHints *) NULL;
407 if (windows->map_info != (XStandardColormap *) NULL)
409 XFree(windows->map_info);
410 windows->map_info=(XStandardColormap *) NULL;
412 if (windows->icon_map != (XStandardColormap *) NULL)
414 XFree(windows->icon_map);
415 windows->icon_map=(XStandardColormap *) NULL;
417 if (windows->visual_info != (XVisualInfo *) NULL)
419 XFree(windows->visual_info);
420 windows->visual_info=(XVisualInfo *) NULL;
422 if (windows->icon_visual != (XVisualInfo *) NULL)
424 XFree(windows->icon_visual);
425 windows->icon_visual=(XVisualInfo *) NULL;
427 (void) XSetWindows((XWindows *) NULL);
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % X A n n o t a t e I m a g e %
439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 % XAnnotateImage() annotates the image with text.
443 % The format of the XAnnotateImage method is:
445 % MagickBooleanType XAnnotateImage(Display *display,
446 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
447 % ExceptionInfo *exception)
449 % A description of each parameter follows:
451 % o display: Specifies a connection to an X server; returned from
454 % o pixel: Specifies a pointer to a XPixelInfo structure.
456 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
458 % o image: the image.
460 % o exception: return any errors or warnings in this structure.
463 MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
464 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
465 ExceptionInfo *exception)
487 virtual_pixel[MaxPixelChannels];
504 Initialize annotated image.
506 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
507 assert(display != (Display *) NULL);
508 assert(pixel != (XPixelInfo *) NULL);
509 assert(annotate_info != (XAnnotateInfo *) NULL);
510 assert(image != (Image *) NULL);
512 Initialize annotated pixmap.
514 root_window=XRootWindow(display,XDefaultScreen(display));
515 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
516 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
517 annotate_info->height,depth);
518 if (annotate_pixmap == (Pixmap) NULL)
521 Initialize graphics info.
523 context_values.background=0;
524 context_values.foreground=(size_t) (~0);
525 context_values.font=annotate_info->font_info->fid;
526 annotate_context=XCreateGC(display,root_window,(unsigned long)
527 (GCBackground | GCFont | GCForeground),&context_values);
528 if (annotate_context == (GC) NULL)
533 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
534 (int) annotate_info->font_info->ascent,annotate_info->text,
535 (int) strlen(annotate_info->text));
536 (void) XFreeGC(display,annotate_context);
538 Initialize annotated X image.
540 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
541 annotate_info->height,AllPlanes,ZPixmap);
542 if (annotate_ximage == (XImage *) NULL)
544 (void) XFreePixmap(display,annotate_pixmap);
546 Initialize annotated image.
548 annotate_image=AcquireImage((ImageInfo *) NULL,&image->exception);
549 if (annotate_image == (Image *) NULL)
551 annotate_image->columns=annotate_info->width;
552 annotate_image->rows=annotate_info->height;
554 Transfer annotated X image to image.
556 width=(unsigned int) image->columns;
557 height=(unsigned int) image->rows;
560 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
561 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,virtual_pixel,
563 annotate_image->background_color.red=virtual_pixel[RedPixelChannel];
564 annotate_image->background_color.green=virtual_pixel[GreenPixelChannel];
565 annotate_image->background_color.blue=virtual_pixel[BluePixelChannel];
566 annotate_image->background_color.alpha=virtual_pixel[AlphaPixelChannel];
567 if (annotate_info->stencil == ForegroundStencil)
568 annotate_image->matte=MagickTrue;
569 exception=(&image->exception);
570 annotate_view=AcquireCacheView(annotate_image);
571 for (y=0; y < (int) annotate_image->rows; y++)
579 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
580 annotate_image->columns,1,exception);
581 if (q == (Quantum *) NULL)
583 for (x=0; x < (int) annotate_image->columns; x++)
585 SetPixelAlpha(annotate_image,OpaqueAlpha,q);
586 if (XGetPixel(annotate_ximage,x,y) == 0)
589 Set this pixel to the background color.
591 SetPixelRed(annotate_image,ScaleShortToQuantum(
592 pixel->box_color.red),q);
593 SetPixelGreen(annotate_image,ScaleShortToQuantum(
594 pixel->box_color.green),q);
595 SetPixelBlue(annotate_image,ScaleShortToQuantum(
596 pixel->box_color.blue),q);
597 if ((annotate_info->stencil == ForegroundStencil) ||
598 (annotate_info->stencil == OpaqueStencil))
599 SetPixelAlpha(annotate_image,TransparentAlpha,q);
604 Set this pixel to the pen color.
606 SetPixelRed(annotate_image,ScaleShortToQuantum(
607 pixel->pen_color.red),q);
608 SetPixelGreen(annotate_image,ScaleShortToQuantum(
609 pixel->pen_color.green),q);
610 SetPixelBlue(annotate_image,ScaleShortToQuantum(
611 pixel->pen_color.blue),q);
612 if (annotate_info->stencil == BackgroundStencil)
613 SetPixelAlpha(annotate_image,TransparentAlpha,q);
615 q+=GetPixelChannels(annotate_image);
617 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
620 annotate_view=DestroyCacheView(annotate_view);
621 XDestroyImage(annotate_ximage);
623 Determine annotate geometry.
625 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
626 if ((width != (unsigned int) annotate_image->columns) ||
627 (height != (unsigned int) annotate_image->rows))
630 image_geometry[MaxTextExtent];
635 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
637 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
640 if (annotate_info->degrees != 0.0)
655 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
656 if (rotate_image == (Image *) NULL)
658 annotate_image=DestroyImage(annotate_image);
659 annotate_image=rotate_image;
661 Annotation is relative to the degree of rotation.
663 normalized_degrees=annotate_info->degrees;
664 while (normalized_degrees < -45.0)
665 normalized_degrees+=360.0;
666 for (rotations=0; normalized_degrees > 45.0; rotations++)
667 normalized_degrees-=90.0;
668 switch (rotations % 4)
678 x-=(int) annotate_image->columns/2;
679 y+=(int) annotate_image->columns/2;
687 x=x-(int) annotate_image->columns;
695 x=x-(int) annotate_image->columns/2;
696 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
702 Composite text onto the image.
704 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
706 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
707 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y,
710 annotate_image=DestroyImage(annotate_image);
715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
719 % X B e s t F o n t %
723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
725 % XBestFont() returns the "best" font. "Best" is defined as a font specified
726 % in the X resource database or a font such that the text width displayed
727 % with the font does not exceed the specified maximum width.
729 % The format of the XBestFont method is:
731 % XFontStruct *XBestFont(Display *display,
732 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
734 % A description of each parameter follows:
736 % o font: XBestFont returns a pointer to a XFontStruct structure.
738 % o display: Specifies a connection to an X server; returned from
741 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
743 % o text_font: True is font should be mono-spaced (typewriter style).
747 static char **FontToList(char *font)
762 if (font == (char *) NULL)
763 return((char **) NULL);
765 Convert string to an ASCII list.
768 for (p=font; *p != '\0'; p++)
769 if ((*p == ':') || (*p == ';') || (*p == ','))
771 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
772 if (fontlist == (char **) NULL)
774 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
776 return((char **) NULL);
779 for (i=0; i < (int) fonts; i++)
781 for (q=p; *q != '\0'; q++)
782 if ((*q == ':') || (*q == ';') || (*q == ','))
784 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
785 sizeof(*fontlist[i]));
786 if (fontlist[i] == (char *) NULL)
788 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
790 return((char **) NULL);
792 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
795 fontlist[i]=(char *) NULL;
799 MagickPrivate XFontStruct *XBestFont(Display *display,
800 const XResourceInfo *resource_info,const MagickBooleanType text_font)
805 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
806 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
807 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
808 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
809 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
810 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
817 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
818 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
819 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
833 font_info=(XFontStruct *) NULL;
834 font_name=resource_info->font;
835 if (text_font != MagickFalse)
836 font_name=resource_info->text_font;
837 if ((font_name != (char *) NULL) && (*font_name != '\0'))
846 Load preferred font specified in the X resource database.
848 fontlist=FontToList(font_name);
849 if (fontlist != (char **) NULL)
851 for (i=0; fontlist[i] != (char *) NULL; i++)
853 if (font_info == (XFontStruct *) NULL)
854 font_info=XLoadQueryFont(display,fontlist[i]);
855 fontlist[i]=DestroyString(fontlist[i]);
857 fontlist=(char **) RelinquishMagickMemory(fontlist);
859 if (font_info == (XFontStruct *) NULL)
860 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
863 Load fonts from list of fonts until one is found.
866 if (text_font != MagickFalse)
868 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
870 while (*p != (char *) NULL)
872 if (font_info != (XFontStruct *) NULL)
874 font_info=XLoadQueryFont(display,(char *) *p);
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885 % X B e s t I c o n S i z e %
889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
891 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
892 % size that maintains the aspect ratio of the image. If the window manager
893 % has preferred icon sizes, one of the preferred sizes is used.
895 % The format of the XBestIconSize method is:
897 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
899 % A description of each parameter follows:
901 % o display: Specifies a connection to an X server; returned from
904 % o image: the image.
907 MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
931 Determine if the window manager has specified preferred icon sizes.
933 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
934 assert(display != (Display *) NULL);
935 assert(window != (XWindowInfo *) NULL);
936 assert(image != (Image *) NULL);
937 window->width=MaxIconSize;
938 window->height=MaxIconSize;
939 icon_size=(XIconSize *) NULL;
941 root_window=XRootWindow(display,window->screen);
942 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
943 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
945 if (icon_size == (XIconSize *) NULL)
948 Window manager does not restrict icon size.
950 icon_size=XAllocIconSize();
951 if (icon_size == (XIconSize *) NULL)
953 ThrowXWindowFatalException(ResourceLimitError,
954 "MemoryAllocationFailed",image->filename);
957 icon_size->min_width=1;
958 icon_size->max_width=MaxIconSize;
959 icon_size->min_height=1;
960 icon_size->max_height=MaxIconSize;
961 icon_size->width_inc=1;
962 icon_size->height_inc=1;
965 Determine aspect ratio of image.
967 width=(unsigned int) image->columns;
968 height=(unsigned int) image->rows;
970 if (window->crop_geometry)
971 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
973 Look for an icon size that maintains the aspect ratio of image.
975 scale_factor=(MagickRealType) icon_size->max_width/width;
976 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
977 scale_factor=(MagickRealType) icon_size->max_height/height;
978 icon_width=(unsigned int) icon_size->min_width;
979 while ((int) icon_width < icon_size->max_width)
981 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
983 icon_width+=icon_size->width_inc;
985 icon_height=(unsigned int) icon_size->min_height;
986 while ((int) icon_height < icon_size->max_height)
988 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
990 icon_height+=icon_size->height_inc;
992 (void) XFree((void *) icon_size);
993 window->width=icon_width;
994 window->height=icon_height;
998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002 % X B e s t P i x e l %
1006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 % XBestPixel() returns a pixel from an array of pixels that is closest to the
1009 % requested color. If the color array is NULL, the colors are obtained from
1012 % The format of the XBestPixel method is:
1014 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
1015 % unsigned int number_colors,XColor *color)
1017 % A description of each parameter follows:
1019 % o pixel: XBestPixel returns the pixel value closest to the requested
1022 % o display: Specifies a connection to an X server; returned from
1025 % o colormap: Specifies the ID of the X server colormap.
1027 % o colors: Specifies an array of XColor structures.
1029 % o number_colors: Specifies the number of XColor structures in the
1030 % color definition array.
1032 % o color: Specifies the desired RGB value to find in the colors array.
1035 MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
1036 XColor *colors,unsigned int number_colors,XColor *color)
1047 register MagickRealType
1058 Find closest representation for the requested RGB color.
1060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1061 assert(display != (Display *) NULL);
1062 assert(color != (XColor *) NULL);
1063 status=XAllocColor(display,colormap,color);
1064 if (status != False)
1066 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1067 if (query_server != MagickFalse)
1070 Read X server colormap.
1072 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1073 if (colors == (XColor *) NULL)
1075 ThrowXWindowFatalException(ResourceLimitError,
1076 "MemoryAllocationFailed","...");
1079 for (i=0; i < (int) number_colors; i++)
1080 colors[i].pixel=(size_t) i;
1081 if (number_colors > 256)
1083 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1085 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1088 for (i=0; i < (int) number_colors; i++)
1090 pixel.red=colors[i].red-(MagickRealType) color->red;
1091 distance=pixel.red*pixel.red;
1092 if (distance > min_distance)
1094 pixel.green=colors[i].green-(MagickRealType) color->green;
1095 distance+=pixel.green*pixel.green;
1096 if (distance > min_distance)
1098 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1099 distance+=pixel.blue*pixel.blue;
1100 if (distance > min_distance)
1102 min_distance=distance;
1103 color->pixel=colors[i].pixel;
1106 (void) XAllocColor(display,colormap,&colors[j]);
1107 if (query_server != MagickFalse)
1108 colors=(XColor *) RelinquishMagickMemory(colors);
1112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1116 % X B e s t V i s u a l I n f o %
1120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1122 % XBestVisualInfo() returns visual information for a visual that is the "best"
1123 % the server supports. "Best" is defined as:
1125 % 1. Restrict the visual list to those supported by the default screen.
1127 % 2. If a visual type is specified, restrict the visual list to those of
1130 % 3. If a map type is specified, choose the visual that matches the id
1131 % specified by the Standard Colormap.
1133 % 4 From the list of visuals, choose one that can display the most
1134 % simultaneous colors. If more than one visual can display the same
1135 % number of simultaneous colors, one is chosen based on a rank.
1137 % The format of the XBestVisualInfo method is:
1139 % XVisualInfo *XBestVisualInfo(Display *display,
1140 % XStandardColormap *map_info,XResourceInfo *resource_info)
1142 % A description of each parameter follows:
1144 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1147 % o display: Specifies a connection to an X server; returned from
1150 % o map_info: If map_type is specified, this structure is initialized
1151 % with info from the Standard Colormap.
1153 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1157 static inline int MagickMax(const int x,const int y)
1164 static inline size_t MagickMin(const unsigned int x,
1165 const unsigned int y)
1172 MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
1173 XStandardColormap *map_info,XResourceInfo *resource_info)
1175 #define MaxStandardColormaps 7
1176 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1177 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1178 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1179 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1205 Restrict visual search by screen number.
1207 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1208 assert(display != (Display *) NULL);
1209 assert(map_info != (XStandardColormap *) NULL);
1210 assert(resource_info != (XResourceInfo *) NULL);
1211 map_type=resource_info->map_type;
1212 visual_type=resource_info->visual_type;
1213 visual_mask=VisualScreenMask;
1214 visual_template.screen=XDefaultScreen(display);
1215 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1217 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1218 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1219 visual_mask|=VisualDepthMask;
1220 if (visual_type != (char *) NULL)
1223 Restrict visual search by class or visual id.
1225 if (LocaleCompare("staticgray",visual_type) == 0)
1227 visual_mask|=VisualClassMask;
1228 visual_template.klass=StaticGray;
1231 if (LocaleCompare("grayscale",visual_type) == 0)
1233 visual_mask|=VisualClassMask;
1234 visual_template.klass=GrayScale;
1237 if (LocaleCompare("staticcolor",visual_type) == 0)
1239 visual_mask|=VisualClassMask;
1240 visual_template.klass=StaticColor;
1243 if (LocaleCompare("pseudocolor",visual_type) == 0)
1245 visual_mask|=VisualClassMask;
1246 visual_template.klass=PseudoColor;
1249 if (LocaleCompare("truecolor",visual_type) == 0)
1251 visual_mask|=VisualClassMask;
1252 visual_template.klass=TrueColor;
1255 if (LocaleCompare("directcolor",visual_type) == 0)
1257 visual_mask|=VisualClassMask;
1258 visual_template.klass=DirectColor;
1261 if (LocaleCompare("default",visual_type) == 0)
1263 visual_mask|=VisualIDMask;
1264 visual_template.visualid=XVisualIDFromVisual(
1265 XDefaultVisual(display,XDefaultScreen(display)));
1268 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1270 visual_mask|=VisualIDMask;
1271 visual_template.visualid=
1272 strtol(visual_type,(char **) NULL,0);
1275 ThrowXWindowFatalException(XServerError,
1276 "UnrecognizedVisualSpecifier",visual_type);
1279 Get all visuals that meet our criteria so far.
1282 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1284 visual_mask=VisualScreenMask | VisualIDMask;
1285 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1288 Failed to get visual; try using the default visual.
1290 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1292 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1293 XDefaultScreen(display)));
1294 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1296 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1297 return((XVisualInfo *) NULL);
1298 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1299 XVisualClassName(visual_list->klass));
1301 resource_info->color_recovery=MagickFalse;
1302 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1308 map_name[MaxTextExtent];
1324 Choose a visual associated with a standard colormap.
1326 root_window=XRootWindow(display,XDefaultScreen(display));
1328 if (LocaleCompare(map_type,"list") != 0)
1331 User specified Standard Colormap.
1333 (void) FormatLocaleString((char *) map_name,MaxTextExtent,
1334 "RGB_%s_MAP",map_type);
1335 LocaleUpper(map_name);
1336 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1337 if (map_property != (Atom) NULL)
1338 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1344 *colormap[MaxStandardColormaps]=
1346 "_HP_RGB_SMOOTH_MAP_LIST",
1356 Choose a standard colormap from a list.
1358 for (i=0; i < MaxStandardColormaps; i++)
1360 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1361 if (map_property == (Atom) NULL)
1363 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1365 if (status != False)
1368 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1370 if (status == False)
1372 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1374 return((XVisualInfo *) NULL);
1377 Search all Standard Colormaps and visuals for ids that match.
1379 *map_info=map_list[0];
1380 #if !defined(PRE_R4_ICCCM)
1381 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1382 for (i=0; i < number_maps; i++)
1383 for (j=0; j < number_visuals; j++)
1384 if (map_list[i].visualid ==
1385 XVisualIDFromVisual(visual_list[j].visual))
1387 *map_info=map_list[i];
1388 visual_template.visualid=XVisualIDFromVisual(
1389 visual_list[j].visual);
1392 if (map_info->visualid != visual_template.visualid)
1394 ThrowXWindowFatalException(XServerError,
1395 "UnableToMatchVisualToStandardColormap",map_type);
1396 return((XVisualInfo *) NULL);
1399 if (map_info->colormap == (Colormap) NULL)
1401 ThrowXWindowFatalException(XServerError,
1402 "StandardColormapIsNotInitialized",map_type);
1403 return((XVisualInfo *) NULL);
1405 (void) XFree((void *) map_list);
1409 static const unsigned int
1424 Pick one visual that displays the most simultaneous colors.
1426 visual_info=visual_list;
1428 for (i=1; i < number_visuals; i++)
1431 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1434 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1435 if (rank[p->klass] > rank[visual_info->klass])
1438 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1440 (void) XFree((void *) visual_list);
1442 Retrieve only one visual by its screen & id number.
1444 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1446 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1447 return((XVisualInfo *) NULL);
1448 return(visual_info);
1452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1456 % X C h e c k D e f i n e C u r s o r %
1460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1462 % XCheckDefineCursor() prevents cursor changes on the root window.
1464 % The format of the XXCheckDefineCursor method is:
1466 % XCheckDefineCursor(display,window,cursor)
1468 % A description of each parameter follows:
1470 % o display: Specifies a connection to an X server; returned from
1473 % o window: the window.
1475 % o cursor: the cursor.
1478 MagickPrivate int XCheckDefineCursor(Display *display,Window window,
1481 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1482 assert(display != (Display *) NULL);
1483 if (window == XRootWindow(display,XDefaultScreen(display)))
1485 return(XDefineCursor(display,window,cursor));
1489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1493 % X C h e c k R e f r e s h W i n d o w s %
1497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1499 % XCheckRefreshWindows() checks the X server for exposure events for a
1500 % particular window and updates the areassociated with the exposure event.
1502 % The format of the XCheckRefreshWindows method is:
1504 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1506 % A description of each parameter follows:
1508 % o display: Specifies a connection to an X server; returned from
1511 % o windows: Specifies a pointer to a XWindows structure.
1514 MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
1522 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1523 assert(display != (Display *) NULL);
1524 assert(windows != (XWindows *) NULL);
1525 XDelay(display,SuspendTime);
1526 id=windows->command.id;
1527 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1528 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1529 id=windows->image.id;
1530 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1531 XRefreshWindow(display,&windows->image,&event);
1532 XDelay(display,SuspendTime << 1);
1533 id=windows->command.id;
1534 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1535 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1536 id=windows->image.id;
1537 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1538 XRefreshWindow(display,&windows->image,&event);
1542 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1546 % X C l i e n t M e s s a g e %
1550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1552 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1553 % initialized with a particular protocol type and atom.
1555 % The format of the XClientMessage function is:
1557 % XClientMessage(display,window,protocol,reason,timestamp)
1559 % A description of each parameter follows:
1561 % o display: Specifies a pointer to the Display structure; returned from
1564 % o window: Specifies a pointer to a Window structure.
1566 % o protocol: Specifies an atom value.
1568 % o reason: Specifies an atom value which is the reason to send.
1570 % o timestamp: Specifies a value of type Time.
1573 MagickPrivate void XClientMessage(Display *display,const Window window,
1574 const Atom protocol,const Atom reason,const Time timestamp)
1579 assert(display != (Display *) NULL);
1580 client_event.type=ClientMessage;
1581 client_event.window=window;
1582 client_event.message_type=protocol;
1583 client_event.format=32;
1584 client_event.data.l[0]=(long) reason;
1585 client_event.data.l[1]=(long) timestamp;
1586 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1594 + X C l i e n t W i n d o w %
1598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1600 % XClientWindow() finds a window, at or below the specified window, which has
1601 % a WM_STATE property. If such a window is found, it is returned, otherwise
1602 % the argument window is returned.
1604 % The format of the XClientWindow function is:
1606 % client_window=XClientWindow(display,target_window)
1608 % A description of each parameter follows:
1610 % o client_window: XClientWindow returns a window, at or below the specified
1611 % window, which has a WM_STATE property otherwise the argument
1612 % target_window is returned.
1614 % o display: Specifies a pointer to the Display structure; returned from
1617 % o target_window: Specifies the window to find a WM_STATE property.
1620 static Window XClientWindow(Display *display,Window target_window)
1642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1643 assert(display != (Display *) NULL);
1644 state=XInternAtom(display,"WM_STATE",MagickTrue);
1645 if (state == (Atom) NULL)
1646 return(target_window);
1648 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1649 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1650 if ((status == Success) && (type != (Atom) NULL))
1651 return(target_window);
1652 client_window=XWindowByProperty(display,target_window,state);
1653 if (client_window == (Window) NULL)
1654 return(target_window);
1655 return(client_window);
1659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663 + X C o m p o n e n t T e r m i n u s %
1667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1669 % XComponentTerminus() destroys the module component.
1671 % The format of the XComponentTerminus method is:
1673 % XComponentTerminus(void)
1676 MagickPrivate void XComponentTerminus(void)
1678 DestroyXResources();
1682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1686 % X C o n f i g u r e I m a g e C o l o r m a p %
1690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1692 % XConfigureImageColormap() creates a new X colormap.
1694 % The format of the XConfigureImageColormap method is:
1696 % void XConfigureImageColormap(Display *display,
1697 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1699 % A description of each parameter follows:
1701 % o display: Specifies a connection to an X server; returned from
1704 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1706 % o windows: Specifies a pointer to a XWindows structure.
1708 % o image: the image.
1711 MagickPrivate void XConfigureImageColormap(Display *display,
1712 XResourceInfo *resource_info,XWindows *windows,Image *image)
1718 Make standard colormap.
1720 XSetCursorState(display,windows,MagickTrue);
1721 XCheckRefreshWindows(display,windows);
1722 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1723 windows->map_info,windows->pixel_info);
1724 colormap=windows->map_info->colormap;
1725 (void) XSetWindowColormap(display,windows->image.id,colormap);
1726 (void) XSetWindowColormap(display,windows->command.id,colormap);
1727 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1728 if (windows->magnify.mapped != MagickFalse)
1729 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1730 if (windows->pan.mapped != MagickFalse)
1731 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1732 XSetCursorState(display,windows,MagickFalse);
1733 XClientMessage(display,windows->image.id,windows->im_protocols,
1734 windows->im_update_colormap,CurrentTime);
1738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1742 % X C o n s t r a i n W i n d o w P o s i t i o n %
1746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1748 % XConstrainWindowPosition() assures a window is positioned within the X
1749 % server boundaries.
1751 % The format of the XConstrainWindowPosition method is:
1753 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1755 % A description of each parameter follows:
1757 % o display: Specifies a pointer to the Display structure; returned from
1760 % o window_info: Specifies a pointer to a XWindowInfo structure.
1763 MagickPrivate void XConstrainWindowPosition(Display *display,
1764 XWindowInfo *window_info)
1769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1770 assert(display != (Display *) NULL);
1771 assert(window_info != (XWindowInfo *) NULL);
1772 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1773 if (window_info->x < 0)
1776 if (window_info->x > (int) limit)
1777 window_info->x=(int) limit;
1778 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1779 if (window_info->y < 0)
1782 if (window_info->y > limit)
1783 window_info->y=limit;
1787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1797 % XDelay() suspends program execution for the number of milliseconds
1800 % The format of the Delay method is:
1802 % void XDelay(Display *display,const size_t milliseconds)
1804 % A description of each parameter follows:
1806 % o display: Specifies a pointer to the Display structure; returned from
1809 % o milliseconds: Specifies the number of milliseconds to delay before
1813 MagickPrivate void XDelay(Display *display,const size_t milliseconds)
1815 assert(display != (Display *) NULL);
1816 (void) XFlush(display);
1817 MagickDelay(milliseconds);
1821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1825 % X D e s t r o y R e s o u r c e I n f o %
1829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1831 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1834 % The format of the XDestroyResourceInfo method is:
1836 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1838 % A description of each parameter follows:
1840 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1843 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1845 if (resource_info->image_geometry != (char *) NULL)
1846 resource_info->image_geometry=(char *)
1847 RelinquishMagickMemory(resource_info->image_geometry);
1848 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1849 resource_info->quantize_info=DestroyQuantizeInfo(
1850 resource_info->quantize_info);
1851 if (resource_info->client_name != (char *) NULL)
1852 resource_info->client_name=(char *)
1853 RelinquishMagickMemory(resource_info->client_name);
1854 if (resource_info->name != (char *) NULL)
1855 resource_info->name=DestroyString(resource_info->name);
1856 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 % X D e s t r o y W i n d o w C o l o r s %
1868 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870 % XDestroyWindowColors() frees X11 color resources previously saved on a
1871 % window by XRetainWindowColors or programs like xsetroot.
1873 % The format of the XDestroyWindowColors method is:
1875 % void XDestroyWindowColors(Display *display,Window window)
1877 % A description of each parameter follows:
1879 % o display: Specifies a connection to an X server; returned from
1882 % o window: Specifies a pointer to a Window structure.
1885 MagickPrivate void XDestroyWindowColors(Display *display,Window window)
1905 If there are previous resources on the root window, destroy them.
1907 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1908 assert(display != (Display *) NULL);
1909 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1910 if (property == (Atom) NULL)
1912 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1916 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1917 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1918 if (status != Success)
1920 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1922 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1923 (void) XDeleteProperty(display,window,property);
1926 (void) XFree((void *) data);
1930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934 % X D i s p l a y I m a g e I n f o %
1938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1940 % XDisplayImageInfo() displays information about an X image.
1942 % The format of the XDisplayImageInfo method is:
1944 % void XDisplayImageInfo(Display *display,
1945 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1948 % A description of each parameter follows:
1950 % o display: Specifies a connection to an X server; returned from
1953 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1955 % o windows: Specifies a pointer to a XWindows structure.
1957 % o undo_image: the undo image.
1959 % o image: the image.
1962 MagickPrivate void XDisplayImageInfo(Display *display,
1963 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1967 filename[MaxTextExtent],
1990 Write info about the X server to a file.
1992 assert(display != (Display *) NULL);
1993 assert(resource_info != (XResourceInfo *) NULL);
1994 assert(windows != (XWindows *) NULL);
1995 assert(image != (Image *) NULL);
1997 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1999 unique_file=AcquireUniqueFileResource(filename);
2000 if (unique_file != -1)
2001 file=fdopen(unique_file,"w");
2002 if ((unique_file == -1) || (file == (FILE *) NULL))
2004 XNoticeWidget(display,windows,"Unable to display image info",filename);
2007 if (resource_info->gamma_correct != MagickFalse)
2008 if (resource_info->display_gamma != (char *) NULL)
2009 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
2010 resource_info->display_gamma);
2012 Write info about the X image to a file.
2014 (void) FormatLocaleFile(file,"X\n visual: %s\n",
2015 XVisualClassName((int) windows->image.storage_class));
2016 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
2017 if (windows->visual_info->colormap_size != 0)
2018 (void) FormatLocaleFile(file," colormap size: %d\n",
2019 windows->visual_info->colormap_size);
2020 if (resource_info->colormap== SharedColormap)
2021 (void) FormatLocaleFile(file," colormap type: Shared\n");
2023 (void) FormatLocaleFile(file," colormap type: Private\n");
2024 (void) FormatLocaleFile(file," geometry: %dx%d\n",
2025 windows->image.ximage->width,windows->image.ximage->height);
2026 if (windows->image.crop_geometry != (char *) NULL)
2027 (void) FormatLocaleFile(file," crop geometry: %s\n",
2028 windows->image.crop_geometry);
2029 if (windows->image.pixmap == (Pixmap) NULL)
2030 (void) FormatLocaleFile(file," type: X Image\n");
2032 (void) FormatLocaleFile(file," type: Pixmap\n");
2033 if (windows->image.shape != MagickFalse)
2034 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2036 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2037 if (windows->image.shared_memory != MagickFalse)
2038 (void) FormatLocaleFile(file," shared memory: True\n");
2040 (void) FormatLocaleFile(file," shared memory: False\n");
2041 (void) FormatLocaleFile(file,"\n");
2042 if (resource_info->font != (char *) NULL)
2043 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2044 if (resource_info->text_font != (char *) NULL)
2045 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2047 Write info about the undo cache to a file.
2050 for (levels=0; undo_image != (Image *) NULL; levels++)
2052 number_pixels=undo_image->list->columns*undo_image->list->rows;
2053 bytes+=number_pixels*sizeof(PixelInfo);
2054 undo_image=GetPreviousImageInList(undo_image);
2056 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2057 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2058 ((bytes+(1 << 19)) >> 20));
2059 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2060 resource_info->undo_cache);
2062 Write info about the image to a file.
2064 (void) IdentifyImage(image,file,MagickTrue,&image->exception);
2065 (void) fclose(file);
2066 text=FileToString(filename,~0,&image->exception);
2067 (void) RelinquishUniqueFileResource(filename);
2068 if (text == (char *) NULL)
2070 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2071 "UnableToDisplayImageInfo");
2074 textlist=StringToList(text);
2075 if (textlist != (char **) NULL)
2078 title[MaxTextExtent];
2081 Display information about the image in the Text View widget.
2083 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2084 (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
2086 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2087 (char const **) textlist);
2088 for (i=0; textlist[i] != (char *) NULL; i++)
2089 textlist[i]=DestroyString(textlist[i]);
2090 textlist=(char **) RelinquishMagickMemory(textlist);
2092 text=DestroyString(text);
2096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2100 + X D i t h e r I m a g e %
2104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2106 % XDitherImage() dithers the reference image as required by the HP Color
2107 % Recovery algorithm. The color values are quantized to 3 bits of red and
2108 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2109 % standard colormap.
2111 % The format of the XDitherImage method is:
2113 % void XDitherImage(Image *image,XImage *ximage)
2115 % A description of each parameter follows:
2117 % o image: the image.
2119 % o ximage: Specifies a pointer to a XImage structure; returned from
2123 static void XDitherImage(Image *image,XImage *ximage)
2125 static const short int
2128 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2129 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2131 dither_green[2][16]=
2133 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2134 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2138 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2139 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2155 register const Quantum
2175 Allocate and initialize dither maps.
2177 for (i=0; i < 2; i++)
2178 for (j=0; j < 16; j++)
2180 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2182 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2183 sizeof(*green_map));
2184 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2186 if ((red_map[i][j] == (unsigned char *) NULL) ||
2187 (green_map[i][j] == (unsigned char *) NULL) ||
2188 (blue_map[i][j] == (unsigned char *) NULL))
2190 ThrowXWindowFatalException(ResourceLimitError,
2191 "MemoryAllocationFailed",image->filename);
2196 Initialize dither tables.
2198 for (i=0; i < 2; i++)
2199 for (j=0; j < 16; j++)
2200 for (x=0; x < 256; x++)
2205 value+=dither_red[i][j];
2206 red_map[i][j][x]=(unsigned char)
2207 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2211 value+=dither_green[i][j];
2212 green_map[i][j][x]=(unsigned char)
2213 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2217 value+=((size_t) dither_blue[i][j] << 1);
2218 blue_map[i][j][x]=(unsigned char)
2219 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2224 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2225 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2229 image_view=AcquireCacheView(image);
2230 for (y=0; y < (int) image->rows; y++)
2232 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2234 if (p == (const Quantum *) NULL)
2236 for (x=0; x < (int) image->columns; x++)
2238 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2239 ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2240 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2241 ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2242 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2243 ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2244 pixel=(size_t) (((size_t) color.red & 0xe0) |
2245 (((size_t) color.green & 0xe0) >> 3) |
2246 (((size_t) color.blue & 0xc0) >> 6));
2248 p+=GetPixelChannels(image);
2258 image_view=DestroyCacheView(image_view);
2260 Free allocated memory.
2262 for (i=0; i < 2; i++)
2263 for (j=0; j < 16; j++)
2265 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2266 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2267 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2276 % X D r a w I m a g e %
2280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2282 % XDrawImage() draws a line on the image.
2284 % The format of the XDrawImage method is:
2286 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
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.
2300 MagickPrivate MagickBooleanType XDrawImage(Display *display,
2301 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2323 virtual_pixel[MaxPixelChannels];
2343 Initialize drawd image.
2345 assert(display != (Display *) NULL);
2346 assert(pixel != (XPixelInfo *) NULL);
2347 assert(draw_info != (XDrawInfo *) NULL);
2348 assert(image != (Image *) NULL);
2349 if (image->debug != MagickFalse)
2350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2352 Initialize drawd pixmap.
2354 root_window=XRootWindow(display,XDefaultScreen(display));
2355 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2356 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2357 draw_info->height,depth);
2358 if (draw_pixmap == (Pixmap) NULL)
2359 return(MagickFalse);
2361 Initialize graphics info.
2363 context_values.background=(size_t) (~0);
2364 context_values.foreground=0;
2365 context_values.line_width=(int) draw_info->line_width;
2366 draw_context=XCreateGC(display,root_window,(size_t)
2367 (GCBackground | GCForeground | GCLineWidth),&context_values);
2368 if (draw_context == (GC) NULL)
2369 return(MagickFalse);
2373 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2376 Draw line to pixmap.
2378 (void) XSetBackground(display,draw_context,0);
2379 (void) XSetForeground(display,draw_context,(size_t) (~0));
2380 if (draw_info->stipple != (Pixmap) NULL)
2382 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2383 (void) XSetStipple(display,draw_context,draw_info->stipple);
2385 switch (draw_info->element)
2390 (void) XDrawLines(display,draw_pixmap,draw_context,
2391 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2397 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2398 draw_info->line_info.y1,draw_info->line_info.x2,
2399 draw_info->line_info.y2);
2402 case RectangleElement:
2404 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2405 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2406 (unsigned int) draw_info->rectangle_info.width,
2407 (unsigned int) draw_info->rectangle_info.height);
2410 case FillRectangleElement:
2412 (void) XFillRectangle(display,draw_pixmap,draw_context,
2413 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2414 (unsigned int) draw_info->rectangle_info.width,
2415 (unsigned int) draw_info->rectangle_info.height);
2419 case EllipseElement:
2421 (void) XDrawArc(display,draw_pixmap,draw_context,
2422 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2423 (unsigned int) draw_info->rectangle_info.width,
2424 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2427 case FillCircleElement:
2428 case FillEllipseElement:
2430 (void) XFillArc(display,draw_pixmap,draw_context,
2431 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2432 (unsigned int) draw_info->rectangle_info.width,
2433 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2436 case PolygonElement:
2441 coordinate_info=draw_info->coordinate_info;
2442 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2443 (int) draw_info->number_coordinates,CoordModeOrigin);
2444 (void) XDrawLine(display,draw_pixmap,draw_context,
2445 coordinate_info[draw_info->number_coordinates-1].x,
2446 coordinate_info[draw_info->number_coordinates-1].y,
2447 coordinate_info[0].x,coordinate_info[0].y);
2450 case FillPolygonElement:
2452 (void) XFillPolygon(display,draw_pixmap,draw_context,
2453 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2458 (void) XFreeGC(display,draw_context);
2462 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2463 draw_info->height,AllPlanes,ZPixmap);
2464 if (draw_ximage == (XImage *) NULL)
2465 return(MagickFalse);
2466 (void) XFreePixmap(display,draw_pixmap);
2468 Initialize draw image.
2470 draw_image=AcquireImage((ImageInfo *) NULL,&image->exception);
2471 if (draw_image == (Image *) NULL)
2472 return(MagickFalse);
2473 draw_image->columns=draw_info->width;
2474 draw_image->rows=draw_info->height;
2476 Transfer drawn X image to image.
2478 width=(unsigned int) image->columns;
2479 height=(unsigned int) image->rows;
2482 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2483 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,virtual_pixel,
2485 draw_image->background_color.red=virtual_pixel[RedPixelChannel];
2486 draw_image->background_color.green=virtual_pixel[GreenPixelChannel];
2487 draw_image->background_color.blue=virtual_pixel[BluePixelChannel];
2488 draw_image->background_color.alpha=virtual_pixel[AlphaPixelChannel];
2489 if (SetImageStorageClass(draw_image,DirectClass,&image->exception) == MagickFalse)
2490 return(MagickFalse);
2491 draw_image->matte=MagickTrue;
2492 exception=(&image->exception);
2493 draw_view=AcquireCacheView(draw_image);
2494 for (y=0; y < (int) draw_image->rows; y++)
2502 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2504 if (q == (Quantum *) NULL)
2506 for (x=0; x < (int) draw_image->columns; x++)
2508 if (XGetPixel(draw_ximage,x,y) == 0)
2511 Set this pixel to the background color.
2513 SetPixelPixelInfo(draw_image,&draw_image->background_color,q);
2514 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2515 OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
2520 Set this pixel to the pen color.
2522 SetPixelRed(draw_image,ScaleShortToQuantum(
2523 pixel->pen_color.red),q);
2524 SetPixelGreen(draw_image,ScaleShortToQuantum(
2525 pixel->pen_color.green),q);
2526 SetPixelBlue(draw_image,ScaleShortToQuantum(
2527 pixel->pen_color.blue),q);
2528 SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
2529 OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
2531 q+=GetPixelChannels(draw_image);
2533 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2536 draw_view=DestroyCacheView(draw_view);
2537 XDestroyImage(draw_ximage);
2539 Determine draw geometry.
2541 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2542 if ((width != (unsigned int) draw_image->columns) ||
2543 (height != (unsigned int) draw_image->rows))
2546 image_geometry[MaxTextExtent];
2551 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
2553 (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2556 if (draw_info->degrees != 0.0)
2570 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2571 if (rotate_image == (Image *) NULL)
2572 return(MagickFalse);
2573 draw_image=DestroyImage(draw_image);
2574 draw_image=rotate_image;
2576 Annotation is relative to the degree of rotation.
2578 normalized_degrees=draw_info->degrees;
2579 while (normalized_degrees < -45.0)
2580 normalized_degrees+=360.0;
2581 for (rotations=0; normalized_degrees > 45.0; rotations++)
2582 normalized_degrees-=90.0;
2583 switch (rotations % 4)
2593 x=x-(int) draw_image->columns/2;
2594 y=y+(int) draw_image->columns/2;
2602 x=x-(int) draw_image->columns;
2610 x=x-(int) draw_image->columns/2;
2611 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2617 Composite text onto the image.
2619 draw_view=AcquireCacheView(draw_image);
2620 for (y=0; y < (int) draw_image->rows; y++)
2628 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2630 if (q == (Quantum *) NULL)
2632 for (x=0; x < (int) draw_image->columns; x++)
2634 if (GetPixelAlpha(image,q) != TransparentAlpha)
2635 SetPixelAlpha(draw_image,OpaqueAlpha,q);
2636 q+=GetPixelChannels(draw_image);
2638 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2641 draw_view=DestroyCacheView(draw_view);
2642 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2643 if (draw_info->stencil == TransparentStencil)
2644 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2645 (ssize_t) y,exception);
2649 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2650 (ssize_t) y,exception);
2653 draw_image=DestroyImage(draw_image);
2658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2668 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2669 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2670 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it
2673 % The format of the XError function is:
2675 % int XError(display,error)
2677 % A description of each parameter follows:
2679 % o display: Specifies a pointer to the Display structure; returned from
2682 % o error: Specifies the error event.
2686 #if defined(__cplusplus) || defined(c_plusplus)
2690 MagickExport int XError(Display *display,XErrorEvent *error)
2692 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2693 assert(display != (Display *) NULL);
2694 assert(error != (XErrorEvent *) NULL);
2695 xerror_alert=MagickTrue;
2696 switch (error->request_code)
2700 if ((int) error->error_code == BadDrawable)
2701 return(MagickFalse);
2704 case X_GetWindowAttributes:
2707 if ((int) error->error_code == BadWindow)
2708 return(MagickFalse);
2713 if ((int) error->error_code == BadValue)
2714 return(MagickFalse);
2721 #if defined(__cplusplus) || defined(c_plusplus)
2726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2730 % X F r e e R e s o u r c e s %
2734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2736 % XFreeResources() frees X11 resources.
2738 % The format of the XFreeResources method is:
2740 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2741 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2742 % XResourceInfo *resource_info,XWindowInfo *window_info)
2743 % resource_info,window_info)
2745 % A description of each parameter follows:
2747 % o display: Specifies a connection to an X server; returned from
2750 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2751 % returned from XGetVisualInfo.
2753 % o map_info: If map_type is specified, this structure is initialized
2754 % with info from the Standard Colormap.
2756 % o pixel: Specifies a pointer to a XPixelInfo structure.
2758 % o font_info: Specifies a pointer to a XFontStruct structure.
2760 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2762 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2765 MagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
2766 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2767 XResourceInfo *resource_info,XWindowInfo *window_info)
2769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2770 assert(display != (Display *) NULL);
2771 assert(resource_info != (XResourceInfo *) NULL);
2772 if (window_info != (XWindowInfo *) NULL)
2777 if (window_info->ximage != (XImage *) NULL)
2778 XDestroyImage(window_info->ximage);
2779 if (window_info->id != (Window) NULL)
2782 Free destroy window and free cursors.
2784 if (window_info->id != XRootWindow(display,visual_info->screen))
2785 (void) XDestroyWindow(display,window_info->id);
2786 if (window_info->annotate_context != (GC) NULL)
2787 (void) XFreeGC(display,window_info->annotate_context);
2788 if (window_info->highlight_context != (GC) NULL)
2789 (void) XFreeGC(display,window_info->highlight_context);
2790 if (window_info->widget_context != (GC) NULL)
2791 (void) XFreeGC(display,window_info->widget_context);
2792 if (window_info->cursor != (Cursor) NULL)
2793 (void) XFreeCursor(display,window_info->cursor);
2794 window_info->cursor=(Cursor) NULL;
2795 if (window_info->busy_cursor != (Cursor) NULL)
2796 (void) XFreeCursor(display,window_info->busy_cursor);
2797 window_info->busy_cursor=(Cursor) NULL;
2803 if (font_info != (XFontStruct *) NULL)
2805 (void) XFreeFont(display,font_info);
2806 font_info=(XFontStruct *) NULL;
2808 if (map_info != (XStandardColormap *) NULL)
2811 Free X Standard Colormap.
2813 if (resource_info->map_type == (char *) NULL)
2814 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2815 (void) XFree((void *) map_info);
2820 if (visual_info != (XVisualInfo *) NULL)
2821 (void) XFree((void *) visual_info);
2822 if (resource_info->close_server != MagickFalse)
2823 (void) XCloseDisplay(display);
2827 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831 % X F r e e S t a n d a r d C o l o r m a p %
2835 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2837 % XFreeStandardColormap() frees an X11 colormap.
2839 % The format of the XFreeStandardColormap method is:
2841 % void XFreeStandardColormap(Display *display,
2842 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2843 % XPixelInfo *pixel)
2845 % A description of each parameter follows:
2847 % o display: Specifies a connection to an X server; returned from
2850 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2851 % returned from XGetVisualInfo.
2853 % o map_info: If map_type is specified, this structure is initialized
2854 % with info from the Standard Colormap.
2856 % o pixel: Specifies a pointer to a XPixelInfo structure.
2859 MagickPrivate void XFreeStandardColormap(Display *display,
2860 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2865 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2866 assert(display != (Display *) NULL);
2867 assert(visual_info != (XVisualInfo *) NULL);
2868 assert(map_info != (XStandardColormap *) NULL);
2869 (void) XFlush(display);
2870 if (map_info->colormap != (Colormap) NULL)
2872 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2873 (void) XFreeColormap(display,map_info->colormap);
2875 if (pixel != (XPixelInfo *) NULL)
2876 if ((visual_info->klass != TrueColor) &&
2877 (visual_info->klass != DirectColor))
2878 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2879 (int) pixel->colors,0);
2881 map_info->colormap=(Colormap) NULL;
2882 if (pixel != (XPixelInfo *) NULL)
2884 if (pixel->pixels != (unsigned long *) NULL)
2885 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2886 pixel->pixels=(unsigned long *) NULL;
2891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % X G e t A n n o t a t e I n f o %
2899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2901 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2903 % The format of the XGetAnnotateInfo method is:
2905 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2907 % A description of each parameter follows:
2909 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2912 MagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2915 Initialize annotate structure.
2917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2918 assert(annotate_info != (XAnnotateInfo *) NULL);
2921 annotate_info->width=0;
2922 annotate_info->height=0;
2923 annotate_info->stencil=ForegroundStencil;
2924 annotate_info->degrees=0.0;
2925 annotate_info->font_info=(XFontStruct *) NULL;
2926 annotate_info->text=(char *) NULL;
2927 *annotate_info->geometry='\0';
2928 annotate_info->previous=(XAnnotateInfo *) NULL;
2929 annotate_info->next=(XAnnotateInfo *) NULL;
2930 (void) XSupportsLocale();
2931 (void) XSetLocaleModifiers("");
2935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2939 % X G e t M a p I n f o %
2943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945 % XGetMapInfo() initializes the XStandardColormap structure.
2947 % The format of the XStandardColormap method is:
2949 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2950 % XStandardColormap *map_info)
2952 % A description of each parameter follows:
2954 % o colormap: Specifies the ID of the X server colormap.
2956 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2957 % returned from XGetVisualInfo.
2959 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2962 MagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
2963 const Colormap colormap,XStandardColormap *map_info)
2966 Initialize map info.
2968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2969 assert(visual_info != (XVisualInfo *) NULL);
2970 assert(map_info != (XStandardColormap *) NULL);
2971 map_info->colormap=colormap;
2972 map_info->red_max=visual_info->red_mask;
2973 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2974 if (map_info->red_max != 0)
2975 while ((map_info->red_max & 0x01) == 0)
2977 map_info->red_max>>=1;
2978 map_info->red_mult<<=1;
2980 map_info->green_max=visual_info->green_mask;
2981 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2982 if (map_info->green_max != 0)
2983 while ((map_info->green_max & 0x01) == 0)
2985 map_info->green_max>>=1;
2986 map_info->green_mult<<=1;
2988 map_info->blue_max=visual_info->blue_mask;
2989 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2990 if (map_info->blue_max != 0)
2991 while ((map_info->blue_max & 0x01) == 0)
2993 map_info->blue_max>>=1;
2994 map_info->blue_mult<<=1;
2996 map_info->base_pixel=0;
3000 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3004 % X G e t P i x e l I n f o %
3008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3010 % XGetPixelInfo() initializes the PixelInfo structure.
3012 % The format of the XGetPixelInfo method is:
3014 % void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
3015 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
3016 % Image *image,XPixelInfo *pixel)
3019 % A description of each parameter follows:
3021 % o display: Specifies a connection to an X server; returned from
3024 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
3025 % returned from XGetVisualInfo.
3027 % o map_info: If map_type is specified, this structure is initialized
3028 % with info from the Standard Colormap.
3030 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3032 % o image: the image.
3034 % o pixel: Specifies a pointer to a XPixelInfo structure.
3037 MagickPrivate void XGetPixelInfo(Display *display,
3038 const XVisualInfo *visual_info,const XStandardColormap *map_info,
3039 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3042 *PenColors[MaxNumberPens]=
3044 "#000000000000", /* black */
3045 "#00000000ffff", /* blue */
3046 "#0000ffffffff", /* cyan */
3047 "#0000ffff0000", /* green */
3048 "#bdbdbdbdbdbd", /* gray */
3049 "#ffff00000000", /* red */
3050 "#ffff0000ffff", /* magenta */
3051 "#ffffffff0000", /* yellow */
3052 "#ffffffffffff", /* white */
3053 "#bdbdbdbdbdbd", /* gray */
3054 "#bdbdbdbdbdbd" /* gray */
3070 Initialize pixel info.
3072 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3073 assert(display != (Display *) NULL);
3074 assert(visual_info != (XVisualInfo *) NULL);
3075 assert(map_info != (XStandardColormap *) NULL);
3076 assert(resource_info != (XResourceInfo *) NULL);
3077 assert(pixel != (XPixelInfo *) NULL);
3079 if (image != (Image *) NULL)
3080 if (image->storage_class == PseudoClass)
3081 pixel->colors=(ssize_t) image->colors;
3082 packets=(unsigned int)
3083 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3084 if (pixel->pixels != (unsigned long *) NULL)
3085 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3086 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3087 sizeof(pixel->pixels));
3088 if (pixel->pixels == (unsigned long *) NULL)
3089 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3092 Set foreground color.
3094 colormap=map_info->colormap;
3095 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3096 &pixel->foreground_color);
3097 status=XParseColor(display,colormap,resource_info->foreground_color,
3098 &pixel->foreground_color);
3099 if (status == False)
3100 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3101 resource_info->foreground_color);
3102 pixel->foreground_color.pixel=
3103 XStandardPixel(map_info,&pixel->foreground_color);
3104 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3106 Set background color.
3108 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3109 status=XParseColor(display,colormap,resource_info->background_color,
3110 &pixel->background_color);
3111 if (status == False)
3112 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3113 resource_info->background_color);
3114 pixel->background_color.pixel=
3115 XStandardPixel(map_info,&pixel->background_color);
3116 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3120 (void) XParseColor(display,colormap,(char *) BorderColor,
3121 &pixel->border_color);
3122 status=XParseColor(display,colormap,resource_info->border_color,
3123 &pixel->border_color);
3124 if (status == False)
3125 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3126 resource_info->border_color);
3127 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3128 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3132 pixel->matte_color=pixel->background_color;
3133 if (resource_info->matte_color != (char *) NULL)
3136 Matte color is specified as a X resource or command line argument.
3138 status=XParseColor(display,colormap,resource_info->matte_color,
3139 &pixel->matte_color);
3140 if (status == False)
3141 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3142 resource_info->matte_color);
3143 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3144 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3147 Set highlight color.
3149 pixel->highlight_color.red=(unsigned short) ((
3150 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3151 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3152 pixel->highlight_color.green=(unsigned short) ((
3153 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3154 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3155 pixel->highlight_color.blue=(unsigned short) ((
3156 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3157 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3158 pixel->highlight_color.pixel=
3159 XStandardPixel(map_info,&pixel->highlight_color);
3160 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3164 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3165 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3166 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3167 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3168 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3169 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3170 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3171 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3175 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3176 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3177 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3178 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3179 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3180 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3181 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3182 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3186 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3187 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3188 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3189 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3190 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3191 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3192 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3193 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3197 for (i=0; i < MaxNumberPens; i++)
3199 (void) XParseColor(display,colormap,(char *) PenColors[i],
3200 &pixel->pen_colors[i]);
3201 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3202 &pixel->pen_colors[i]);
3203 if (status == False)
3204 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3205 resource_info->pen_colors[i]);
3206 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3207 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3209 pixel->box_color=pixel->background_color;
3210 pixel->pen_color=pixel->foreground_color;
3213 if (image != (Image *) NULL)
3215 if ((resource_info->gamma_correct != MagickFalse) &&
3216 (image->gamma != 0.0))
3225 Initialize map relative to display and image gamma.
3227 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3228 red_gamma=geometry_info.rho;
3229 green_gamma=geometry_info.sigma;
3230 if ((flags & SigmaValue) == 0)
3231 green_gamma=red_gamma;
3232 blue_gamma=geometry_info.xi;
3233 if ((flags & XiValue) == 0)
3234 blue_gamma=red_gamma;
3235 red_gamma*=image->gamma;
3236 green_gamma*=image->gamma;
3237 blue_gamma*=image->gamma;
3239 if (image->storage_class == PseudoClass)
3242 Initialize pixel array for images of type PseudoClass.
3244 for (i=0; i < (ssize_t) image->colors; i++)
3245 pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
3246 for (i=0; i < MaxNumberPens; i++)
3247 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3248 pixel->colors+=MaxNumberPens;
3254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3258 % X G e t R e s o u r c e C l a s s %
3262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3264 % XGetResourceClass() queries the X server for the specified resource name or
3265 % class. If the resource name or class is not defined in the database, the
3266 % supplied default value is returned.
3268 % The format of the XGetResourceClass method is:
3270 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3271 % const char *keyword,char *resource_default)
3273 % A description of each parameter follows:
3275 % o database: Specifies a resource database; returned from
3276 % XrmGetStringDatabase.
3278 % o client_name: Specifies the application name used to retrieve resource
3279 % info from the X server database.
3281 % o keyword: Specifies the keyword of the value being retrieved.
3283 % o resource_default: Specifies the default value to return if the query
3284 % fails to find the specified keyword/class.
3287 MagickExport char *XGetResourceClass(XrmDatabase database,
3288 const char *client_name,const char *keyword,char *resource_default)
3291 resource_class[MaxTextExtent],
3292 resource_name[MaxTextExtent];
3303 if (database == (XrmDatabase) NULL)
3304 return(resource_default);
3305 *resource_name='\0';
3306 *resource_class='\0';
3307 if (keyword != (char *) NULL)
3314 Initialize resource keyword and class.
3316 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
3317 client_name,keyword);
3318 c=(int) (*client_name);
3319 if ((c >= XK_a) && (c <= XK_z))
3322 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3323 c-=(XK_agrave-XK_Agrave);
3325 if ((c >= XK_oslash) && (c <= XK_thorn))
3326 c-=(XK_oslash-XK_Ooblique);
3328 if ((k >= XK_a) && (k <= XK_z))
3331 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3332 k-=(XK_agrave-XK_Agrave);
3334 if ((k >= XK_oslash) && (k <= XK_thorn))
3335 k-=(XK_oslash-XK_Ooblique);
3336 (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3337 client_name+1,k,keyword+1);
3339 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3341 if (status == False)
3342 return(resource_default);
3343 return(resource_value.addr);
3347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3351 % X G e t R e s o u r c e D a t a b a s e %
3355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3357 % XGetResourceDatabase() creates a new resource database and initializes it.
3359 % The format of the XGetResourceDatabase method is:
3361 % XrmDatabase XGetResourceDatabase(Display *display,
3362 % const char *client_name)
3364 % A description of each parameter follows:
3366 % o database: XGetResourceDatabase() returns the database after it is
3369 % o display: Specifies a connection to an X server; returned from
3372 % o client_name: Specifies the application name used to retrieve resource
3373 % info from the X server database.
3376 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3377 const char *client_name)
3380 filename[MaxTextExtent];
3392 if (display == (Display *) NULL)
3393 return((XrmDatabase) NULL);
3394 assert(client_name != (char *) NULL);
3396 Initialize resource database.
3399 (void) XGetDefault(display,(char *) client_name,"dummy");
3400 resource_database=XrmGetDatabase(display);
3402 Combine application database.
3404 if (client_name != (char *) NULL)
3407 Get basename of client.
3409 p=client_name+(strlen(client_name)-1);
3410 while ((p > client_name) && (*p != '/'))
3415 c=(int) (*client_name);
3416 if ((c >= XK_a) && (c <= XK_z))
3419 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3420 c-=(XK_agrave-XK_Agrave);
3422 if ((c >= XK_oslash) && (c <= XK_thorn))
3423 c-=(XK_oslash-XK_Ooblique);
3424 #if defined(X11_APPLICATION_PATH)
3425 (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
3426 X11_APPLICATION_PATH,c,client_name+1);
3427 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3429 if (XResourceManagerString(display) != (char *) NULL)
3432 Combine server database.
3434 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3435 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3438 Merge user preferences database.
3440 #if defined(X11_PREFERENCES_PATH)
3441 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
3442 X11_PREFERENCES_PATH,client_name);
3443 ExpandFilename(filename);
3444 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3446 return(resource_database);
3450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3454 % X G e t R e s o u r c e I n f o %
3458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3460 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3462 % The format of the XGetResourceInfo method is:
3464 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3465 % const char *client_name,XResourceInfo *resource_info)
3467 % A description of each parameter follows:
3469 % o image_info: the image info.
3471 % o database: Specifies a resource database; returned from
3472 % XrmGetStringDatabase.
3474 % o client_name: Specifies the application name used to retrieve
3475 % resource info from the X server database.
3477 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3480 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3481 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=IsMagickTrue(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 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3521 resource_value=XGetResourceClass(database,client_name,
3522 "colorRecovery",(char *) "False");
3523 resource_info->color_recovery=IsMagickTrue(resource_value);
3524 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3526 resource_info->confirm_exit=IsMagickTrue(resource_value);
3527 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3529 resource_info->confirm_edit=IsMagickTrue(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=IsMagickTrue(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=IsMagickTrue(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=IsMagickTrue(resource_value);
3581 resource_value=XGetResourceClass(database,client_name,"immutable",
3582 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3584 resource_info->immutable=IsMagickTrue(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=IsMagickTrue(resource_value);
3632 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3634 resource_info->use_pixmap=IsMagickTrue(resource_value);
3635 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3637 resource_info->use_shared_memory=IsMagickTrue(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,
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.
3857 MagickPrivate MagickBooleanType XGetWindowColor(Display *display,
3858 XWindows *windows,char *name)
3889 Choose a pixel from the X server.
3891 assert(display != (Display *) NULL);
3892 assert(name != (char *) NULL);
3893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3895 target_window=XSelectWindow(display,&crop_info);
3896 if (target_window == (Window) NULL)
3897 return(MagickFalse);
3898 root_window=XRootWindow(display,XDefaultScreen(display));
3899 client_window=target_window;
3900 if (target_window != root_window)
3908 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3909 if (status != False)
3911 client_window=XClientWindow(display,target_window);
3912 target_window=client_window;
3916 Verify window is viewable.
3918 status=XGetWindowAttributes(display,target_window,&window_attributes);
3919 if ((status == False) || (window_attributes.map_state != IsViewable))
3920 return(MagickFalse);
3924 (void) XTranslateCoordinates(display,root_window,target_window,
3925 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3926 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3927 if (ximage == (XImage *) NULL)
3928 return(MagickFalse);
3929 color.pixel=XGetPixel(ximage,0,0);
3930 XDestroyImage(ximage);
3932 Match color against the color database.
3934 (void) XQueryColor(display,window_attributes.colormap,&color);
3935 pixel.red=ScaleShortToQuantum(color.red);
3936 pixel.green=ScaleShortToQuantum(color.green);
3937 pixel.blue=ScaleShortToQuantum(color.blue);
3938 pixel.alpha=OpaqueAlpha;
3939 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3940 &windows->image.image->exception);
3945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3949 + X G e t W i n d o w I m a g e %
3953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3955 % XGetWindowImage() reads an image from the target X window and returns it.
3956 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3957 % target image with each child image in an optimized fashion. Any child
3958 % window that have the same visual, colormap, and are contained by its parent
3961 % The format of the XGetWindowImage method is:
3963 % Image *XGetWindowImage(Display *display,const Window window,
3964 % const unsigned int borders,const unsigned int level)
3966 % A description of each parameter follows:
3968 % o display: Specifies a connection to an X server; returned from
3971 % o window: Specifies the window to obtain the image from.
3973 % o borders: Specifies whether borders pixels are to be saved with
3976 % o level: Specifies an unsigned integer representing the level of
3977 % decent in the window hierarchy. This value must be zero or one on
3978 % the initial call to XGetWindowImage. A value of zero returns after
3979 % one call. A value of one causes the function to descend the window
3980 % hierarchy and overlay the target image with each subwindow image.
3983 static Image *XGetWindowImage(Display *display,const Window window,
3984 const unsigned int borders,const unsigned int level)
3986 typedef struct _ColormapInfo
3994 struct _ColormapInfo
3998 typedef struct _WindowInfo
4034 *colormap_info = (ColormapInfo *) NULL;
4054 Verify window is viewable.
4056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4057 assert(display != (Display *) NULL);
4058 status=XGetWindowAttributes(display,window,&window_attributes);
4059 if ((status == False) || (window_attributes.map_state != IsViewable))
4060 return((Image *) NULL);
4062 Cropping rectangle is relative to root window.
4064 root_window=XRootWindow(display,XDefaultScreen(display));
4065 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4067 crop_info.x=(ssize_t) x_offset;
4068 crop_info.y=(ssize_t) y_offset;
4069 crop_info.width=(size_t) window_attributes.width;
4070 crop_info.height=(size_t) window_attributes.height;
4071 if (borders != MagickFalse)
4074 Include border in image.
4076 crop_info.x-=(ssize_t) window_attributes.border_width;
4077 crop_info.y-=(ssize_t) window_attributes.border_width;
4078 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4079 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4082 Crop to root window.
4084 if (crop_info.x < 0)
4086 crop_info.width+=crop_info.x;
4089 if (crop_info.y < 0)
4091 crop_info.height+=crop_info.y;
4094 display_width=XDisplayWidth(display,XDefaultScreen(display));
4095 if ((int) (crop_info.x+crop_info.width) > display_width)
4096 crop_info.width=(size_t) (display_width-crop_info.x);
4097 display_height=XDisplayHeight(display,XDefaultScreen(display));
4098 if ((int) (crop_info.y+crop_info.height) > display_height)
4099 crop_info.height=(size_t) (display_height-crop_info.y);
4101 Initialize window info attributes.
4103 if (number_windows >= max_windows)
4106 Allocate or resize window info buffer.
4109 if (window_info == (WindowInfo *) NULL)
4110 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4111 sizeof(*window_info));
4113 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4114 max_windows,sizeof(*window_info));
4116 if (window_info == (WindowInfo *) NULL)
4118 ThrowXWindowFatalException(ResourceLimitError,
4119 "MemoryAllocationFailed","...");
4120 return((Image *) NULL);
4122 id=number_windows++;
4123 window_info[id].window=window;
4124 window_info[id].visual=window_attributes.visual;
4125 window_info[id].colormap=window_attributes.colormap;
4126 window_info[id].bounds.x1=(short) crop_info.x;
4127 window_info[id].bounds.y1=(short) crop_info.y;
4128 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4129 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4130 crop_info.x-=x_offset;
4131 crop_info.y-=y_offset;
4132 window_info[id].crop_info=crop_info;
4142 Descend the window hierarchy.
4144 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4145 &children,&number_children);
4146 for (i=0; i < id; i++)
4147 if ((window_info[i].window == window_info[id].parent) &&
4148 (window_info[i].visual == window_info[id].visual) &&
4149 (window_info[i].colormap == window_info[id].colormap))
4151 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4152 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4153 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4154 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4157 Eliminate windows not circumscribed by their parent.
4163 if ((status == True) && (number_children != 0))
4165 for (i=0; i < (int) number_children; i++)
4166 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4167 (void) XFree((void *) children);
4211 Get X image for each window in the list.
4213 image=NewImageList();
4214 for (id=0; id < number_windows; id++)
4217 Does target window intersect top level window?
4220 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4221 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4222 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4223 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4224 MagickTrue : MagickFalse;
4226 Is target window contained by another window with the same colormap?
4228 for (j=0; j < id; j++)
4229 if ((window_info[id].visual == window_info[j].visual) &&
4230 (window_info[id].colormap == window_info[j].colormap))
4232 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4233 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4234 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4235 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4239 if ((window_info[id].visual != window_info[j].visual) ||
4240 (window_info[id].colormap != window_info[j].colormap))
4242 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4243 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4244 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4245 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4248 if (import == MagickFalse)
4253 ximage=XGetImage(display,window_info[id].window,(int)
4254 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4255 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4256 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4257 if (ximage == (XImage *) NULL)
4260 Initialize window colormap.
4263 colors=(XColor *) NULL;
4264 if (window_info[id].colormap != (Colormap) NULL)
4270 Search colormap list for window colormap.
4272 number_colors=(unsigned int) window_info[id].visual->map_entries;
4273 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4274 if (p->colormap == window_info[id].colormap)
4276 if (p == (ColormapInfo *) NULL)
4279 Get the window colormap.
4281 colors=(XColor *) AcquireQuantumMemory(number_colors,
4283 if (colors == (XColor *) NULL)
4285 XDestroyImage(ximage);
4286 return((Image *) NULL);
4288 if ((window_info[id].visual->klass != DirectColor) &&
4289 (window_info[id].visual->klass != TrueColor))
4290 for (i=0; i < (int) number_colors; i++)
4292 colors[i].pixel=(size_t) i;
4306 DirectColor or TrueColor visual.
4311 red_bit=window_info[id].visual->red_mask &
4312 (~(window_info[id].visual->red_mask)+1);
4313 green_bit=window_info[id].visual->green_mask &
4314 (~(window_info[id].visual->green_mask)+1);
4315 blue_bit=window_info[id].visual->blue_mask &
4316 (~(window_info[id].visual->blue_mask)+1);
4317 for (i=0; i < (int) number_colors; i++)
4319 colors[i].pixel=(unsigned long) (red | green | blue);
4322 if (red > window_info[id].visual->red_mask)
4325 if (green > window_info[id].visual->green_mask)
4328 if (blue > window_info[id].visual->blue_mask)
4332 (void) XQueryColors(display,window_info[id].colormap,colors,
4333 (int) number_colors);
4335 Append colormap to colormap list.
4337 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4338 if (p == (ColormapInfo *) NULL)
4339 return((Image *) NULL);
4340 p->colormap=window_info[id].colormap;
4342 p->next=colormap_info;
4348 Allocate image structure.
4350 composite_image=AcquireImage((ImageInfo *) NULL,&image->exception);
4351 if (composite_image == (Image *) NULL)
4353 XDestroyImage(ximage);
4354 return((Image *) NULL);
4357 Convert X image to MIFF format.
4359 if ((window_info[id].visual->klass != TrueColor) &&
4360 (window_info[id].visual->klass != DirectColor))
4361 composite_image->storage_class=PseudoClass;
4362 composite_image->columns=(size_t) ximage->width;
4363 composite_image->rows=(size_t) ximage->height;
4364 exception=(&composite_image->exception);
4365 composite_view=AcquireCacheView(composite_image);
4366 switch (composite_image->storage_class)
4384 Determine shift and mask for red, green, and blue.
4386 red_mask=window_info[id].visual->red_mask;
4388 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4393 green_mask=window_info[id].visual->green_mask;
4395 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4400 blue_mask=window_info[id].visual->blue_mask;
4402 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4408 Convert X image to DirectClass packets.
4410 if ((number_colors != 0) &&
4411 (window_info[id].visual->klass == DirectColor))
4412 for (y=0; y < (int) composite_image->rows; y++)
4414 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4415 composite_image->columns,1,exception);
4416 if (q == (Quantum *) NULL)
4418 for (x=0; x < (int) composite_image->columns; x++)
4420 pixel=XGetPixel(ximage,x,y);
4421 index=(pixel >> red_shift) & red_mask;
4422 SetPixelRed(composite_image,
4423 ScaleShortToQuantum(colors[index].red),q);
4424 index=(pixel >> green_shift) & green_mask;
4425 SetPixelGreen(composite_image,
4426 ScaleShortToQuantum(colors[index].green),q);
4427 index=(pixel >> blue_shift) & blue_mask;
4428 SetPixelBlue(composite_image,
4429 ScaleShortToQuantum(colors[index].blue),q);
4430 q+=GetPixelChannels(composite_image);
4432 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4436 for (y=0; y < (int) composite_image->rows; y++)
4438 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4439 composite_image->columns,1,exception);
4440 if (q == (Quantum *) NULL)
4442 for (x=0; x < (int) composite_image->columns; x++)
4444 pixel=XGetPixel(ximage,x,y);
4445 color=(pixel >> red_shift) & red_mask;
4446 color=(65535UL*color)/red_mask;
4447 SetPixelRed(composite_image,
4448 ScaleShortToQuantum((unsigned short) color),q);
4449 color=(pixel >> green_shift) & green_mask;
4450 color=(65535UL*color)/green_mask;
4451 SetPixelGreen(composite_image,
4452 ScaleShortToQuantum((unsigned short) color),q);
4453 color=(pixel >> blue_shift) & blue_mask;
4454 color=(65535UL*color)/blue_mask;
4455 SetPixelBlue(composite_image,
4456 ScaleShortToQuantum((unsigned short) color),q);
4457 q+=GetPixelChannels(composite_image);
4459 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4469 if (AcquireImageColormap(composite_image,number_colors,exception) == MagickFalse)
4471 XDestroyImage(ximage);
4472 composite_image=DestroyImage(composite_image);
4473 return((Image *) NULL);
4475 for (i=0; i < (int) composite_image->colors; i++)
4477 composite_image->colormap[colors[i].pixel].red=
4478 ScaleShortToQuantum(colors[i].red);
4479 composite_image->colormap[colors[i].pixel].green=
4480 ScaleShortToQuantum(colors[i].green);
4481 composite_image->colormap[colors[i].pixel].blue=
4482 ScaleShortToQuantum(colors[i].blue);
4485 Convert X image to PseudoClass packets.
4487 for (y=0; y < (int) composite_image->rows; y++)
4489 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4490 composite_image->columns,1,exception);
4491 if (q == (Quantum *) NULL)
4493 for (x=0; x < (int) composite_image->columns; x++)
4495 index=(Quantum) XGetPixel(ximage,x,y);
4496 SetPixelIndex(composite_image,index,q);
4497 SetPixelPixelInfo(composite_image,
4498 composite_image->colormap+(ssize_t) index,q);
4499 q+=GetPixelChannels(composite_image);
4501 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4507 composite_view=DestroyCacheView(composite_view);
4508 XDestroyImage(ximage);
4509 if (image == (Image *) NULL)
4511 image=composite_image;
4515 Composite any children in back-to-front order.
4517 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4518 &x_offset,&y_offset,&child);
4519 x_offset-=(int) crop_info.x;
4522 y_offset-=(int) crop_info.y;
4525 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4526 x_offset,(ssize_t) y_offset,exception);
4529 Relinquish resources.
4531 while (colormap_info != (ColormapInfo *) NULL)
4533 next=colormap_info->next;
4534 colormap_info->colors=(XColor *) RelinquishMagickMemory(
4535 colormap_info->colors);
4536 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4540 Relinquish resources and restore initial state.
4542 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4545 colormap_info=(ColormapInfo *) NULL;
4548 return((Image *) NULL);
4552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4556 % X G e t W i n d o w I n f o %
4560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4562 % XGetWindowInfo() initializes the XWindowInfo structure.
4564 % The format of the XGetWindowInfo method is:
4566 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4567 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4568 % XResourceInfo *resource_info,XWindowInfo *window)
4569 % resource_info,window)
4571 % A description of each parameter follows:
4573 % o display: Specifies a connection to an X server; returned from
4576 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4577 % returned from XGetVisualInfo.
4579 % o map_info: If map_type is specified, this structure is initialized
4580 % with info from the Standard Colormap.
4582 % o pixel: Specifies a pointer to a XPixelInfo structure.
4584 % o font_info: Specifies a pointer to a XFontStruct structure.
4586 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4589 MagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4590 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4591 XResourceInfo *resource_info,XWindowInfo *window)
4594 Initialize window info.
4596 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4597 assert(display != (Display *) NULL);
4598 assert(visual_info != (XVisualInfo *) NULL);
4599 assert(map_info != (XStandardColormap *) NULL);
4600 assert(pixel != (XPixelInfo *) NULL);
4601 assert(resource_info != (XResourceInfo *) NULL);
4602 assert(window != (XWindowInfo *) NULL);
4603 if (window->id != (Window) NULL)
4605 if (window->cursor != (Cursor) NULL)
4606 (void) XFreeCursor(display,window->cursor);
4607 if (window->busy_cursor != (Cursor) NULL)
4608 (void) XFreeCursor(display,window->busy_cursor);
4609 if (window->highlight_stipple != (Pixmap) NULL)
4610 (void) XFreePixmap(display,window->highlight_stipple);
4611 if (window->shadow_stipple != (Pixmap) NULL)
4612 (void) XFreePixmap(display,window->shadow_stipple);
4613 if (window->name == (char *) NULL)
4614 window->name=AcquireString("");
4615 if (window->icon_name == (char *) NULL)
4616 window->icon_name=AcquireString("");
4621 Initialize these attributes just once.
4623 window->id=(Window) NULL;
4624 if (window->name == (char *) NULL)
4625 window->name=AcquireString("");
4626 if (window->icon_name == (char *) NULL)
4627 window->icon_name=AcquireString("");
4628 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4629 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4630 window->ximage=(XImage *) NULL;
4631 window->matte_image=(XImage *) NULL;
4632 window->pixmap=(Pixmap) NULL;
4633 window->matte_pixmap=(Pixmap) NULL;
4634 window->mapped=MagickFalse;
4635 window->stasis=MagickFalse;
4636 window->shared_memory=MagickTrue;
4637 window->segment_info=(void *) NULL;
4638 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4643 if (window->segment_info == (void *) NULL)
4644 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4645 segment_info=(XShmSegmentInfo *) window->segment_info;
4646 segment_info[0].shmid=(-1);
4647 segment_info[0].shmaddr=(char *) NULL;
4648 segment_info[1].shmid=(-1);
4649 segment_info[1].shmaddr=(char *) NULL;
4654 Initialize these attributes every time function is called.
4656 window->screen=visual_info->screen;
4657 window->root=XRootWindow(display,visual_info->screen);
4658 window->visual=visual_info->visual;
4659 window->storage_class=(unsigned int) visual_info->klass;
4660 window->depth=(unsigned int) visual_info->depth;
4661 window->visual_info=visual_info;
4662 window->map_info=map_info;
4663 window->pixel_info=pixel;
4664 window->font_info=font_info;
4665 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4666 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4667 window->geometry=(char *) NULL;
4668 window->icon_geometry=(char *) NULL;
4669 if (resource_info->icon_geometry != (char *) NULL)
4670 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4671 window->crop_geometry=(char *) NULL;
4672 window->flags=(size_t) PSize;
4675 window->min_width=1;
4676 window->min_height=1;
4677 window->width_inc=1;
4678 window->height_inc=1;
4679 window->border_width=resource_info->border_width;
4680 window->annotate_context=pixel->annotate_context;
4681 window->highlight_context=pixel->highlight_context;
4682 window->widget_context=pixel->widget_context;
4683 window->shadow_stipple=(Pixmap) NULL;
4684 window->highlight_stipple=(Pixmap) NULL;
4685 window->use_pixmap=MagickTrue;
4686 window->immutable=MagickFalse;
4687 window->shape=MagickFalse;
4689 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4690 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4691 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4692 window->attributes.background_pixel=pixel->background_color.pixel;
4693 window->attributes.background_pixmap=(Pixmap) NULL;
4694 window->attributes.bit_gravity=ForgetGravity;
4695 window->attributes.backing_store=WhenMapped;
4696 window->attributes.save_under=MagickTrue;
4697 window->attributes.border_pixel=pixel->border_color.pixel;
4698 window->attributes.colormap=map_info->colormap;
4699 window->attributes.cursor=window->cursor;
4700 window->attributes.do_not_propagate_mask=NoEventMask;
4701 window->attributes.event_mask=NoEventMask;
4702 window->attributes.override_redirect=MagickFalse;
4703 window->attributes.win_gravity=NorthWestGravity;
4704 window->orphan=MagickFalse;
4708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4712 % X H i g h l i g h t E l l i p s e %
4716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4718 % XHighlightEllipse() puts a border on the X server around a region defined by
4721 % The format of the XHighlightEllipse method is:
4723 % void XHighlightEllipse(Display *display,Window window,
4724 % GC annotate_context,const RectangleInfo *highlight_info)
4726 % A description of each parameter follows:
4728 % o display: Specifies a connection to an X server; returned from
4731 % o window: Specifies a pointer to a Window structure.
4733 % o annotate_context: Specifies a pointer to a GC structure.
4735 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4736 % contains the extents of any highlighting rectangle.
4739 MagickPrivate void XHighlightEllipse(Display *display,Window window,
4740 GC annotate_context,const RectangleInfo *highlight_info)
4742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4743 assert(display != (Display *) NULL);
4744 assert(window != (Window) NULL);
4745 assert(annotate_context != (GC) NULL);
4746 assert(highlight_info != (RectangleInfo *) NULL);
4747 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4749 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4750 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4751 (unsigned int) highlight_info->height-1,0,360*64);
4752 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4753 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4754 (unsigned int) highlight_info->height-3,0,360*64);
4758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4762 % X H i g h l i g h t L i n e %
4766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4768 % XHighlightLine() puts a border on the X server around a region defined by
4771 % The format of the XHighlightLine method is:
4773 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4774 % const XSegment *highlight_info)
4776 % A description of each parameter follows:
4778 % o display: Specifies a connection to an X server; returned from
4781 % o window: Specifies a pointer to a Window structure.
4783 % o annotate_context: Specifies a pointer to a GC structure.
4785 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4786 % contains the extents of any highlighting rectangle.
4789 MagickPrivate void XHighlightLine(Display *display,Window window,
4790 GC annotate_context,const XSegment *highlight_info)
4792 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4793 assert(display != (Display *) NULL);
4794 assert(window != (Window) NULL);
4795 assert(annotate_context != (GC) NULL);
4796 assert(highlight_info != (XSegment *) NULL);
4797 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4798 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4806 % X H i g h l i g h t R e c t a n g l e %
4810 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4812 % XHighlightRectangle() puts a border on the X server around a region defined
4813 % by highlight_info.
4815 % The format of the XHighlightRectangle method is:
4817 % void XHighlightRectangle(Display *display,Window window,
4818 % GC annotate_context,const RectangleInfo *highlight_info)
4820 % A description of each parameter follows:
4822 % o display: Specifies a connection to an X server; returned from
4825 % o window: Specifies a pointer to a Window structure.
4827 % o annotate_context: Specifies a pointer to a GC structure.
4829 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4830 % contains the extents of any highlighting rectangle.
4833 MagickPrivate void XHighlightRectangle(Display *display,Window window,
4834 GC annotate_context,const RectangleInfo *highlight_info)
4836 assert(display != (Display *) NULL);
4837 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4838 assert(window != (Window) NULL);
4839 assert(annotate_context != (GC) NULL);
4840 assert(highlight_info != (RectangleInfo *) NULL);
4841 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4843 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4844 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4845 (unsigned int) highlight_info->height-1);
4846 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4847 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4848 (unsigned int) highlight_info->height-3);
4852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4856 % X I m p o r t I m a g e %
4860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4862 % XImportImage() reads an image from an X window.
4864 % The format of the XImportImage method is:
4866 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
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.
4875 MagickExport Image *XImportImage(const ImageInfo *image_info,
4876 XImportInfo *ximage_info)
4909 Open X server connection.
4911 assert(image_info != (const ImageInfo *) NULL);
4912 assert(image_info->signature == MagickSignature);
4913 if (image_info->debug != MagickFalse)
4914 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4915 image_info->filename);
4916 assert(ximage_info != (XImportInfo *) NULL);
4917 display=XOpenDisplay(image_info->server_name);
4918 if (display == (Display *) NULL)
4920 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4921 XDisplayName(image_info->server_name));
4922 return((Image *) NULL);
4925 Set our forgiving exception handler.
4927 (void) XSetErrorHandler(XError);
4929 Select target window.
4935 root=XRootWindow(display,XDefaultScreen(display));
4936 target=(Window) NULL;
4937 if ((image_info->filename != (char *) NULL) &&
4938 (*image_info->filename != '\0'))
4940 if (LocaleCompare(image_info->filename,"root") == 0)
4945 Select window by ID or name.
4947 if (isdigit((unsigned char) *image_info->filename) != 0)
4948 target=XWindowByID(display,root,(Window)
4949 strtol(image_info->filename,(char **) NULL,0));
4950 if (target == (Window) NULL)
4951 target=XWindowByName(display,root,image_info->filename);
4952 if (target == (Window) NULL)
4953 ThrowXWindowFatalException(XServerError,
4954 "NoWindowWithSpecifiedIDExists",image_info->filename);
4958 If target window is not defined, interactively select one.
4960 prior_target=target;
4961 if (target == (Window) NULL)
4962 target=XSelectWindow(display,&crop_info);
4963 if (target == (Window) NULL)
4964 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4965 image_info->filename);
4966 client=target; /* obsolete */
4972 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4973 if (status != False)
4981 Find window manager frame.
4983 status=XQueryTree(display,target,&root,&parent,&children,&d);
4984 if ((status != False) && (children != (Window *) NULL))
4985 (void) XFree((char *) children);
4986 if ((status == False) || (parent == (Window) NULL) ||
4994 client=XClientWindow(display,target);
4995 if (ximage_info->frame == MagickFalse)
4997 if ((ximage_info->frame == MagickFalse) &&
4998 (prior_target != MagickFalse))
4999 target=prior_target;
5000 XDelay(display,SuspendTime << 4);
5003 if (ximage_info->screen)
5015 Obtain window image directly from screen.
5017 status=XGetWindowAttributes(display,target,&window_attributes);
5018 if (status == False)
5020 ThrowXWindowFatalException(XServerError,
5021 "UnableToReadXWindowAttributes",image_info->filename);
5022 (void) XCloseDisplay(display);
5023 return((Image *) NULL);
5025 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5026 crop_info.x=(ssize_t) x;
5027 crop_info.y=(ssize_t) y;
5028 crop_info.width=(size_t) window_attributes.width;
5029 crop_info.height=(size_t) window_attributes.height;
5030 if (ximage_info->borders != 0)
5033 Include border in image.
5035 crop_info.x-=window_attributes.border_width;
5036 crop_info.y-=window_attributes.border_width;
5037 crop_info.width+=window_attributes.border_width << 1;
5038 crop_info.height+=window_attributes.border_width << 1;
5043 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
5046 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5047 if ((status == True) && (number_windows > 0))
5049 ximage_info->descend=MagickTrue;
5050 (void) XFree ((char *) children);
5052 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5053 if (number_colormaps > 0)
5055 if (number_colormaps > 1)
5056 ximage_info->descend=MagickTrue;
5057 (void) XFree((char *) colormaps);
5060 Alert the user not to alter the screen.
5062 if (ximage_info->silent == MagickFalse)
5063 (void) XBell(display,0);
5065 Get image by window id.
5067 (void) XGrabServer(display);
5068 image=XGetWindowImage(display,target,ximage_info->borders,
5069 ximage_info->descend ? 1U : 0U);
5070 (void) XUngrabServer(display);
5071 if (image == (Image *) NULL)
5072 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5073 image_info->filename)
5076 (void) CopyMagickString(image->filename,image_info->filename,
5078 if ((crop_info.width != 0) && (crop_info.height != 0))
5085 Crop image as defined by the cropping rectangle.
5087 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5088 if (clone_image != (Image *) NULL)
5090 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5091 if (crop_image != (Image *) NULL)
5093 image=DestroyImage(image);
5098 status=XGetWMName(display,target,&window_name);
5101 if ((image_info->filename != (char *) NULL) &&
5102 (*image_info->filename == '\0'))
5103 (void) CopyMagickString(image->filename,(char *) window_name.value,
5104 (size_t) window_name.nitems+1);
5105 (void) XFree((void *) window_name.value);
5108 if (ximage_info->silent == MagickFalse)
5111 Alert the user we're done.
5113 (void) XBell(display,0);
5114 (void) XBell(display,0);
5116 (void) XCloseDisplay(display);
5121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5125 % X I n i t i a l i z e W i n d o w s %
5129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5131 % XInitializeWindows() initializes the XWindows structure.
5133 % The format of the XInitializeWindows method is:
5135 % XWindows *XInitializeWindows(Display *display,
5136 % XResourceInfo *resource_info)
5138 % A description of each parameter follows:
5140 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5142 % o display: Specifies a connection to an X server; returned from
5145 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5148 MagickPrivate XWindows *XInitializeWindows(Display *display,
5149 XResourceInfo *resource_info)
5158 Allocate windows structure.
5160 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5161 if (windows == (XWindows *) NULL)
5163 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5165 return((XWindows *) NULL);
5167 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5168 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5169 sizeof(*windows->pixel_info));
5170 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5171 sizeof(*windows->icon_pixel));
5172 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5173 sizeof(*windows->icon_resources));
5174 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5175 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5176 (windows->icon_resources == (XResourceInfo *) NULL))
5178 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5180 return((XWindows *) NULL);
5183 Initialize windows structure.
5185 windows->display=display;
5186 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5187 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5188 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5189 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5190 windows->im_remote_command=
5191 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5192 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5193 windows->im_update_colormap=
5194 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5195 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5196 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5197 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5198 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5199 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5200 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5201 (void) XSynchronize(display,IsWindows95());
5203 if (IsEventLogging())
5205 (void) XSynchronize(display,MagickTrue);
5206 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5207 GetMagickVersion((size_t *) NULL));
5208 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5209 (void) LogMagickEvent(X11Event,GetMagickModule(),
5210 " Window Manager: 0x%lx",windows->wm_protocols);
5211 (void) LogMagickEvent(X11Event,GetMagickModule(),
5212 " delete window: 0x%lx",windows->wm_delete_window);
5213 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5214 windows->wm_take_focus);
5215 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5216 windows->im_protocols);
5217 (void) LogMagickEvent(X11Event,GetMagickModule(),
5218 " remote command: 0x%lx",windows->im_remote_command);
5219 (void) LogMagickEvent(X11Event,GetMagickModule(),
5220 " update widget: 0x%lx",windows->im_update_widget);
5221 (void) LogMagickEvent(X11Event,GetMagickModule(),
5222 " update colormap: 0x%lx",windows->im_update_colormap);
5223 (void) LogMagickEvent(X11Event,GetMagickModule(),
5224 " former image: 0x%lx",windows->im_former_image);
5225 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5226 windows->im_next_image);
5227 (void) LogMagickEvent(X11Event,GetMagickModule(),
5228 " retain colors: 0x%lx",windows->im_retain_colors);
5229 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5231 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5232 windows->dnd_protocols);
5235 Allocate standard colormap.
5237 windows->map_info=XAllocStandardColormap();
5238 windows->icon_map=XAllocStandardColormap();
5239 if ((windows->map_info == (XStandardColormap *) NULL) ||
5240 (windows->icon_map == (XStandardColormap *) NULL))
5241 ThrowXWindowFatalException(ResourceLimitFatalError,
5242 "MemoryAllocationFailed","...");
5243 windows->map_info->colormap=(Colormap) NULL;
5244 windows->icon_map->colormap=(Colormap) NULL;
5245 windows->pixel_info->pixels=(unsigned long *) NULL;
5246 windows->pixel_info->annotate_context=(GC) NULL;
5247 windows->pixel_info->highlight_context=(GC) NULL;
5248 windows->pixel_info->widget_context=(GC) NULL;
5249 windows->font_info=(XFontStruct *) NULL;
5250 windows->icon_pixel->annotate_context=(GC) NULL;
5251 windows->icon_pixel->pixels=(unsigned long *) NULL;
5255 *windows->icon_resources=(*resource_info);
5256 windows->icon_resources->visual_type=(char *) "default";
5257 windows->icon_resources->colormap=SharedColormap;
5258 windows->visual_info=
5259 XBestVisualInfo(display,windows->map_info,resource_info);
5260 windows->icon_visual=
5261 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5262 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5263 (windows->icon_visual == (XVisualInfo *) NULL))
5264 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5265 resource_info->visual_type);
5266 if (IsEventLogging())
5268 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5269 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5270 windows->visual_info->visualid);
5271 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5272 XVisualClassName(windows->visual_info->klass));
5273 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5274 windows->visual_info->depth);
5275 (void) LogMagickEvent(X11Event,GetMagickModule(),
5276 " size of colormap: %d entries",windows->visual_info->colormap_size);
5277 (void) LogMagickEvent(X11Event,GetMagickModule(),
5278 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5279 windows->visual_info->red_mask,windows->visual_info->green_mask,
5280 windows->visual_info->blue_mask);
5281 (void) LogMagickEvent(X11Event,GetMagickModule(),
5282 " significant bits in color: %d bits",
5283 windows->visual_info->bits_per_rgb);
5286 Allocate class and manager hints.
5288 windows->class_hints=XAllocClassHint();
5289 windows->manager_hints=XAllocWMHints();
5290 if ((windows->class_hints == (XClassHint *) NULL) ||
5291 (windows->manager_hints == (XWMHints *) NULL))
5292 ThrowXWindowFatalException(ResourceLimitFatalError,
5293 "MemoryAllocationFailed","...");
5295 Determine group leader if we have one.
5297 root_window=XRootWindow(display,windows->visual_info->screen);
5298 windows->group_leader.id=(Window) NULL;
5299 if (resource_info->window_group != (char *) NULL)
5301 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5302 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5303 strtol((char *) resource_info->window_group,(char **) NULL,0));
5304 if (windows->group_leader.id == (Window) NULL)
5305 windows->group_leader.id=
5306 XWindowByName(display,root_window,resource_info->window_group);
5312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5316 % X M a k e C u r s o r %
5320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5322 % XMakeCursor() creates a crosshairs X11 cursor.
5324 % The format of the XMakeCursor method is:
5326 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5327 % char *background_color,char *foreground_color)
5329 % A description of each parameter follows:
5331 % o display: Specifies a connection to an X server; returned from
5334 % o window: Specifies the ID of the window for which the cursor is
5337 % o colormap: Specifies the ID of the colormap from which the background
5338 % and foreground color will be retrieved.
5340 % o background_color: Specifies the color to use for the cursor background.
5342 % o foreground_color: Specifies the color to use for the cursor foreground.
5345 MagickPrivate Cursor XMakeCursor(Display *display,Window window,
5346 Colormap colormap,char *background_color,char *foreground_color)
5348 #define scope_height 17
5349 #define scope_x_hot 8
5350 #define scope_y_hot 8
5351 #define scope_width 17
5353 static const unsigned char
5356 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5357 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5358 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5359 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5360 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5364 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5365 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5366 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5367 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5368 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5382 assert(display != (Display *) NULL);
5383 assert(window != (Window) NULL);
5384 assert(colormap != (Colormap) NULL);
5385 assert(background_color != (char *) NULL);
5386 assert(foreground_color != (char *) NULL);
5387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5388 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5390 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5391 scope_width,scope_height);
5392 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5394 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5395 return((Cursor) NULL);
5397 (void) XParseColor(display,colormap,background_color,&background);
5398 (void) XParseColor(display,colormap,foreground_color,&foreground);
5399 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5400 scope_x_hot,scope_y_hot);
5401 (void) XFreePixmap(display,source);
5402 (void) XFreePixmap(display,mask);
5407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5411 % X M a k e I m a g e %
5415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5417 % XMakeImage() creates an X11 image. If the image size differs from the X11
5418 % image size, the image is first resized.
5420 % The format of the XMakeImage method is:
5422 % MagickBooleanType XMakeImage(Display *display,
5423 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5424 % unsigned int width,unsigned int height,ExceptionInfo *exception)
5426 % A description of each parameter follows:
5428 % o display: Specifies a connection to an X server; returned from
5431 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5433 % o window: Specifies a pointer to a XWindowInfo structure.
5435 % o image: the image.
5437 % o width: Specifies the width in pixels of the rectangular area to
5440 % o height: Specifies the height in pixels of the rectangular area to
5443 % o exception: return any errors or warnings in this structure.
5446 MagickPrivate MagickBooleanType XMakeImage(Display *display,
5447 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5448 unsigned int width,unsigned int height,ExceptionInfo *exception)
5450 #define CheckOverflowException(length,width,height) \
5451 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5464 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5465 assert(display != (Display *) NULL);
5466 assert(resource_info != (XResourceInfo *) NULL);
5467 assert(window != (XWindowInfo *) NULL);
5469 assert(height != 0);
5470 if ((window->width == 0) || (window->height == 0))
5471 return(MagickFalse);
5473 Apply user transforms to the image.
5475 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5476 (void) XFlush(display);
5477 depth=(int) window->depth;
5478 if (window->destroy)
5479 window->image=DestroyImage(window->image);
5480 window->image=image;
5481 window->destroy=MagickFalse;
5482 if (window->image != (Image *) NULL)
5484 if (window->crop_geometry != (char *) NULL)
5495 window->image->page.x=0;
5496 window->image->page.y=0;
5497 (void) ParsePageGeometry(window->image,window->crop_geometry,
5498 &crop_info,&image->exception);
5499 crop_image=CropImage(window->image,&crop_info,&image->exception);
5500 if (crop_image != (Image *) NULL)
5502 if (window->image != image)
5503 window->image=DestroyImage(window->image);
5504 window->image=crop_image;
5505 window->destroy=MagickTrue;
5508 if ((width != (unsigned int) window->image->columns) ||
5509 (height != (unsigned int) window->image->rows))
5517 resize_image=NewImageList();
5518 if (window->pixel_info->colors != 0)
5519 resize_image=SampleImage(window->image,width,height,
5522 resize_image=ThumbnailImage(window->image,width,height,
5524 if (resize_image != (Image *) NULL)
5526 if (window->image != image)
5527 window->image=DestroyImage(window->image);
5528 window->image=resize_image;
5529 window->destroy=MagickTrue;
5532 width=(unsigned int) window->image->columns;
5533 assert((size_t) width == window->image->columns);
5534 height=(unsigned int) window->image->rows;
5535 assert((size_t) height == window->image->rows);
5540 ximage=(XImage *) NULL;
5541 format=(depth == 1) ? XYBitmap : ZPixmap;
5542 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5543 if (window->shared_memory != MagickFalse)
5548 segment_info=(XShmSegmentInfo *) window->segment_info;
5549 segment_info[1].shmid=(-1);
5550 segment_info[1].shmaddr=(char *) NULL;
5551 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5552 (char *) NULL,&segment_info[1],width,height);
5553 if (ximage == (XImage *) NULL)
5554 window->shared_memory=MagickFalse;
5555 length=(size_t) ximage->bytes_per_line*ximage->height;
5556 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5557 window->shared_memory=MagickFalse;
5558 if (window->shared_memory != MagickFalse)
5559 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5560 if (window->shared_memory != MagickFalse)
5561 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5562 if (segment_info[1].shmid < 0)
5563 window->shared_memory=MagickFalse;
5564 if (window->shared_memory != MagickFalse)
5565 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5568 if (ximage != (XImage *) NULL)
5569 XDestroyImage(ximage);
5570 ximage=(XImage *) NULL;
5571 if (segment_info[1].shmaddr)
5573 (void) shmdt(segment_info[1].shmaddr);
5574 segment_info[1].shmaddr=(char *) NULL;
5576 if (segment_info[1].shmid >= 0)
5578 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5579 segment_info[1].shmid=(-1);
5585 Allocate X image pixel data.
5587 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5588 if (window->shared_memory)
5596 (void) XSync(display,MagickFalse);
5597 xerror_alert=MagickFalse;
5598 segment_info=(XShmSegmentInfo *) window->segment_info;
5599 ximage->data=segment_info[1].shmaddr;
5600 segment_info[1].readOnly=MagickFalse;
5601 status=XShmAttach(display,&segment_info[1]);
5602 if (status != False)
5603 (void) XSync(display,MagickFalse);
5604 if ((status == False) || (xerror_alert != MagickFalse))
5606 window->shared_memory=MagickFalse;
5607 if (status != False)
5608 XShmDetach(display,&segment_info[1]);
5609 if (ximage != (XImage *) NULL)
5612 XDestroyImage(ximage);
5613 ximage=(XImage *) NULL;
5615 if (segment_info[1].shmid >= 0)
5617 if (segment_info[1].shmaddr != NULL)
5618 (void) shmdt(segment_info[1].shmaddr);
5619 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5620 segment_info[1].shmid=(-1);
5621 segment_info[1].shmaddr=(char *) NULL;
5626 if (window->shared_memory == MagickFalse)
5627 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5628 (char *) NULL,width,height,XBitmapPad(display),0);
5629 if (ximage == (XImage *) NULL)
5632 Unable to create X image.
5634 (void) XCheckDefineCursor(display,window->id,window->cursor);
5635 return(MagickFalse);
5637 length=(size_t) ximage->bytes_per_line*ximage->height;
5638 if (IsEventLogging())
5640 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5641 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5642 ximage->width,ximage->height);
5643 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5645 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5646 ximage->byte_order);
5647 (void) LogMagickEvent(X11Event,GetMagickModule(),
5648 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5649 ximage->bitmap_bit_order,ximage->bitmap_pad);
5650 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5652 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5653 ximage->bytes_per_line);
5654 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5655 ximage->bits_per_pixel);
5656 (void) LogMagickEvent(X11Event,GetMagickModule(),
5657 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5658 ximage->green_mask,ximage->blue_mask);
5660 if (window->shared_memory == MagickFalse)
5662 if (ximage->format != XYBitmap)
5663 ximage->data=(char *) AcquireQuantumMemory((size_t)
5664 ximage->bytes_per_line,(size_t) ximage->height);
5666 ximage->data=(char *) AcquireQuantumMemory((size_t)
5667 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5669 if (ximage->data == (char *) NULL)
5672 Unable to allocate pixel data.
5674 XDestroyImage(ximage);
5675 ximage=(XImage *) NULL;
5676 (void) XCheckDefineCursor(display,window->id,window->cursor);
5677 return(MagickFalse);
5679 if (window->ximage != (XImage *) NULL)
5682 Destroy previous X image.
5684 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5685 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5686 if (window->segment_info != (XShmSegmentInfo *) NULL)
5691 segment_info=(XShmSegmentInfo *) window->segment_info;
5692 if (segment_info[0].shmid >= 0)
5694 (void) XSync(display,MagickFalse);
5695 (void) XShmDetach(display,&segment_info[0]);
5696 (void) XSync(display,MagickFalse);
5697 if (segment_info[0].shmaddr != (char *) NULL)
5698 (void) shmdt(segment_info[0].shmaddr);
5699 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5700 segment_info[0].shmid=(-1);
5701 segment_info[0].shmaddr=(char *) NULL;
5702 window->ximage->data=(char *) NULL;
5706 if (window->ximage->data != (char *) NULL)
5707 free(window->ximage->data);
5708 window->ximage->data=(char *) NULL;
5709 XDestroyImage(window->ximage);
5710 window->ximage=(XImage *) NULL;
5712 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5713 if (window->segment_info != (XShmSegmentInfo *) NULL)
5718 segment_info=(XShmSegmentInfo *) window->segment_info;
5719 segment_info[0]=segment_info[1];
5722 window->ximage=ximage;
5723 matte_image=(XImage *) NULL;
5724 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5725 if ((window->image->matte != MagickFalse) &&
5726 ((int) width <= XDisplayWidth(display,window->screen)) &&
5727 ((int) height <= XDisplayHeight(display,window->screen)))
5732 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5733 (char *) NULL,width,height,XBitmapPad(display),0);
5734 if (IsEventLogging())
5736 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5737 (void) LogMagickEvent(X11Event,GetMagickModule(),
5738 " width, height: %dx%d",matte_image->width,matte_image->height);
5740 if (matte_image != (XImage *) NULL)
5743 Allocate matte image pixel data.
5745 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5746 matte_image->bytes_per_line*matte_image->depth,
5747 (size_t) matte_image->height);
5748 if (matte_image->data == (char *) NULL)
5750 XDestroyImage(matte_image);
5751 matte_image=(XImage *) NULL;
5755 if (window->matte_image != (XImage *) NULL)
5760 if (window->matte_image->data != (char *) NULL)
5761 free(window->matte_image->data);
5762 window->matte_image->data=(char *) NULL;
5763 XDestroyImage(window->matte_image);
5764 window->matte_image=(XImage *) NULL;
5766 window->matte_image=matte_image;
5767 if (window->matte_pixmap != (Pixmap) NULL)
5769 (void) XFreePixmap(display,window->matte_pixmap);
5770 window->matte_pixmap=(Pixmap) NULL;
5771 #if defined(MAGICKCORE_HAVE_SHAPE)
5772 if (window->shape != MagickFalse)
5773 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5776 window->stasis=MagickFalse;
5778 Convert pixels to X image data.
5780 if (window->image != (Image *) NULL)
5782 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5783 (ximage->bitmap_bit_order == LSBFirst)))
5784 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5785 matte_image,exception);
5787 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5788 matte_image,exception);
5790 if (window->matte_image != (XImage *) NULL)
5793 Create matte pixmap.
5795 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5796 if (window->matte_pixmap != (Pixmap) NULL)
5805 Copy matte image to matte pixmap.
5807 context_values.background=0;
5808 context_values.foreground=1;
5809 graphics_context=XCreateGC(display,window->matte_pixmap,
5810 (size_t) (GCBackground | GCForeground),&context_values);
5811 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5812 window->matte_image,0,0,0,0,width,height);
5813 (void) XFreeGC(display,graphics_context);
5814 #if defined(MAGICKCORE_HAVE_SHAPE)
5815 if (window->shape != MagickFalse)
5816 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5817 window->matte_pixmap,ShapeSet);
5821 (void) XMakePixmap(display,resource_info,window);
5825 (void) XCheckDefineCursor(display,window->id,window->cursor);
5830 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5834 + X M a k e I m a g e L S B F i r s t %
5838 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5840 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5841 % pixels are copied in least-significant bit and byte first order. The
5842 % server's scanline pad is respected. Rather than using one or two general
5843 % cases, many special cases are found here to help speed up the image
5846 % The format of the XMakeImageLSBFirst method is:
5848 % void XMakeImageLSBFirst(Display *display,XWindows *windows,
5849 % ExceptionInfo *exception)
5851 % A description of each parameter follows:
5853 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5855 % o window: Specifies a pointer to a XWindowInfo structure.
5857 % o image: the image.
5859 % o ximage: Specifies a pointer to a XImage structure; returned from
5862 % o matte_image: Specifies a pointer to a XImage structure; returned from
5865 % o exception: return any errors or warnings in this structure.
5868 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5869 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5870 ExceptionInfo *exception)
5881 register const Quantum
5887 register unsigned char
5904 assert(resource_info != (XResourceInfo *) NULL);
5905 assert(window != (XWindowInfo *) NULL);
5906 assert(image != (Image *) NULL);
5907 if (image->debug != MagickFalse)
5908 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5910 if ((window->immutable == MagickFalse) &&
5911 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5914 size[MaxTextExtent];
5922 image_info=AcquireImageInfo();
5923 (void) CopyMagickString(image_info->filename,
5924 resource_info->image_info->texture != (char *) NULL ?
5925 resource_info->image_info->texture : "pattern:checkerboard",
5927 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5928 image->columns,(double) image->rows);
5929 image_info->size=ConstantString(size);
5930 pattern=ReadImage(image_info,&image->exception);
5931 image_info=DestroyImageInfo(image_info);
5932 if (pattern != (Image *) NULL)
5934 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5935 if (canvas != (Image *) NULL)
5936 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0,
5938 pattern=DestroyImage(pattern);
5941 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5942 ximage->bits_per_pixel) >> 3));
5943 map_info=window->map_info;
5944 pixels=window->pixel_info->pixels;
5945 q=(unsigned char *) ximage->data;
5947 canvas_view=AcquireCacheView(canvas);
5948 if (ximage->format == XYBitmap)
5950 register unsigned short
5958 Convert canvas to big-endian bitmap.
5960 background=(unsigned char)
5961 (XPixelIntensity(&window->pixel_info->foreground_color) <
5962 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5963 foreground=(unsigned char)
5964 (XPixelIntensity(&window->pixel_info->background_color) <
5965 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5966 polarity=(unsigned short) ((GetPixelInfoIntensity(
5967 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5968 if (canvas->colors == 2)
5969 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
5970 GetPixelInfoIntensity(&canvas->colormap[1]);
5971 for (y=0; y < (int) canvas->rows; y++)
5973 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5974 &canvas->exception);
5975 if (p == (const Quantum *) NULL)
5979 for (x=0; x < (int) canvas->columns; x++)
5982 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
5993 p+=GetPixelChannels(canvas);
6001 if (window->pixel_info->colors != 0)
6002 switch (ximage->bits_per_pixel)
6006 register unsigned int
6010 Convert to 2 bit color-mapped X canvas.
6012 for (y=0; y < (int) canvas->rows; y++)
6014 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6015 canvas->columns,1,&canvas->exception);
6016 if (p == (const Quantum *) NULL)
6019 for (x=0; x < (int) canvas->columns; x++)
6021 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
6026 *q=(unsigned char) pixel;
6032 *q|=(unsigned char) (pixel << 2);
6038 *q|=(unsigned char) (pixel << 4);
6044 *q|=(unsigned char) (pixel << 6);
6050 p+=GetPixelChannels(canvas);
6058 register unsigned int
6062 Convert to 4 bit color-mapped X canvas.
6064 for (y=0; y < (int) canvas->rows; y++)
6066 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6067 canvas->columns,1,&canvas->exception);
6068 if (p == (const Quantum *) NULL)
6071 for (x=0; x < (int) canvas->columns; x++)
6073 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
6078 *q=(unsigned char) pixel;
6084 *q|=(unsigned char) (pixel << 4);
6090 p+=GetPixelChannels(canvas);
6100 Convert to 8 bit color-mapped X canvas.
6102 if (resource_info->color_recovery &&
6103 resource_info->quantize_info->dither)
6105 XDitherImage(canvas,ximage);
6108 for (y=0; y < (int) canvas->rows; y++)
6110 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6111 canvas->columns,1,&canvas->exception);
6112 if (p == (const Quantum *) NULL)
6114 for (x=0; x < (int) canvas->columns; x++)
6116 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6117 *q++=(unsigned char) pixel;
6118 p+=GetPixelChannels(canvas);
6129 register unsigned int
6133 channel[sizeof(size_t)];
6136 Convert to multi-byte color-mapped X canvas.
6138 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6139 for (y=0; y < (int) canvas->rows; y++)
6141 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6142 canvas->columns,1,&canvas->exception);
6143 if (p == (const Quantum *) NULL)
6145 for (x=0; x < (int) canvas->columns; x++)
6147 pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
6148 for (k=0; k < (int) bytes_per_pixel; k++)
6150 channel[k]=(unsigned char) pixel;
6153 for (k=0; k < (int) bytes_per_pixel; k++)
6155 p+=GetPixelChannels(canvas);
6163 switch (ximage->bits_per_pixel)
6167 register unsigned int
6171 Convert to contiguous 2 bit continuous-tone X canvas.
6173 for (y=0; y < (int) canvas->rows; y++)
6176 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6177 canvas->columns,1,&canvas->exception);
6178 if (p == (const Quantum *) NULL)
6180 for (x=0; x < (int) canvas->columns; x++)
6182 pixel=XGammaPixel(canvas,map_info,p);
6188 *q=(unsigned char) pixel;
6194 *q|=(unsigned char) (pixel << 2);
6200 *q|=(unsigned char) (pixel << 4);
6206 *q|=(unsigned char) (pixel << 6);
6212 p+=GetPixelChannels(canvas);
6220 register unsigned int
6224 Convert to contiguous 4 bit continuous-tone X canvas.
6226 for (y=0; y < (int) canvas->rows; y++)
6228 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6229 canvas->columns,1,&canvas->exception);
6230 if (p == (const Quantum *) NULL)
6233 for (x=0; x < (int) canvas->columns; x++)
6235 pixel=XGammaPixel(canvas,map_info,p);
6241 *q=(unsigned char) pixel;
6247 *q|=(unsigned char) (pixel << 4);
6253 p+=GetPixelChannels(canvas);
6263 Convert to contiguous 8 bit continuous-tone X canvas.
6265 if (resource_info->color_recovery &&
6266 resource_info->quantize_info->dither)
6268 XDitherImage(canvas,ximage);
6271 for (y=0; y < (int) canvas->rows; y++)
6273 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6274 canvas->columns,1,&canvas->exception);
6275 if (p == (const Quantum *) NULL)
6277 for (x=0; x < (int) canvas->columns; x++)
6279 pixel=XGammaPixel(canvas,map_info,p);
6280 *q++=(unsigned char) pixel;
6281 p+=GetPixelChannels(canvas);
6289 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6290 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6291 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6292 (map_info->blue_mult == 1))
6295 Convert to 32 bit continuous-tone X canvas.
6297 for (y=0; y < (int) canvas->rows; y++)
6299 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6300 canvas->columns,1,&canvas->exception);
6301 if (p == (const Quantum *) NULL)
6303 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6304 (blue_gamma != 1.0))
6307 Gamma correct canvas.
6309 for (x=(int) canvas->columns-1; x >= 0; x--)
6311 *q++=ScaleQuantumToChar(XBlueGamma(
6312 GetPixelBlue(canvas,p)));
6313 *q++=ScaleQuantumToChar(XGreenGamma(
6314 GetPixelGreen(canvas,p)));
6315 *q++=ScaleQuantumToChar(XRedGamma(
6316 GetPixelRed(canvas,p)));
6318 p+=GetPixelChannels(canvas);
6322 for (x=(int) canvas->columns-1; x >= 0; x--)
6324 *q++=ScaleQuantumToChar((Quantum)
6325 GetPixelBlue(canvas,p));
6326 *q++=ScaleQuantumToChar((Quantum)
6327 GetPixelGreen(canvas,p));
6328 *q++=ScaleQuantumToChar((Quantum)
6329 GetPixelRed(canvas,p));
6331 p+=GetPixelChannels(canvas);
6336 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6337 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6338 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6339 (map_info->blue_mult == 65536L))
6342 Convert to 32 bit continuous-tone X canvas.
6344 for (y=0; y < (int) canvas->rows; y++)
6346 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6347 canvas->columns,1,&canvas->exception);
6348 if (p == (const Quantum *) NULL)
6350 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6351 (blue_gamma != 1.0))
6354 Gamma correct canvas.
6356 for (x=(int) canvas->columns-1; x >= 0; x--)
6358 *q++=ScaleQuantumToChar(XRedGamma(
6359 GetPixelRed(canvas,p)));
6360 *q++=ScaleQuantumToChar(XGreenGamma(
6361 GetPixelGreen(canvas,p)));
6362 *q++=ScaleQuantumToChar(XBlueGamma(
6363 GetPixelBlue(canvas,p)));
6365 p+=GetPixelChannels(canvas);
6369 for (x=(int) canvas->columns-1; x >= 0; x--)
6371 *q++=ScaleQuantumToChar((Quantum)
6372 GetPixelRed(canvas,p));
6373 *q++=ScaleQuantumToChar((Quantum)
6374 GetPixelGreen(canvas,p));
6375 *q++=ScaleQuantumToChar((Quantum)
6376 GetPixelBlue(canvas,p));
6378 p+=GetPixelChannels(canvas);
6387 register unsigned int
6391 channel[sizeof(size_t)];
6394 Convert to multi-byte continuous-tone X canvas.
6396 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6397 for (y=0; y < (int) canvas->rows; y++)
6399 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6400 canvas->columns,1,&canvas->exception);
6401 if (p == (const Quantum *) NULL)
6403 for (x=0; x < (int) canvas->columns; x++)
6405 pixel=XGammaPixel(canvas,map_info,p);
6406 for (k=0; k < (int) bytes_per_pixel; k++)
6408 channel[k]=(unsigned char) pixel;
6411 for (k=0; k < (int) bytes_per_pixel; k++)
6413 p+=GetPixelChannels(canvas);
6421 if (matte_image != (XImage *) NULL)
6424 Initialize matte canvas.
6426 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6427 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6428 q=(unsigned char *) matte_image->data;
6429 for (y=0; y < (int) canvas->rows; y++)
6431 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6432 &canvas->exception);
6433 if (p == (const Quantum *) NULL)
6437 for (x=(int) canvas->columns-1; x >= 0; x--)
6440 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
6449 p+=GetPixelChannels(canvas);
6456 canvas_view=DestroyCacheView(canvas_view);
6457 if (canvas != image)
6458 canvas=DestroyImage(canvas);
6462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6466 + X M a k e I m a g e M S B F i r s t %
6470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6472 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6473 % image pixels are copied in most-significant bit and byte first order. The
6474 % server's scanline pad is also respected. Rather than using one or two
6475 % general cases, many special cases are found here to help speed up the image
6478 % The format of the XMakeImageMSBFirst method is:
6480 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6481 % ExceptionInfo *exception)
6483 % A description of each parameter follows:
6485 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6487 % o window: Specifies a pointer to a XWindowInfo structure.
6489 % o image: the image.
6491 % o ximage: Specifies a pointer to a XImage structure; returned from
6494 % o matte_image: Specifies a pointer to a XImage structure; returned from
6497 % o exception: return any errors or warnings in this structure.
6500 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6501 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6502 ExceptionInfo *exception)
6516 register const Quantum
6519 register unsigned char
6536 assert(resource_info != (XResourceInfo *) NULL);
6537 assert(window != (XWindowInfo *) NULL);
6538 assert(image != (Image *) NULL);
6539 if (image->debug != MagickFalse)
6540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6542 if ((window->immutable != MagickFalse) &&
6543 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6546 size[MaxTextExtent];
6554 image_info=AcquireImageInfo();
6555 (void) CopyMagickString(image_info->filename,
6556 resource_info->image_info->texture != (char *) NULL ?
6557 resource_info->image_info->texture : "pattern:checkerboard",
6559 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6560 image->columns,(double) image->rows);
6561 image_info->size=ConstantString(size);
6562 pattern=ReadImage(image_info,&image->exception);
6563 image_info=DestroyImageInfo(image_info);
6564 if (pattern != (Image *) NULL)
6566 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6567 if (canvas != (Image *) NULL)
6568 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0,
6570 pattern=DestroyImage(pattern);
6573 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
6574 ximage->bits_per_pixel) >> 3));
6575 map_info=window->map_info;
6576 pixels=window->pixel_info->pixels;
6577 q=(unsigned char *) ximage->data;
6579 canvas_view=AcquireCacheView(canvas);
6580 if (ximage->format == XYBitmap)
6582 register unsigned short
6590 Convert canvas to big-endian bitmap.
6592 background=(unsigned char)
6593 (XPixelIntensity(&window->pixel_info->foreground_color) <
6594 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6595 foreground=(unsigned char)
6596 (XPixelIntensity(&window->pixel_info->background_color) <
6597 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6598 polarity=(unsigned short) ((GetPixelInfoIntensity(
6599 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6600 if (canvas->colors == 2)
6601 polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
6602 GetPixelInfoIntensity(&canvas->colormap[1]);
6603 for (y=0; y < (int) canvas->rows; y++)
6605 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6606 &canvas->exception);
6607 if (p == (const Quantum *) NULL)
6611 for (x=(int) canvas->columns-1; x >= 0; x--)
6614 if (GetPixelIndex(canvas,p) == (Quantum) polarity)
6625 p+=GetPixelChannels(canvas);
6633 if (window->pixel_info->colors != 0)
6634 switch (ximage->bits_per_pixel)
6638 register unsigned int
6642 Convert to 2 bit color-mapped X canvas.
6644 for (y=0; y < (int) canvas->rows; y++)
6646 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6647 canvas->columns,1,&canvas->exception);
6648 if (p == (const Quantum *) NULL)
6651 for (x=0; x < (int) canvas->columns; x++)
6653 pixel=pixels[(ssize_t)
6654 GetPixelIndex(canvas,p)] & 0xf;
6659 *q=(unsigned char) (pixel << 6);
6665 *q|=(unsigned char) (pixel << 4);
6671 *q|=(unsigned char) (pixel << 2);
6677 *q|=(unsigned char) pixel;
6683 p+=GetPixelChannels(canvas);
6691 register unsigned int
6695 Convert to 4 bit color-mapped X canvas.
6697 for (y=0; y < (int) canvas->rows; y++)
6699 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6700 canvas->columns,1,&canvas->exception);
6701 if (p == (const Quantum *) NULL)
6704 for (x=0; x < (int) canvas->columns; x++)
6706 pixel=pixels[(ssize_t)
6707 GetPixelIndex(canvas,p)] & 0xf;
6712 *q=(unsigned char) (pixel << 4);
6718 *q|=(unsigned char) pixel;
6724 p+=GetPixelChannels(canvas);
6734 Convert to 8 bit color-mapped X canvas.
6736 if (resource_info->color_recovery &&
6737 resource_info->quantize_info->dither)
6739 XDitherImage(canvas,ximage);
6742 for (y=0; y < (int) canvas->rows; y++)
6744 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6745 canvas->columns,1,&canvas->exception);
6746 if (p == (const Quantum *) NULL)
6748 for (x=0; x < (int) canvas->columns; x++)
6750 pixel=pixels[(ssize_t)
6751 GetPixelIndex(canvas,p)];
6752 *q++=(unsigned char) pixel;
6753 p+=GetPixelChannels(canvas);
6764 register unsigned int
6768 channel[sizeof(size_t)];
6771 Convert to 8 bit color-mapped X canvas.
6773 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6774 for (y=0; y < (int) canvas->rows; y++)
6776 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6777 canvas->columns,1,&canvas->exception);
6778 if (p == (const Quantum *) NULL)
6780 for (x=0; x < (int) canvas->columns; x++)
6782 pixel=pixels[(ssize_t)
6783 GetPixelIndex(canvas,p)];
6784 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6786 channel[k]=(unsigned char) pixel;
6789 for (k=0; k < (int) bytes_per_pixel; k++)
6791 p+=GetPixelChannels(canvas);
6799 switch (ximage->bits_per_pixel)
6803 register unsigned int
6807 Convert to 4 bit continuous-tone X canvas.
6809 for (y=0; y < (int) canvas->rows; y++)
6811 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6812 canvas->columns,1,&canvas->exception);
6813 if (p == (const Quantum *) NULL)
6816 for (x=(int) canvas->columns-1; x >= 0; x--)
6818 pixel=XGammaPixel(canvas,map_info,p);
6824 *q=(unsigned char) (pixel << 6);
6830 *q|=(unsigned char) (pixel << 4);
6836 *q|=(unsigned char) (pixel << 2);
6842 *q|=(unsigned char) pixel;
6848 p+=GetPixelChannels(canvas);
6856 register unsigned int
6860 Convert to 4 bit continuous-tone X canvas.
6862 for (y=0; y < (int) canvas->rows; y++)
6864 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6865 canvas->columns,1,&canvas->exception);
6866 if (p == (const Quantum *) NULL)
6869 for (x=(int) canvas->columns-1; x >= 0; x--)
6871 pixel=XGammaPixel(canvas,map_info,p);
6877 *q=(unsigned char) (pixel << 4);
6883 *q|=(unsigned char) pixel;
6889 p+=GetPixelChannels(canvas);
6899 Convert to 8 bit continuous-tone X canvas.
6901 if (resource_info->color_recovery &&
6902 resource_info->quantize_info->dither)
6904 XDitherImage(canvas,ximage);
6907 for (y=0; y < (int) canvas->rows; y++)
6909 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6910 canvas->columns,1,&canvas->exception);
6911 if (p == (const Quantum *) NULL)
6913 for (x=(int) canvas->columns-1; x >= 0; x--)
6915 pixel=XGammaPixel(canvas,map_info,p);
6916 *q++=(unsigned char) pixel;
6917 p+=GetPixelChannels(canvas);
6925 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6926 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6927 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6928 (map_info->blue_mult == 1))
6931 Convert to 32 bit continuous-tone X canvas.
6933 for (y=0; y < (int) canvas->rows; y++)
6935 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6936 canvas->columns,1,&canvas->exception);
6937 if (p == (const Quantum *) NULL)
6939 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6940 (blue_gamma != 1.0))
6943 Gamma correct canvas.
6945 for (x=(int) canvas->columns-1; x >= 0; x--)
6948 *q++=ScaleQuantumToChar(XRedGamma(
6949 GetPixelRed(canvas,p)));
6950 *q++=ScaleQuantumToChar(XGreenGamma(
6951 GetPixelGreen(canvas,p)));
6952 *q++=ScaleQuantumToChar(XBlueGamma(
6953 GetPixelBlue(canvas,p)));
6954 p+=GetPixelChannels(canvas);
6958 for (x=(int) canvas->columns-1; x >= 0; x--)
6961 *q++=ScaleQuantumToChar((Quantum)
6962 GetPixelRed(canvas,p));
6963 *q++=ScaleQuantumToChar((Quantum)
6964 GetPixelGreen(canvas,p));
6965 *q++=ScaleQuantumToChar((Quantum)
6966 GetPixelBlue(canvas,p));
6967 p+=GetPixelChannels(canvas);
6972 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6973 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6974 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6975 (map_info->blue_mult == 65536L))
6978 Convert to 32 bit continuous-tone X canvas.
6980 for (y=0; y < (int) canvas->rows; y++)
6982 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6983 canvas->columns,1,&canvas->exception);
6984 if (p == (const Quantum *) NULL)
6986 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6987 (blue_gamma != 1.0))
6990 Gamma correct canvas.
6992 for (x=(int) canvas->columns-1; x >= 0; x--)
6995 *q++=ScaleQuantumToChar(XBlueGamma(
6996 GetPixelBlue(canvas,p)));
6997 *q++=ScaleQuantumToChar(XGreenGamma(
6998 GetPixelGreen(canvas,p)));
6999 *q++=ScaleQuantumToChar(XRedGamma(
7000 GetPixelRed(canvas,p)));
7001 p+=GetPixelChannels(canvas);
7005 for (x=(int) canvas->columns-1; x >= 0; x--)
7008 *q++=ScaleQuantumToChar((Quantum)
7009 GetPixelBlue(canvas,p));
7010 *q++=ScaleQuantumToChar((Quantum)
7011 GetPixelGreen(canvas,p));
7012 *q++=ScaleQuantumToChar((Quantum)
7013 GetPixelRed(canvas,p));
7014 p+=GetPixelChannels(canvas);
7023 register unsigned int
7027 channel[sizeof(size_t)];
7030 Convert to multi-byte continuous-tone X canvas.
7032 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
7033 for (y=0; y < (int) canvas->rows; y++)
7035 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
7036 canvas->columns,1,&canvas->exception);
7037 if (p == (const Quantum *) NULL)
7039 for (x=(int) canvas->columns-1; x >= 0; x--)
7041 pixel=XGammaPixel(canvas,map_info,p);
7042 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
7044 channel[k]=(unsigned char) pixel;
7047 for (k=0; k < (int) bytes_per_pixel; k++)
7049 p+=GetPixelChannels(canvas);
7057 if (matte_image != (XImage *) NULL)
7060 Initialize matte canvas.
7062 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7063 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7064 q=(unsigned char *) matte_image->data;
7065 for (y=0; y < (int) canvas->rows; y++)
7067 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7068 &canvas->exception);
7069 if (p == (const Quantum *) NULL)
7073 for (x=(int) canvas->columns-1; x >= 0; x--)
7076 if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
7085 p+=GetPixelChannels(canvas);
7092 canvas_view=DestroyCacheView(canvas_view);
7093 if (canvas != image)
7094 canvas=DestroyImage(canvas);
7098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7102 % X M a k e M a g n i f y I m a g e %
7106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7108 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7110 % The format of the XMakeMagnifyImage method is:
7112 % void XMakeMagnifyImage(display,windows)
7114 % A description of each parameter follows:
7116 % o display: Specifies a connection to an X server; returned from
7119 % o windows: Specifies a pointer to a XWindows structure.
7122 MagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows)
7125 tuple[MaxTextExtent];
7139 register unsigned char
7147 previous_magnify = 0;
7165 Check boundary conditions.
7167 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7168 assert(display != (Display *) NULL);
7169 assert(windows != (XWindows *) NULL);
7171 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7173 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7175 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7177 while (magnify > windows->magnify.width)
7179 while (magnify > windows->magnify.height)
7181 if (magnify != previous_magnify)
7190 New magnify factor: update magnify window name.
7193 while ((1 << i) <= (int) magnify)
7195 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7196 "Magnify %.20gX",(double) i);
7197 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7198 if (status != False)
7200 XSetWMName(display,windows->magnify.id,&window_name);
7201 XSetWMIconName(display,windows->magnify.id,&window_name);
7202 (void) XFree((void *) window_name.value);
7205 previous_magnify=magnify;
7206 ximage=windows->image.ximage;
7207 width=(unsigned int) windows->magnify.ximage->width;
7208 height=(unsigned int) windows->magnify.ximage->height;
7209 if ((windows->magnify.x < 0) ||
7210 (windows->magnify.x >= windows->image.ximage->width))
7211 windows->magnify.x=windows->image.ximage->width >> 1;
7212 x=windows->magnify.x-((width/magnify) >> 1);
7216 if (x > (int) (ximage->width-(width/magnify)))
7217 x=ximage->width-width/magnify;
7218 if ((windows->magnify.y < 0) ||
7219 (windows->magnify.y >= windows->image.ximage->height))
7220 windows->magnify.y=windows->image.ximage->height >> 1;
7221 y=windows->magnify.y-((height/magnify) >> 1);
7225 if (y > (int) (ximage->height-(height/magnify)))
7226 y=ximage->height-height/magnify;
7227 q=(unsigned char *) windows->magnify.ximage->data;
7228 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7229 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7230 if (ximage->bits_per_pixel < 8)
7232 register unsigned char
7239 register unsigned int
7245 pixel_info=windows->magnify.pixel_info;
7246 switch (ximage->bitmap_bit_order)
7251 Magnify little-endian bitmap.
7255 if (ximage->format == XYBitmap)
7257 background=(unsigned char)
7258 (XPixelIntensity(&pixel_info->foreground_color) <
7259 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7260 foreground=(unsigned char)
7261 (XPixelIntensity(&pixel_info->background_color) <
7262 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7263 if (windows->magnify.depth > 1)
7264 Swap(background,foreground);
7266 for (i=0; i < (ssize_t) height; i+=magnify)
7269 Propogate pixel magnify rows.
7271 for (j=0; j < magnify; j++)
7273 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7274 ((x*ximage->bits_per_pixel) >> 3);
7275 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7278 for (k=0; k < width; k+=magnify)
7281 Propogate pixel magnify columns.
7283 for (l=0; l < magnify; l++)
7286 Propogate each bit plane.
7288 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7291 if (*p & (0x01 << (p_bit+plane)))
7304 p_bit+=ximage->bits_per_pixel;
7311 *q=byte >> (8-q_bit);
7323 Magnify big-endian bitmap.
7327 if (ximage->format == XYBitmap)
7329 background=(unsigned char)
7330 (XPixelIntensity(&pixel_info->foreground_color) <
7331 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7332 foreground=(unsigned char)
7333 (XPixelIntensity(&pixel_info->background_color) <
7334 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7335 if (windows->magnify.depth > 1)
7336 Swap(background,foreground);
7338 for (i=0; i < (ssize_t) height; i+=magnify)
7341 Propogate pixel magnify rows.
7343 for (j=0; j < magnify; j++)
7345 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7346 ((x*ximage->bits_per_pixel) >> 3);
7347 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7350 for (k=0; k < width; k+=magnify)
7353 Propogate pixel magnify columns.
7355 for (l=0; l < magnify; l++)
7358 Propogate each bit plane.
7360 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7363 if (*p & (0x80 >> (p_bit+plane)))
7376 p_bit+=ximage->bits_per_pixel;
7383 *q=byte << (8-q_bit);
7394 switch (ximage->bits_per_pixel)
7400 Magnify 8 bit X image.
7402 for (i=0; i < (ssize_t) height; i+=magnify)
7405 Propogate pixel magnify rows.
7407 for (j=0; j < magnify; j++)
7409 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7410 ((x*ximage->bits_per_pixel) >> 3);
7411 for (k=0; k < width; k+=magnify)
7414 Propogate pixel magnify columns.
7416 for (l=0; l < magnify; l++)
7428 register unsigned int
7433 Magnify multi-byte X image.
7435 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7436 for (i=0; i < (ssize_t) height; i+=magnify)
7439 Propogate pixel magnify rows.
7441 for (j=0; j < magnify; j++)
7443 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7444 ((x*ximage->bits_per_pixel) >> 3);
7445 for (k=0; k < width; k+=magnify)
7448 Propogate pixel magnify columns.
7450 for (l=0; l < magnify; l++)
7451 for (m=0; m < bytes_per_pixel; m++)
7463 Copy X image to magnify pixmap.
7465 x=windows->magnify.x-((width/magnify) >> 1);
7467 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7469 if (x > (int) (ximage->width-(width/magnify)))
7470 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7473 y=windows->magnify.y-((height/magnify) >> 1);
7475 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7477 if (y > (int) (ximage->height-(height/magnify)))
7478 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7481 if ((x != 0) || (y != 0))
7482 (void) XFillRectangle(display,windows->magnify.pixmap,
7483 windows->magnify.annotate_context,0,0,width,height);
7484 (void) XPutImage(display,windows->magnify.pixmap,
7485 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7487 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7488 (magnify <= (height >> 1))))
7494 Highlight center pixel.
7496 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7497 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7498 highlight_info.width=magnify;
7499 highlight_info.height=magnify;
7500 (void) XDrawRectangle(display,windows->magnify.pixmap,
7501 windows->magnify.highlight_context,(int) highlight_info.x,
7502 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7503 (unsigned int) highlight_info.height-1);
7505 (void) XDrawRectangle(display,windows->magnify.pixmap,
7506 windows->magnify.annotate_context,(int) highlight_info.x+1,
7507 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7508 (unsigned int) highlight_info.height-3);
7511 Show center pixel color.
7513 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7514 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7515 &windows->image.image->exception);
7516 (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
7517 windows->magnify.x,windows->magnify.y);
7518 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7519 ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7520 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7521 ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7522 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7523 ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
7524 if (pixel.colorspace == CMYKColorspace)
7526 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7527 ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
7529 if (pixel.matte != MagickFalse)
7531 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7532 ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
7534 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7535 height=(unsigned int) windows->magnify.font_info->ascent+
7536 windows->magnify.font_info->descent;
7537 x=windows->magnify.font_info->max_bounds.width >> 1;
7538 y=windows->magnify.font_info->ascent+(height >> 2);
7539 (void) XDrawImageString(display,windows->magnify.pixmap,
7540 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7541 GetColorTuple(&pixel,MagickTrue,tuple);
7543 (void) XDrawImageString(display,windows->magnify.pixmap,
7544 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7545 (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7546 &windows->image.image->exception);
7548 (void) XDrawImageString(display,windows->magnify.pixmap,
7549 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7551 Refresh magnify window.
7553 magnify_window=windows->magnify;
7556 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7564 % X M a k e P i x m a p %
7568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7570 % XMakePixmap() creates an X11 pixmap.
7572 % The format of the XMakePixmap method is:
7574 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7575 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7576 % XPixelInfo *pixel)
7578 % A description of each parameter follows:
7580 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7582 % o display: Specifies a connection to an X server; returned from
7585 % o window: Specifies a pointer to a XWindowInfo structure.
7588 static MagickBooleanType XMakePixmap(Display *display,
7589 const XResourceInfo *resource_info,XWindowInfo *window)
7595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7596 assert(display != (Display *) NULL);
7597 assert(resource_info != (XResourceInfo *) NULL);
7598 assert(window != (XWindowInfo *) NULL);
7599 if (window->pixmap != (Pixmap) NULL)
7602 Destroy previous X pixmap.
7604 (void) XFreePixmap(display,window->pixmap);
7605 window->pixmap=(Pixmap) NULL;
7607 if (window->use_pixmap == MagickFalse)
7608 return(MagickFalse);
7609 if (window->ximage == (XImage *) NULL)
7610 return(MagickFalse);
7612 Display busy cursor.
7614 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7615 (void) XFlush(display);
7619 width=(unsigned int) window->ximage->width;
7620 height=(unsigned int) window->ximage->height;
7621 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7622 if (window->pixmap == (Pixmap) NULL)
7625 Unable to allocate pixmap.
7627 (void) XCheckDefineCursor(display,window->id,window->cursor);
7628 return(MagickFalse);
7631 Copy X image to pixmap.
7633 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7634 if (window->shared_memory)
7635 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7636 window->ximage,0,0,0,0,width,height,MagickTrue);
7638 if (window->shared_memory == MagickFalse)
7639 (void) XPutImage(display,window->pixmap,window->annotate_context,
7640 window->ximage,0,0,0,0,width,height);
7641 if (IsEventLogging())
7643 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7644 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7650 (void) XCheckDefineCursor(display,window->id,window->cursor);
7655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7659 % X M a k e S t a n d a r d C o l o r m a p %
7663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7665 % XMakeStandardColormap() creates an X11 Standard Colormap.
7667 % The format of the XMakeStandardColormap method is:
7669 % XMakeStandardColormap(display,visual_info,resource_info,image,
7672 % A description of each parameter follows:
7674 % o display: Specifies a connection to an X server; returned from
7677 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7678 % returned from XGetVisualInfo.
7680 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7682 % o image: the image.
7684 % o map_info: If a Standard Colormap type is specified, this structure is
7685 % initialized with info from the Standard Colormap.
7687 % o pixel: Specifies a pointer to a XPixelInfo structure.
7691 #if defined(__cplusplus) || defined(c_plusplus)
7695 static inline MagickRealType DiversityPixelIntensity(
7696 const DiversityPacket *pixel)
7701 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7705 static int IntensityCompare(const void *x,const void *y)
7714 color_1=(DiversityPacket *) x;
7715 color_2=(DiversityPacket *) y;
7716 diversity=(int) (DiversityPixelIntensity(color_2)-
7717 DiversityPixelIntensity(color_1));
7721 static int PopularityCompare(const void *x,const void *y)
7727 color_1=(DiversityPacket *) x;
7728 color_2=(DiversityPacket *) y;
7729 return((int) color_2->count-(int) color_1->count);
7732 #if defined(__cplusplus) || defined(c_plusplus)
7736 static inline Quantum ScaleXToQuantum(const size_t x,
7739 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7742 MagickPrivate void XMakeStandardColormap(Display *display,
7743 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7744 XStandardColormap *map_info,XPixelInfo *pixel)
7770 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7771 assert(display != (Display *) NULL);
7772 assert(visual_info != (XVisualInfo *) NULL);
7773 assert(map_info != (XStandardColormap *) NULL);
7774 assert(resource_info != (XResourceInfo *) NULL);
7775 assert(pixel != (XPixelInfo *) NULL);
7776 exception=(&image->exception);
7777 if (resource_info->map_type != (char *) NULL)
7780 Standard Colormap is already defined (i.e. xstdcmap).
7782 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7784 number_colors=(unsigned int) (map_info->base_pixel+
7785 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7786 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7787 if ((image->matte == MagickFalse) &&
7788 (resource_info->color_recovery == MagickFalse) &&
7789 resource_info->quantize_info->dither &&
7790 (number_colors < MaxColormapSize))
7799 Improve image appearance with error diffusion.
7801 affinity_image=AcquireImage((ImageInfo *) NULL,&image->exception);
7802 if (affinity_image == (Image *) NULL)
7803 ThrowXWindowFatalException(ResourceLimitFatalError,
7804 "UnableToDitherImage",image->filename);
7805 affinity_image->columns=number_colors;
7806 affinity_image->rows=1;
7808 Initialize colormap image.
7810 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7812 if (q != (Quantum *) NULL)
7814 for (i=0; i < (ssize_t) number_colors; i++)
7816 SetPixelRed(affinity_image,0,q);
7817 if (map_info->red_max != 0)
7818 SetPixelRed(affinity_image,
7819 ScaleXToQuantum((size_t) (i/map_info->red_mult),
7820 map_info->red_max),q);
7821 SetPixelGreen(affinity_image,0,q);
7822 if (map_info->green_max != 0)
7823 SetPixelGreen(affinity_image,
7824 ScaleXToQuantum((size_t) ((i/map_info->green_mult) %
7825 (map_info->green_max+1)),map_info->green_max),q);
7826 SetPixelBlue(affinity_image,0,q);
7827 if (map_info->blue_max != 0)
7828 SetPixelBlue(affinity_image,
7829 ScaleXToQuantum((size_t) (i % map_info->green_mult),
7830 map_info->blue_max),q);
7831 SetPixelAlpha(affinity_image,
7832 TransparentAlpha,q);
7833 q+=GetPixelChannels(affinity_image);
7835 (void) SyncAuthenticPixels(affinity_image,exception);
7836 (void) RemapImage(resource_info->quantize_info,image,
7837 affinity_image,exception);
7839 XGetPixelInfo(display,visual_info,map_info,resource_info,image,
7841 (void) SetImageStorageClass(image,DirectClass,exception);
7842 affinity_image=DestroyImage(affinity_image);
7844 if (IsEventLogging())
7846 (void) LogMagickEvent(X11Event,GetMagickModule(),
7847 "Standard Colormap:");
7848 (void) LogMagickEvent(X11Event,GetMagickModule(),
7849 " colormap id: 0x%lx",map_info->colormap);
7850 (void) LogMagickEvent(X11Event,GetMagickModule(),
7851 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7852 map_info->green_max,map_info->blue_max);
7853 (void) LogMagickEvent(X11Event,GetMagickModule(),
7854 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7855 map_info->green_mult,map_info->blue_mult);
7859 if ((visual_info->klass != DirectColor) &&
7860 (visual_info->klass != TrueColor))
7861 if ((image->storage_class == DirectClass) ||
7862 ((int) image->colors > visual_info->colormap_size))
7868 Image has more colors than the visual supports.
7870 quantize_info=(*resource_info->quantize_info);
7871 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7872 (void) QuantizeImage(&quantize_info,image,exception);
7875 Free previous and create new colormap.
7877 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7878 colormap=XDefaultColormap(display,visual_info->screen);
7879 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7880 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7881 visual_info->visual,visual_info->klass == DirectColor ?
7882 AllocAll : AllocNone);
7883 if (colormap == (Colormap) NULL)
7884 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7887 Initialize the map and pixel info structures.
7889 XGetMapInfo(visual_info,colormap,map_info);
7890 XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
7892 Allocating colors in server colormap is based on visual class.
7894 switch (visual_info->klass)
7900 Define Standard Colormap for StaticGray or StaticColor visual.
7902 number_colors=image->colors;
7903 colors=(XColor *) AcquireQuantumMemory((size_t)
7904 visual_info->colormap_size,sizeof(*colors));
7905 if (colors == (XColor *) NULL)
7906 ThrowXWindowFatalException(ResourceLimitFatalError,
7907 "UnableToCreateColormap",image->filename);
7909 color.flags=(char) (DoRed | DoGreen | DoBlue);
7910 for (i=0; i < (ssize_t) image->colors; i++)
7912 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7913 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7914 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7915 if (visual_info->klass != StaticColor)
7917 gray_value=(unsigned short) XPixelIntensity(&color);
7918 color.red=gray_value;
7919 color.green=gray_value;
7920 color.blue=gray_value;
7922 status=XAllocColor(display,colormap,&color);
7923 if (status == False)
7925 colormap=XCopyColormapAndFree(display,colormap);
7926 (void) XAllocColor(display,colormap,&color);
7928 pixel->pixels[i]=color.pixel;
7940 Define Standard Colormap for GrayScale or PseudoColor visual.
7942 number_colors=image->colors;
7943 colors=(XColor *) AcquireQuantumMemory((size_t)
7944 visual_info->colormap_size,sizeof(*colors));
7945 if (colors == (XColor *) NULL)
7946 ThrowXWindowFatalException(ResourceLimitFatalError,
7947 "UnableToCreateColormap",image->filename);
7949 Preallocate our GUI colors.
7951 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7952 (void) XAllocColor(display,colormap,&pixel->background_color);
7953 (void) XAllocColor(display,colormap,&pixel->border_color);
7954 (void) XAllocColor(display,colormap,&pixel->matte_color);
7955 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7956 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7957 (void) XAllocColor(display,colormap,&pixel->depth_color);
7958 (void) XAllocColor(display,colormap,&pixel->trough_color);
7959 for (i=0; i < MaxNumberPens; i++)
7960 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7962 Determine if image colors will "fit" into X server colormap.
7964 colormap_type=resource_info->colormap;
7965 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7966 NULL,0,pixel->pixels,(unsigned int) image->colors);
7967 if (status != False)
7968 colormap_type=PrivateColormap;
7969 if (colormap_type == SharedColormap)
7990 Define Standard colormap for shared GrayScale or PseudoColor visual.
7992 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7993 sizeof(*diversity));
7994 if (diversity == (DiversityPacket *) NULL)
7995 ThrowXWindowFatalException(ResourceLimitFatalError,
7996 "UnableToCreateColormap",image->filename);
7997 for (i=0; i < (ssize_t) image->colors; i++)
7999 diversity[i].red=image->colormap[i].red;
8000 diversity[i].green=image->colormap[i].green;
8001 diversity[i].blue=image->colormap[i].blue;
8002 diversity[i].index=(unsigned short) i;
8003 diversity[i].count=0;
8005 image_view=AcquireCacheView(image);
8006 for (y=0; y < (int) image->rows; y++)
8011 register const Quantum
8014 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
8015 image->columns,1,exception);
8016 if (p == (const Quantum *) NULL)
8018 for (x=(int) image->columns-1; x >= 0; x--)
8020 diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8021 p+=GetPixelChannels(image);
8024 image_view=DestroyCacheView(image_view);
8026 Sort colors by decreasing intensity.
8028 qsort((void *) diversity,image->colors,sizeof(*diversity),
8030 for (i=0; i < (ssize_t) image->colors; )
8032 diversity[i].count<<=4; /* increase this colors popularity */
8033 i+=MagickMax((int) (image->colors >> 4),2);
8035 diversity[image->colors-1].count<<=4;
8036 qsort((void *) diversity,image->colors,sizeof(*diversity),
8042 color.flags=(char) (DoRed | DoGreen | DoBlue);
8043 for (i=0; i < (ssize_t) image->colors; i++)
8045 index=diversity[i].index;
8047 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8049 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8051 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8052 if (visual_info->klass != PseudoColor)
8054 gray_value=(unsigned short) XPixelIntensity(&color);
8055 color.red=gray_value;
8056 color.green=gray_value;
8057 color.blue=gray_value;
8059 status=XAllocColor(display,colormap,&color);
8060 if (status == False)
8062 pixel->pixels[index]=color.pixel;
8066 Read X server colormap.
8068 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8069 visual_info->colormap_size,sizeof(*server_colors));
8070 if (server_colors == (XColor *) NULL)
8071 ThrowXWindowFatalException(ResourceLimitFatalError,
8072 "UnableToCreateColormap",image->filename);
8073 for (x=visual_info->colormap_size-1; x >= 0; x--)
8074 server_colors[x].pixel=(size_t) x;
8075 (void) XQueryColors(display,colormap,server_colors,
8076 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8078 Select remaining colors from X server colormap.
8080 for (; i < (ssize_t) image->colors; i++)
8082 index=diversity[i].index;
8084 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8086 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8088 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8089 if (visual_info->klass != PseudoColor)
8091 gray_value=(unsigned short) XPixelIntensity(&color);
8092 color.red=gray_value;
8093 color.green=gray_value;
8094 color.blue=gray_value;
8096 XBestPixel(display,colormap,server_colors,(unsigned int)
8097 visual_info->colormap_size,&color);
8098 pixel->pixels[index]=color.pixel;
8101 if ((int) image->colors < visual_info->colormap_size)
8104 Fill up colors array-- more choices for pen colors.
8106 retain_colors=MagickMin((unsigned int)
8107 (visual_info->colormap_size-image->colors),256);
8108 for (i=0; i < (ssize_t) retain_colors; i++)
8109 *p++=server_colors[i];
8110 number_colors+=retain_colors;
8112 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8113 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8117 Define Standard colormap for private GrayScale or PseudoColor visual.
8119 if (status == False)
8122 Not enough colormap entries in the colormap-- Create a new colormap.
8124 colormap=XCreateColormap(display,
8125 XRootWindow(display,visual_info->screen),visual_info->visual,
8127 if (colormap == (Colormap) NULL)
8128 ThrowXWindowFatalException(ResourceLimitFatalError,
8129 "UnableToCreateColormap",image->filename);
8130 map_info->colormap=colormap;
8131 if ((int) image->colors < visual_info->colormap_size)
8134 Retain colors from the default colormap to help lessens the
8135 effects of colormap flashing.
8137 retain_colors=MagickMin((unsigned int)
8138 (visual_info->colormap_size-image->colors),256);
8139 p=colors+image->colors;
8140 for (i=0; i < (ssize_t) retain_colors; i++)
8142 p->pixel=(unsigned long) i;
8145 (void) XQueryColors(display,
8146 XDefaultColormap(display,visual_info->screen),
8147 colors+image->colors,(int) retain_colors);
8149 Transfer colors from default to private colormap.
8151 (void) XAllocColorCells(display,colormap,MagickFalse,
8152 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8154 p=colors+image->colors;
8155 for (i=0; i < (ssize_t) retain_colors; i++)
8157 p->pixel=pixel->pixels[i];
8160 (void) XStoreColors(display,colormap,colors+image->colors,
8161 (int) retain_colors);
8162 number_colors+=retain_colors;
8164 (void) XAllocColorCells(display,colormap,MagickFalse,
8165 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8169 Store the image colormap.
8172 color.flags=(char) (DoRed | DoGreen | DoBlue);
8173 for (i=0; i < (ssize_t) image->colors; i++)
8175 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8176 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8177 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8178 if (visual_info->klass != PseudoColor)
8180 gray_value=(unsigned short) XPixelIntensity(&color);
8181 color.red=gray_value;
8182 color.green=gray_value;
8183 color.blue=gray_value;
8185 color.pixel=pixel->pixels[i];
8188 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8199 Define Standard Colormap for TrueColor or DirectColor visual.
8201 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8202 (map_info->green_max*map_info->green_mult)+
8203 (map_info->blue_max*map_info->blue_mult)+1);
8204 linear_colormap=(number_colors > 4096) ||
8205 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8206 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8207 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8208 MagickTrue : MagickFalse;
8209 if (linear_colormap != MagickFalse)
8210 number_colors=(size_t) visual_info->colormap_size;
8212 Allocate color array.
8214 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8215 if (colors == (XColor *) NULL)
8216 ThrowXWindowFatalException(ResourceLimitFatalError,
8217 "UnableToCreateColormap",image->filename);
8219 Initialize linear color ramp.
8222 color.flags=(char) (DoRed | DoGreen | DoBlue);
8223 if (linear_colormap != MagickFalse)
8224 for (i=0; i < (ssize_t) number_colors; i++)
8226 color.blue=(unsigned short) 0;
8227 if (map_info->blue_max != 0)
8228 color.blue=(unsigned short) ((size_t)
8229 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8230 color.green=color.blue;
8231 color.red=color.blue;
8232 color.pixel=XStandardPixel(map_info,&color);
8236 for (i=0; i < (ssize_t) number_colors; i++)
8238 color.red=(unsigned short) 0;
8239 if (map_info->red_max != 0)
8240 color.red=(unsigned short) ((size_t)
8241 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8242 color.green=(unsigned int) 0;
8243 if (map_info->green_max != 0)
8244 color.green=(unsigned short) ((size_t)
8245 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8246 map_info->green_max));
8247 color.blue=(unsigned short) 0;
8248 if (map_info->blue_max != 0)
8249 color.blue=(unsigned short) ((size_t)
8250 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8251 color.pixel=XStandardPixel(map_info,&color);
8254 if ((visual_info->klass == DirectColor) &&
8255 (colormap != XDefaultColormap(display,visual_info->screen)))
8256 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8258 for (i=0; i < (ssize_t) number_colors; i++)
8259 (void) XAllocColor(display,colormap,&colors[i]);
8263 if ((visual_info->klass != DirectColor) &&
8264 (visual_info->klass != TrueColor))
8267 Set foreground, background, border, etc. pixels.
8269 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8270 &pixel->foreground_color);
8271 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8272 &pixel->background_color);
8273 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8276 Foreground and background colors must differ.
8278 pixel->background_color.red=(~pixel->foreground_color.red);
8279 pixel->background_color.green=
8280 (~pixel->foreground_color.green);
8281 pixel->background_color.blue=
8282 (~pixel->foreground_color.blue);
8283 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8284 &pixel->background_color);
8286 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8287 &pixel->border_color);
8288 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8289 &pixel->matte_color);
8290 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8291 &pixel->highlight_color);
8292 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8293 &pixel->shadow_color);
8294 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8295 &pixel->depth_color);
8296 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8297 &pixel->trough_color);
8298 for (i=0; i < MaxNumberPens; i++)
8300 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8301 &pixel->pen_colors[i]);
8302 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8304 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8306 colors=(XColor *) RelinquishMagickMemory(colors);
8307 if (IsEventLogging())
8309 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8310 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8311 map_info->colormap);
8312 (void) LogMagickEvent(X11Event,GetMagickModule(),
8313 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8314 map_info->green_max,map_info->blue_max);
8315 (void) LogMagickEvent(X11Event,GetMagickModule(),
8316 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8317 map_info->green_mult,map_info->blue_mult);
8322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8326 % X M a k e W i n d o w %
8330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8332 % XMakeWindow() creates an X11 window.
8334 % The format of the XMakeWindow method is:
8336 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8337 % XClassHint *class_hint,XWMHints *manager_hints,
8338 % XWindowInfo *window_info)
8340 % A description of each parameter follows:
8342 % o display: Specifies a connection to an X server; returned from
8345 % o parent: Specifies the parent window_info.
8347 % o argv: Specifies the application's argument list.
8349 % o argc: Specifies the number of arguments.
8351 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8353 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8355 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8358 MagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
8359 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8360 XWindowInfo *window_info)
8362 #define MinWindowSize 64
8370 static XTextProperty
8381 Set window info hints.
8383 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8384 assert(display != (Display *) NULL);
8385 assert(window_info != (XWindowInfo *) NULL);
8386 size_hints=XAllocSizeHints();
8387 if (size_hints == (XSizeHints *) NULL)
8388 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8389 size_hints->flags=(int) window_info->flags;
8390 size_hints->x=window_info->x;
8391 size_hints->y=window_info->y;
8392 size_hints->width=(int) window_info->width;
8393 size_hints->height=(int) window_info->height;
8394 if (window_info->immutable != MagickFalse)
8397 Window size cannot be changed.
8399 size_hints->min_width=size_hints->width;
8400 size_hints->min_height=size_hints->height;
8401 size_hints->max_width=size_hints->width;
8402 size_hints->max_height=size_hints->height;
8403 size_hints->flags|=PMinSize;
8404 size_hints->flags|=PMaxSize;
8409 Window size can be changed.
8411 size_hints->min_width=(int) window_info->min_width;
8412 size_hints->min_height=(int) window_info->min_height;
8413 size_hints->flags|=PResizeInc;
8414 size_hints->width_inc=(int) window_info->width_inc;
8415 size_hints->height_inc=(int) window_info->height_inc;
8416 #if !defined(PRE_R4_ICCCM)
8417 size_hints->flags|=PBaseSize;
8418 size_hints->base_width=size_hints->width_inc;
8419 size_hints->base_height=size_hints->height_inc;
8422 gravity=NorthWestGravity;
8423 if (window_info->geometry != (char *) NULL)
8426 default_geometry[MaxTextExtent],
8427 geometry[MaxTextExtent];
8436 User specified geometry.
8438 (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
8439 size_hints->width,size_hints->height);
8440 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8442 while (strlen(p) != 0)
8444 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8447 (void) CopyMagickString(p,p+1,MaxTextExtent);
8449 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8450 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8451 &size_hints->width,&size_hints->height,&gravity);
8452 if ((flags & WidthValue) && (flags & HeightValue))
8453 size_hints->flags|=USSize;
8454 if ((flags & XValue) && (flags & YValue))
8456 size_hints->flags|=USPosition;
8457 window_info->x=size_hints->x;
8458 window_info->y=size_hints->y;
8461 #if !defined(PRE_R4_ICCCM)
8462 size_hints->win_gravity=gravity;
8463 size_hints->flags|=PWinGravity;
8465 if (window_info->id == (Window) NULL)
8466 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8467 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8468 window_info->border_width,(int) window_info->depth,InputOutput,
8469 window_info->visual,(unsigned long) window_info->mask,
8470 &window_info->attributes);
8483 Window already exists; change relevant attributes.
8485 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8486 window_info->mask,&window_info->attributes);
8487 mask=ConfigureNotify;
8488 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8489 window_changes.x=window_info->x;
8490 window_changes.y=window_info->y;
8491 window_changes.width=(int) window_info->width;
8492 window_changes.height=(int) window_info->height;
8493 mask=(MagickStatusType) (CWWidth | CWHeight);
8494 if (window_info->flags & USPosition)
8496 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8497 mask,&window_changes);
8499 if (window_info->id == (Window) NULL)
8500 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8502 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8503 if (status == False)
8504 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8506 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8507 if (status == False)
8508 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8509 window_info->icon_name);
8510 if (window_info->icon_geometry != (char *) NULL)
8518 User specified icon geometry.
8520 size_hints->flags|=USPosition;
8521 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8522 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8523 &manager_hints->icon_y,&width,&height,&gravity);
8524 if ((flags & XValue) && (flags & YValue))
8525 manager_hints->flags|=IconPositionHint;
8527 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8528 size_hints,manager_hints,class_hint);
8529 if (window_name.value != (void *) NULL)
8531 (void) XFree((void *) window_name.value);
8532 window_name.value=(unsigned char *) NULL;
8533 window_name.nitems=0;
8535 if (icon_name.value != (void *) NULL)
8537 (void) XFree((void *) icon_name.value);
8538 icon_name.value=(unsigned char *) NULL;
8541 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8542 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8543 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8544 (void) XFree((void *) size_hints);
8545 if (window_info->shape != MagickFalse)
8547 #if defined(MAGICKCORE_HAVE_SHAPE)
8553 Can we apply a non-rectangular shaping mask?
8557 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8558 window_info->shape=MagickFalse;
8560 window_info->shape=MagickFalse;
8563 if (window_info->shared_memory)
8565 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8567 Can we use shared memory with this window?
8569 if (XShmQueryExtension(display) == 0)
8570 window_info->shared_memory=MagickFalse;
8572 window_info->shared_memory=MagickFalse;
8575 window_info->image=NewImageList();
8576 window_info->destroy=MagickFalse;
8580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8584 % X M a g i c k P r o g r e s s M o n i t o r %
8588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8590 % XMagickProgressMonitor() displays the progress a task is making in
8591 % completing a task.
8593 % The format of the XMagickProgressMonitor method is:
8595 % void XMagickProgressMonitor(const char *task,
8596 % const MagickOffsetType quantum,const MagickSizeType span,
8597 % void *client_data)
8599 % A description of each parameter follows:
8601 % o task: Identifies the task in progress.
8603 % o quantum: Specifies the quantum position within the span which represents
8604 % how much progress has been made in completing a task.
8606 % o span: Specifies the span relative to completing a task.
8608 % o client_data: Pointer to any client data.
8612 static const char *GetLocaleMonitorMessage(const char *text)
8615 message[MaxTextExtent],
8624 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8626 if (p != (char *) NULL)
8628 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
8629 locale_message=GetLocaleMessage(message);
8630 if (locale_message == message)
8632 return(locale_message);
8635 MagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
8636 const MagickOffsetType quantum,const MagickSizeType span,
8637 void *magick_unused(client_data))
8642 windows=XSetWindows((XWindows *) ~0);
8643 if (windows == (XWindows *) NULL)
8645 if (windows->info.mapped != MagickFalse)
8646 XProgressMonitorWidget(windows->display,windows,
8647 GetLocaleMonitorMessage(tag),quantum,span);
8652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8656 % X Q u e r y C o l o r D a t a b a s e %
8660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8662 % XQueryColorCompliance() looks up a RGB values for a color given in the target
8665 % The format of the XQueryColorDatabase method is:
8667 % MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
8669 % A description of each parameter follows:
8671 % o target: Specifies the color to lookup in the X color database.
8673 % o color: A pointer to an PixelInfo structure. The RGB value of the target
8674 % color is returned as this value.
8677 MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
8684 *display = (Display *) NULL;
8693 Initialize color return value.
8695 assert(color != (XColor *) NULL);
8699 color->flags=(char) (DoRed | DoGreen | DoBlue);
8700 if ((target == (char *) NULL) || (*target == '\0'))
8701 target="#ffffffffffff";
8703 Let the X server define the color for us.
8705 if (display == (Display *) NULL)
8706 display=XOpenDisplay((char *) NULL);
8707 if (display == (Display *) NULL)
8709 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8710 return(MagickFalse);
8712 colormap=XDefaultColormap(display,XDefaultScreen(display));
8713 status=XParseColor(display,colormap,(char *) target,&xcolor);
8714 if (status == False)
8715 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8718 color->red=xcolor.red;
8719 color->green=xcolor.green;
8720 color->blue=xcolor.blue;
8721 color->flags=xcolor.flags;
8723 return(status != False ? MagickTrue : MagickFalse);
8727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8731 % X Q u e r y P o s i t i o n %
8735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8737 % XQueryPosition() gets the pointer coordinates relative to a window.
8739 % The format of the XQueryPosition method is:
8741 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8743 % A description of each parameter follows:
8745 % o display: Specifies a connection to an X server; returned from
8748 % o window: Specifies a pointer to a Window.
8750 % o x: Return the x coordinate of the pointer relative to the origin of the
8753 % o y: Return the y coordinate of the pointer relative to the origin of the
8757 MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,int *y)
8769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8770 assert(display != (Display *) NULL);
8771 assert(window != (Window) NULL);
8772 assert(x != (int *) NULL);
8773 assert(y != (int *) NULL);
8774 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8783 % X R e f r e s h W i n d o w %
8787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8789 % XRefreshWindow() refreshes an image in a X window.
8791 % The format of the XRefreshWindow method is:
8793 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8794 % const XEvent *event)
8796 % A description of each parameter follows:
8798 % o display: Specifies a connection to an X server; returned from
8801 % o window: Specifies a pointer to a XWindowInfo structure.
8803 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8804 % the entire image is refreshed.
8807 MagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
8808 const XEvent *event)
8818 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8819 assert(display != (Display *) NULL);
8820 assert(window != (XWindowInfo *) NULL);
8821 if (window->ximage == (XImage *) NULL)
8823 if (event != (XEvent *) NULL)
8826 Determine geometry from expose event.
8830 width=(unsigned int) event->xexpose.width;
8831 height=(unsigned int) event->xexpose.height;
8839 Refresh entire window; discard outstanding expose events.
8843 width=window->width;
8844 height=window->height;
8845 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8846 if (window->matte_pixmap != (Pixmap) NULL)
8848 #if defined(MAGICKCORE_HAVE_SHAPE)
8849 if (window->shape != MagickFalse)
8850 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8851 window->matte_pixmap,ShapeSet);
8856 Check boundary conditions.
8858 if ((window->ximage->width-(x+window->x)) < (int) width)
8859 width=(unsigned int) (window->ximage->width-(x+window->x));
8860 if ((window->ximage->height-(y+window->y)) < (int) height)
8861 height=(unsigned int) (window->ximage->height-(y+window->y));
8865 if (window->matte_pixmap != (Pixmap) NULL)
8866 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8867 if (window->pixmap != (Pixmap) NULL)
8869 if (window->depth > 1)
8870 (void) XCopyArea(display,window->pixmap,window->id,
8871 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8873 (void) XCopyPlane(display,window->pixmap,window->id,
8874 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8879 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8880 if (window->shared_memory)
8881 (void) XShmPutImage(display,window->id,window->annotate_context,
8882 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8884 if (window->shared_memory == MagickFalse)
8885 (void) XPutImage(display,window->id,window->annotate_context,
8886 window->ximage,x+window->x,y+window->y,x,y,width,height);
8888 if (window->matte_pixmap != (Pixmap) NULL)
8889 (void) XSetClipMask(display,window->annotate_context,None);
8890 (void) XFlush(display);
8894 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8898 % X R e m o t e C o m m a n d %
8902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8904 % XRemoteCommand() forces a remote display(1) to display the specified
8907 % The format of the XRemoteCommand method is:
8909 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8910 % const char *filename)
8912 % A description of each parameter follows:
8914 % o display: Specifies a connection to an X server; returned from
8917 % o window: Specifies the name or id of an X window.
8919 % o filename: the name of the image filename to display.
8922 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8923 const char *window,const char *filename)
8932 assert(filename != (char *) NULL);
8933 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8934 if (display == (Display *) NULL)
8935 display=XOpenDisplay((char *) NULL);
8936 if (display == (Display *) NULL)
8938 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8939 return(MagickFalse);
8941 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8942 remote_window=(Window) NULL;
8943 root_window=XRootWindow(display,XDefaultScreen(display));
8944 if (window != (char *) NULL)
8947 Search window hierarchy and identify any clients by name or ID.
8949 if (isdigit((unsigned char) *window) != 0)
8950 remote_window=XWindowByID(display,root_window,(Window)
8951 strtol((char *) window,(char **) NULL,0));
8952 if (remote_window == (Window) NULL)
8953 remote_window=XWindowByName(display,root_window,window);
8955 if (remote_window == (Window) NULL)
8956 remote_window=XWindowByProperty(display,root_window,remote_atom);
8957 if (remote_window == (Window) NULL)
8959 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8961 return(MagickFalse);
8964 Send remote command.
8966 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8967 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8968 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8969 (void) XSync(display,MagickFalse);
8974 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8978 % X R e t a i n W i n d o w C o l o r s %
8982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8984 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8985 % the colors associated with an image displayed on the window.
8987 % The format of the XRetainWindowColors method is:
8989 % void XRetainWindowColors(Display *display,const Window window)
8991 % A description of each parameter follows:
8993 % o display: Specifies a connection to an X server; returned from
8996 % o window: Specifies a pointer to a XWindowInfo structure.
8999 MagickExport void XRetainWindowColors(Display *display,const Window window)
9008 Put property on the window.
9010 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9011 assert(display != (Display *) NULL);
9012 assert(window != (Window) NULL);
9013 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
9014 if (property == (Atom) NULL)
9016 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
9020 pixmap=XCreatePixmap(display,window,1,1,1);
9021 if (pixmap == (Pixmap) NULL)
9023 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
9026 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
9027 (unsigned char *) &pixmap,1);
9028 (void) XSetCloseDownMode(display,RetainPermanent);
9032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9036 % X S e l e c t W i n d o w %
9040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9042 % XSelectWindow() allows a user to select a window using the mouse. If the
9043 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
9044 % is returned in the crop_info structure.
9046 % The format of the XSelectWindow function is:
9048 % target_window=XSelectWindow(display,crop_info)
9050 % A description of each parameter follows:
9052 % o window: XSelectWindow returns the window id.
9054 % o display: Specifies a pointer to the Display structure; returned from
9057 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9058 % contains the extents of any cropping rectangle.
9061 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9063 #define MinimumCropArea (unsigned int) 9
9090 Initialize graphic context.
9092 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9093 assert(display != (Display *) NULL);
9094 assert(crop_info != (RectangleInfo *) NULL);
9095 root_window=XRootWindow(display,XDefaultScreen(display));
9096 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9097 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9098 context_values.function=GXinvert;
9099 context_values.plane_mask=
9100 context_values.background ^ context_values.foreground;
9101 context_values.subwindow_mode=IncludeInferiors;
9102 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9103 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9104 if (annotate_context == (GC) NULL)
9105 return(MagickFalse);
9107 Grab the pointer using target cursor.
9109 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9110 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9111 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9112 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9113 GrabModeAsync,root_window,target_cursor,CurrentTime);
9114 if (status != GrabSuccess)
9116 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9117 return((Window) NULL);
9123 crop_info->height=0;
9125 target_window=(Window) NULL;
9130 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9131 (void) XDrawRectangle(display,root_window,annotate_context,
9132 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9133 (unsigned int) crop_info->height-1);
9135 Allow another event.
9137 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9138 (void) XWindowEvent(display,root_window,ButtonPressMask |
9139 ButtonReleaseMask | ButtonMotionMask,&event);
9140 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9141 (void) XDrawRectangle(display,root_window,annotate_context,
9142 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9143 (unsigned int) crop_info->height-1);
9148 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9149 event.xbutton.x,event.xbutton.y);
9150 if (target_window == (Window) NULL)
9151 target_window=root_window;
9152 x_offset=event.xbutton.x_root;
9153 y_offset=event.xbutton.y_root;
9154 crop_info->x=(ssize_t) x_offset;
9155 crop_info->y=(ssize_t) y_offset;
9157 crop_info->height=0;
9169 Discard pending button motion events.
9171 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9172 crop_info->x=(ssize_t) event.xmotion.x;
9173 crop_info->y=(ssize_t) event.xmotion.y;
9175 Check boundary conditions.
9177 if ((int) crop_info->x < x_offset)
9178 crop_info->width=(size_t) (x_offset-crop_info->x);
9181 crop_info->width=(size_t) (crop_info->x-x_offset);
9182 crop_info->x=(ssize_t) x_offset;
9184 if ((int) crop_info->y < y_offset)
9185 crop_info->height=(size_t) (y_offset-crop_info->y);
9188 crop_info->height=(size_t) (crop_info->y-y_offset);
9189 crop_info->y=(ssize_t) y_offset;
9195 } while ((target_window == (Window) NULL) || (presses > 0));
9196 (void) XUngrabPointer(display,CurrentTime);
9197 (void) XFreeCursor(display,target_cursor);
9198 (void) XFreeGC(display,annotate_context);
9199 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9202 crop_info->height=0;
9204 if ((crop_info->width != 0) && (crop_info->height != 0))
9205 target_window=root_window;
9206 return(target_window);
9210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9214 % X S e t C u r s o r S t a t e %
9218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9220 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9221 % reset to their default.
9223 % The format of the XXSetCursorState method is:
9225 % XSetCursorState(display,windows,const MagickStatusType state)
9227 % A description of each parameter follows:
9229 % o display: Specifies a connection to an X server; returned from
9232 % o windows: Specifies a pointer to a XWindows structure.
9234 % o state: An unsigned integer greater than 0 sets the cursor state
9235 % to busy, otherwise the cursor are reset to their default.
9238 MagickPrivate void XSetCursorState(Display *display,XWindows *windows,
9239 const MagickStatusType state)
9241 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9242 assert(display != (Display *) NULL);
9243 assert(windows != (XWindows *) NULL);
9246 (void) XCheckDefineCursor(display,windows->image.id,
9247 windows->image.busy_cursor);
9248 (void) XCheckDefineCursor(display,windows->pan.id,
9249 windows->pan.busy_cursor);
9250 (void) XCheckDefineCursor(display,windows->magnify.id,
9251 windows->magnify.busy_cursor);
9252 (void) XCheckDefineCursor(display,windows->command.id,
9253 windows->command.busy_cursor);
9257 (void) XCheckDefineCursor(display,windows->image.id,
9258 windows->image.cursor);
9259 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9260 (void) XCheckDefineCursor(display,windows->magnify.id,
9261 windows->magnify.cursor);
9262 (void) XCheckDefineCursor(display,windows->command.id,
9263 windows->command.cursor);
9264 (void) XCheckDefineCursor(display,windows->command.id,
9265 windows->widget.cursor);
9266 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9268 windows->info.mapped=MagickFalse;
9272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9276 % X S e t W i n d o w s %
9280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9282 % XSetWindows() sets the X windows structure if the windows info is specified.
9283 % Otherwise the current windows structure is returned.
9285 % The format of the XSetWindows method is:
9287 % XWindows *XSetWindows(XWindows *windows_info)
9289 % A description of each parameter follows:
9291 % o windows_info: Initialize the Windows structure with this information.
9294 MagickPrivate XWindows *XSetWindows(XWindows *windows_info)
9297 *windows = (XWindows *) NULL;
9299 if (windows_info != (XWindows *) ~0)
9301 windows=(XWindows *) RelinquishMagickMemory(windows);
9302 windows=windows_info;
9307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9311 % X U s e r P r e f e r e n c e s %
9315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9317 % XUserPreferences() saves the preferences in a configuration file in the
9318 % users' home directory.
9320 % The format of the XUserPreferences method is:
9322 % void XUserPreferences(XResourceInfo *resource_info)
9324 % A description of each parameter follows:
9326 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9329 MagickPrivate void XUserPreferences(XResourceInfo *resource_info)
9331 #if defined(X11_PREFERENCES_PATH)
9333 cache[MaxTextExtent],
9334 filename[MaxTextExtent],
9335 specifier[MaxTextExtent];
9342 preferences_database;
9345 Save user preferences to the client configuration file.
9347 assert(resource_info != (XResourceInfo *) NULL);
9348 client_name=GetClientName();
9349 preferences_database=XrmGetStringDatabase("");
9350 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9351 value=resource_info->backdrop ? "True" : "False";
9352 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9353 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
9354 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9355 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9356 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9358 value=resource_info->confirm_exit ? "True" : "False";
9359 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9360 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9362 value=resource_info->confirm_edit ? "True" : "False";
9363 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9364 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9366 value=resource_info->display_warnings ? "True" : "False";
9367 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9368 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
9369 value=resource_info->quantize_info->dither ? "True" : "False";
9370 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9371 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9373 value=resource_info->gamma_correct ? "True" : "False";
9374 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9375 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9376 (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
9377 resource_info->undo_cache);
9378 XrmPutStringResource(&preferences_database,specifier,cache);
9379 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9380 value=resource_info->use_pixmap ? "True" : "False";
9381 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9382 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9383 X11_PREFERENCES_PATH,client_name);
9384 ExpandFilename(filename);
9385 XrmPutFileDatabase(preferences_database,filename);
9390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9394 % X V i s u a l C l a s s N a m e %
9398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9400 % XVisualClassName() returns the visual class name as a character string.
9402 % The format of the XVisualClassName method is:
9404 % char *XVisualClassName(const int visual_class)
9406 % A description of each parameter follows:
9408 % o visual_type: XVisualClassName returns the visual class as a character
9411 % o class: Specifies the visual class.
9414 static const char *XVisualClassName(const int visual_class)
9416 switch (visual_class)
9418 case StaticGray: return("StaticGray");
9419 case GrayScale: return("GrayScale");
9420 case StaticColor: return("StaticColor");
9421 case PseudoColor: return("PseudoColor");
9422 case TrueColor: return("TrueColor");
9423 case DirectColor: return("DirectColor");
9425 return("unknown visual class");
9429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9439 % XWarning() displays a warning reason in a Notice widget.
9441 % The format of the XWarning method is:
9443 % void XWarning(const unsigned int warning,const char *reason,
9444 % const char *description)
9446 % A description of each parameter follows:
9448 % o warning: Specifies the numeric warning category.
9450 % o reason: Specifies the reason to display before terminating the
9453 % o description: Specifies any description to the reason.
9456 MagickPrivate void XWarning(const ExceptionType magick_unused(warning),
9457 const char *reason,const char *description)
9460 text[MaxTextExtent];
9465 if (reason == (char *) NULL)
9467 (void) CopyMagickString(text,reason,MaxTextExtent);
9468 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9469 windows=XSetWindows((XWindows *) ~0);
9470 XNoticeWidget(windows->display,windows,text,(char *) description);
9474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9478 % X W i n d o w B y I D %
9482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9484 % XWindowByID() locates a child window with a given ID. If not window with
9485 % the given name is found, 0 is returned. Only the window specified and its
9486 % subwindows are searched.
9488 % The format of the XWindowByID function is:
9490 % child=XWindowByID(display,window,id)
9492 % A description of each parameter follows:
9494 % o child: XWindowByID returns the window with the specified
9495 % id. If no windows are found, XWindowByID returns 0.
9497 % o display: Specifies a pointer to the Display structure; returned from
9500 % o id: Specifies the id of the window to locate.
9503 MagickPrivate Window XWindowByID(Display *display,const Window root_window,
9523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9524 assert(display != (Display *) NULL);
9525 assert(root_window != (Window) NULL);
9527 return(XSelectWindow(display,&rectangle_info));
9528 if (root_window == id)
9529 return(root_window);
9530 status=XQueryTree(display,root_window,&child,&child,&children,
9532 if (status == False)
9533 return((Window) NULL);
9534 window=(Window) NULL;
9535 for (i=0; i < (int) number_children; i++)
9538 Search each child and their children.
9540 window=XWindowByID(display,children[i],id);
9541 if (window != (Window) NULL)
9544 if (children != (Window *) NULL)
9545 (void) XFree((void *) children);
9550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9554 % X W i n d o w B y N a m e %
9558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9560 % XWindowByName() locates a window with a given name on a display. If no
9561 % window with the given name is found, 0 is returned. If more than one window
9562 % has the given name, the first one is returned. Only root and its children
9565 % The format of the XWindowByName function is:
9567 % window=XWindowByName(display,root_window,name)
9569 % A description of each parameter follows:
9571 % o window: XWindowByName returns the window id.
9573 % o display: Specifies a pointer to the Display structure; returned from
9576 % o root_window: Specifies the id of the root window.
9578 % o name: Specifies the name of the window to locate.
9581 MagickPrivate Window XWindowByName(Display *display,const Window root_window,
9601 assert(display != (Display *) NULL);
9602 assert(root_window != (Window) NULL);
9603 assert(name != (char *) NULL);
9604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9605 if (XGetWMName(display,root_window,&window_name) != 0)
9606 if (LocaleCompare((char *) window_name.value,name) == 0)
9607 return(root_window);
9608 status=XQueryTree(display,root_window,&child,&child,&children,
9610 if (status == False)
9611 return((Window) NULL);
9612 window=(Window) NULL;
9613 for (i=0; i < (int) number_children; i++)
9616 Search each child and their children.
9618 window=XWindowByName(display,children[i],name);
9619 if (window != (Window) NULL)
9622 if (children != (Window *) NULL)
9623 (void) XFree((void *) children);
9628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9632 % X W i n d o w B y P r o p e r y %
9636 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9638 % XWindowByProperty() locates a child window with a given property. If not
9639 % window with the given name is found, 0 is returned. If more than one window
9640 % has the given property, the first one is returned. Only the window
9641 % specified and its subwindows are searched.
9643 % The format of the XWindowByProperty function is:
9645 % child=XWindowByProperty(display,window,property)
9647 % A description of each parameter follows:
9649 % o child: XWindowByProperty returns the window id with the specified
9650 % property. If no windows are found, XWindowByProperty returns 0.
9652 % o display: Specifies a pointer to the Display structure; returned from
9655 % o property: Specifies the property of the window to locate.
9658 MagickPrivate Window XWindowByProperty(Display *display,const Window window,
9659 const Atom property)
9687 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9688 assert(display != (Display *) NULL);
9689 assert(window != (Window) NULL);
9690 assert(property != (Atom) NULL);
9691 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9692 if (status == False)
9693 return((Window) NULL);
9695 child=(Window) NULL;
9696 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9698 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9699 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9701 (void) XFree((void *) data);
9702 if ((status == Success) && (type != (Atom) NULL))
9705 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9706 child=XWindowByProperty(display,children[i],property);
9707 if (children != (Window *) NULL)
9708 (void) XFree((void *) children);
9714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9718 % X I m p o r t I m a g e %
9722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9724 % XImportImage() reads an image from an X window.
9726 % The format of the XImportImage method is:
9728 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9730 % A description of each parameter follows:
9732 % o image_info: the image info..
9734 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9737 MagickPrivate Image *XImportImage(const ImageInfo *image_info,
9738 XImportInfo *ximage_info)
9740 assert(image_info != (const ImageInfo *) NULL);
9741 assert(image_info->signature == MagickSignature);
9742 if (image_info->debug != MagickFalse)
9743 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9744 image_info->filename);
9745 assert(ximage_info != (XImportInfo *) NULL);
9746 return((Image *) NULL);
9751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9755 + X C o m p o n e n t G e n e s i s %
9759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9761 % XComponentGenesis() instantiates the X component.
9763 % The format of the XComponentGenesis method is:
9765 % MagickBooleanType XComponentGenesis(void)
9768 MagickPrivate MagickBooleanType XComponentGenesis(void)
9774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9778 % X G e t I m p o r t I n f o %
9782 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9784 % XGetImportInfo() initializes the XImportInfo structure.
9786 % The format of the XGetImportInfo method is:
9788 % void XGetImportInfo(XImportInfo *ximage_info)
9790 % A description of each parameter follows:
9792 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9795 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9797 assert(ximage_info != (XImportInfo *) NULL);
9798 ximage_info->frame=MagickFalse;
9799 ximage_info->borders=MagickFalse;
9800 ximage_info->screen=MagickFalse;
9801 ximage_info->descend=MagickTrue;
9802 ximage_info->silent=MagickFalse;