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-2010 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 "magick/studio.h"
43 #include "magick/animate.h"
44 #include "magick/artifact.h"
45 #include "magick/blob.h"
46 #include "magick/cache.h"
47 #include "magick/client.h"
48 #include "magick/color.h"
49 #include "magick/color-private.h"
50 #include "magick/composite.h"
51 #include "magick/display.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/geometry.h"
55 #include "magick/identify.h"
56 #include "magick/image.h"
57 #include "magick/image-private.h"
58 #include "magick/list.h"
59 #include "magick/locale_.h"
60 #include "magick/log.h"
61 #include "magick/magick.h"
62 #include "magick/memory_.h"
63 #include "magick/monitor.h"
64 #include "magick/option.h"
65 #include "magick/PreRvIcccm.h"
66 #include "magick/quantize.h"
67 #include "magick/quantum.h"
68 #include "magick/quantum-private.h"
69 #include "magick/resource_.h"
70 #include "magick/resize.h"
71 #include "magick/shear.h"
72 #include "magick/statistic.h"
73 #include "magick/string_.h"
74 #include "magick/string-private.h"
75 #include "magick/transform.h"
76 #include "magick/utility.h"
77 #include "magick/widget.h"
78 #include "magick/xwindow.h"
79 #include "magick/xwindow-private.h"
80 #include "magick/version.h"
84 #if defined(MAGICKCORE_X11_DELEGATE)
85 #include <X11/Xproto.h>
86 #include <X11/Xlocale.h>
87 #if defined(MAGICK_HAVE_POLL)
88 # include <sys/poll.h>
90 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
91 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
92 # include <machine/param.h>
96 #include <X11/extensions/XShm.h>
98 #if defined(MAGICKCORE_HAVE_SHAPE)
99 #include <X11/extensions/shape.h>
105 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
106 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
108 #define XGammaPixel(map,color) (unsigned long) (map->base_pixel+ \
109 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
111 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
113 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
115 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
116 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
118 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
119 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
121 #define XStandardPixel(map,color) (unsigned long) (map->base_pixel+ \
122 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
123 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
124 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
126 #define AccentuateModulate ScaleCharToQuantum(80)
127 #define HighlightModulate ScaleCharToQuantum(125)
128 #define ShadowModulate ScaleCharToQuantum(135)
129 #define DepthModulate ScaleCharToQuantum(185)
130 #define TroughModulate ScaleCharToQuantum(110)
132 #define XLIB_ILLEGAL_ACCESS 1
134 #undef NorthWestGravity
136 #undef NorthEastGravity
140 #undef SouthWestGravity
142 #undef SouthEastGravity
149 #define XFD_SET fd_set
153 Enumeration declarations.
167 Typedef declarations.
169 typedef struct _DiversityPacket
184 Constant declaractions.
186 static MagickBooleanType
187 xerror_alert = MagickFalse;
193 *XVisualClassName(const int);
195 static MagickRealType
200 static MagickBooleanType
201 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
204 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
206 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
210 XSelectWindow(Display *,RectangleInfo *);
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 % D e s t r o y X R e s o u r c e s %
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 % DestroyXResources() destroys any X resources.
225 % The format of the DestroyXResources method is:
227 % void DestroyXResources()
229 % A description of each parameter follows:
232 MagickExport void DestroyXResources(void)
241 *magick_windows[MaxXWindows];
247 windows=XSetWindows((XWindows *) ~0);
248 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
251 magick_windows[number_windows++]=(&windows->context);
252 magick_windows[number_windows++]=(&windows->group_leader);
253 magick_windows[number_windows++]=(&windows->backdrop);
254 magick_windows[number_windows++]=(&windows->icon);
255 magick_windows[number_windows++]=(&windows->image);
256 magick_windows[number_windows++]=(&windows->info);
257 magick_windows[number_windows++]=(&windows->magnify);
258 magick_windows[number_windows++]=(&windows->pan);
259 magick_windows[number_windows++]=(&windows->command);
260 magick_windows[number_windows++]=(&windows->widget);
261 magick_windows[number_windows++]=(&windows->popup);
262 magick_windows[number_windows++]=(&windows->context);
263 for (i=0; i < (int) number_windows; i++)
265 if (magick_windows[i]->mapped != MagickFalse)
267 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
268 magick_windows[i]->screen);
269 magick_windows[i]->mapped=MagickFalse;
271 if (magick_windows[i]->name != (char *) NULL)
272 magick_windows[i]->name=(char *)
273 RelinquishMagickMemory(magick_windows[i]->name);
274 if (magick_windows[i]->icon_name != (char *) NULL)
275 magick_windows[i]->icon_name=(char *)
276 RelinquishMagickMemory(magick_windows[i]->icon_name);
277 if (magick_windows[i]->cursor != (Cursor) NULL)
279 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
280 magick_windows[i]->cursor=(Cursor) NULL;
282 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
284 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
285 magick_windows[i]->busy_cursor=(Cursor) NULL;
287 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
289 (void) XFreePixmap(windows->display,
290 magick_windows[i]->highlight_stipple);
291 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
293 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
295 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
296 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
298 if (magick_windows[i]->ximage != (XImage *) NULL)
300 XDestroyImage(magick_windows[i]->ximage);
301 magick_windows[i]->ximage=(XImage *) NULL;
303 if (magick_windows[i]->pixmap != (Pixmap) NULL)
305 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
306 magick_windows[i]->pixmap=(Pixmap) NULL;
308 if (magick_windows[i]->id != (Window) NULL)
310 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
311 magick_windows[i]->id=(Window) NULL;
313 if (magick_windows[i]->destroy != MagickFalse)
315 if (magick_windows[i]->image != (Image *) NULL)
317 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
318 magick_windows[i]->image=NewImageList();
320 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
322 (void) XFreePixmap(windows->display,
323 magick_windows[i]->matte_pixmap);
324 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
327 if (magick_windows[i]->segment_info != (void *) NULL)
329 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
333 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
334 if (segment_info != (XShmSegmentInfo *) NULL)
335 if (segment_info[0].shmid >= 0)
337 if (segment_info[0].shmaddr != NULL)
338 (void) shmdt(segment_info[0].shmaddr);
339 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
340 segment_info[0].shmaddr=NULL;
341 segment_info[0].shmid=(-1);
344 magick_windows[i]->segment_info=(void *)
345 RelinquishMagickMemory(magick_windows[i]->segment_info);
348 windows->icon_resources=(XResourceInfo *)
349 RelinquishMagickMemory(windows->icon_resources);
350 if (windows->icon_pixel != (XPixelInfo *) NULL)
352 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
353 windows->icon_pixel->pixels=(unsigned long *)
354 RelinquishMagickMemory(windows->icon_pixel->pixels);
355 if (windows->icon_pixel->annotate_context != (GC) NULL)
356 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
357 windows->icon_pixel=(XPixelInfo *)
358 RelinquishMagickMemory(windows->icon_pixel);
360 if (windows->pixel_info != (XPixelInfo *) NULL)
362 if (windows->pixel_info->pixels != (unsigned long *) NULL)
363 windows->pixel_info->pixels=(unsigned long *)
364 RelinquishMagickMemory(windows->pixel_info->pixels);
365 if (windows->pixel_info->annotate_context != (GC) NULL)
366 XFreeGC(windows->display,windows->pixel_info->annotate_context);
367 if (windows->pixel_info->widget_context != (GC) NULL)
368 XFreeGC(windows->display,windows->pixel_info->widget_context);
369 if (windows->pixel_info->highlight_context != (GC) NULL)
370 XFreeGC(windows->display,windows->pixel_info->highlight_context);
371 windows->pixel_info=(XPixelInfo *)
372 RelinquishMagickMemory(windows->pixel_info);
374 if (windows->font_info != (XFontStruct *) NULL)
376 XFreeFont(windows->display,windows->font_info);
377 windows->font_info=(XFontStruct *) NULL;
379 if (windows->class_hints != (XClassHint *) NULL)
381 if (windows->class_hints->res_name != (char *) NULL)
382 XFree(windows->class_hints->res_name);
383 if (windows->class_hints->res_class != (char *) NULL)
384 XFree(windows->class_hints->res_class);
385 XFree(windows->class_hints);
386 windows->class_hints=(XClassHint *) NULL;
388 if (windows->manager_hints != (XWMHints *) NULL)
390 XFree(windows->manager_hints);
391 windows->manager_hints=(XWMHints *) NULL;
393 if (windows->map_info != (XStandardColormap *) NULL)
395 XFree(windows->map_info);
396 windows->map_info=(XStandardColormap *) NULL;
398 if (windows->icon_map != (XStandardColormap *) NULL)
400 XFree(windows->icon_map);
401 windows->icon_map=(XStandardColormap *) NULL;
403 if (windows->visual_info != (XVisualInfo *) NULL)
405 XFree(windows->visual_info);
406 windows->visual_info=(XVisualInfo *) NULL;
408 if (windows->icon_visual != (XVisualInfo *) NULL)
410 XFree(windows->icon_visual);
411 windows->icon_visual=(XVisualInfo *) NULL;
413 (void) XSetWindows((XWindows *) NULL);
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 % X A n n o t a t e I m a g e %
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 % XAnnotateImage() annotates the image with text.
429 % The format of the XAnnotateImage method is:
431 % MagickBooleanType XAnnotateImage(Display *display,
432 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
434 % A description of each parameter follows:
436 % o display: Specifies a connection to an X server; returned from
439 % o pixel: Specifies a pointer to a XPixelInfo structure.
441 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
443 % o image: the image.
446 MagickExport MagickBooleanType XAnnotateImage(Display *display,
447 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
483 Initialize annotated image.
485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
486 assert(display != (Display *) NULL);
487 assert(pixel != (XPixelInfo *) NULL);
488 assert(annotate_info != (XAnnotateInfo *) NULL);
489 assert(image != (Image *) NULL);
491 Initialize annotated pixmap.
493 root_window=XRootWindow(display,XDefaultScreen(display));
494 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
495 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
496 annotate_info->height,depth);
497 if (annotate_pixmap == (Pixmap) NULL)
500 Initialize graphics info.
502 context_values.background=0;
503 context_values.foreground=(unsigned long) (~0);
504 context_values.font=annotate_info->font_info->fid;
505 annotate_context=XCreateGC(display,root_window,(unsigned long)
506 GCBackground | GCFont | GCForeground,&context_values);
507 if (annotate_context == (GC) NULL)
512 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
513 (int) annotate_info->font_info->ascent,annotate_info->text,
514 (int) strlen(annotate_info->text));
515 (void) XFreeGC(display,annotate_context);
517 Initialize annotated X image.
519 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
520 annotate_info->height,AllPlanes,ZPixmap);
521 if (annotate_ximage == (XImage *) NULL)
523 (void) XFreePixmap(display,annotate_pixmap);
525 Initialize annotated image.
527 annotate_image=AcquireImage((ImageInfo *) NULL);
528 if (annotate_image == (Image *) NULL)
530 annotate_image->columns=annotate_info->width;
531 annotate_image->rows=annotate_info->height;
533 Transfer annotated X image to image.
535 width=(unsigned int) image->columns;
536 height=(unsigned int) image->rows;
539 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
540 (void) GetOneVirtualPixel(image,x,y,&annotate_image->background_color,
542 if (annotate_info->stencil == ForegroundStencil)
543 annotate_image->matte=MagickTrue;
544 exception=(&image->exception);
545 for (y=0; y < (int) annotate_image->rows; y++)
553 q=GetAuthenticPixels(annotate_image,0,y,annotate_image->columns,1,
555 if (q == (PixelPacket *) NULL)
557 for (x=0; x < (long) annotate_image->columns; x++)
559 SetOpacityPixelComponent(q,OpaqueOpacity);
560 if (XGetPixel(annotate_ximage,x,y) == 0)
563 Set this pixel to the background color.
565 q->red=ScaleShortToQuantum(pixel->box_color.red);
566 q->green=ScaleShortToQuantum(pixel->box_color.green);
567 q->blue=ScaleShortToQuantum(pixel->box_color.blue);
568 if ((annotate_info->stencil == ForegroundStencil) ||
569 (annotate_info->stencil == OpaqueStencil))
570 q->opacity=(Quantum) TransparentOpacity;
575 Set this pixel to the pen color.
577 q->red=ScaleShortToQuantum(pixel->pen_color.red);
578 q->green=ScaleShortToQuantum(pixel->pen_color.green);
579 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
580 if (annotate_info->stencil == BackgroundStencil)
581 q->opacity=(Quantum) TransparentOpacity;
585 if (SyncAuthenticPixels(annotate_image,exception) == MagickFalse)
588 XDestroyImage(annotate_ximage);
590 Determine annotate geometry.
592 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
593 if ((width != (unsigned int) annotate_image->columns) ||
594 (height != (unsigned int) annotate_image->rows))
597 image_geometry[MaxTextExtent];
602 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
604 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
606 if (annotate_info->degrees != 0.0)
621 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
622 if (rotate_image == (Image *) NULL)
624 annotate_image=DestroyImage(annotate_image);
625 annotate_image=rotate_image;
627 Annotation is relative to the degree of rotation.
629 normalized_degrees=annotate_info->degrees;
630 while (normalized_degrees < -45.0)
631 normalized_degrees+=360.0;
632 for (rotations=0; normalized_degrees > 45.0; rotations++)
633 normalized_degrees-=90.0;
634 switch (rotations % 4)
644 x-=(int) annotate_image->columns/2;
645 y+=(int) annotate_image->columns/2;
653 x=x-(int) annotate_image->columns;
661 x=x-(int) annotate_image->columns/2;
662 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
668 Composite text onto the image.
670 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
672 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
673 OverCompositeOp : CopyCompositeOp,annotate_image,x,y);
675 annotate_image=DestroyImage(annotate_image);
680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 % X B e s t F o n t %
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % XBestFont() returns the "best" font. "Best" is defined as a font specified
691 % in the X resource database or a font such that the text width displayed
692 % with the font does not exceed the specified maximum width.
694 % The format of the XBestFont method is:
696 % XFontStruct *XBestFont(Display *display,
697 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
699 % A description of each parameter follows:
701 % o font: XBestFont returns a pointer to a XFontStruct structure.
703 % o display: Specifies a connection to an X server; returned from
706 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
708 % o text_font: True is font should be mono-spaced (typewriter style).
712 static char **FontToList(char *font)
727 if (font == (char *) NULL)
728 return((char **) NULL);
730 Convert string to an ASCII list.
733 for (p=font; *p != '\0'; p++)
734 if ((*p == ':') || (*p == ';') || (*p == ','))
736 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
737 if (fontlist == (char **) NULL)
739 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
741 return((char **) NULL);
744 for (i=0; i < (int) fonts; i++)
746 for (q=p; *q != '\0'; q++)
747 if ((*q == ':') || (*q == ';') || (*q == ','))
749 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
750 sizeof(*fontlist[i]));
751 if (fontlist[i] == (char *) NULL)
753 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
755 return((char **) NULL);
757 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
760 fontlist[i]=(char *) NULL;
764 MagickExport XFontStruct *XBestFont(Display *display,
765 const XResourceInfo *resource_info,const MagickBooleanType text_font)
770 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
771 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
772 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
773 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
774 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
775 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
782 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
783 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
784 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
798 font_info=(XFontStruct *) NULL;
799 font_name=resource_info->font;
800 if (text_font != MagickFalse)
801 font_name=resource_info->text_font;
802 if ((font_name != (char *) NULL) && (*font_name != '\0'))
811 Load preferred font specified in the X resource database.
813 fontlist=FontToList(font_name);
814 if (fontlist != (char **) NULL)
816 for (i=0; fontlist[i] != (char *) NULL; i++)
818 if (font_info == (XFontStruct *) NULL)
819 font_info=XLoadQueryFont(display,fontlist[i]);
820 fontlist[i]=DestroyString(fontlist[i]);
822 fontlist=(char **) RelinquishMagickMemory(fontlist);
824 if (font_info == (XFontStruct *) NULL)
825 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
828 Load fonts from list of fonts until one is found.
831 if (text_font != MagickFalse)
833 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
835 while (*p != (char *) NULL)
837 if (font_info != (XFontStruct *) NULL)
839 font_info=XLoadQueryFont(display,(char *) *p);
846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850 % X B e s t I c o n S i z e %
854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
857 % size that maintains the aspect ratio of the image. If the window manager
858 % has preferred icon sizes, one of the preferred sizes is used.
860 % The format of the XBestIconSize method is:
862 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
864 % A description of each parameter follows:
866 % o display: Specifies a connection to an X server; returned from
869 % o image: the image.
872 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
896 Determine if the window manager has specified preferred icon sizes.
898 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
899 assert(display != (Display *) NULL);
900 assert(window != (XWindowInfo *) NULL);
901 assert(image != (Image *) NULL);
902 window->width=MaxIconSize;
903 window->height=MaxIconSize;
904 icon_size=(XIconSize *) NULL;
906 root_window=XRootWindow(display,window->screen);
907 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
908 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
910 if (icon_size == (XIconSize *) NULL)
913 Window manager does not restrict icon size.
915 icon_size=XAllocIconSize();
916 if (icon_size == (XIconSize *) NULL)
918 ThrowXWindowFatalException(ResourceLimitError,
919 "MemoryAllocationFailed",image->filename);
922 icon_size->min_width=1;
923 icon_size->max_width=MaxIconSize;
924 icon_size->min_height=1;
925 icon_size->max_height=MaxIconSize;
926 icon_size->width_inc=1;
927 icon_size->height_inc=1;
930 Determine aspect ratio of image.
932 width=(unsigned int) image->columns;
933 height=(unsigned int) image->rows;
935 if (window->crop_geometry)
936 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
938 Look for an icon size that maintains the aspect ratio of image.
940 scale_factor=(MagickRealType) icon_size->max_width/width;
941 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
942 scale_factor=(MagickRealType) icon_size->max_height/height;
943 icon_width=(unsigned int) icon_size->min_width;
944 while ((int) icon_width < icon_size->max_width)
946 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
948 icon_width+=icon_size->width_inc;
950 icon_height=(unsigned int) icon_size->min_height;
951 while ((int) icon_height < icon_size->max_height)
953 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
955 icon_height+=icon_size->height_inc;
957 (void) XFree((void *) icon_size);
958 window->width=icon_width;
959 window->height=icon_height;
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 % X B e s t P i x e l %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % XBestPixel() returns a pixel from an array of pixels that is closest to the
974 % requested color. If the color array is NULL, the colors are obtained from
977 % The format of the XBestPixel method is:
979 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
980 % unsigned int number_colors,XColor *color)
982 % A description of each parameter follows:
984 % o pixel: XBestPixel returns the pixel value closest to the requested
987 % o display: Specifies a connection to an X server; returned from
990 % o colormap: Specifies the ID of the X server colormap.
992 % o colors: Specifies an array of XColor structures.
994 % o number_colors: Specifies the number of XColor structures in the
995 % color definition array.
997 % o color: Specifies the desired RGB value to find in the colors array.
1000 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1001 XColor *colors,unsigned int number_colors,XColor *color)
1012 register MagickRealType
1023 Find closest representation for the requested RGB color.
1025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1026 assert(display != (Display *) NULL);
1027 assert(color != (XColor *) NULL);
1028 status=XAllocColor(display,colormap,color);
1029 if (status != False)
1031 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1032 if (query_server != MagickFalse)
1035 Read X server colormap.
1037 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1038 if (colors == (XColor *) NULL)
1040 ThrowXWindowFatalException(ResourceLimitError,
1041 "MemoryAllocationFailed","...");
1044 for (i=0; i < (int) number_colors; i++)
1045 colors[i].pixel=(unsigned long) i;
1046 if (number_colors > 256)
1048 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1050 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1053 for (i=0; i < (int) number_colors; i++)
1055 pixel.red=colors[i].red-(MagickRealType) color->red;
1056 distance=pixel.red*pixel.red;
1057 if (distance > min_distance)
1059 pixel.green=colors[i].green-(MagickRealType) color->green;
1060 distance+=pixel.green*pixel.green;
1061 if (distance > min_distance)
1063 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1064 distance+=pixel.blue*pixel.blue;
1065 if (distance > min_distance)
1067 min_distance=distance;
1068 color->pixel=colors[i].pixel;
1071 (void) XAllocColor(display,colormap,&colors[j]);
1072 if (query_server != MagickFalse)
1073 colors=(XColor *) RelinquishMagickMemory(colors);
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 % X B e s t V i s u a l I n f o %
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % XBestVisualInfo() returns visual information for a visual that is the "best"
1088 % the server supports. "Best" is defined as:
1090 % 1. Restrict the visual list to those supported by the default screen.
1092 % 2. If a visual type is specified, restrict the visual list to those of
1095 % 3. If a map type is specified, choose the visual that matches the id
1096 % specified by the Standard Colormap.
1098 % 4 From the list of visuals, choose one that can display the most
1099 % simultaneous colors. If more than one visual can display the same
1100 % number of simultaneous colors, one is chosen based on a rank.
1102 % The format of the XBestVisualInfo method is:
1104 % XVisualInfo *XBestVisualInfo(Display *display,
1105 % XStandardColormap *map_info,XResourceInfo *resource_info)
1107 % A description of each parameter follows:
1109 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1112 % o display: Specifies a connection to an X server; returned from
1115 % o map_info: If map_type is specified, this structure is initialized
1116 % with info from the Standard Colormap.
1118 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1122 static inline int MagickMax(const int x,const int y)
1129 static inline unsigned long MagickMin(const unsigned int x,
1130 const unsigned int y)
1137 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1138 XStandardColormap *map_info,XResourceInfo *resource_info)
1140 #define MaxStandardColormaps 7
1141 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1142 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1143 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1144 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1167 Restrict visual search by screen number.
1169 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1170 assert(display != (Display *) NULL);
1171 assert(map_info != (XStandardColormap *) NULL);
1172 assert(resource_info != (XResourceInfo *) NULL);
1173 map_type=resource_info->map_type;
1174 visual_type=resource_info->visual_type;
1175 visual_mask=VisualScreenMask;
1176 visual_template.screen=XDefaultScreen(display);
1177 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1178 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1179 if (resource_info->colors <= (1UL << (unsigned long) visual_template.depth))
1180 visual_mask|=VisualDepthMask;
1181 if (visual_type != (char *) NULL)
1184 Restrict visual search by class or visual id.
1186 if (LocaleCompare("staticgray",visual_type) == 0)
1188 visual_mask|=VisualClassMask;
1189 visual_template.klass=StaticGray;
1192 if (LocaleCompare("grayscale",visual_type) == 0)
1194 visual_mask|=VisualClassMask;
1195 visual_template.klass=GrayScale;
1198 if (LocaleCompare("staticcolor",visual_type) == 0)
1200 visual_mask|=VisualClassMask;
1201 visual_template.klass=StaticColor;
1204 if (LocaleCompare("pseudocolor",visual_type) == 0)
1206 visual_mask|=VisualClassMask;
1207 visual_template.klass=PseudoColor;
1210 if (LocaleCompare("truecolor",visual_type) == 0)
1212 visual_mask|=VisualClassMask;
1213 visual_template.klass=TrueColor;
1216 if (LocaleCompare("directcolor",visual_type) == 0)
1218 visual_mask|=VisualClassMask;
1219 visual_template.klass=DirectColor;
1222 if (LocaleCompare("default",visual_type) == 0)
1224 visual_mask|=VisualIDMask;
1225 visual_template.visualid=XVisualIDFromVisual(
1226 XDefaultVisual(display,XDefaultScreen(display)));
1229 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1231 visual_mask|=VisualIDMask;
1232 visual_template.visualid=
1233 strtol(visual_type,(char **) NULL,0);
1236 ThrowXWindowFatalException(XServerError,
1237 "UnrecognizedVisualSpecifier",visual_type);
1240 Get all visuals that meet our criteria so far.
1243 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1245 visual_mask=VisualScreenMask | VisualIDMask;
1246 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1249 Failed to get visual; try using the default visual.
1251 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1253 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1254 XDefaultScreen(display)));
1255 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1257 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1258 return((XVisualInfo *) NULL);
1259 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1260 XVisualClassName(visual_list->klass));
1262 resource_info->color_recovery=MagickFalse;
1263 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1269 map_name[MaxTextExtent];
1285 Choose a visual associated with a standard colormap.
1287 root_window=XRootWindow(display,XDefaultScreen(display));
1289 if (LocaleCompare(map_type,"list") != 0)
1292 User specified Standard Colormap.
1294 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1295 "RGB_%s_MAP",map_type);
1296 LocaleUpper(map_name);
1297 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1298 if (map_property != (Atom) NULL)
1299 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1305 *colormap[MaxStandardColormaps]=
1307 "_HP_RGB_SMOOTH_MAP_LIST",
1317 Choose a standard colormap from a list.
1319 for (i=0; i < MaxStandardColormaps; i++)
1321 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1322 if (map_property == (Atom) NULL)
1324 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1326 if (status != False)
1329 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1331 if (status == False)
1333 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1335 return((XVisualInfo *) NULL);
1338 Search all Standard Colormaps and visuals for ids that match.
1340 *map_info=map_list[0];
1341 #if !defined(PRE_R4_ICCCM)
1342 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1343 for (i=0; i < number_maps; i++)
1344 for (j=0; j < number_visuals; j++)
1345 if (map_list[i].visualid ==
1346 XVisualIDFromVisual(visual_list[j].visual))
1348 *map_info=map_list[i];
1349 visual_template.visualid=XVisualIDFromVisual(
1350 visual_list[j].visual);
1353 if (map_info->visualid != visual_template.visualid)
1355 ThrowXWindowFatalException(XServerError,
1356 "UnableToMatchVisualToStandardColormap",map_type);
1357 return((XVisualInfo *) NULL);
1360 if (map_info->colormap == (Colormap) NULL)
1362 ThrowXWindowFatalException(XServerError,
1363 "StandardColormapIsNotInitialized",map_type);
1364 return((XVisualInfo *) NULL);
1366 (void) XFree((void *) map_list);
1370 static const unsigned int
1385 Pick one visual that displays the most simultaneous colors.
1387 visual_info=visual_list;
1389 for (i=1; i < number_visuals; i++)
1392 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1395 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1396 if (rank[p->klass] > rank[visual_info->klass])
1399 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1401 (void) XFree((void *) visual_list);
1403 Retrieve only one visual by its screen & id number.
1405 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1407 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1408 return((XVisualInfo *) NULL);
1409 return(visual_info);
1413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1417 % X C h e c k D e f i n e C u r s o r %
1421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1423 % XCheckDefineCursor() prevents cursor changes on the root window.
1425 % The format of the XXCheckDefineCursor method is:
1427 % XCheckDefineCursor(display,window,cursor)
1429 % A description of each parameter follows:
1431 % o display: Specifies a connection to an X server; returned from
1434 % o window: the window.
1436 % o cursor: the cursor.
1439 MagickExport int XCheckDefineCursor(Display *display,Window window,
1442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1443 assert(display != (Display *) NULL);
1444 if (window == XRootWindow(display,XDefaultScreen(display)))
1446 return(XDefineCursor(display,window,cursor));
1450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1454 % X C h e c k R e f r e s h W i n d o w s %
1458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1460 % XCheckRefreshWindows() checks the X server for exposure events for a
1461 % particular window and updates the areassociated with the exposure event.
1463 % The format of the XCheckRefreshWindows method is:
1465 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1467 % A description of each parameter follows:
1469 % o display: Specifies a connection to an X server; returned from
1472 % o windows: Specifies a pointer to a XWindows structure.
1475 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1484 assert(display != (Display *) NULL);
1485 assert(windows != (XWindows *) NULL);
1486 XDelay(display,SuspendTime);
1487 id=windows->command.id;
1488 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1489 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1490 id=windows->image.id;
1491 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1492 XRefreshWindow(display,&windows->image,&event);
1493 XDelay(display,SuspendTime << 1);
1494 id=windows->command.id;
1495 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1496 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1497 id=windows->image.id;
1498 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1499 XRefreshWindow(display,&windows->image,&event);
1503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1507 % X C l i e n t M e s s a g e %
1511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1514 % initialized with a particular protocol type and atom.
1516 % The format of the XClientMessage function is:
1518 % XClientMessage(display,window,protocol,reason,timestamp)
1520 % A description of each parameter follows:
1522 % o display: Specifies a pointer to the Display structure; returned from
1525 % o window: Specifies a pointer to a Window structure.
1527 % o protocol: Specifies an atom value.
1529 % o reason: Specifies an atom value which is the reason to send.
1531 % o timestamp: Specifies a value of type Time.
1534 MagickExport void XClientMessage(Display *display,const Window window,
1535 const Atom protocol,const Atom reason,const Time timestamp)
1540 assert(display != (Display *) NULL);
1541 client_event.type=ClientMessage;
1542 client_event.window=window;
1543 client_event.message_type=protocol;
1544 client_event.format=32;
1545 client_event.data.l[0]=(long) reason;
1546 client_event.data.l[1]=(long) timestamp;
1547 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555 + X C l i e n t W i n d o w %
1559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1561 % XClientWindow() finds a window, at or below the specified window, which has
1562 % a WM_STATE property. If such a window is found, it is returned, otherwise
1563 % the argument window is returned.
1565 % The format of the XClientWindow function is:
1567 % client_window=XClientWindow(display,target_window)
1569 % A description of each parameter follows:
1571 % o client_window: XClientWindow returns a window, at or below the specified
1572 % window, which has a WM_STATE property otherwise the argument
1573 % target_window is returned.
1575 % o display: Specifies a pointer to the Display structure; returned from
1578 % o target_window: Specifies the window to find a WM_STATE property.
1581 static Window XClientWindow(Display *display,Window target_window)
1603 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1604 assert(display != (Display *) NULL);
1605 state=XInternAtom(display,"WM_STATE",MagickTrue);
1606 if (state == (Atom) NULL)
1607 return(target_window);
1609 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1610 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1611 if ((status == Success) && (type != (Atom) NULL))
1612 return(target_window);
1613 client_window=XWindowByProperty(display,target_window,state);
1614 if (client_window == (Window) NULL)
1615 return(target_window);
1616 return(client_window);
1620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1624 + X C o m p o n e n t T e r m i n u s %
1628 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1630 % XComponentTerminus() destroys the module component.
1632 % The format of the XComponentTerminus method is:
1634 % XComponentTerminus(void)
1637 MagickExport void XComponentTerminus(void)
1639 DestroyXResources();
1643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1647 % X C o n f i g u r e I m a g e C o l o r m a p %
1651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1653 % XConfigureImageColormap() creates a new X colormap.
1655 % The format of the XConfigureImageColormap method is:
1657 % void XConfigureImageColormap(Display *display,
1658 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1660 % A description of each parameter follows:
1662 % o display: Specifies a connection to an X server; returned from
1665 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1667 % o windows: Specifies a pointer to a XWindows structure.
1669 % o image: the image.
1672 MagickExport void XConfigureImageColormap(Display *display,
1673 XResourceInfo *resource_info,XWindows *windows,Image *image)
1679 Make standard colormap.
1681 XSetCursorState(display,windows,MagickTrue);
1682 XCheckRefreshWindows(display,windows);
1683 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1684 windows->map_info,windows->pixel_info);
1685 colormap=windows->map_info->colormap;
1686 (void) XSetWindowColormap(display,windows->image.id,colormap);
1687 (void) XSetWindowColormap(display,windows->command.id,colormap);
1688 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1689 if (windows->magnify.mapped != MagickFalse)
1690 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1691 if (windows->pan.mapped != MagickFalse)
1692 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1693 XSetCursorState(display,windows,MagickFalse);
1694 XClientMessage(display,windows->image.id,windows->im_protocols,
1695 windows->im_update_colormap,CurrentTime);
1699 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1703 % X C o n s t r a i n W i n d o w P o s i t i o n %
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1709 % XConstrainWindowPosition() assures a window is positioned within the X
1710 % server boundaries.
1712 % The format of the XConstrainWindowPosition method is:
1714 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1716 % A description of each parameter follows:
1718 % o display: Specifies a pointer to the Display structure; returned from
1721 % o window_info: Specifies a pointer to a XWindowInfo structure.
1724 MagickExport void XConstrainWindowPosition(Display *display,
1725 XWindowInfo *window_info)
1730 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1731 assert(display != (Display *) NULL);
1732 assert(window_info != (XWindowInfo *) NULL);
1733 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1734 if (window_info->x < 0)
1737 if (window_info->x > (int) limit)
1738 window_info->x=(int) limit;
1739 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1740 if (window_info->y < 0)
1743 if (window_info->y > limit)
1744 window_info->y=limit;
1748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758 % XDelay() suspends program execution for the number of milliseconds
1761 % The format of the Delay method is:
1763 % void XDelay(Display *display,const unsigned long milliseconds)
1765 % A description of each parameter follows:
1767 % o display: Specifies a pointer to the Display structure; returned from
1770 % o milliseconds: Specifies the number of milliseconds to delay before
1774 MagickExport void XDelay(Display *display,const unsigned long milliseconds)
1776 assert(display != (Display *) NULL);
1777 (void) XFlush(display);
1778 if (milliseconds == 0)
1780 #if defined(__WINDOWS__)
1781 Sleep(milliseconds);
1787 timer=milliseconds/1000.0;
1790 #elif defined(MAGICKCORE_HAVE_USLEEP)
1791 usleep(1000*milliseconds);
1792 #elif defined(MAGICKCORE_HAVE_SELECT)
1797 timer.tv_sec=(long) milliseconds/1000;
1798 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1799 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1801 #elif defined(MAGICKCORE_HAVE_POLL)
1802 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1803 #elif defined(__BEOS__)
1804 snooze(1000*milliseconds);
1806 # error "Time delay method not defined."
1811 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1815 % X D e s t r o y R e s o u r c e I n f o %
1819 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1821 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1824 % The format of the XDestroyResourceInfo method is:
1826 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1828 % A description of each parameter follows:
1830 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1833 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1835 if (resource_info->image_geometry != (char *) NULL)
1836 resource_info->image_geometry=(char *)
1837 RelinquishMagickMemory(resource_info->image_geometry);
1838 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1839 resource_info->quantize_info=DestroyQuantizeInfo(
1840 resource_info->quantize_info);
1841 if (resource_info->client_name != (char *) NULL)
1842 resource_info->client_name=(char *)
1843 RelinquishMagickMemory(resource_info->client_name);
1844 if (resource_info->name != (char *) NULL)
1845 resource_info->name=DestroyString(resource_info->name);
1846 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1854 % X D e s t r o y W i n d o w C o l o r s %
1858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1860 % XDestroyWindowColors() frees X11 color resources previously saved on a
1861 % window by XRetainWindowColors or programs like xsetroot.
1863 % The format of the XDestroyWindowColors method is:
1865 % void XDestroyWindowColors(Display *display,Window window)
1867 % A description of each parameter follows:
1869 % o display: Specifies a connection to an X server; returned from
1872 % o window: Specifies a pointer to a Window structure.
1875 MagickExport void XDestroyWindowColors(Display *display,Window window)
1895 If there are previous resources on the root window, destroy them.
1897 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1898 assert(display != (Display *) NULL);
1899 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1900 if (property == (Atom) NULL)
1902 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1906 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1907 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1908 if (status != Success)
1910 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1912 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1913 (void) XDeleteProperty(display,window,property);
1916 (void) XFree((void *) data);
1920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1924 % X D i s p l a y I m a g e I n f o %
1928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1930 % XDisplayImageInfo() displays information about an X image.
1932 % The format of the XDisplayImageInfo method is:
1934 % void XDisplayImageInfo(Display *display,
1935 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1938 % A description of each parameter follows:
1940 % o display: Specifies a connection to an X server; returned from
1943 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1945 % o windows: Specifies a pointer to a XWindows structure.
1947 % o undo_image: the undo image.
1949 % o image: the image.
1952 MagickExport void XDisplayImageInfo(Display *display,
1953 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1957 filename[MaxTextExtent],
1980 Write info about the X server to a file.
1982 assert(display != (Display *) NULL);
1983 assert(resource_info != (XResourceInfo *) NULL);
1984 assert(windows != (XWindows *) NULL);
1985 assert(image != (Image *) NULL);
1987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1989 unique_file=AcquireUniqueFileResource(filename);
1990 if (unique_file != -1)
1991 file=fdopen(unique_file,"w");
1992 if ((unique_file == -1) || (file == (FILE *) NULL))
1994 XNoticeWidget(display,windows,"Unable to display image info",filename);
1997 if (resource_info->gamma_correct != MagickFalse)
1998 if (resource_info->display_gamma != (char *) NULL)
1999 (void) fprintf(file,"Display\n gamma: %s\n\n",
2000 resource_info->display_gamma);
2002 Write info about the X image to a file.
2004 (void) fprintf(file,"X\n visual: %s\n",
2005 XVisualClassName((int) windows->image.storage_class));
2006 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
2007 if (windows->visual_info->colormap_size != 0)
2008 (void) fprintf(file," colormap size: %d\n",
2009 windows->visual_info->colormap_size);
2010 if (resource_info->colormap== SharedColormap)
2011 (void) fprintf(file," colormap type: Shared\n");
2013 (void) fprintf(file," colormap type: Private\n");
2014 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
2015 windows->image.ximage->height);
2016 if (windows->image.crop_geometry != (char *) NULL)
2017 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
2018 if (windows->image.pixmap == (Pixmap) NULL)
2019 (void) fprintf(file," type: X Image\n");
2021 (void) fprintf(file," type: Pixmap\n");
2022 if (windows->image.shape != MagickFalse)
2023 (void) fprintf(file," non-rectangular shape: True\n");
2025 (void) fprintf(file," non-rectangular shape: False\n");
2026 if (windows->image.shared_memory != MagickFalse)
2027 (void) fprintf(file," shared memory: True\n");
2029 (void) fprintf(file," shared memory: False\n");
2030 (void) fprintf(file,"\n");
2031 if (resource_info->font != (char *) NULL)
2032 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2033 if (resource_info->text_font != (char *) NULL)
2034 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2036 Write info about the undo cache to a file.
2039 for (levels=0; undo_image != (Image *) NULL; levels++)
2041 number_pixels=undo_image->list->columns*undo_image->list->rows;
2042 bytes+=number_pixels*sizeof(PixelPacket);
2043 undo_image=GetPreviousImageInList(undo_image);
2045 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2046 (void) fprintf(file," bytes: %lumb\n",(unsigned long)
2047 (bytes+(1 << 19)) >> 20);
2048 (void) fprintf(file," limit: %lumb\n\n",resource_info->undo_cache);
2050 Write info about the image to a file.
2052 (void) IdentifyImage(image,file,MagickTrue);
2053 (void) fclose(file);
2054 text=FileToString(filename,~0,&image->exception);
2055 (void) RelinquishUniqueFileResource(filename);
2056 if (text == (char *) NULL)
2058 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2059 "UnableToDisplayImageInfo");
2062 textlist=StringToList(text);
2063 if (textlist != (char **) NULL)
2066 title[MaxTextExtent];
2069 Display information about the image in the Text View widget.
2071 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2072 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2074 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2075 (char const **) textlist);
2076 for (i=0; textlist[i] != (char *) NULL; i++)
2077 textlist[i]=DestroyString(textlist[i]);
2078 textlist=(char **) RelinquishMagickMemory(textlist);
2080 text=DestroyString(text);
2084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2088 + X D i t h e r I m a g e %
2092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2094 % XDitherImage() dithers the reference image as required by the HP Color
2095 % Recovery algorithm. The color values are quantized to 3 bits of red and
2096 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2097 % standard colormap.
2099 % The format of the XDitherImage method is:
2101 % void XDitherImage(Image *image,XImage *ximage)
2103 % A description of each parameter follows:
2105 % o image: the image.
2107 % o ximage: Specifies a pointer to a XImage structure; returned from
2111 static void XDitherImage(Image *image,XImage *ximage)
2113 static const short int
2116 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2117 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2119 dither_green[2][16]=
2121 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2122 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2126 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2127 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2142 register const PixelPacket
2153 register unsigned long
2162 Allocate and initialize dither maps.
2164 for (i=0; i < 2; i++)
2165 for (j=0; j < 16; j++)
2167 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2169 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2170 sizeof(*green_map));
2171 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2173 if ((red_map[i][j] == (unsigned char *) NULL) ||
2174 (green_map[i][j] == (unsigned char *) NULL) ||
2175 (blue_map[i][j] == (unsigned char *) NULL))
2177 ThrowXWindowFatalException(ResourceLimitError,
2178 "MemoryAllocationFailed",image->filename);
2183 Initialize dither tables.
2185 for (i=0; i < 2; i++)
2186 for (j=0; j < 16; j++)
2187 for (x=0; x < 256; x++)
2192 value+=dither_red[i][j];
2193 red_map[i][j][x]=(unsigned char)
2194 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2198 value+=dither_green[i][j];
2199 green_map[i][j][x]=(unsigned char)
2200 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2204 value+=((unsigned long) dither_blue[i][j] << 1);
2205 blue_map[i][j][x]=(unsigned char)
2206 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2211 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2212 ((unsigned long) (ximage->width*ximage->bits_per_pixel) >> 3));
2216 for (y=0; y < (int) image->rows; y++)
2218 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2219 if (p == (const PixelPacket *) NULL)
2221 for (x=0; x < (int) image->columns; x++)
2223 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2224 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2225 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2226 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2227 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2228 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2229 pixel=(unsigned long) (((unsigned long) color.red & 0xe0) |
2230 (((unsigned long) color.green & 0xe0) >> 3) |
2231 (((unsigned long) color.blue & 0xc0) >> 6));
2244 Free allocated memory.
2246 for (i=0; i < 2; i++)
2247 for (j=0; j < 16; j++)
2249 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2250 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2251 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260 % X D r a w I m a g e %
2264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2266 % XDrawImage() draws a line on the image.
2268 % The format of the XDrawImage method is:
2270 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2272 % A description of each parameter follows:
2274 % o display: Specifies a connection to an X server; returned from
2277 % o pixel: Specifies a pointer to a XPixelInfo structure.
2279 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2281 % o image: the image.
2284 MagickExport MagickBooleanType XDrawImage(Display *display,
2285 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2321 Initialize drawd image.
2323 assert(display != (Display *) NULL);
2324 assert(pixel != (XPixelInfo *) NULL);
2325 assert(draw_info != (XDrawInfo *) NULL);
2326 assert(image != (Image *) NULL);
2327 if (image->debug != MagickFalse)
2328 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2330 Initialize drawd pixmap.
2332 root_window=XRootWindow(display,XDefaultScreen(display));
2333 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2334 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2335 draw_info->height,depth);
2336 if (draw_pixmap == (Pixmap) NULL)
2337 return(MagickFalse);
2339 Initialize graphics info.
2341 context_values.background=(unsigned long) (~0);
2342 context_values.foreground=0;
2343 context_values.line_width=(int) draw_info->line_width;
2344 draw_context=XCreateGC(display,root_window,(unsigned long)
2345 (GCBackground | GCForeground | GCLineWidth),&context_values);
2346 if (draw_context == (GC) NULL)
2347 return(MagickFalse);
2351 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2354 Draw line to pixmap.
2356 (void) XSetBackground(display,draw_context,0);
2357 (void) XSetForeground(display,draw_context,(unsigned long) (~0));
2358 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2359 (void) XSetStipple(display,draw_context,draw_info->stipple);
2360 switch (draw_info->element)
2365 (void) XDrawLines(display,draw_pixmap,draw_context,
2366 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2372 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2373 draw_info->line_info.y1,draw_info->line_info.x2,
2374 draw_info->line_info.y2);
2377 case RectangleElement:
2379 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2380 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2381 (unsigned int) draw_info->rectangle_info.width,
2382 (unsigned int) draw_info->rectangle_info.height);
2385 case FillRectangleElement:
2387 (void) XFillRectangle(display,draw_pixmap,draw_context,
2388 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2389 (unsigned int) draw_info->rectangle_info.width,
2390 (unsigned int) draw_info->rectangle_info.height);
2394 case EllipseElement:
2396 (void) XDrawArc(display,draw_pixmap,draw_context,
2397 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2398 (unsigned int) draw_info->rectangle_info.width,
2399 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2402 case FillCircleElement:
2403 case FillEllipseElement:
2405 (void) XFillArc(display,draw_pixmap,draw_context,
2406 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2407 (unsigned int) draw_info->rectangle_info.width,
2408 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2411 case PolygonElement:
2416 coordinate_info=draw_info->coordinate_info;
2417 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2418 (int) draw_info->number_coordinates,CoordModeOrigin);
2419 (void) XDrawLine(display,draw_pixmap,draw_context,
2420 coordinate_info[draw_info->number_coordinates-1].x,
2421 coordinate_info[draw_info->number_coordinates-1].y,
2422 coordinate_info[0].x,coordinate_info[0].y);
2425 case FillPolygonElement:
2427 (void) XFillPolygon(display,draw_pixmap,draw_context,
2428 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2433 (void) XFreeGC(display,draw_context);
2437 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2438 draw_info->height,AllPlanes,ZPixmap);
2439 if (draw_ximage == (XImage *) NULL)
2440 return(MagickFalse);
2441 (void) XFreePixmap(display,draw_pixmap);
2443 Initialize draw image.
2445 draw_image=AcquireImage((ImageInfo *) NULL);
2446 if (draw_image == (Image *) NULL)
2447 return(MagickFalse);
2448 draw_image->columns=draw_info->width;
2449 draw_image->rows=draw_info->height;
2451 Transfer drawn X image to image.
2453 width=(unsigned int) image->columns;
2454 height=(unsigned int) image->rows;
2457 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2458 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2460 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2461 return(MagickFalse);
2462 draw_image->matte=MagickTrue;
2463 exception=(&image->exception);
2464 for (y=0; y < (int) draw_image->rows; y++)
2469 register PixelPacket
2472 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2473 if (q == (PixelPacket *) NULL)
2475 for (x=0; x < (long) draw_image->columns; x++)
2477 if (XGetPixel(draw_ximage,x,y) == 0)
2480 Set this pixel to the background color.
2482 *q=draw_image->background_color;
2483 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2484 TransparentOpacity : OpaqueOpacity);
2489 Set this pixel to the pen color.
2491 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2492 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2493 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2494 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2495 OpaqueOpacity : TransparentOpacity);
2499 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2502 XDestroyImage(draw_ximage);
2504 Determine draw geometry.
2506 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2507 if ((width != (unsigned int) draw_image->columns) ||
2508 (height != (unsigned int) draw_image->rows))
2511 image_geometry[MaxTextExtent];
2516 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2518 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2520 if (draw_info->degrees != 0.0)
2534 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2535 if (rotate_image == (Image *) NULL)
2536 return(MagickFalse);
2537 draw_image=DestroyImage(draw_image);
2538 draw_image=rotate_image;
2540 Annotation is relative to the degree of rotation.
2542 normalized_degrees=draw_info->degrees;
2543 while (normalized_degrees < -45.0)
2544 normalized_degrees+=360.0;
2545 for (rotations=0; normalized_degrees > 45.0; rotations++)
2546 normalized_degrees-=90.0;
2547 switch (rotations % 4)
2557 x=x-(int) draw_image->columns/2;
2558 y=y+(int) draw_image->columns/2;
2566 x=x-(int) draw_image->columns;
2574 x=x-(int) draw_image->columns/2;
2575 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2581 Composite text onto the image.
2583 for (y=0; y < (int) draw_image->rows; y++)
2588 register PixelPacket
2591 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2592 if (q == (PixelPacket *) NULL)
2594 for (x=0; x < (long) draw_image->columns; x++)
2596 if (q->opacity != (Quantum) TransparentOpacity)
2597 SetOpacityPixelComponent(q,OpaqueOpacity);
2600 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2603 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2604 if (draw_info->stencil == TransparentStencil)
2605 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2609 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2612 draw_image=DestroyImage(draw_image);
2617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2625 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2628 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2629 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2632 % The format of the XError function is:
2634 % XError(display,error)
2636 % A description of each parameter follows:
2638 % o display: Specifies a pointer to the Display structure; returned from
2641 % o error: Specifies the error event.
2645 #if defined(__cplusplus) || defined(c_plusplus)
2649 MagickExport int XError(Display *display,XErrorEvent *error)
2651 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2652 assert(display != (Display *) NULL);
2653 assert(error != (XErrorEvent *) NULL);
2654 xerror_alert=MagickTrue;
2655 switch (error->request_code)
2659 if ((int) error->error_code == BadDrawable)
2660 return(MagickFalse);
2663 case X_GetWindowAttributes:
2666 if ((int) error->error_code == BadWindow)
2667 return(MagickFalse);
2672 if ((int) error->error_code == BadValue)
2673 return(MagickFalse);
2680 #if defined(__cplusplus) || defined(c_plusplus)
2685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2689 % X F r e e R e s o u r c e s %
2693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695 % XFreeResources() frees X11 resources.
2697 % The format of the XFreeResources method is:
2699 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2700 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2701 % XResourceInfo *resource_info,XWindowInfo *window_info)
2702 % resource_info,window_info)
2704 % A description of each parameter follows:
2706 % o display: Specifies a connection to an X server; returned from
2709 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2710 % returned from XGetVisualInfo.
2712 % o map_info: If map_type is specified, this structure is initialized
2713 % with info from the Standard Colormap.
2715 % o pixel: Specifies a pointer to a XPixelInfo structure.
2717 % o font_info: Specifies a pointer to a XFontStruct structure.
2719 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2721 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2724 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2725 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2726 XResourceInfo *resource_info,XWindowInfo *window_info)
2728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2729 assert(display != (Display *) NULL);
2730 assert(resource_info != (XResourceInfo *) NULL);
2731 if (window_info != (XWindowInfo *) NULL)
2736 if (window_info->ximage != (XImage *) NULL)
2737 XDestroyImage(window_info->ximage);
2738 if (window_info->id != (Window) NULL)
2741 Free destroy window and free cursors.
2743 if (window_info->id != XRootWindow(display,visual_info->screen))
2744 (void) XDestroyWindow(display,window_info->id);
2745 if (window_info->annotate_context != (GC) NULL)
2746 (void) XFreeGC(display,window_info->annotate_context);
2747 if (window_info->highlight_context != (GC) NULL)
2748 (void) XFreeGC(display,window_info->highlight_context);
2749 if (window_info->widget_context != (GC) NULL)
2750 (void) XFreeGC(display,window_info->widget_context);
2751 if (window_info->cursor != (Cursor) NULL)
2752 (void) XFreeCursor(display,window_info->cursor);
2753 window_info->cursor=(Cursor) NULL;
2754 if (window_info->busy_cursor != (Cursor) NULL)
2755 (void) XFreeCursor(display,window_info->busy_cursor);
2756 window_info->busy_cursor=(Cursor) NULL;
2762 if (font_info != (XFontStruct *) NULL)
2763 (void) XFreeFont(display,font_info);
2764 if (map_info != (XStandardColormap *) NULL)
2767 Free X Standard Colormap.
2769 if (resource_info->map_type == (char *) NULL)
2770 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2771 (void) XFree((void *) map_info);
2776 if (visual_info != (XVisualInfo *) NULL)
2777 (void) XFree((void *) visual_info);
2778 if (resource_info->close_server != MagickFalse)
2779 (void) XCloseDisplay(display);
2783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2787 % X F r e e S t a n d a r d C o l o r m a p %
2791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2793 % XFreeStandardColormap() frees an X11 colormap.
2795 % The format of the XFreeStandardColormap method is:
2797 % void XFreeStandardColormap(Display *display,
2798 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2799 % XPixelInfo *pixel)
2801 % A description of each parameter follows:
2803 % o display: Specifies a connection to an X server; returned from
2806 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2807 % returned from XGetVisualInfo.
2809 % o map_info: If map_type is specified, this structure is initialized
2810 % with info from the Standard Colormap.
2812 % o pixel: Specifies a pointer to a XPixelInfo structure.
2815 MagickExport void XFreeStandardColormap(Display *display,
2816 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2822 assert(display != (Display *) NULL);
2823 assert(visual_info != (XVisualInfo *) NULL);
2824 assert(map_info != (XStandardColormap *) NULL);
2825 (void) XFlush(display);
2826 if (map_info->colormap != (Colormap) NULL)
2828 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2829 (void) XFreeColormap(display,map_info->colormap);
2831 if (pixel != (XPixelInfo *) NULL)
2832 if ((visual_info->klass != TrueColor) &&
2833 (visual_info->klass != DirectColor))
2834 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2835 (int) pixel->colors,0);
2837 map_info->colormap=(Colormap) NULL;
2838 if (pixel != (XPixelInfo *) NULL)
2840 if (pixel->pixels != (unsigned long *) NULL)
2841 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2842 pixel->pixels=(unsigned long *) NULL;
2847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2851 % X G e t A n n o t a t e I n f o %
2855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2857 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2859 % The format of the XGetAnnotateInfo method is:
2861 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2863 % A description of each parameter follows:
2865 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2868 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2871 Initialize annotate structure.
2873 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2874 assert(annotate_info != (XAnnotateInfo *) NULL);
2877 annotate_info->width=0;
2878 annotate_info->height=0;
2879 annotate_info->stencil=ForegroundStencil;
2880 annotate_info->degrees=0.0;
2881 annotate_info->font_info=(XFontStruct *) NULL;
2882 annotate_info->text=(char *) NULL;
2883 *annotate_info->geometry='\0';
2884 annotate_info->previous=(XAnnotateInfo *) NULL;
2885 annotate_info->next=(XAnnotateInfo *) NULL;
2886 (void) XSupportsLocale();
2887 (void) XSetLocaleModifiers("");
2891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2895 % X G e t M a p I n f o %
2899 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2901 % XGetMapInfo() initializes the XStandardColormap structure.
2903 % The format of the XStandardColormap method is:
2905 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2906 % XStandardColormap *map_info)
2908 % A description of each parameter follows:
2910 % o colormap: Specifies the ID of the X server colormap.
2912 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2913 % returned from XGetVisualInfo.
2915 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2918 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2919 const Colormap colormap,XStandardColormap *map_info)
2922 Initialize map info.
2924 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2925 assert(visual_info != (XVisualInfo *) NULL);
2926 assert(map_info != (XStandardColormap *) NULL);
2927 map_info->colormap=colormap;
2928 map_info->red_max=visual_info->red_mask;
2929 map_info->red_mult=(unsigned long) (map_info->red_max != 0 ? 1 : 0);
2930 if (map_info->red_max != 0)
2931 while ((map_info->red_max & 0x01) == 0)
2933 map_info->red_max>>=1;
2934 map_info->red_mult<<=1;
2936 map_info->green_max=visual_info->green_mask;
2937 map_info->green_mult=(unsigned long) (map_info->green_max != 0 ? 1 : 0);
2938 if (map_info->green_max != 0)
2939 while ((map_info->green_max & 0x01) == 0)
2941 map_info->green_max>>=1;
2942 map_info->green_mult<<=1;
2944 map_info->blue_max=visual_info->blue_mask;
2945 map_info->blue_mult=(unsigned long) (map_info->blue_max != 0 ? 1 : 0);
2946 if (map_info->blue_max != 0)
2947 while ((map_info->blue_max & 0x01) == 0)
2949 map_info->blue_max>>=1;
2950 map_info->blue_mult<<=1;
2952 map_info->base_pixel=0;
2956 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2960 % X G e t P i x e l I n f o %
2964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2966 % XGetPixelPacket() initializes the PixelPacket structure.
2968 % The format of the XGetPixelPacket method is:
2970 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2971 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2972 % Image *image,XPixelInfo *pixel)
2975 % A description of each parameter follows:
2977 % o display: Specifies a connection to an X server; returned from
2980 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2981 % returned from XGetVisualInfo.
2983 % o map_info: If map_type is specified, this structure is initialized
2984 % with info from the Standard Colormap.
2986 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2988 % o image: the image.
2990 % o pixel: Specifies a pointer to a XPixelInfo structure.
2993 MagickExport void XGetPixelPacket(Display *display,
2994 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2995 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
2998 *PenColors[MaxNumberPens]=
3000 "#000000000000", /* black */
3001 "#00000000ffff", /* blue */
3002 "#0000ffffffff", /* cyan */
3003 "#0000ffff0000", /* green */
3004 "#bdbdbdbdbdbd", /* gray */
3005 "#ffff00000000", /* red */
3006 "#ffff0000ffff", /* magenta */
3007 "#ffffffff0000", /* yellow */
3008 "#ffffffffffff", /* white */
3009 "#bdbdbdbdbdbd", /* gray */
3010 "#bdbdbdbdbdbd" /* gray */
3026 Initialize pixel info.
3028 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3029 assert(display != (Display *) NULL);
3030 assert(visual_info != (XVisualInfo *) NULL);
3031 assert(map_info != (XStandardColormap *) NULL);
3032 assert(resource_info != (XResourceInfo *) NULL);
3033 assert(pixel != (XPixelInfo *) NULL);
3035 if (image != (Image *) NULL)
3036 if (image->storage_class == PseudoClass)
3037 pixel->colors=image->colors;
3038 packets=(unsigned int)
3039 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3040 if (pixel->pixels != (unsigned long *) NULL)
3041 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3042 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3043 sizeof(pixel->pixels));
3044 if (pixel->pixels == (unsigned long *) NULL)
3045 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3048 Set foreground color.
3050 colormap=map_info->colormap;
3051 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3052 &pixel->foreground_color);
3053 status=XParseColor(display,colormap,resource_info->foreground_color,
3054 &pixel->foreground_color);
3055 if (status == False)
3056 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3057 resource_info->foreground_color);
3058 pixel->foreground_color.pixel=
3059 XStandardPixel(map_info,&pixel->foreground_color);
3060 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3062 Set background color.
3064 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3065 status=XParseColor(display,colormap,resource_info->background_color,
3066 &pixel->background_color);
3067 if (status == False)
3068 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3069 resource_info->background_color);
3070 pixel->background_color.pixel=
3071 XStandardPixel(map_info,&pixel->background_color);
3072 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3076 (void) XParseColor(display,colormap,(char *) BorderColor,
3077 &pixel->border_color);
3078 status=XParseColor(display,colormap,resource_info->border_color,
3079 &pixel->border_color);
3080 if (status == False)
3081 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3082 resource_info->border_color);
3083 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3084 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3088 pixel->matte_color=pixel->background_color;
3089 if (resource_info->matte_color != (char *) NULL)
3092 Matte color is specified as a X resource or command line argument.
3094 status=XParseColor(display,colormap,resource_info->matte_color,
3095 &pixel->matte_color);
3096 if (status == False)
3097 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3098 resource_info->matte_color);
3099 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3100 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3103 Set highlight color.
3105 pixel->highlight_color.red=(unsigned short) ((
3106 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3107 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3108 pixel->highlight_color.green=(unsigned short) ((
3109 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3110 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3111 pixel->highlight_color.blue=(unsigned short) ((
3112 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3113 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3114 pixel->highlight_color.pixel=
3115 XStandardPixel(map_info,&pixel->highlight_color);
3116 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3120 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3121 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3122 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3123 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3124 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3125 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3126 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3127 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3131 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3132 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3133 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3134 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3135 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3136 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3137 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3138 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3142 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3143 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3144 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3145 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3146 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3147 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3148 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3149 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3153 for (i=0; i < MaxNumberPens; i++)
3155 (void) XParseColor(display,colormap,(char *) PenColors[i],
3156 &pixel->pen_colors[i]);
3157 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3158 &pixel->pen_colors[i]);
3159 if (status == False)
3160 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3161 resource_info->pen_colors[i]);
3162 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3163 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3165 pixel->box_color=pixel->background_color;
3166 pixel->pen_color=pixel->foreground_color;
3169 if (image != (Image *) NULL)
3171 if ((resource_info->gamma_correct != MagickFalse) &&
3172 (image->gamma != 0.0))
3181 Initialize map relative to display and image gamma.
3183 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3184 red_gamma=geometry_info.rho;
3185 green_gamma=geometry_info.sigma;
3186 if ((flags & SigmaValue) == 0)
3187 green_gamma=red_gamma;
3188 blue_gamma=geometry_info.xi;
3189 if ((flags & XiValue) == 0)
3190 blue_gamma=red_gamma;
3191 red_gamma*=image->gamma;
3192 green_gamma*=image->gamma;
3193 blue_gamma*=image->gamma;
3195 if (image->storage_class == PseudoClass)
3198 Initialize pixel array for images of type PseudoClass.
3200 for (i=0; i < (long) image->colors; i++)
3202 XGammaPixel(map_info,image->colormap+i);
3203 for (i=0; i < MaxNumberPens; i++)
3204 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3205 pixel->colors+=MaxNumberPens;
3211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3215 % X G e t R e s o u r c e C l a s s %
3219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3221 % XGetResourceClass() queries the X server for the specified resource name or
3222 % class. If the resource name or class is not defined in the database, the
3223 % supplied default value is returned.
3225 % The format of the XGetResourceClass method is:
3227 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3228 % const char *keyword,char *resource_default)
3230 % A description of each parameter follows:
3232 % o database: Specifies a resource database; returned from
3233 % XrmGetStringDatabase.
3235 % o client_name: Specifies the application name used to retrieve resource
3236 % info from the X server database.
3238 % o keyword: Specifies the keyword of the value being retrieved.
3240 % o resource_default: Specifies the default value to return if the query
3241 % fails to find the specified keyword/class.
3244 MagickExport char *XGetResourceClass(XrmDatabase database,
3245 const char *client_name,const char *keyword,char *resource_default)
3248 resource_class[MaxTextExtent],
3249 resource_name[MaxTextExtent];
3260 if (database == (XrmDatabase) NULL)
3261 return(resource_default);
3262 *resource_name='\0';
3263 *resource_class='\0';
3264 if (keyword != (char *) NULL)
3271 Initialize resource keyword and class.
3273 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3274 client_name,keyword);
3275 c=(int) (*client_name);
3276 if ((c >= XK_a) && (c <= XK_z))
3279 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3280 c-=(XK_agrave-XK_Agrave);
3282 if ((c >= XK_oslash) && (c <= XK_thorn))
3283 c-=(XK_oslash-XK_Ooblique);
3285 if ((k >= XK_a) && (k <= XK_z))
3288 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3289 k-=(XK_agrave-XK_Agrave);
3291 if ((k >= XK_oslash) && (k <= XK_thorn))
3292 k-=(XK_oslash-XK_Ooblique);
3293 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3294 client_name+1,k,keyword+1);
3296 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3298 if (status == False)
3299 return(resource_default);
3300 return(resource_value.addr);
3304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3308 % X G e t R e s o u r c e D a t a b a s e %
3312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3314 % XGetResourceDatabase() creates a new resource database and initializes it.
3316 % The format of the XGetResourceDatabase method is:
3318 % XrmDatabase XGetResourceDatabase(Display *display,
3319 % const char *client_name)
3321 % A description of each parameter follows:
3323 % o database: XGetResourceDatabase() returns the database after it is
3326 % o display: Specifies a connection to an X server; returned from
3329 % o client_name: Specifies the application name used to retrieve resource
3330 % info from the X server database.
3333 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3334 const char *client_name)
3337 filename[MaxTextExtent];
3349 if (display == (Display *) NULL)
3350 return((XrmDatabase) NULL);
3351 assert(client_name != (char *) NULL);
3353 Initialize resource database.
3356 (void) XGetDefault(display,(char *) client_name,"dummy");
3357 resource_database=XrmGetDatabase(display);
3359 Combine application database.
3361 if (client_name != (char *) NULL)
3364 Get basename of client.
3366 p=client_name+(strlen(client_name)-1);
3367 while ((p > client_name) && (*p != '/'))
3372 c=(int) (*client_name);
3373 if ((c >= XK_a) && (c <= XK_z))
3376 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3377 c-=(XK_agrave-XK_Agrave);
3379 if ((c >= XK_oslash) && (c <= XK_thorn))
3380 c-=(XK_oslash-XK_Ooblique);
3381 #if defined(X11_APPLICATION_PATH)
3382 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3383 X11_APPLICATION_PATH,c,client_name+1);
3384 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3386 if (XResourceManagerString(display) != (char *) NULL)
3389 Combine server database.
3391 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3392 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3395 Merge user preferences database.
3397 #if defined(X11_PREFERENCES_PATH)
3398 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3399 X11_PREFERENCES_PATH,client_name);
3400 ExpandFilename(filename);
3401 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3403 return(resource_database);
3407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3411 % X G e t R e s o u r c e I n f o %
3415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3417 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3419 % The format of the XGetResourceInfo method is:
3421 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3422 % const char *client_name,XResourceInfo *resource_info)
3424 % A description of each parameter follows:
3426 % o image_info: the image info.
3428 % o database: Specifies a resource database; returned from
3429 % XrmGetStringDatabase.
3431 % o client_name: Specifies the application name used to retrieve
3432 % resource info from the X server database.
3434 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3437 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3438 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3445 Initialize resource info fields.
3447 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3448 assert(resource_info != (XResourceInfo *) NULL);
3449 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3450 resource_info->resource_database=database;
3451 resource_info->image_info=(ImageInfo *) image_info;
3452 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3453 XMagickProgressMonitor,(void *) NULL);
3454 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3455 resource_info->close_server=MagickTrue;
3456 resource_info->client_name=AcquireString(client_name);
3457 resource_value=XGetResourceClass(database,client_name,"backdrop",
3459 resource_info->backdrop=IsMagickTrue(resource_value);
3460 resource_info->background_color=XGetResourceInstance(database,client_name,
3461 "background",(char *) "#d6d6d6d6d6d6");
3462 resource_info->border_color=XGetResourceInstance(database,client_name,
3463 "borderColor",BorderColor);
3464 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3466 resource_info->border_width=(unsigned int) StringToUnsignedLong(resource_value);
3467 resource_value=XGetResourceClass(database,client_name,"colormap",
3469 resource_info->colormap=UndefinedColormap;
3470 if (LocaleCompare("private",resource_value) == 0)
3471 resource_info->colormap=PrivateColormap;
3472 if (LocaleCompare("shared",resource_value) == 0)
3473 resource_info->colormap=SharedColormap;
3474 if (resource_info->colormap == UndefinedColormap)
3475 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3477 resource_value=XGetResourceClass(database,client_name,
3478 "colorRecovery",(char *) "False");
3479 resource_info->color_recovery=IsMagickTrue(resource_value);
3480 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3482 resource_info->confirm_exit=IsMagickTrue(resource_value);
3483 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3485 resource_info->confirm_edit=IsMagickTrue(resource_value);
3486 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3487 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3488 resource_info->display_gamma=XGetResourceClass(database,client_name,
3489 "displayGamma",(char *) "2.2");
3490 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3492 resource_info->display_warnings=IsMagickTrue(resource_value);
3493 resource_info->font=XGetResourceClass(database,client_name,"font",
3495 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3496 resource_info->font);
3497 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3499 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3500 (char *) "variable");
3501 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3503 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3505 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3506 (char *) "7x13bold");
3507 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3508 (char *) "8x13bold");
3509 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3510 (char *) "9x15bold");
3511 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3513 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3515 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3517 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3519 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3520 "foreground",ForegroundColor);
3521 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3523 resource_info->gamma_correct=IsMagickTrue(resource_value);
3524 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3525 client_name,"geometry",(char *) NULL));
3526 resource_value=XGetResourceClass(database,client_name,"gravity",
3528 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3529 MagickFalse,resource_value);
3530 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3531 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3532 "iconGeometry",(char *) NULL);
3533 resource_value=XGetResourceClass(database,client_name,"iconic",
3535 resource_info->iconic=IsMagickTrue(resource_value);
3536 resource_value=XGetResourceClass(database,client_name,"immutable",
3537 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3539 resource_info->immutable=IsMagickTrue(resource_value);
3540 resource_value=XGetResourceClass(database,client_name,"magnify",
3542 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3543 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3545 resource_info->matte_color=XGetResourceInstance(database,client_name,
3546 "mattecolor",(char *) NULL);
3547 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3548 "name",(char *) NULL));
3549 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3551 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3553 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3555 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3557 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3559 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3561 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3562 (char *) "magenta");
3563 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3565 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3567 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3569 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3571 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3572 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3573 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3574 resource_info->quantum=StringToLong(resource_value);
3575 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3576 "font",(char *) "fixed");
3577 resource_info->text_font=XGetResourceClass(database,client_name,
3578 "textFontList",resource_info->text_font);
3579 resource_info->title=XGetResourceClass(database,client_name,"title",
3581 resource_value=XGetResourceClass(database,client_name,"undoCache",
3583 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3584 resource_value=XGetResourceClass(database,client_name,"update",
3586 resource_info->update=IsMagickTrue(resource_value);
3587 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3589 resource_info->use_pixmap=IsMagickTrue(resource_value);
3590 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3592 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3593 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3595 resource_info->window_group=XGetResourceClass(database,client_name,
3596 "windowGroup",(char *) NULL);
3597 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3599 resource_info->write_filename=XGetResourceClass(database,client_name,
3600 "writeFilename",(char *) NULL);
3604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3608 % X G e t R e s o u r c e I n s t a n c e %
3612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3614 % XGetResourceInstance() queries the X server for the specified resource name.
3615 % If the resource name is not defined in the database, the supplied default
3616 % value is returned.
3618 % The format of the XGetResourceInstance method is:
3620 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3621 % const char *keyword,const char *resource_default)
3623 % A description of each parameter follows:
3625 % o database: Specifies a resource database; returned from
3626 % XrmGetStringDatabase.
3628 % o client_name: Specifies the application name used to retrieve
3629 % resource info from the X server database.
3631 % o keyword: Specifies the keyword of the value being retrieved.
3633 % o resource_default: Specifies the default value to return if the query
3634 % fails to find the specified keyword/class.
3637 MagickExport char *XGetResourceInstance(XrmDatabase database,
3638 const char *client_name,const char *keyword,const char *resource_default)
3642 resource_name[MaxTextExtent];
3650 if (database == (XrmDatabase) NULL)
3651 return((char *) resource_default);
3652 *resource_name='\0';
3653 if (keyword != (char *) NULL)
3654 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3656 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3658 if (status == False)
3659 return((char *) resource_default);
3660 return(resource_value.addr);
3664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3668 % X G e t S c r e e n D e n s i t y %
3672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3674 % XGetScreenDensity() returns the density of the X server screen in
3677 % The format of the XGetScreenDensity method is:
3679 % char *XGetScreenDensity(Display *display)
3681 % A description of each parameter follows:
3683 % o density: XGetScreenDensity() returns the density of the X screen in
3686 % o display: Specifies a connection to an X server; returned from
3690 MagickExport char *XGetScreenDensity(Display *display)
3693 density[MaxTextExtent];
3700 Set density as determined by screen size.
3702 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3703 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3704 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3705 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3706 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,
3708 return(GetPageGeometry(density));
3712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3716 + X G e t S u b w i n d o w %
3720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3722 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3723 % pointer and a button press.
3725 % The format of the XGetSubwindow method is:
3727 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3729 % A description of each parameter follows:
3731 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3732 % otherwise the subwindow is returned.
3734 % o display: Specifies a connection to an X server; returned from
3737 % o window: Specifies a pointer to a Window.
3739 % o x: the x coordinate of the pointer relative to the origin of the
3742 % o y: the y coordinate of the pointer relative to the origin of the
3746 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3759 assert(display != (Display *) NULL);
3760 source_window=XRootWindow(display,XDefaultScreen(display));
3761 if (window == (Window) NULL)
3762 return(source_window);
3763 target_window=window;
3766 status=XTranslateCoordinates(display,source_window,window,x,y,
3767 &x_offset,&y_offset,&target_window);
3770 if (target_window == (Window) NULL)
3772 source_window=window;
3773 window=target_window;
3777 if (target_window == (Window) NULL)
3778 target_window=window;
3779 return(target_window);
3783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3787 % X G e t W i n d o w C o l o r %
3791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3793 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3796 % The format of the XGetWindowColor method is:
3798 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3801 % A description of each parameter follows:
3803 % o display: Specifies a connection to an X server; returned from
3806 % o windows: Specifies a pointer to a XWindows structure.
3808 % o name: the name of the color if found in the X Color Database is
3809 % returned in this character string.
3812 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3813 XWindows *windows,char *name)
3844 Choose a pixel from the X server.
3846 assert(display != (Display *) NULL);
3847 assert(name != (char *) NULL);
3848 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3850 target_window=XSelectWindow(display,&crop_info);
3851 if (target_window == (Window) NULL)
3852 return(MagickFalse);
3853 root_window=XRootWindow(display,XDefaultScreen(display));
3854 client_window=target_window;
3855 if (target_window != root_window)
3863 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3864 if (status != False)
3866 client_window=XClientWindow(display,target_window);
3867 target_window=client_window;
3871 Verify window is viewable.
3873 status=XGetWindowAttributes(display,target_window,&window_attributes);
3874 if ((status == False) || (window_attributes.map_state != IsViewable))
3875 return(MagickFalse);
3879 (void) XTranslateCoordinates(display,root_window,target_window,
3880 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3881 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3882 if (ximage == (XImage *) NULL)
3883 return(MagickFalse);
3884 color.pixel=XGetPixel(ximage,0,0);
3885 XDestroyImage(ximage);
3887 Match color against the color database.
3889 (void) XQueryColor(display,window_attributes.colormap,&color);
3890 pixel.red=ScaleShortToQuantum(color.red);
3891 pixel.green=ScaleShortToQuantum(color.green);
3892 pixel.blue=ScaleShortToQuantum(color.blue);
3893 pixel.opacity=OpaqueOpacity;
3894 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3895 &windows->image.image->exception);
3900 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3904 + X G e t W i n d o w I m a g e %
3908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3910 % XGetWindowImage() reads an image from the target X window and returns it.
3911 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3912 % target image with each child image in an optimized fashion. Any child
3913 % window that have the same visual, colormap, and are contained by its parent
3916 % The format of the XGetWindowImage method is:
3918 % Image *XGetWindowImage(Display *display,const Window window,
3919 % const unsigned int borders,const unsigned int level)
3921 % A description of each parameter follows:
3923 % o display: Specifies a connection to an X server; returned from
3926 % o window: Specifies the window to obtain the image from.
3928 % o borders: Specifies whether borders pixels are to be saved with
3931 % o level: Specifies an unsigned integer representing the level of
3932 % decent in the window hierarchy. This value must be zero or one on
3933 % the initial call to XGetWindowImage. A value of zero returns after
3934 % one call. A value of one causes the function to descend the window
3935 % hierarchy and overlay the target image with each subwindow image.
3938 static Image *XGetWindowImage(Display *display,const Window window,
3939 const unsigned int borders,const unsigned int level)
3941 typedef struct _ColormapInfo
3949 struct _ColormapInfo
3953 typedef struct _WindowInfo
3985 register IndexPacket
3992 *colormap_info = (ColormapInfo *) NULL;
4012 Verify window is viewable.
4014 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4015 assert(display != (Display *) NULL);
4016 status=XGetWindowAttributes(display,window,&window_attributes);
4017 if ((status == False) || (window_attributes.map_state != IsViewable))
4018 return((Image *) NULL);
4020 Cropping rectangle is relative to root window.
4022 root_window=XRootWindow(display,XDefaultScreen(display));
4023 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4025 crop_info.x=(long) x_offset;
4026 crop_info.y=(long) y_offset;
4027 crop_info.width=(unsigned long) window_attributes.width;
4028 crop_info.height=(unsigned long) window_attributes.height;
4029 if (borders != MagickFalse)
4032 Include border in image.
4034 crop_info.x-=(long) window_attributes.border_width;
4035 crop_info.y-=(long) window_attributes.border_width;
4036 crop_info.width+=(unsigned long) (window_attributes.border_width << 1);
4037 crop_info.height+=(unsigned long) (window_attributes.border_width << 1);
4040 Crop to root window.
4042 if (crop_info.x < 0)
4044 crop_info.width+=crop_info.x;
4047 if (crop_info.y < 0)
4049 crop_info.height+=crop_info.y;
4052 display_width=XDisplayWidth(display,XDefaultScreen(display));
4053 if ((int) (crop_info.x+crop_info.width) > display_width)
4054 crop_info.width=(unsigned long) (display_width-crop_info.x);
4055 display_height=XDisplayHeight(display,XDefaultScreen(display));
4056 if ((int) (crop_info.y+crop_info.height) > display_height)
4057 crop_info.height=(unsigned long) (display_height-crop_info.y);
4059 Initialize window info attributes.
4061 if (number_windows >= max_windows)
4064 Allocate or resize window info buffer.
4067 if (window_info == (WindowInfo *) NULL)
4068 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4069 sizeof(*window_info));
4071 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4072 max_windows,sizeof(*window_info));
4074 if (window_info == (WindowInfo *) NULL)
4076 ThrowXWindowFatalException(ResourceLimitError,
4077 "MemoryAllocationFailed","...");
4078 return((Image *) NULL);
4080 id=number_windows++;
4081 window_info[id].window=window;
4082 window_info[id].visual=window_attributes.visual;
4083 window_info[id].colormap=window_attributes.colormap;
4084 window_info[id].bounds.x1=(short) crop_info.x;
4085 window_info[id].bounds.y1=(short) crop_info.y;
4086 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4087 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4088 crop_info.x-=x_offset;
4089 crop_info.y-=y_offset;
4090 window_info[id].crop_info=crop_info;
4100 Descend the window hierarchy.
4102 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4103 &children,&number_children);
4104 for (i=0; i < id; i++)
4105 if ((window_info[i].window == window_info[id].parent) &&
4106 (window_info[i].visual == window_info[id].visual) &&
4107 (window_info[i].colormap == window_info[id].colormap))
4109 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4110 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4111 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4112 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4115 Eliminate windows not circumscribed by their parent.
4121 if ((status == True) && (number_children != 0))
4123 for (i=0; i < (int) number_children; i++)
4124 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4125 (void) XFree((void *) children);
4150 register PixelPacket
4153 register unsigned long
4166 Get X image for each window in the list.
4168 image=NewImageList();
4169 for (id=0; id < number_windows; id++)
4172 Does target window intersect top level window?
4175 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4176 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4177 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4178 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4179 MagickTrue : MagickFalse;
4181 Is target window contained by another window with the same colormap?
4183 for (j=0; j < id; j++)
4184 if ((window_info[id].visual == window_info[j].visual) &&
4185 (window_info[id].colormap == window_info[j].colormap))
4187 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4188 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4189 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4190 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4194 if ((window_info[id].visual != window_info[j].visual) ||
4195 (window_info[id].colormap != window_info[j].colormap))
4197 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4198 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4199 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4200 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4203 if (import == MagickFalse)
4208 ximage=XGetImage(display,window_info[id].window,(int)
4209 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4210 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4211 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4212 if (ximage == (XImage *) NULL)
4215 Initialize window colormap.
4218 colors=(XColor *) NULL;
4219 if (window_info[id].colormap != (Colormap) NULL)
4225 Search colormap list for window colormap.
4227 number_colors=(unsigned int) window_info[id].visual->map_entries;
4228 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4229 if (p->colormap == window_info[id].colormap)
4231 if (p == (ColormapInfo *) NULL)
4234 Get the window colormap.
4236 colors=(XColor *) AcquireQuantumMemory(number_colors,
4238 if (colors == (XColor *) NULL)
4240 XDestroyImage(ximage);
4241 return((Image *) NULL);
4243 if ((window_info[id].visual->klass != DirectColor) &&
4244 (window_info[id].visual->klass != TrueColor))
4245 for (i=0; i < (int) number_colors; i++)
4247 colors[i].pixel=(unsigned long) i;
4261 DirectColor or TrueColor visual.
4266 red_bit=window_info[id].visual->red_mask &
4267 (~(window_info[id].visual->red_mask)+1);
4268 green_bit=window_info[id].visual->green_mask &
4269 (~(window_info[id].visual->green_mask)+1);
4270 blue_bit=window_info[id].visual->blue_mask &
4271 (~(window_info[id].visual->blue_mask)+1);
4272 for (i=0; i < (int) number_colors; i++)
4274 colors[i].pixel=red | green | blue;
4277 if (red > window_info[id].visual->red_mask)
4280 if (green > window_info[id].visual->green_mask)
4283 if (blue > window_info[id].visual->blue_mask)
4287 (void) XQueryColors(display,window_info[id].colormap,colors,
4288 (int) number_colors);
4290 Append colormap to colormap list.
4292 p=(ColormapInfo *) AcquireAlignedMemory(1,sizeof(*p));
4293 if (p == (ColormapInfo *) NULL)
4294 return((Image *) NULL);
4295 p->colormap=window_info[id].colormap;
4297 p->next=colormap_info;
4303 Allocate image structure.
4305 composite_image=AcquireImage((ImageInfo *) NULL);
4306 if (composite_image == (Image *) NULL)
4308 XDestroyImage(ximage);
4309 return((Image *) NULL);
4312 Convert X image to MIFF format.
4314 if ((window_info[id].visual->klass != TrueColor) &&
4315 (window_info[id].visual->klass != DirectColor))
4316 composite_image->storage_class=PseudoClass;
4317 composite_image->columns=(unsigned long) ximage->width;
4318 composite_image->rows=(unsigned long) ximage->height;
4319 exception=(&composite_image->exception);
4320 switch (composite_image->storage_class)
4325 register unsigned long
4338 Determine shift and mask for red, green, and blue.
4340 red_mask=window_info[id].visual->red_mask;
4342 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4347 green_mask=window_info[id].visual->green_mask;
4349 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4354 blue_mask=window_info[id].visual->blue_mask;
4356 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4362 Convert X image to DirectClass packets.
4364 if ((number_colors != 0) &&
4365 (window_info[id].visual->klass == DirectColor))
4366 for (y=0; y < (int) composite_image->rows; y++)
4368 q=QueueAuthenticPixels(composite_image,0,y,
4369 composite_image->columns,1,exception);
4370 if (q == (PixelPacket *) NULL)
4372 for (x=0; x < (int) composite_image->columns; x++)
4374 pixel=XGetPixel(ximage,x,y);
4375 index=(pixel >> red_shift) & red_mask;
4376 q->red=ScaleShortToQuantum(colors[index].red);
4377 index=(pixel >> green_shift) & green_mask;
4378 q->green=ScaleShortToQuantum(colors[index].green);
4379 index=(pixel >> blue_shift) & blue_mask;
4380 q->blue=ScaleShortToQuantum(colors[index].blue);
4383 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4387 for (y=0; y < (int) composite_image->rows; y++)
4389 q=QueueAuthenticPixels(composite_image,0,y,
4390 composite_image->columns,1,exception);
4391 if (q == (PixelPacket *) NULL)
4393 for (x=0; x < (int) composite_image->columns; x++)
4395 pixel=XGetPixel(ximage,x,y);
4396 color=(pixel >> red_shift) & red_mask;
4397 color=(65535UL*color)/red_mask;
4398 q->red=ScaleShortToQuantum((unsigned short) color);
4399 color=(pixel >> green_shift) & green_mask;
4400 color=(65535UL*color)/green_mask;
4401 q->green=ScaleShortToQuantum((unsigned short) color);
4402 color=(pixel >> blue_shift) & blue_mask;
4403 color=(65535UL*color)/blue_mask;
4404 q->blue=ScaleShortToQuantum((unsigned short) color);
4407 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4417 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4419 XDestroyImage(ximage);
4420 composite_image=DestroyImage(composite_image);
4421 return((Image *) NULL);
4423 for (i=0; i < (int) composite_image->colors; i++)
4425 composite_image->colormap[colors[i].pixel].red=
4426 ScaleShortToQuantum(colors[i].red);
4427 composite_image->colormap[colors[i].pixel].green=
4428 ScaleShortToQuantum(colors[i].green);
4429 composite_image->colormap[colors[i].pixel].blue=
4430 ScaleShortToQuantum(colors[i].blue);
4433 Convert X image to PseudoClass packets.
4435 for (y=0; y < (int) composite_image->rows; y++)
4437 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4438 if (q == (PixelPacket *) NULL)
4440 indexes=GetAuthenticIndexQueue(composite_image);
4441 for (x=0; x < (int) composite_image->columns; x++)
4443 index=(IndexPacket) XGetPixel(ximage,x,y);
4445 *q++=composite_image->colormap[(long) index];
4447 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4453 XDestroyImage(ximage);
4454 if (image == (Image *) NULL)
4456 image=composite_image;
4460 Composite any children in back-to-front order.
4462 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4463 &x_offset,&y_offset,&child);
4464 x_offset-=(int) crop_info.x;
4467 y_offset-=(int) crop_info.y;
4470 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4474 Relinquish resources.
4476 while (colormap_info != (ColormapInfo *) NULL)
4478 next=colormap_info->next;
4479 colormap_info->colors=(XColor *)
4480 RelinquishMagickMemory(colormap_info->colors);
4481 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4485 Relinquish resources and restore initial state.
4487 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4490 colormap_info=(ColormapInfo *) NULL;
4493 return((Image *) NULL);
4497 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4501 % X G e t W i n d o w I n f o %
4505 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4507 % XGetWindowInfo() initializes the XWindowInfo structure.
4509 % The format of the XGetWindowInfo method is:
4511 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4512 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4513 % XResourceInfo *resource_info,XWindowInfo *window)
4514 % resource_info,window)
4516 % A description of each parameter follows:
4518 % o display: Specifies a connection to an X server; returned from
4521 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4522 % returned from XGetVisualInfo.
4524 % o map_info: If map_type is specified, this structure is initialized
4525 % with info from the Standard Colormap.
4527 % o pixel: Specifies a pointer to a XPixelInfo structure.
4529 % o font_info: Specifies a pointer to a XFontStruct structure.
4531 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4534 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4535 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4536 XResourceInfo *resource_info,XWindowInfo *window)
4539 Initialize window info.
4541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4542 assert(display != (Display *) NULL);
4543 assert(visual_info != (XVisualInfo *) NULL);
4544 assert(map_info != (XStandardColormap *) NULL);
4545 assert(pixel != (XPixelInfo *) NULL);
4546 assert(resource_info != (XResourceInfo *) NULL);
4547 assert(window != (XWindowInfo *) NULL);
4548 if (window->id != (Window) NULL)
4550 if (window->cursor != (Cursor) NULL)
4551 (void) XFreeCursor(display,window->cursor);
4552 if (window->busy_cursor != (Cursor) NULL)
4553 (void) XFreeCursor(display,window->busy_cursor);
4554 if (window->highlight_stipple != (Pixmap) NULL)
4555 (void) XFreePixmap(display,window->highlight_stipple);
4556 if (window->shadow_stipple != (Pixmap) NULL)
4557 (void) XFreePixmap(display,window->shadow_stipple);
4558 if (window->name == (char *) NULL)
4559 window->name=AcquireString("");
4560 if (window->icon_name == (char *) NULL)
4561 window->icon_name=AcquireString("");
4566 Initialize these attributes just once.
4568 window->id=(Window) NULL;
4569 if (window->name == (char *) NULL)
4570 window->name=AcquireString("");
4571 if (window->icon_name == (char *) NULL)
4572 window->icon_name=AcquireString("");
4573 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4574 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4575 window->ximage=(XImage *) NULL;
4576 window->matte_image=(XImage *) NULL;
4577 window->pixmap=(Pixmap) NULL;
4578 window->matte_pixmap=(Pixmap) NULL;
4579 window->mapped=MagickFalse;
4580 window->stasis=MagickFalse;
4581 window->shared_memory=MagickTrue;
4582 window->segment_info=(void *) NULL;
4583 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4588 if (window->segment_info == (void *) NULL)
4589 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4590 segment_info=(XShmSegmentInfo *) window->segment_info;
4591 segment_info[0].shmid=(-1);
4592 segment_info[0].shmaddr=(char *) NULL;
4593 segment_info[1].shmid=(-1);
4594 segment_info[1].shmaddr=(char *) NULL;
4599 Initialize these attributes every time function is called.
4601 window->screen=visual_info->screen;
4602 window->root=XRootWindow(display,visual_info->screen);
4603 window->visual=visual_info->visual;
4604 window->storage_class=(unsigned int) visual_info->klass;
4605 window->depth=(unsigned int) visual_info->depth;
4606 window->visual_info=visual_info;
4607 window->map_info=map_info;
4608 window->pixel_info=pixel;
4609 window->font_info=font_info;
4610 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4611 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4612 window->geometry=(char *) NULL;
4613 window->icon_geometry=(char *) NULL;
4614 if (resource_info->icon_geometry != (char *) NULL)
4615 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4616 window->crop_geometry=(char *) NULL;
4617 window->flags=(unsigned long) PSize;
4620 window->min_width=1;
4621 window->min_height=1;
4622 window->width_inc=1;
4623 window->height_inc=1;
4624 window->border_width=resource_info->border_width;
4625 window->annotate_context=pixel->annotate_context;
4626 window->highlight_context=pixel->highlight_context;
4627 window->widget_context=pixel->widget_context;
4628 window->shadow_stipple=(Pixmap) NULL;
4629 window->highlight_stipple=(Pixmap) NULL;
4630 window->use_pixmap=MagickTrue;
4631 window->immutable=MagickFalse;
4632 window->shape=MagickFalse;
4634 window->mask=(unsigned long) (CWBackingStore | CWBackPixel | CWBackPixmap |
4635 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4636 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4637 window->attributes.background_pixel=pixel->background_color.pixel;
4638 window->attributes.background_pixmap=(Pixmap) NULL;
4639 window->attributes.bit_gravity=ForgetGravity;
4640 window->attributes.backing_store=WhenMapped;
4641 window->attributes.save_under=MagickTrue;
4642 window->attributes.border_pixel=pixel->border_color.pixel;
4643 window->attributes.colormap=map_info->colormap;
4644 window->attributes.cursor=window->cursor;
4645 window->attributes.do_not_propagate_mask=NoEventMask;
4646 window->attributes.event_mask=NoEventMask;
4647 window->attributes.override_redirect=MagickFalse;
4648 window->attributes.win_gravity=NorthWestGravity;
4649 window->orphan=MagickFalse;
4653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4657 % X H i g h l i g h t E l l i p s e %
4661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4663 % XHighlightEllipse() puts a border on the X server around a region defined by
4666 % The format of the XHighlightEllipse method is:
4668 % void XHighlightEllipse(Display *display,Window window,
4669 % GC annotate_context,const RectangleInfo *highlight_info)
4671 % A description of each parameter follows:
4673 % o display: Specifies a connection to an X server; returned from
4676 % o window: Specifies a pointer to a Window structure.
4678 % o annotate_context: Specifies a pointer to a GC structure.
4680 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4681 % contains the extents of any highlighting rectangle.
4684 MagickExport void XHighlightEllipse(Display *display,Window window,
4685 GC annotate_context,const RectangleInfo *highlight_info)
4687 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4688 assert(display != (Display *) NULL);
4689 assert(window != (Window) NULL);
4690 assert(annotate_context != (GC) NULL);
4691 assert(highlight_info != (RectangleInfo *) NULL);
4692 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4694 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4695 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4696 (unsigned int) highlight_info->height-1,0,360*64);
4697 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4698 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4699 (unsigned int) highlight_info->height-3,0,360*64);
4703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4707 % X H i g h l i g h t L i n e %
4711 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4713 % XHighlightLine() puts a border on the X server around a region defined by
4716 % The format of the XHighlightLine method is:
4718 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4719 % const XSegment *highlight_info)
4721 % A description of each parameter follows:
4723 % o display: Specifies a connection to an X server; returned from
4726 % o window: Specifies a pointer to a Window structure.
4728 % o annotate_context: Specifies a pointer to a GC structure.
4730 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4731 % contains the extents of any highlighting rectangle.
4734 MagickExport void XHighlightLine(Display *display,Window window,
4735 GC annotate_context,const XSegment *highlight_info)
4737 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4738 assert(display != (Display *) NULL);
4739 assert(window != (Window) NULL);
4740 assert(annotate_context != (GC) NULL);
4741 assert(highlight_info != (XSegment *) NULL);
4742 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4743 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4751 % X H i g h l i g h t R e c t a n g l e %
4755 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4757 % XHighlightRectangle() puts a border on the X server around a region defined
4758 % by highlight_info.
4760 % The format of the XHighlightRectangle method is:
4762 % void XHighlightRectangle(Display *display,Window window,
4763 % GC annotate_context,const RectangleInfo *highlight_info)
4765 % A description of each parameter follows:
4767 % o display: Specifies a connection to an X server; returned from
4770 % o window: Specifies a pointer to a Window structure.
4772 % o annotate_context: Specifies a pointer to a GC structure.
4774 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4775 % contains the extents of any highlighting rectangle.
4778 MagickExport void XHighlightRectangle(Display *display,Window window,
4779 GC annotate_context,const RectangleInfo *highlight_info)
4781 assert(display != (Display *) NULL);
4782 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4783 assert(window != (Window) NULL);
4784 assert(annotate_context != (GC) NULL);
4785 assert(highlight_info != (RectangleInfo *) NULL);
4786 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4788 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4789 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4790 (unsigned int) highlight_info->height-1);
4791 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4792 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4793 (unsigned int) highlight_info->height-3);
4797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4801 % X I m p o r t I m a g e %
4805 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4807 % XImportImage() reads an image from an X window.
4809 % The format of the XImportImage method is:
4811 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4813 % A description of each parameter follows:
4815 % o image_info: the image info.
4817 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4820 MagickExport Image *XImportImage(const ImageInfo *image_info,
4821 XImportInfo *ximage_info)
4854 Open X server connection.
4856 assert(image_info != (const ImageInfo *) NULL);
4857 assert(image_info->signature == MagickSignature);
4858 if (image_info->debug != MagickFalse)
4859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4860 image_info->filename);
4861 assert(ximage_info != (XImportInfo *) NULL);
4862 display=XOpenDisplay(image_info->server_name);
4863 if (display == (Display *) NULL)
4865 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4866 XDisplayName(image_info->server_name));
4867 return((Image *) NULL);
4870 Set our forgiving exception handler.
4872 (void) XSetErrorHandler(XError);
4874 Select target window.
4880 root=XRootWindow(display,XDefaultScreen(display));
4881 target=(Window) NULL;
4882 if ((image_info->filename != (char *) NULL) &&
4883 (*image_info->filename != '\0'))
4885 if (LocaleCompare(image_info->filename,"root") == 0)
4890 Select window by ID or name.
4892 if (isdigit((unsigned char) *image_info->filename) != 0)
4893 target=XWindowByID(display,root,(Window)
4894 strtol(image_info->filename,(char **) NULL,0));
4895 if (target == (Window) NULL)
4896 target=XWindowByName(display,root,image_info->filename);
4897 if (target == (Window) NULL)
4898 ThrowXWindowFatalException(XServerError,
4899 "NoWindowWithSpecifiedIDExists",image_info->filename);
4903 If target window is not defined, interactively select one.
4905 prior_target=target;
4906 if (target == (Window) NULL)
4907 target=XSelectWindow(display,&crop_info);
4908 if (target == (Window) NULL)
4909 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4910 image_info->filename);
4911 client=target; /* obsolete */
4917 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4918 if (status != False)
4926 Find window manager frame.
4928 status=XQueryTree(display,target,&root,&parent,&children,&d);
4929 if ((status != False) && (children != (Window *) NULL))
4930 (void) XFree((char *) children);
4931 if ((status == False) || (parent == (Window) NULL) ||
4939 client=XClientWindow(display,target);
4940 if (ximage_info->frame == MagickFalse)
4942 if ((ximage_info->frame == MagickFalse) &&
4943 (prior_target != MagickFalse))
4944 target=prior_target;
4945 XDelay(display,SuspendTime << 4);
4948 if (ximage_info->screen)
4960 Obtain window image directly from screen.
4962 status=XGetWindowAttributes(display,target,&window_attributes);
4963 if (status == False)
4965 ThrowXWindowFatalException(XServerError,
4966 "UnableToReadXWindowAttributes",image_info->filename);
4967 (void) XCloseDisplay(display);
4968 return((Image *) NULL);
4970 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4973 crop_info.width=(unsigned long) window_attributes.width;
4974 crop_info.height=(unsigned long) window_attributes.height;
4975 if (ximage_info->borders)
4978 Include border in image.
4980 crop_info.x-=window_attributes.border_width;
4981 crop_info.y-=window_attributes.border_width;
4982 crop_info.width+=window_attributes.border_width << 1;
4983 crop_info.height+=window_attributes.border_width << 1;
4988 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4991 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4992 if ((status == True) && (number_windows > 0))
4994 ximage_info->descend=MagickTrue;
4995 (void) XFree ((char *) children);
4997 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
4998 if (number_colormaps > 0)
5000 if (number_colormaps > 1)
5001 ximage_info->descend=MagickTrue;
5002 (void) XFree((char *) colormaps);
5005 Alert the user not to alter the screen.
5007 if (ximage_info->silent == MagickFalse)
5008 (void) XBell(display,0);
5010 Get image by window id.
5012 (void) XGrabServer(display);
5013 image=XGetWindowImage(display,target,ximage_info->borders,
5014 ximage_info->descend ? 1U : 0U);
5015 (void) XUngrabServer(display);
5016 if (image == (Image *) NULL)
5017 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5018 image_info->filename)
5021 (void) CopyMagickString(image->filename,image_info->filename,
5023 if ((crop_info.width != 0) && (crop_info.height != 0))
5030 Crop image as defined by the cropping rectangle.
5032 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5033 if (clone_image != (Image *) NULL)
5035 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5036 if (crop_image != (Image *) NULL)
5038 image=DestroyImage(image);
5043 status=XGetWMName(display,target,&window_name);
5046 if ((image_info->filename != (char *) NULL) &&
5047 (*image_info->filename == '\0'))
5048 (void) CopyMagickString(image->filename,(char *) window_name.value,
5049 (size_t) window_name.nitems+1);
5050 (void) XFree((void *) window_name.value);
5053 if (ximage_info->silent == MagickFalse)
5056 Alert the user we're done.
5058 (void) XBell(display,0);
5059 (void) XBell(display,0);
5061 (void) XCloseDisplay(display);
5066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5070 % X I n i t i a l i z e W i n d o w s %
5074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5076 % XInitializeWindows() initializes the XWindows structure.
5078 % The format of the XInitializeWindows method is:
5080 % XWindows *XInitializeWindows(Display *display,
5081 % XResourceInfo *resource_info)
5083 % A description of each parameter follows:
5085 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5087 % o display: Specifies a connection to an X server; returned from
5090 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5093 MagickExport XWindows *XInitializeWindows(Display *display,
5094 XResourceInfo *resource_info)
5103 Allocate windows structure.
5105 windows=(XWindows *) AcquireAlignedMemory(1,sizeof(*windows));
5106 if (windows == (XWindows *) NULL)
5108 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5110 return((XWindows *) NULL);
5112 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5113 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5114 sizeof(*windows->pixel_info));
5115 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5116 sizeof(*windows->icon_pixel));
5117 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5118 sizeof(*windows->icon_resources));
5119 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5120 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5121 (windows->icon_resources == (XResourceInfo *) NULL))
5123 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5125 return((XWindows *) NULL);
5128 Initialize windows structure.
5130 windows->display=display;
5131 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5132 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5133 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5134 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5135 windows->im_remote_command=
5136 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5137 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5138 windows->im_update_colormap=
5139 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5140 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5141 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5142 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5143 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5144 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5145 #if defined(__WINDOWS__)
5146 (void) XSynchronize(display,IsWindows95());
5148 if (IsEventLogging())
5150 (void) XSynchronize(display,MagickTrue);
5151 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5152 GetMagickVersion((unsigned long *) NULL));
5153 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5154 (void) LogMagickEvent(X11Event,GetMagickModule(),
5155 " Window Manager: 0x%lx",windows->wm_protocols);
5156 (void) LogMagickEvent(X11Event,GetMagickModule(),
5157 " delete window: 0x%lx",windows->wm_delete_window);
5158 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5159 windows->wm_take_focus);
5160 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5161 windows->im_protocols);
5162 (void) LogMagickEvent(X11Event,GetMagickModule(),
5163 " remote command: 0x%lx",windows->im_remote_command);
5164 (void) LogMagickEvent(X11Event,GetMagickModule(),
5165 " update widget: 0x%lx",windows->im_update_widget);
5166 (void) LogMagickEvent(X11Event,GetMagickModule(),
5167 " update colormap: 0x%lx",windows->im_update_colormap);
5168 (void) LogMagickEvent(X11Event,GetMagickModule(),
5169 " former image: 0x%lx",windows->im_former_image);
5170 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5171 windows->im_next_image);
5172 (void) LogMagickEvent(X11Event,GetMagickModule(),
5173 " retain colors: 0x%lx",windows->im_retain_colors);
5174 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5176 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5177 windows->dnd_protocols);
5180 Allocate standard colormap.
5182 windows->map_info=XAllocStandardColormap();
5183 windows->icon_map=XAllocStandardColormap();
5184 if ((windows->map_info == (XStandardColormap *) NULL) ||
5185 (windows->icon_map == (XStandardColormap *) NULL))
5186 ThrowXWindowFatalException(ResourceLimitFatalError,
5187 "MemoryAllocationFailed","...");
5188 windows->map_info->colormap=(Colormap) NULL;
5189 windows->icon_map->colormap=(Colormap) NULL;
5190 windows->pixel_info->pixels=(unsigned long *) NULL;
5191 windows->pixel_info->annotate_context=(GC) NULL;
5192 windows->pixel_info->highlight_context=(GC) NULL;
5193 windows->pixel_info->widget_context=(GC) NULL;
5194 windows->font_info=(XFontStruct *) NULL;
5195 windows->icon_pixel->annotate_context=(GC) NULL;
5196 windows->icon_pixel->pixels=(unsigned long *) NULL;
5200 *windows->icon_resources=(*resource_info);
5201 windows->icon_resources->visual_type=(char *) "default";
5202 windows->icon_resources->colormap=SharedColormap;
5203 windows->visual_info=
5204 XBestVisualInfo(display,windows->map_info,resource_info);
5205 windows->icon_visual=
5206 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5207 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5208 (windows->icon_visual == (XVisualInfo *) NULL))
5209 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5210 resource_info->visual_type);
5211 if (IsEventLogging())
5213 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5214 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5215 windows->visual_info->visualid);
5216 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5217 XVisualClassName(windows->visual_info->klass));
5218 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5219 windows->visual_info->depth);
5220 (void) LogMagickEvent(X11Event,GetMagickModule(),
5221 " size of colormap: %d entries",windows->visual_info->colormap_size);
5222 (void) LogMagickEvent(X11Event,GetMagickModule(),
5223 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5224 windows->visual_info->red_mask,windows->visual_info->green_mask,
5225 windows->visual_info->blue_mask);
5226 (void) LogMagickEvent(X11Event,GetMagickModule(),
5227 " significant bits in color: %d bits",
5228 windows->visual_info->bits_per_rgb);
5231 Allocate class and manager hints.
5233 windows->class_hints=XAllocClassHint();
5234 windows->manager_hints=XAllocWMHints();
5235 if ((windows->class_hints == (XClassHint *) NULL) ||
5236 (windows->manager_hints == (XWMHints *) NULL))
5237 ThrowXWindowFatalException(ResourceLimitFatalError,
5238 "MemoryAllocationFailed","...");
5240 Determine group leader if we have one.
5242 root_window=XRootWindow(display,windows->visual_info->screen);
5243 windows->group_leader.id=(Window) NULL;
5244 if (resource_info->window_group != (char *) NULL)
5246 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5247 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5248 strtol((char *) resource_info->window_group,(char **) NULL,0));
5249 if (windows->group_leader.id == (Window) NULL)
5250 windows->group_leader.id=
5251 XWindowByName(display,root_window,resource_info->window_group);
5257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5261 % X M a k e C u r s o r %
5265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5267 % XMakeCursor() creates a crosshairs X11 cursor.
5269 % The format of the XMakeCursor method is:
5271 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5272 % char *background_color,char *foreground_color)
5274 % A description of each parameter follows:
5276 % o display: Specifies a connection to an X server; returned from
5279 % o window: Specifies the ID of the window for which the cursor is
5282 % o colormap: Specifies the ID of the colormap from which the background
5283 % and foreground color will be retrieved.
5285 % o background_color: Specifies the color to use for the cursor background.
5287 % o foreground_color: Specifies the color to use for the cursor foreground.
5290 MagickExport Cursor XMakeCursor(Display *display,Window window,
5291 Colormap colormap,char *background_color,char *foreground_color)
5293 #define scope_height 17
5294 #define scope_x_hot 8
5295 #define scope_y_hot 8
5296 #define scope_width 17
5298 static const unsigned char
5301 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5302 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5303 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5304 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5305 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5309 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5310 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5311 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5312 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5313 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5327 assert(display != (Display *) NULL);
5328 assert(window != (Window) NULL);
5329 assert(colormap != (Colormap) NULL);
5330 assert(background_color != (char *) NULL);
5331 assert(foreground_color != (char *) NULL);
5332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5333 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5335 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5336 scope_width,scope_height);
5337 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5339 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5340 return((Cursor) NULL);
5342 (void) XParseColor(display,colormap,background_color,&background);
5343 (void) XParseColor(display,colormap,foreground_color,&foreground);
5344 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5345 scope_x_hot,scope_y_hot);
5346 (void) XFreePixmap(display,source);
5347 (void) XFreePixmap(display,mask);
5352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5356 % X M a k e I m a g e %
5360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5362 % XMakeImage() creates an X11 image. If the image size differs from the X11
5363 % image size, the image is first resized.
5365 % The format of the XMakeImage method is:
5367 % MagickBooleanType XMakeImage(Display *display,
5368 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5369 % unsigned int width,unsigned int height)
5371 % A description of each parameter follows:
5373 % o display: Specifies a connection to an X server; returned from
5376 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5378 % o window: Specifies a pointer to a XWindowInfo structure.
5380 % o image: the image.
5382 % o width: Specifies the width in pixels of the rectangular area to
5385 % o height: Specifies the height in pixels of the rectangular area to
5389 MagickExport MagickBooleanType XMakeImage(Display *display,
5390 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5391 unsigned int width,unsigned int height)
5393 #define CheckOverflowException(length,width,height) \
5394 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5407 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5408 assert(display != (Display *) NULL);
5409 assert(resource_info != (XResourceInfo *) NULL);
5410 assert(window != (XWindowInfo *) NULL);
5412 assert(height != 0);
5413 if ((window->width == 0) || (window->height == 0))
5414 return(MagickFalse);
5416 Apply user transforms to the image.
5418 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5419 (void) XFlush(display);
5420 depth=(int) window->depth;
5421 if (window->destroy)
5422 window->image=DestroyImage(window->image);
5423 window->image=image;
5424 window->destroy=MagickFalse;
5425 if (window->image != (Image *) NULL)
5427 if (window->crop_geometry != (char *) NULL)
5438 window->image->page.x=0;
5439 window->image->page.y=0;
5440 (void) ParsePageGeometry(window->image,window->crop_geometry,
5441 &crop_info,&image->exception);
5442 crop_image=CropImage(window->image,&crop_info,&image->exception);
5443 if (crop_image != (Image *) NULL)
5445 if (window->image != image)
5446 window->image=DestroyImage(window->image);
5447 window->image=crop_image;
5448 window->destroy=MagickTrue;
5451 if ((width != (unsigned int) window->image->columns) ||
5452 (height != (unsigned int) window->image->rows))
5460 resize_image=NewImageList();
5461 if (window->pixel_info->colors != 0)
5462 resize_image=SampleImage(window->image,width,height,
5465 resize_image=ThumbnailImage(window->image,width,height,
5467 if (resize_image != (Image *) NULL)
5469 if (window->image != image)
5470 window->image=DestroyImage(window->image);
5471 window->image=resize_image;
5472 window->destroy=MagickTrue;
5475 width=(unsigned int) window->image->columns;
5476 assert((unsigned long) width == window->image->columns);
5477 height=(unsigned int) window->image->rows;
5478 assert((unsigned long) height == window->image->rows);
5483 ximage=(XImage *) NULL;
5484 format=(depth == 1) ? XYBitmap : ZPixmap;
5485 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5486 if (window->shared_memory != MagickFalse)
5491 segment_info=(XShmSegmentInfo *) window->segment_info;
5492 segment_info[1].shmid=(-1);
5493 segment_info[1].shmaddr=(char *) NULL;
5494 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5495 (char *) NULL,&segment_info[1],width,height);
5496 if (ximage == (XImage *) NULL)
5497 window->shared_memory=MagickFalse;
5498 length=(size_t) ximage->bytes_per_line*ximage->height;
5499 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5500 window->shared_memory=MagickFalse;
5501 if (window->shared_memory != MagickFalse)
5502 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5503 if (window->shared_memory != MagickFalse)
5504 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5505 if (segment_info[1].shmid < 0)
5506 window->shared_memory=MagickFalse;
5507 if (window->shared_memory != MagickFalse)
5508 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5511 if (ximage != (XImage *) NULL)
5512 XDestroyImage(ximage);
5513 ximage=(XImage *) NULL;
5514 if (segment_info[1].shmaddr)
5516 (void) shmdt(segment_info[1].shmaddr);
5517 segment_info[1].shmaddr=(char *) NULL;
5519 if (segment_info[1].shmid >= 0)
5521 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5522 segment_info[1].shmid=(-1);
5528 Allocate X image pixel data.
5530 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5531 if (window->shared_memory)
5539 (void) XSync(display,MagickFalse);
5540 xerror_alert=MagickFalse;
5541 segment_info=(XShmSegmentInfo *) window->segment_info;
5542 ximage->data=segment_info[1].shmaddr;
5543 segment_info[1].readOnly=MagickFalse;
5544 status=XShmAttach(display,&segment_info[1]);
5545 if (status != False)
5546 (void) XSync(display,MagickFalse);
5547 if ((status == False) || (xerror_alert != MagickFalse))
5549 window->shared_memory=MagickFalse;
5550 if (status != False)
5551 XShmDetach(display,&segment_info[1]);
5552 if (ximage != (XImage *) NULL)
5555 XDestroyImage(ximage);
5556 ximage=(XImage *) NULL;
5558 if (segment_info[1].shmid >= 0)
5560 if (segment_info[1].shmaddr != NULL)
5561 (void) shmdt(segment_info[1].shmaddr);
5562 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5563 segment_info[1].shmid=(-1);
5564 segment_info[1].shmaddr=(char *) NULL;
5569 if (window->shared_memory == MagickFalse)
5570 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5571 (char *) NULL,width,height,XBitmapPad(display),0);
5572 if (ximage == (XImage *) NULL)
5575 Unable to create X image.
5577 (void) XCheckDefineCursor(display,window->id,window->cursor);
5578 return(MagickFalse);
5580 length=(size_t) ximage->bytes_per_line*ximage->height;
5581 if (IsEventLogging())
5583 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5584 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5585 ximage->width,ximage->height);
5586 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5588 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5589 ximage->byte_order);
5590 (void) LogMagickEvent(X11Event,GetMagickModule(),
5591 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5592 ximage->bitmap_bit_order,ximage->bitmap_pad);
5593 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5595 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5596 ximage->bytes_per_line);
5597 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5598 ximage->bits_per_pixel);
5599 (void) LogMagickEvent(X11Event,GetMagickModule(),
5600 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5601 ximage->green_mask,ximage->blue_mask);
5603 if (window->shared_memory == MagickFalse)
5605 if (ximage->format != XYBitmap)
5606 ximage->data=(char *) AcquireQuantumMemory((size_t)
5607 ximage->bytes_per_line,(size_t) ximage->height);
5609 ximage->data=(char *) AcquireQuantumMemory((size_t)
5610 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5612 if (ximage->data == (char *) NULL)
5615 Unable to allocate pixel data.
5617 XDestroyImage(ximage);
5618 ximage=(XImage *) NULL;
5619 (void) XCheckDefineCursor(display,window->id,window->cursor);
5620 return(MagickFalse);
5622 if (window->ximage != (XImage *) NULL)
5625 Destroy previous X image.
5627 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5628 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5629 if (window->segment_info != (XShmSegmentInfo *) NULL)
5634 segment_info=(XShmSegmentInfo *) window->segment_info;
5635 if (segment_info[0].shmid >= 0)
5637 (void) XSync(display,MagickFalse);
5638 (void) XShmDetach(display,&segment_info[0]);
5639 (void) XSync(display,MagickFalse);
5640 if (segment_info[0].shmaddr != (char *) NULL)
5641 (void) shmdt(segment_info[0].shmaddr);
5642 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5643 segment_info[0].shmid=(-1);
5644 segment_info[0].shmaddr=(char *) NULL;
5645 window->ximage->data=(char *) NULL;
5649 if (window->ximage->data != (char *) NULL)
5650 free(window->ximage->data);
5651 window->ximage->data=(char *) NULL;
5652 XDestroyImage(window->ximage);
5653 window->ximage=(XImage *) NULL;
5655 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5656 if (window->segment_info != (XShmSegmentInfo *) NULL)
5661 segment_info=(XShmSegmentInfo *) window->segment_info;
5662 segment_info[0]=segment_info[1];
5665 window->ximage=ximage;
5666 matte_image=(XImage *) NULL;
5667 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5668 if ((window->image->matte != MagickFalse) &&
5669 ((long) width <= XDisplayWidth(display,window->screen)) &&
5670 ((long) height <= XDisplayHeight(display,window->screen)))
5675 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5676 (char *) NULL,width,height,XBitmapPad(display),0);
5677 if (IsEventLogging())
5679 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5680 (void) LogMagickEvent(X11Event,GetMagickModule(),
5681 " width, height: %dx%d",matte_image->width,matte_image->height);
5683 if (matte_image != (XImage *) NULL)
5686 Allocate matte image pixel data.
5688 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5689 matte_image->bytes_per_line*matte_image->depth,
5690 (size_t) matte_image->height);
5691 if (matte_image->data == (char *) NULL)
5693 XDestroyImage(matte_image);
5694 matte_image=(XImage *) NULL;
5698 if (window->matte_image != (XImage *) NULL)
5703 if (window->matte_image->data != (char *) NULL)
5704 free(window->matte_image->data);
5705 window->matte_image->data=(char *) NULL;
5706 XDestroyImage(window->matte_image);
5707 window->matte_image=(XImage *) NULL;
5709 window->matte_image=matte_image;
5710 if (window->matte_pixmap != (Pixmap) NULL)
5712 (void) XFreePixmap(display,window->matte_pixmap);
5713 window->matte_pixmap=(Pixmap) NULL;
5714 #if defined(MAGICKCORE_HAVE_SHAPE)
5715 if (window->shape != MagickFalse)
5716 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5719 window->stasis=MagickFalse;
5721 Convert pixels to X image data.
5723 if (window->image != (Image *) NULL)
5725 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5726 (ximage->bitmap_bit_order == LSBFirst)))
5727 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5730 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5733 if (window->matte_image != (XImage *) NULL)
5736 Create matte pixmap.
5738 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5739 if (window->matte_pixmap != (Pixmap) NULL)
5748 Copy matte image to matte pixmap.
5750 context_values.background=1;
5751 context_values.foreground=0;
5752 graphics_context=XCreateGC(display,window->matte_pixmap,
5753 (unsigned long) (GCBackground | GCForeground),&context_values);
5754 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5755 window->matte_image,0,0,0,0,width,height);
5756 (void) XFreeGC(display,graphics_context);
5757 #if defined(MAGICKCORE_HAVE_SHAPE)
5758 if (window->shape != MagickFalse)
5759 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5760 window->matte_pixmap,ShapeSet);
5764 (void) XMakePixmap(display,resource_info,window);
5768 (void) XCheckDefineCursor(display,window->id,window->cursor);
5773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5777 + X M a k e I m a g e L S B F i r s t %
5781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5783 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5784 % pixels are copied in least-significant bit and byte first order. The
5785 % server's scanline pad is respected. Rather than using one or two general
5786 % cases, many special cases are found here to help speed up the image
5789 % The format of the XMakeImageLSBFirst method is:
5791 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5793 % A description of each parameter follows:
5795 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5797 % o window: Specifies a pointer to a XWindowInfo structure.
5799 % o image: the image.
5801 % o ximage: Specifies a pointer to a XImage structure; returned from
5804 % o matte_image: Specifies a pointer to a XImage structure; returned from
5808 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5809 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5817 register const IndexPacket
5820 register const PixelPacket
5826 register unsigned char
5843 assert(resource_info != (XResourceInfo *) NULL);
5844 assert(window != (XWindowInfo *) NULL);
5845 assert(image != (Image *) NULL);
5846 if (image->debug != MagickFalse)
5847 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5849 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
5852 size[MaxTextExtent];
5860 image_info=AcquireImageInfo();
5861 (void) CopyMagickString(image_info->filename,
5862 resource_info->image_info->texture != (char *) NULL ?
5863 resource_info->image_info->texture : "pattern:checkerboard",
5865 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
5867 image_info->size=ConstantString(size);
5868 pattern=ReadImage(image_info,&image->exception);
5869 image_info=DestroyImageInfo(image_info);
5870 if (pattern != (Image *) NULL)
5872 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5873 if (canvas != (Image *) NULL)
5874 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5875 pattern=DestroyImage(pattern);
5878 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5879 ximage->bits_per_pixel) >> 3));
5880 map_info=window->map_info;
5881 pixels=window->pixel_info->pixels;
5882 q=(unsigned char *) ximage->data;
5884 if (ximage->format == XYBitmap)
5886 register unsigned short
5894 Convert canvas to big-endian bitmap.
5896 background=(unsigned char)
5897 (XPixelIntensity(&window->pixel_info->foreground_color) <
5898 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5899 foreground=(unsigned char)
5900 (XPixelIntensity(&window->pixel_info->background_color) <
5901 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5902 polarity=(unsigned short) ((PixelIntensityToQuantum(
5903 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5904 if (canvas->colors == 2)
5905 polarity=PixelIntensity(&canvas->colormap[0]) <
5906 PixelIntensity(&canvas->colormap[1]);
5907 for (y=0; y < (int) canvas->rows; y++)
5909 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5910 if (p == (const PixelPacket *) NULL)
5912 indexes=GetVirtualIndexQueue(canvas);
5915 for (x=0; x < (int) canvas->columns; x++)
5918 if (indexes[x] == (IndexPacket) polarity)
5936 if (window->pixel_info->colors != 0)
5937 switch (ximage->bits_per_pixel)
5941 register unsigned int
5945 Convert to 2 bit color-mapped X canvas.
5947 for (y=0; y < (int) canvas->rows; y++)
5949 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5950 if (p == (const PixelPacket *) NULL)
5952 indexes=GetVirtualIndexQueue(canvas);
5954 for (x=0; x < (int) canvas->columns; x++)
5956 pixel=pixels[(long) indexes[x]] & 0x0f;
5961 *q=(unsigned char) pixel;
5967 *q|=(unsigned char) (pixel << 2);
5973 *q|=(unsigned char) (pixel << 4);
5979 *q|=(unsigned char) (pixel << 6);
5992 register unsigned int
5996 Convert to 4 bit color-mapped X canvas.
5998 for (y=0; y < (int) canvas->rows; y++)
6000 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6001 if (p == (const PixelPacket *) NULL)
6003 indexes=GetVirtualIndexQueue(canvas);
6005 for (x=0; x < (int) canvas->columns; x++)
6007 pixel=pixels[(long) indexes[x]] & 0xf;
6012 *q=(unsigned char) pixel;
6018 *q|=(unsigned char) (pixel << 4);
6033 Convert to 8 bit color-mapped X canvas.
6035 if (resource_info->color_recovery &&
6036 resource_info->quantize_info->dither)
6038 XDitherImage(canvas,ximage);
6041 for (y=0; y < (int) canvas->rows; y++)
6043 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6044 if (p == (const PixelPacket *) NULL)
6046 indexes=GetVirtualIndexQueue(canvas);
6047 for (x=0; x < (int) canvas->columns; x++)
6049 pixel=pixels[(long) indexes[x]];
6050 *q++=(unsigned char) pixel;
6061 register unsigned int
6065 channel[sizeof(unsigned long)];
6068 Convert to multi-byte color-mapped X canvas.
6070 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6071 for (y=0; y < (int) canvas->rows; y++)
6073 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6074 if (p == (const PixelPacket *) NULL)
6076 indexes=GetVirtualIndexQueue(canvas);
6077 for (x=0; x < (int) canvas->columns; x++)
6079 pixel=pixels[(long) indexes[x]];
6080 for (k=0; k < (int) bytes_per_pixel; k++)
6082 channel[k]=(unsigned char) pixel;
6085 for (k=0; k < (int) bytes_per_pixel; k++)
6094 switch (ximage->bits_per_pixel)
6098 register unsigned int
6102 Convert to contiguous 2 bit continuous-tone X canvas.
6104 for (y=0; y < (int) canvas->rows; y++)
6107 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6108 if (p == (const PixelPacket *) NULL)
6110 for (x=0; x < (int) canvas->columns; x++)
6112 pixel=XGammaPixel(map_info,p);
6118 *q=(unsigned char) pixel;
6124 *q|=(unsigned char) (pixel << 2);
6130 *q|=(unsigned char) (pixel << 4);
6136 *q|=(unsigned char) (pixel << 6);
6150 register unsigned int
6154 Convert to contiguous 4 bit continuous-tone X canvas.
6156 for (y=0; y < (int) canvas->rows; y++)
6158 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6159 if (p == (const PixelPacket *) NULL)
6162 for (x=0; x < (int) canvas->columns; x++)
6164 pixel=XGammaPixel(map_info,p);
6170 *q=(unsigned char) pixel;
6176 *q|=(unsigned char) (pixel << 4);
6192 Convert to contiguous 8 bit continuous-tone X canvas.
6194 if (resource_info->color_recovery &&
6195 resource_info->quantize_info->dither)
6197 XDitherImage(canvas,ximage);
6200 for (y=0; y < (int) canvas->rows; y++)
6202 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6203 if (p == (const PixelPacket *) NULL)
6205 for (x=0; x < (int) canvas->columns; x++)
6207 pixel=XGammaPixel(map_info,p);
6208 *q++=(unsigned char) pixel;
6217 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6218 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6219 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6220 (map_info->blue_mult == 1))
6223 Convert to 32 bit continuous-tone X canvas.
6225 for (y=0; y < (int) canvas->rows; y++)
6227 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6228 &canvas->exception);
6229 if (p == (const PixelPacket *) NULL)
6231 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6232 (blue_gamma != 1.0))
6235 Gamma correct canvas.
6237 for (x=(int) canvas->columns-1; x >= 0; x--)
6239 *q++=ScaleQuantumToChar(XBlueGamma(
6240 GetBluePixelComponent(p)));
6241 *q++=ScaleQuantumToChar(XGreenGamma(
6242 GetGreenPixelComponent(p)));
6243 *q++=ScaleQuantumToChar(XRedGamma(
6244 GetRedPixelComponent(p)));
6250 for (x=(int) canvas->columns-1; x >= 0; x--)
6252 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6253 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6254 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6261 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6262 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6263 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6264 (map_info->blue_mult == 65536L))
6267 Convert to 32 bit continuous-tone X canvas.
6269 for (y=0; y < (int) canvas->rows; y++)
6271 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6272 &canvas->exception);
6273 if (p == (const PixelPacket *) NULL)
6275 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6276 (blue_gamma != 1.0))
6279 Gamma correct canvas.
6281 for (x=(int) canvas->columns-1; x >= 0; x--)
6283 *q++=ScaleQuantumToChar(XRedGamma(
6284 GetRedPixelComponent(p)));
6285 *q++=ScaleQuantumToChar(XGreenGamma(
6286 GetGreenPixelComponent(p)));
6287 *q++=ScaleQuantumToChar(XBlueGamma(
6288 GetBluePixelComponent(p)));
6294 for (x=(int) canvas->columns-1; x >= 0; x--)
6296 *q++=ScaleQuantumToChar((Quantum)
6297 GetRedPixelComponent(p));
6298 *q++=ScaleQuantumToChar((Quantum)
6299 GetGreenPixelComponent(p));
6300 *q++=ScaleQuantumToChar((Quantum)
6301 GetBluePixelComponent(p));
6312 register unsigned int
6316 channel[sizeof(unsigned long)];
6319 Convert to multi-byte continuous-tone X canvas.
6321 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6322 for (y=0; y < (int) canvas->rows; y++)
6324 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6325 &canvas->exception);
6326 if (p == (PixelPacket *) NULL)
6328 for (x=0; x < (long) canvas->columns; x++)
6330 pixel=XGammaPixel(map_info,p);
6331 for (k=0; k < (int) bytes_per_pixel; k++)
6333 channel[k]=(unsigned char) pixel;
6336 for (k=0; k < (int) bytes_per_pixel; k++)
6346 if (matte_image != (XImage *) NULL)
6349 Initialize matte canvas.
6351 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6352 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6353 q=(unsigned char *) matte_image->data;
6354 for (y=0; y < (int) canvas->rows; y++)
6356 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6357 if (p == (const PixelPacket *) NULL)
6361 for (x=(int) canvas->columns-1; x >= 0; x--)
6364 if (p->opacity > (long) (QuantumRange/2))
6380 if (canvas != image)
6381 canvas=DestroyImage(canvas);
6385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6389 + X M a k e I m a g e M S B F i r s t %
6393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6395 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6396 % image pixels are copied in most-significant bit and byte first order. The
6397 % server's scanline pad is also respected. Rather than using one or two
6398 % general cases, many special cases are found here to help speed up the image
6401 % The format of the XMakeImageMSBFirst method is:
6403 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6405 % A description of each parameter follows:
6407 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6409 % o window: Specifies a pointer to a XWindowInfo structure.
6411 % o image: the image.
6413 % o ximage: Specifies a pointer to a XImage structure; returned from
6416 % o matte_image: Specifies a pointer to a XImage structure; returned from
6420 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6421 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6432 register const IndexPacket
6435 register const PixelPacket
6438 register unsigned char
6455 assert(resource_info != (XResourceInfo *) NULL);
6456 assert(window != (XWindowInfo *) NULL);
6457 assert(image != (Image *) NULL);
6458 if (image->debug != MagickFalse)
6459 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6461 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
6464 size[MaxTextExtent];
6472 image_info=AcquireImageInfo();
6473 (void) CopyMagickString(image_info->filename,
6474 resource_info->image_info->texture != (char *) NULL ?
6475 resource_info->image_info->texture : "pattern:checkerboard",
6477 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
6479 image_info->size=ConstantString(size);
6480 pattern=ReadImage(image_info,&image->exception);
6481 image_info=DestroyImageInfo(image_info);
6482 if (pattern != (Image *) NULL)
6484 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6485 if (canvas != (Image *) NULL)
6486 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6487 pattern=DestroyImage(pattern);
6490 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6491 ((ximage->width*ximage->bits_per_pixel) >> 3));
6492 map_info=window->map_info;
6493 pixels=window->pixel_info->pixels;
6494 q=(unsigned char *) ximage->data;
6496 if (ximage->format == XYBitmap)
6498 register unsigned short
6506 Convert canvas to big-endian bitmap.
6508 background=(unsigned char)
6509 (XPixelIntensity(&window->pixel_info->foreground_color) <
6510 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6511 foreground=(unsigned char)
6512 (XPixelIntensity(&window->pixel_info->background_color) <
6513 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6514 polarity=(unsigned short) ((PixelIntensityToQuantum(
6515 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6516 if (canvas->colors == 2)
6517 polarity=PixelIntensity(&canvas->colormap[0]) <
6518 PixelIntensity(&canvas->colormap[1]);
6519 for (y=0; y < (int) canvas->rows; y++)
6521 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6522 if (p == (const PixelPacket *) NULL)
6524 indexes=GetVirtualIndexQueue(canvas);
6527 for (x=(int) canvas->columns-1; x >= 0; x--)
6530 if (indexes[x] == (IndexPacket) polarity)
6548 if (window->pixel_info->colors != 0)
6549 switch (ximage->bits_per_pixel)
6553 register unsigned int
6557 Convert to 2 bit color-mapped X canvas.
6559 for (y=0; y < (int) canvas->rows; y++)
6561 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6562 if (p == (const PixelPacket *) NULL)
6564 indexes=GetVirtualIndexQueue(canvas);
6566 for (x=0; x < (int) canvas->columns; x++)
6568 pixel=pixels[(long) indexes[x]] & 0xf;
6573 *q=(unsigned char) (pixel << 6);
6579 *q|=(unsigned char) (pixel << 4);
6585 *q|=(unsigned char) (pixel << 2);
6591 *q|=(unsigned char) pixel;
6604 register unsigned int
6608 Convert to 4 bit color-mapped X canvas.
6610 for (y=0; y < (int) canvas->rows; y++)
6612 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6613 if (p == (const PixelPacket *) NULL)
6615 indexes=GetVirtualIndexQueue(canvas);
6617 for (x=0; x < (int) canvas->columns; x++)
6619 pixel=pixels[(long) indexes[x]] & 0xf;
6624 *q=(unsigned char) (pixel << 4);
6630 *q|=(unsigned char) pixel;
6645 Convert to 8 bit color-mapped X canvas.
6647 if (resource_info->color_recovery &&
6648 resource_info->quantize_info->dither)
6650 XDitherImage(canvas,ximage);
6653 for (y=0; y < (int) canvas->rows; y++)
6655 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6656 if (p == (const PixelPacket *) NULL)
6658 indexes=GetVirtualIndexQueue(canvas);
6659 for (x=0; x < (int) canvas->columns; x++)
6661 pixel=pixels[(long) indexes[x]];
6662 *q++=(unsigned char) pixel;
6673 register unsigned int
6677 channel[sizeof(unsigned long)];
6680 Convert to 8 bit color-mapped X canvas.
6682 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6683 for (y=0; y < (int) canvas->rows; y++)
6685 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6686 if (p == (const PixelPacket *) NULL)
6688 indexes=GetVirtualIndexQueue(canvas);
6689 for (x=0; x < (int) canvas->columns; x++)
6691 pixel=pixels[(long) indexes[x]];
6692 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6694 channel[k]=(unsigned char) pixel;
6697 for (k=0; k < (int) bytes_per_pixel; k++)
6706 switch (ximage->bits_per_pixel)
6710 register unsigned int
6714 Convert to 4 bit continuous-tone X canvas.
6716 for (y=0; y < (int) canvas->rows; y++)
6718 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6719 if (p == (const PixelPacket *) NULL)
6722 for (x=(int) canvas->columns-1; x >= 0; x--)
6724 pixel=XGammaPixel(map_info,p);
6730 *q=(unsigned char) (pixel << 6);
6736 *q|=(unsigned char) (pixel << 4);
6742 *q|=(unsigned char) (pixel << 2);
6748 *q|=(unsigned char) pixel;
6762 register unsigned int
6766 Convert to 4 bit continuous-tone X canvas.
6768 for (y=0; y < (int) canvas->rows; y++)
6770 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6771 if (p == (const PixelPacket *) NULL)
6774 for (x=(int) canvas->columns-1; x >= 0; x--)
6776 pixel=XGammaPixel(map_info,p);
6782 *q=(unsigned char) (pixel << 4);
6788 *q|=(unsigned char) pixel;
6804 Convert to 8 bit continuous-tone X canvas.
6806 if (resource_info->color_recovery &&
6807 resource_info->quantize_info->dither)
6809 XDitherImage(canvas,ximage);
6812 for (y=0; y < (int) canvas->rows; y++)
6814 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6815 if (p == (const PixelPacket *) NULL)
6817 for (x=(int) canvas->columns-1; x >= 0; x--)
6819 pixel=XGammaPixel(map_info,p);
6820 *q++=(unsigned char) pixel;
6829 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6830 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6831 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6832 (map_info->blue_mult == 1))
6835 Convert to 32 bit continuous-tone X canvas.
6837 for (y=0; y < (int) canvas->rows; y++)
6839 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6840 &canvas->exception);
6841 if (p == (const PixelPacket *) NULL)
6843 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6844 (blue_gamma != 1.0))
6847 Gamma correct canvas.
6849 for (x=(int) canvas->columns-1; x >= 0; x--)
6852 *q++=ScaleQuantumToChar(XRedGamma(
6853 GetRedPixelComponent(p)));
6854 *q++=ScaleQuantumToChar(XGreenGamma(
6855 GetGreenPixelComponent(p)));
6856 *q++=ScaleQuantumToChar(XBlueGamma(
6857 GetBluePixelComponent(p)));
6862 for (x=(int) canvas->columns-1; x >= 0; x--)
6865 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6866 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6867 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6873 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6874 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6875 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6876 (map_info->blue_mult == 65536L))
6879 Convert to 32 bit continuous-tone X canvas.
6881 for (y=0; y < (int) canvas->rows; y++)
6883 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6884 &canvas->exception);
6885 if (p == (const PixelPacket *) NULL)
6887 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6888 (blue_gamma != 1.0))
6891 Gamma correct canvas.
6893 for (x=(int) canvas->columns-1; x >= 0; x--)
6896 *q++=ScaleQuantumToChar(XBlueGamma(
6897 GetBluePixelComponent(p)));
6898 *q++=ScaleQuantumToChar(XGreenGamma(
6899 GetGreenPixelComponent(p)));
6900 *q++=ScaleQuantumToChar(XRedGamma(
6901 GetRedPixelComponent(p)));
6906 for (x=(int) canvas->columns-1; x >= 0; x--)
6909 *q++=ScaleQuantumToChar((Quantum)
6910 GetBluePixelComponent(p));
6911 *q++=ScaleQuantumToChar((Quantum)
6912 GetGreenPixelComponent(p));
6913 *q++=ScaleQuantumToChar((Quantum)
6914 GetRedPixelComponent(p));
6924 register unsigned int
6928 channel[sizeof(unsigned long)];
6931 Convert to multi-byte continuous-tone X canvas.
6933 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6934 for (y=0; y < (int) canvas->rows; y++)
6936 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6937 &canvas->exception);
6938 if (p == (const PixelPacket *) NULL)
6940 for (x=(int) canvas->columns-1; x >= 0; x--)
6942 pixel=XGammaPixel(map_info,p);
6943 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6945 channel[k]=(unsigned char) pixel;
6948 for (k=0; k < (int) bytes_per_pixel; k++)
6958 if (matte_image != (XImage *) NULL)
6961 Initialize matte canvas.
6963 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6964 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6965 q=(unsigned char *) matte_image->data;
6966 for (y=0; y < (int) canvas->rows; y++)
6968 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6969 if (p == (const PixelPacket *) NULL)
6973 for (x=(int) canvas->columns-1; x >= 0; x--)
6976 if (p->opacity > (long) (QuantumRange/2))
6992 if (canvas != image)
6993 canvas=DestroyImage(canvas);
6997 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7001 % X M a k e M a g n i f y I m a g e %
7005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7007 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7009 % The format of the XMakeMagnifyImage method is:
7011 % void XMakeMagnifyImage(display,windows)
7013 % A description of each parameter follows:
7015 % o display: Specifies a connection to an X server; returned from
7018 % o windows: Specifies a pointer to a XWindows structure.
7021 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7024 tuple[MaxTextExtent];
7041 register unsigned char
7046 previous_magnify = 0;
7064 Check boundary conditions.
7066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7067 assert(display != (Display *) NULL);
7068 assert(windows != (XWindows *) NULL);
7070 for (n=1; n < (long) windows->magnify.data; n++)
7072 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7074 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7076 while (magnify > windows->magnify.width)
7078 while (magnify > windows->magnify.height)
7080 if (magnify != previous_magnify)
7089 New magnify factor: update magnify window name.
7092 while ((1 << i) <= (int) magnify)
7094 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7096 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7097 if (status != False)
7099 XSetWMName(display,windows->magnify.id,&window_name);
7100 XSetWMIconName(display,windows->magnify.id,&window_name);
7101 (void) XFree((void *) window_name.value);
7104 previous_magnify=magnify;
7105 ximage=windows->image.ximage;
7106 width=(unsigned int) windows->magnify.ximage->width;
7107 height=(unsigned int) windows->magnify.ximage->height;
7108 if ((windows->magnify.x < 0) ||
7109 (windows->magnify.x >= windows->image.ximage->width))
7110 windows->magnify.x=windows->image.ximage->width >> 1;
7111 x=windows->magnify.x-((width/magnify) >> 1);
7115 if (x > (int) (ximage->width-(width/magnify)))
7116 x=ximage->width-width/magnify;
7117 if ((windows->magnify.y < 0) ||
7118 (windows->magnify.y >= windows->image.ximage->height))
7119 windows->magnify.y=windows->image.ximage->height >> 1;
7120 y=windows->magnify.y-((height/magnify) >> 1);
7124 if (y > (int) (ximage->height-(height/magnify)))
7125 y=ximage->height-height/magnify;
7126 q=(unsigned char *) windows->magnify.ximage->data;
7127 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7128 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7129 if (ximage->bits_per_pixel < 8)
7131 register unsigned char
7138 register unsigned int
7144 pixel_info=windows->magnify.pixel_info;
7145 switch (ximage->bitmap_bit_order)
7150 Magnify little-endian bitmap.
7154 if (ximage->format == XYBitmap)
7156 background=(unsigned char)
7157 (XPixelIntensity(&pixel_info->foreground_color) <
7158 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7159 foreground=(unsigned char)
7160 (XPixelIntensity(&pixel_info->background_color) <
7161 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7162 if (windows->magnify.depth > 1)
7163 Swap(background,foreground);
7165 for (i=0; i < (long) height; i+=magnify)
7168 Propogate pixel magnify rows.
7170 for (j=0; j < magnify; j++)
7172 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7173 ((x*ximage->bits_per_pixel) >> 3);
7174 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7177 for (k=0; k < width; k+=magnify)
7180 Propogate pixel magnify columns.
7182 for (l=0; l < magnify; l++)
7185 Propogate each bit plane.
7187 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7190 if (*p & (0x01 << (p_bit+plane)))
7203 p_bit+=ximage->bits_per_pixel;
7210 *q=byte >> (8-q_bit);
7222 Magnify big-endian bitmap.
7226 if (ximage->format == XYBitmap)
7228 background=(unsigned char)
7229 (XPixelIntensity(&pixel_info->foreground_color) <
7230 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7231 foreground=(unsigned char)
7232 (XPixelIntensity(&pixel_info->background_color) <
7233 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7234 if (windows->magnify.depth > 1)
7235 Swap(background,foreground);
7237 for (i=0; i < (long) height; i+=magnify)
7240 Propogate pixel magnify rows.
7242 for (j=0; j < magnify; j++)
7244 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7245 ((x*ximage->bits_per_pixel) >> 3);
7246 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7249 for (k=0; k < width; k+=magnify)
7252 Propogate pixel magnify columns.
7254 for (l=0; l < magnify; l++)
7257 Propogate each bit plane.
7259 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7262 if (*p & (0x80 >> (p_bit+plane)))
7275 p_bit+=ximage->bits_per_pixel;
7282 *q=byte << (8-q_bit);
7293 switch (ximage->bits_per_pixel)
7299 Magnify 8 bit X image.
7301 for (i=0; i < (long) height; i+=magnify)
7304 Propogate pixel magnify rows.
7306 for (j=0; j < magnify; j++)
7308 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7309 ((x*ximage->bits_per_pixel) >> 3);
7310 for (k=0; k < width; k+=magnify)
7313 Propogate pixel magnify columns.
7315 for (l=0; l < magnify; l++)
7327 register unsigned int
7332 Magnify multi-byte X image.
7334 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7335 for (i=0; i < (long) height; i+=magnify)
7338 Propogate pixel magnify rows.
7340 for (j=0; j < magnify; j++)
7342 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7343 ((x*ximage->bits_per_pixel) >> 3);
7344 for (k=0; k < width; k+=magnify)
7347 Propogate pixel magnify columns.
7349 for (l=0; l < magnify; l++)
7350 for (m=0; m < bytes_per_pixel; m++)
7362 Copy X image to magnify pixmap.
7364 x=windows->magnify.x-((width/magnify) >> 1);
7366 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7368 if (x > (int) (ximage->width-(width/magnify)))
7369 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7372 y=windows->magnify.y-((height/magnify) >> 1);
7374 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7376 if (y > (int) (ximage->height-(height/magnify)))
7377 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7380 if ((x != 0) || (y != 0))
7381 (void) XFillRectangle(display,windows->magnify.pixmap,
7382 windows->magnify.annotate_context,0,0,width,height);
7383 (void) XPutImage(display,windows->magnify.pixmap,
7384 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7386 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7387 (magnify <= (height >> 1))))
7393 Highlight center pixel.
7395 highlight_info.x=(long) windows->magnify.width >> 1;
7396 highlight_info.y=(long) windows->magnify.height >> 1;
7397 highlight_info.width=magnify;
7398 highlight_info.height=magnify;
7399 (void) XDrawRectangle(display,windows->magnify.pixmap,
7400 windows->magnify.highlight_context,(int) highlight_info.x,
7401 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7402 (unsigned int) highlight_info.height-1);
7404 (void) XDrawRectangle(display,windows->magnify.pixmap,
7405 windows->magnify.annotate_context,(int) highlight_info.x+1,
7406 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7407 (unsigned int) highlight_info.height-3);
7410 Show center pixel color.
7412 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7413 windows->magnify.y,&pixel,&windows->image.image->exception);
7414 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7415 windows->magnify.x,windows->magnify.y);
7416 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7417 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7418 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7419 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7420 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7421 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7422 if (pixel.colorspace == CMYKColorspace)
7424 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7425 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7427 if (pixel.matte != MagickFalse)
7429 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7430 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7432 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7433 height=(unsigned int) windows->magnify.font_info->ascent+
7434 windows->magnify.font_info->descent;
7435 x=windows->magnify.font_info->max_bounds.width >> 1;
7436 y=windows->magnify.font_info->ascent+(height >> 2);
7437 (void) XDrawImageString(display,windows->magnify.pixmap,
7438 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7439 GetColorTuple(&pixel,MagickTrue,tuple);
7441 (void) XDrawImageString(display,windows->magnify.pixmap,
7442 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7443 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7444 &windows->image.image->exception);
7446 (void) XDrawImageString(display,windows->magnify.pixmap,
7447 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7449 Refresh magnify window.
7451 magnify_window=windows->magnify;
7454 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7462 % X M a k e P i x m a p %
7466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7468 % XMakePixmap() creates an X11 pixmap.
7470 % The format of the XMakePixmap method is:
7472 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7473 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7474 % XPixelInfo *pixel)
7476 % A description of each parameter follows:
7478 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7480 % o display: Specifies a connection to an X server; returned from
7483 % o window: Specifies a pointer to a XWindowInfo structure.
7486 static MagickBooleanType XMakePixmap(Display *display,
7487 const XResourceInfo *resource_info,XWindowInfo *window)
7493 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7494 assert(display != (Display *) NULL);
7495 assert(resource_info != (XResourceInfo *) NULL);
7496 assert(window != (XWindowInfo *) NULL);
7497 if (window->pixmap != (Pixmap) NULL)
7500 Destroy previous X pixmap.
7502 (void) XFreePixmap(display,window->pixmap);
7503 window->pixmap=(Pixmap) NULL;
7505 if (window->use_pixmap == MagickFalse)
7506 return(MagickFalse);
7507 if (window->ximage == (XImage *) NULL)
7508 return(MagickFalse);
7510 Display busy cursor.
7512 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7513 (void) XFlush(display);
7517 width=(unsigned int) window->ximage->width;
7518 height=(unsigned int) window->ximage->height;
7519 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7520 if (window->pixmap == (Pixmap) NULL)
7523 Unable to allocate pixmap.
7525 (void) XCheckDefineCursor(display,window->id,window->cursor);
7526 return(MagickFalse);
7529 Copy X image to pixmap.
7531 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7532 if (window->shared_memory)
7533 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7534 window->ximage,0,0,0,0,width,height,MagickTrue);
7536 if (window->shared_memory == MagickFalse)
7537 (void) XPutImage(display,window->pixmap,window->annotate_context,
7538 window->ximage,0,0,0,0,width,height);
7539 if (IsEventLogging())
7541 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7542 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7548 (void) XCheckDefineCursor(display,window->id,window->cursor);
7553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7557 % X M a k e S t a n d a r d C o l o r m a p %
7561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7563 % XMakeStandardColormap() creates an X11 Standard Colormap.
7565 % The format of the XMakeStandardColormap method is:
7567 % XMakeStandardColormap(display,visual_info,resource_info,image,
7570 % A description of each parameter follows:
7572 % o display: Specifies a connection to an X server; returned from
7575 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7576 % returned from XGetVisualInfo.
7578 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7580 % o image: the image.
7582 % o map_info: If a Standard Colormap type is specified, this structure is
7583 % initialized with info from the Standard Colormap.
7585 % o pixel: Specifies a pointer to a XPixelInfo structure.
7589 #if defined(__cplusplus) || defined(c_plusplus)
7593 static inline MagickRealType DiversityPixelIntensity(
7594 const DiversityPacket *pixel)
7599 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7603 static int IntensityCompare(const void *x,const void *y)
7612 color_1=(DiversityPacket *) x;
7613 color_2=(DiversityPacket *) y;
7614 diversity=(int) (DiversityPixelIntensity(color_2)-
7615 DiversityPixelIntensity(color_1));
7619 static int PopularityCompare(const void *x,const void *y)
7625 color_1=(DiversityPacket *) x;
7626 color_2=(DiversityPacket *) y;
7627 return((int) color_2->count-(int) color_1->count);
7630 #if defined(__cplusplus) || defined(c_plusplus)
7634 static inline Quantum ScaleXToQuantum(const unsigned long x,
7635 const unsigned long scale)
7637 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7640 MagickExport void XMakeStandardColormap(Display *display,
7641 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7642 XStandardColormap *map_info,XPixelInfo *pixel)
7650 register IndexPacket
7671 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7672 assert(display != (Display *) NULL);
7673 assert(visual_info != (XVisualInfo *) NULL);
7674 assert(map_info != (XStandardColormap *) NULL);
7675 assert(resource_info != (XResourceInfo *) NULL);
7676 assert(pixel != (XPixelInfo *) NULL);
7677 exception=(&image->exception);
7678 if (resource_info->map_type != (char *) NULL)
7681 Standard Colormap is already defined (i.e. xstdcmap).
7683 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7685 number_colors=(unsigned int) (map_info->base_pixel+
7686 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7687 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7688 if ((image->matte == MagickFalse) &&
7689 (resource_info->color_recovery == MagickFalse) &&
7690 resource_info->quantize_info->dither &&
7691 (number_colors < MaxColormapSize))
7696 register PixelPacket
7700 Improve image appearance with error diffusion.
7702 affinity_image=AcquireImage((ImageInfo *) NULL);
7703 if (affinity_image == (Image *) NULL)
7704 ThrowXWindowFatalException(ResourceLimitFatalError,
7705 "UnableToDitherImage",image->filename);
7706 affinity_image->columns=number_colors;
7707 affinity_image->rows=1;
7709 Initialize colormap image.
7711 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7713 if (q != (PixelPacket *) NULL)
7715 for (i=0; i < (long) number_colors; i++)
7718 if (map_info->red_max != 0)
7719 q->red=ScaleXToQuantum((unsigned long) (i/
7720 map_info->red_mult),map_info->red_max);
7721 q->green=(Quantum) 0;
7722 if (map_info->green_max != 0)
7723 q->green=ScaleXToQuantum((unsigned long) ((i/
7724 map_info->green_mult) % (map_info->green_max+1)),
7725 map_info->green_max);
7726 q->blue=(Quantum) 0;
7727 if (map_info->blue_max != 0)
7728 q->blue=ScaleXToQuantum((unsigned long) (i %
7729 map_info->green_mult),map_info->blue_max);
7730 q->opacity=(Quantum) TransparentOpacity;
7733 (void) SyncAuthenticPixels(affinity_image,exception);
7734 (void) RemapImage(resource_info->quantize_info,image,
7737 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7739 (void) SetImageStorageClass(image,DirectClass);
7740 affinity_image=DestroyImage(affinity_image);
7742 if (IsEventLogging())
7744 (void) LogMagickEvent(X11Event,GetMagickModule(),
7745 "Standard Colormap:");
7746 (void) LogMagickEvent(X11Event,GetMagickModule(),
7747 " colormap id: 0x%lx",map_info->colormap);
7748 (void) LogMagickEvent(X11Event,GetMagickModule(),
7749 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7750 map_info->green_max,map_info->blue_max);
7751 (void) LogMagickEvent(X11Event,GetMagickModule(),
7752 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7753 map_info->green_mult,map_info->blue_mult);
7757 if ((visual_info->klass != DirectColor) &&
7758 (visual_info->klass != TrueColor))
7759 if ((image->storage_class == DirectClass) ||
7760 ((int) image->colors > visual_info->colormap_size))
7766 Image has more colors than the visual supports.
7768 quantize_info=(*resource_info->quantize_info);
7769 quantize_info.number_colors=(unsigned long) visual_info->colormap_size;
7770 (void) QuantizeImage(&quantize_info,image);
7773 Free previous and create new colormap.
7775 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7776 colormap=XDefaultColormap(display,visual_info->screen);
7777 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7778 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7779 visual_info->visual,visual_info->klass == DirectColor ?
7780 AllocAll : AllocNone);
7781 if (colormap == (Colormap) NULL)
7782 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7785 Initialize the map and pixel info structures.
7787 XGetMapInfo(visual_info,colormap,map_info);
7788 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7790 Allocating colors in server colormap is based on visual class.
7792 switch (visual_info->klass)
7798 Define Standard Colormap for StaticGray or StaticColor visual.
7800 number_colors=image->colors;
7801 colors=(XColor *) AcquireQuantumMemory((size_t)
7802 visual_info->colormap_size,sizeof(*colors));
7803 if (colors == (XColor *) NULL)
7804 ThrowXWindowFatalException(ResourceLimitFatalError,
7805 "UnableToCreateColormap",image->filename);
7807 color.flags=(char) (DoRed | DoGreen | DoBlue);
7808 for (i=0; i < (long) image->colors; i++)
7810 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7811 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7812 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7813 if (visual_info->klass != StaticColor)
7815 gray_value=(unsigned short) XPixelIntensity(&color);
7816 color.red=gray_value;
7817 color.green=gray_value;
7818 color.blue=gray_value;
7820 status=XAllocColor(display,colormap,&color);
7821 if (status == False)
7823 colormap=XCopyColormapAndFree(display,colormap);
7824 (void) XAllocColor(display,colormap,&color);
7826 pixel->pixels[i]=color.pixel;
7838 Define Standard Colormap for GrayScale or PseudoColor visual.
7840 number_colors=image->colors;
7841 colors=(XColor *) AcquireQuantumMemory((size_t)
7842 visual_info->colormap_size,sizeof(*colors));
7843 if (colors == (XColor *) NULL)
7844 ThrowXWindowFatalException(ResourceLimitFatalError,
7845 "UnableToCreateColormap",image->filename);
7847 Preallocate our GUI colors.
7849 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7850 (void) XAllocColor(display,colormap,&pixel->background_color);
7851 (void) XAllocColor(display,colormap,&pixel->border_color);
7852 (void) XAllocColor(display,colormap,&pixel->matte_color);
7853 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7854 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7855 (void) XAllocColor(display,colormap,&pixel->depth_color);
7856 (void) XAllocColor(display,colormap,&pixel->trough_color);
7857 for (i=0; i < MaxNumberPens; i++)
7858 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7860 Determine if image colors will "fit" into X server colormap.
7862 colormap_type=resource_info->colormap;
7863 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7864 NULL,0,pixel->pixels,(unsigned int) image->colors);
7865 if (status != False)
7866 colormap_type=PrivateColormap;
7867 if (colormap_type == SharedColormap)
7885 Define Standard colormap for shared GrayScale or PseudoColor visual.
7887 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7888 sizeof(*diversity));
7889 if (diversity == (DiversityPacket *) NULL)
7890 ThrowXWindowFatalException(ResourceLimitFatalError,
7891 "UnableToCreateColormap",image->filename);
7892 for (i=0; i < (long) image->colors; i++)
7894 diversity[i].red=image->colormap[i].red;
7895 diversity[i].green=image->colormap[i].green;
7896 diversity[i].blue=image->colormap[i].blue;
7897 diversity[i].index=(unsigned short) i;
7898 diversity[i].count=0;
7900 for (y=0; y < (int) image->rows; y++)
7905 register PixelPacket
7908 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7909 if (q == (PixelPacket *) NULL)
7911 indexes=GetAuthenticIndexQueue(image);
7912 for (x=(long) image->columns-1; x >= 0; x--)
7913 diversity[(long) indexes[x]].count++;
7916 Sort colors by decreasing intensity.
7918 qsort((void *) diversity,image->colors,sizeof(*diversity),
7920 for (i=0; i < (long) image->colors; )
7922 diversity[i].count<<=4; /* increase this colors popularity */
7923 i+=MagickMax((long) (image->colors >> 4),2);
7925 diversity[image->colors-1].count<<=4;
7926 qsort((void *) diversity,image->colors,sizeof(*diversity),
7932 color.flags=(char) (DoRed | DoGreen | DoBlue);
7933 for (i=0; i < (long) image->colors; i++)
7935 index=diversity[i].index;
7937 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7939 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7941 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7942 if (visual_info->klass != PseudoColor)
7944 gray_value=(unsigned short) XPixelIntensity(&color);
7945 color.red=gray_value;
7946 color.green=gray_value;
7947 color.blue=gray_value;
7949 status=XAllocColor(display,colormap,&color);
7950 if (status == False)
7952 pixel->pixels[index]=color.pixel;
7956 Read X server colormap.
7958 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7959 visual_info->colormap_size,sizeof(*server_colors));
7960 if (server_colors == (XColor *) NULL)
7961 ThrowXWindowFatalException(ResourceLimitFatalError,
7962 "UnableToCreateColormap",image->filename);
7963 for (x=visual_info->colormap_size-1; x >= 0; x--)
7964 server_colors[x].pixel=(unsigned long) x;
7965 (void) XQueryColors(display,colormap,server_colors,
7966 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7968 Select remaining colors from X server colormap.
7970 for (; i < (long) image->colors; i++)
7972 index=diversity[i].index;
7974 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7976 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7978 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7979 if (visual_info->klass != PseudoColor)
7981 gray_value=(unsigned short) XPixelIntensity(&color);
7982 color.red=gray_value;
7983 color.green=gray_value;
7984 color.blue=gray_value;
7986 XBestPixel(display,colormap,server_colors,(unsigned int)
7987 visual_info->colormap_size,&color);
7988 pixel->pixels[index]=color.pixel;
7991 if ((int) image->colors < visual_info->colormap_size)
7994 Fill up colors array-- more choices for pen colors.
7996 retain_colors=MagickMin((unsigned int)
7997 (visual_info->colormap_size-image->colors),256);
7998 for (i=0; i < (long) retain_colors; i++)
7999 *p++=server_colors[i];
8000 number_colors+=retain_colors;
8002 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8003 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8007 Define Standard colormap for private GrayScale or PseudoColor visual.
8009 if (status == False)
8012 Not enough colormap entries in the colormap-- Create a new colormap.
8014 colormap=XCreateColormap(display,
8015 XRootWindow(display,visual_info->screen),visual_info->visual,
8017 if (colormap == (Colormap) NULL)
8018 ThrowXWindowFatalException(ResourceLimitFatalError,
8019 "UnableToCreateColormap",image->filename);
8020 map_info->colormap=colormap;
8021 if ((int) image->colors < visual_info->colormap_size)
8024 Retain colors from the default colormap to help lessens the
8025 effects of colormap flashing.
8027 retain_colors=MagickMin((unsigned int)
8028 (visual_info->colormap_size-image->colors),256);
8029 p=colors+image->colors;
8030 for (i=0; i < (long) retain_colors; i++)
8032 p->pixel=(unsigned long) i;
8035 (void) XQueryColors(display,
8036 XDefaultColormap(display,visual_info->screen),
8037 colors+image->colors,(int) retain_colors);
8039 Transfer colors from default to private colormap.
8041 (void) XAllocColorCells(display,colormap,MagickFalse,
8042 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8044 p=colors+image->colors;
8045 for (i=0; i < (long) retain_colors; i++)
8047 p->pixel=pixel->pixels[i];
8050 (void) XStoreColors(display,colormap,colors+image->colors,
8051 (int) retain_colors);
8052 number_colors+=retain_colors;
8054 (void) XAllocColorCells(display,colormap,MagickFalse,
8055 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8059 Store the image colormap.
8062 color.flags=(char) (DoRed | DoGreen | DoBlue);
8063 for (i=0; i < (long) image->colors; i++)
8065 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8066 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8067 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8068 if (visual_info->klass != PseudoColor)
8070 gray_value=(unsigned short) XPixelIntensity(&color);
8071 color.red=gray_value;
8072 color.green=gray_value;
8073 color.blue=gray_value;
8075 color.pixel=pixel->pixels[i];
8078 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8089 Define Standard Colormap for TrueColor or DirectColor visual.
8091 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8092 (map_info->green_max*map_info->green_mult)+
8093 (map_info->blue_max*map_info->blue_mult)+1);
8094 linear_colormap=(number_colors > 4096) ||
8095 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8096 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8097 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8098 MagickTrue : MagickFalse;
8099 if (linear_colormap != MagickFalse)
8100 number_colors=(unsigned long) visual_info->colormap_size;
8102 Allocate color array.
8104 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8105 if (colors == (XColor *) NULL)
8106 ThrowXWindowFatalException(ResourceLimitFatalError,
8107 "UnableToCreateColormap",image->filename);
8109 Initialize linear color ramp.
8112 color.flags=(char) (DoRed | DoGreen | DoBlue);
8113 if (linear_colormap != MagickFalse)
8114 for (i=0; i < (long) number_colors; i++)
8116 color.blue=(unsigned short) 0;
8117 if (map_info->blue_max != 0)
8118 color.blue=(unsigned short) ((unsigned long)
8119 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8120 color.green=color.blue;
8121 color.red=color.blue;
8122 color.pixel=XStandardPixel(map_info,&color);
8126 for (i=0; i < (long) number_colors; i++)
8128 color.red=(unsigned short) 0;
8129 if (map_info->red_max != 0)
8130 color.red=(unsigned short) ((unsigned long)
8131 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8132 color.green=(unsigned int) 0;
8133 if (map_info->green_max != 0)
8134 color.green=(unsigned short) ((unsigned long)
8135 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8136 map_info->green_max));
8137 color.blue=(unsigned short) 0;
8138 if (map_info->blue_max != 0)
8139 color.blue=(unsigned short) ((unsigned long)
8140 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8141 color.pixel=XStandardPixel(map_info,&color);
8144 if ((visual_info->klass == DirectColor) &&
8145 (colormap != XDefaultColormap(display,visual_info->screen)))
8146 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8148 for (i=0; i < (long) number_colors; i++)
8149 (void) XAllocColor(display,colormap,&colors[i]);
8153 if ((visual_info->klass != DirectColor) &&
8154 (visual_info->klass != TrueColor))
8157 Set foreground, background, border, etc. pixels.
8159 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8160 &pixel->foreground_color);
8161 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8162 &pixel->background_color);
8163 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8166 Foreground and background colors must differ.
8168 pixel->background_color.red=(~pixel->foreground_color.red);
8169 pixel->background_color.green=
8170 (~pixel->foreground_color.green);
8171 pixel->background_color.blue=
8172 (~pixel->foreground_color.blue);
8173 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8174 &pixel->background_color);
8176 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8177 &pixel->border_color);
8178 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8179 &pixel->matte_color);
8180 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8181 &pixel->highlight_color);
8182 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8183 &pixel->shadow_color);
8184 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8185 &pixel->depth_color);
8186 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8187 &pixel->trough_color);
8188 for (i=0; i < MaxNumberPens; i++)
8190 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8191 &pixel->pen_colors[i]);
8192 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8194 pixel->colors=image->colors+MaxNumberPens;
8196 colors=(XColor *) RelinquishMagickMemory(colors);
8197 if (IsEventLogging())
8199 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8200 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8201 map_info->colormap);
8202 (void) LogMagickEvent(X11Event,GetMagickModule(),
8203 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8204 map_info->green_max,map_info->blue_max);
8205 (void) LogMagickEvent(X11Event,GetMagickModule(),
8206 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8207 map_info->green_mult,map_info->blue_mult);
8212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8216 % X M a k e W i n d o w %
8220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8222 % XMakeWindow() creates an X11 window.
8224 % The format of the XMakeWindow method is:
8226 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8227 % XClassHint *class_hint,XWMHints *manager_hints,
8228 % XWindowInfo *window_info)
8230 % A description of each parameter follows:
8232 % o display: Specifies a connection to an X server; returned from
8235 % o parent: Specifies the parent window_info.
8237 % o argv: Specifies the application's argument list.
8239 % o argc: Specifies the number of arguments.
8241 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8243 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8245 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8248 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8249 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8250 XWindowInfo *window_info)
8252 #define MinWindowSize 64
8260 static XTextProperty
8271 Set window info hints.
8273 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8274 assert(display != (Display *) NULL);
8275 assert(window_info != (XWindowInfo *) NULL);
8276 size_hints=XAllocSizeHints();
8277 if (size_hints == (XSizeHints *) NULL)
8278 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8279 size_hints->flags=(long) window_info->flags;
8280 size_hints->x=window_info->x;
8281 size_hints->y=window_info->y;
8282 size_hints->width=(int) window_info->width;
8283 size_hints->height=(int) window_info->height;
8284 if (window_info->immutable != MagickFalse)
8287 Window size cannot be changed.
8289 size_hints->min_width=size_hints->width;
8290 size_hints->min_height=size_hints->height;
8291 size_hints->max_width=size_hints->width;
8292 size_hints->max_height=size_hints->height;
8293 size_hints->flags|=PMinSize;
8294 size_hints->flags|=PMaxSize;
8299 Window size can be changed.
8301 size_hints->min_width=(int) window_info->min_width;
8302 size_hints->min_height=(int) window_info->min_height;
8303 size_hints->flags|=PResizeInc;
8304 size_hints->width_inc=(int) window_info->width_inc;
8305 size_hints->height_inc=(int) window_info->height_inc;
8306 #if !defined(PRE_R4_ICCCM)
8307 size_hints->flags|=PBaseSize;
8308 size_hints->base_width=size_hints->width_inc;
8309 size_hints->base_height=size_hints->height_inc;
8312 gravity=NorthWestGravity;
8313 if (window_info->geometry != (char *) NULL)
8316 default_geometry[MaxTextExtent],
8317 geometry[MaxTextExtent];
8326 User specified geometry.
8328 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8329 size_hints->width,size_hints->height);
8330 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8332 while (strlen(p) != 0)
8334 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8337 (void) CopyMagickString(p,p+1,MaxTextExtent);
8339 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8340 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8341 &size_hints->width,&size_hints->height,&gravity);
8342 if ((flags & WidthValue) && (flags & HeightValue))
8343 size_hints->flags|=USSize;
8344 if ((flags & XValue) && (flags & YValue))
8346 size_hints->flags|=USPosition;
8347 window_info->x=size_hints->x;
8348 window_info->y=size_hints->y;
8351 #if !defined(PRE_R4_ICCCM)
8352 size_hints->win_gravity=gravity;
8353 size_hints->flags|=PWinGravity;
8355 if (window_info->id == (Window) NULL)
8356 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8357 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8358 window_info->border_width,(int) window_info->depth,InputOutput,
8359 window_info->visual,window_info->mask,&window_info->attributes);
8372 Window already exists; change relevant attributes.
8374 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8375 &window_info->attributes);
8376 mask=ConfigureNotify;
8377 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8378 window_changes.x=window_info->x;
8379 window_changes.y=window_info->y;
8380 window_changes.width=(int) window_info->width;
8381 window_changes.height=(int) window_info->height;
8382 mask=(MagickStatusType) (CWWidth | CWHeight);
8383 if (window_info->flags & USPosition)
8385 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8386 mask,&window_changes);
8388 if (window_info->id == (Window) NULL)
8389 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8391 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8392 if (status == False)
8393 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8395 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8396 if (status == False)
8397 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8398 window_info->icon_name);
8399 if (window_info->icon_geometry != (char *) NULL)
8407 User specified icon geometry.
8409 size_hints->flags|=USPosition;
8410 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8411 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8412 &manager_hints->icon_y,&width,&height,&gravity);
8413 if ((flags & XValue) && (flags & YValue))
8414 manager_hints->flags|=IconPositionHint;
8416 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8417 size_hints,manager_hints,class_hint);
8418 if (window_name.value != (void *) NULL)
8420 (void) XFree((void *) window_name.value);
8421 window_name.value=(unsigned char *) NULL;
8422 window_name.nitems=0;
8424 if (icon_name.value != (void *) NULL)
8426 (void) XFree((void *) icon_name.value);
8427 icon_name.value=(unsigned char *) NULL;
8430 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8431 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8432 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8433 (void) XFree((void *) size_hints);
8434 if (window_info->shape != MagickFalse)
8436 #if defined(MAGICKCORE_HAVE_SHAPE)
8442 Can we apply a non-rectangular shaping mask?
8446 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8447 window_info->shape=MagickFalse;
8449 window_info->shape=MagickFalse;
8452 if (window_info->shared_memory)
8454 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8456 Can we use shared memory with this window?
8458 if (XShmQueryExtension(display) == 0)
8459 window_info->shared_memory=MagickFalse;
8461 window_info->shared_memory=MagickFalse;
8464 window_info->image=NewImageList();
8465 window_info->destroy=MagickFalse;
8469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8473 % X M a g i c k P r o g r e s s M o n i t o r %
8477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8479 % XMagickProgressMonitor() displays the progress a task is making in
8480 % completing a task.
8482 % The format of the XMagickProgressMonitor method is:
8484 % void XMagickProgressMonitor(const char *task,
8485 % const MagickOffsetType quantum,const MagickSizeType span,
8486 % void *client_data)
8488 % A description of each parameter follows:
8490 % o task: Identifies the task in progress.
8492 % o quantum: Specifies the quantum position within the span which represents
8493 % how much progress has been made in completing a task.
8495 % o span: Specifies the span relative to completing a task.
8497 % o client_data: Pointer to any client data.
8501 static const char *GetLocaleMonitorMessage(const char *text)
8504 message[MaxTextExtent],
8513 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8515 if (p != (char *) NULL)
8517 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8518 locale_message=GetLocaleMessage(message);
8519 if (locale_message == message)
8521 return(locale_message);
8524 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8525 const MagickOffsetType quantum,const MagickSizeType span,
8526 void *magick_unused(client_data))
8531 windows=XSetWindows((XWindows *) ~0);
8532 if (windows == (XWindows *) NULL)
8534 if (windows->info.mapped != MagickFalse)
8535 XProgressMonitorWidget(windows->display,windows,
8536 GetLocaleMonitorMessage(tag),quantum,span);
8541 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8545 % X Q u e r y C o l o r D a t a b a s e %
8549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8551 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8554 % The format of the XQueryColorDatabase method is:
8556 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8558 % A description of each parameter follows:
8560 % o target: Specifies the color to lookup in the X color database.
8562 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8563 % color is returned as this value.
8566 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8573 *display = (Display *) NULL;
8582 Initialize color return value.
8584 assert(color != (XColor *) NULL);
8588 color->flags=(char) (DoRed | DoGreen | DoBlue);
8589 if ((target == (char *) NULL) || (*target == '\0'))
8590 target="#ffffffffffff";
8592 Let the X server define the color for us.
8594 if (display == (Display *) NULL)
8595 display=XOpenDisplay((char *) NULL);
8596 if (display == (Display *) NULL)
8598 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8599 return(MagickFalse);
8601 colormap=XDefaultColormap(display,XDefaultScreen(display));
8602 status=XParseColor(display,colormap,(char *) target,&xcolor);
8603 if (status == False)
8604 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8607 color->red=xcolor.red;
8608 color->green=xcolor.green;
8609 color->blue=xcolor.blue;
8610 color->flags=xcolor.flags;
8612 return(status != False ? MagickTrue : MagickFalse);
8616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8620 % X Q u e r y P o s i t i o n %
8624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8626 % XQueryPosition() gets the pointer coordinates relative to a window.
8628 % The format of the XQueryPosition method is:
8630 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8632 % A description of each parameter follows:
8634 % o display: Specifies a connection to an X server; returned from
8637 % o window: Specifies a pointer to a Window.
8639 % o x: Return the x coordinate of the pointer relative to the origin of the
8642 % o y: Return the y coordinate of the pointer relative to the origin of the
8646 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8658 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8659 assert(display != (Display *) NULL);
8660 assert(window != (Window) NULL);
8661 assert(x != (int *) NULL);
8662 assert(y != (int *) NULL);
8663 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8672 % X R e f r e s h W i n d o w %
8676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8678 % XRefreshWindow() refreshes an image in a X window.
8680 % The format of the XRefreshWindow method is:
8682 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8683 % const XEvent *event)
8685 % A description of each parameter follows:
8687 % o display: Specifies a connection to an X server; returned from
8690 % o window: Specifies a pointer to a XWindowInfo structure.
8692 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8693 % the entire image is refreshed.
8696 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8697 const XEvent *event)
8707 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8708 assert(display != (Display *) NULL);
8709 assert(window != (XWindowInfo *) NULL);
8710 if (window->ximage == (XImage *) NULL)
8712 if (event != (XEvent *) NULL)
8715 Determine geometry from expose event.
8719 width=(unsigned int) event->xexpose.width;
8720 height=(unsigned int) event->xexpose.height;
8728 Refresh entire window; discard outstanding expose events.
8732 width=window->width;
8733 height=window->height;
8734 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8737 Check boundary conditions.
8739 if ((window->ximage->width-(x+window->x)) < (int) width)
8740 width=(unsigned int) (window->ximage->width-(x+window->x));
8741 if ((window->ximage->height-(y+window->y)) < (int) height)
8742 height=(unsigned int) (window->ximage->height-(y+window->y));
8746 if (window->matte_pixmap != (Pixmap) NULL)
8748 #if defined(MAGICKCORE_HAVE_SHAPE)
8749 if (window->shape != MagickFalse)
8750 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8751 window->matte_pixmap,ShapeSet);
8753 (void) XSetClipMask(display,window->annotate_context,
8754 window->matte_pixmap);
8756 if (window->pixmap != (Pixmap) NULL)
8758 if (window->depth > 1)
8759 (void) XCopyArea(display,window->pixmap,window->id,
8760 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8762 (void) XCopyPlane(display,window->pixmap,window->id,
8763 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8768 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8769 if (window->shared_memory)
8770 (void) XShmPutImage(display,window->id,window->annotate_context,
8771 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8773 if (window->shared_memory == MagickFalse)
8774 (void) XPutImage(display,window->id,window->annotate_context,
8775 window->ximage,x+window->x,y+window->y,x,y,width,height);
8777 if (window->matte_pixmap != (Pixmap) NULL)
8778 (void) XSetClipMask(display,window->annotate_context,None);
8779 (void) XFlush(display);
8783 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8787 % X R e m o t e C o m m a n d %
8791 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8793 % XRemoteCommand() forces a remote display(1) to display the specified
8796 % The format of the XRemoteCommand method is:
8798 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8799 % const char *filename)
8801 % A description of each parameter follows:
8803 % o display: Specifies a connection to an X server; returned from
8806 % o window: Specifies the name or id of an X window.
8808 % o filename: the name of the image filename to display.
8811 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8812 const char *window,const char *filename)
8821 assert(filename != (char *) NULL);
8822 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8823 if (display == (Display *) NULL)
8824 display=XOpenDisplay((char *) NULL);
8825 if (display == (Display *) NULL)
8827 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8828 return(MagickFalse);
8830 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8831 remote_window=(Window) NULL;
8832 root_window=XRootWindow(display,XDefaultScreen(display));
8833 if (window != (char *) NULL)
8836 Search window hierarchy and identify any clients by name or ID.
8838 if (isdigit((unsigned char) *window) != 0)
8839 remote_window=XWindowByID(display,root_window,(Window)
8840 strtol((char *) window,(char **) NULL,0));
8841 if (remote_window == (Window) NULL)
8842 remote_window=XWindowByName(display,root_window,window);
8844 if (remote_window == (Window) NULL)
8845 remote_window=XWindowByProperty(display,root_window,remote_atom);
8846 if (remote_window == (Window) NULL)
8848 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8850 return(MagickFalse);
8853 Send remote command.
8855 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8856 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8857 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8858 (void) XSync(display,MagickFalse);
8863 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8867 % X R e t a i n W i n d o w C o l o r s %
8871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8873 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8874 % the colors associated with an image displayed on the window.
8876 % The format of the XRetainWindowColors method is:
8878 % void XRetainWindowColors(Display *display,const Window window)
8880 % A description of each parameter follows:
8882 % o display: Specifies a connection to an X server; returned from
8885 % o window: Specifies a pointer to a XWindowInfo structure.
8888 MagickExport void XRetainWindowColors(Display *display,const Window window)
8897 Put property on the window.
8899 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8900 assert(display != (Display *) NULL);
8901 assert(window != (Window) NULL);
8902 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8903 if (property == (Atom) NULL)
8905 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8909 pixmap=XCreatePixmap(display,window,1,1,1);
8910 if (pixmap == (Pixmap) NULL)
8912 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8915 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8916 (unsigned char *) &pixmap,1);
8917 (void) XSetCloseDownMode(display,RetainPermanent);
8921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8925 % X S e l e c t W i n d o w %
8929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8931 % XSelectWindow() allows a user to select a window using the mouse. If the
8932 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8933 % is returned in the crop_info structure.
8935 % The format of the XSelectWindow function is:
8937 % target_window=XSelectWindow(display,crop_info)
8939 % A description of each parameter follows:
8941 % o window: XSelectWindow returns the window id.
8943 % o display: Specifies a pointer to the Display structure; returned from
8946 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8947 % contains the extents of any cropping rectangle.
8950 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8952 #define MinimumCropArea (unsigned int) 9
8979 Initialize graphic context.
8981 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8982 assert(display != (Display *) NULL);
8983 assert(crop_info != (RectangleInfo *) NULL);
8984 root_window=XRootWindow(display,XDefaultScreen(display));
8985 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8986 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8987 context_values.function=GXinvert;
8988 context_values.plane_mask=
8989 context_values.background ^ context_values.foreground;
8990 context_values.subwindow_mode=IncludeInferiors;
8991 annotate_context=XCreateGC(display,root_window,(unsigned long) (GCBackground |
8992 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8993 if (annotate_context == (GC) NULL)
8994 return(MagickFalse);
8996 Grab the pointer using target cursor.
8998 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
8999 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9000 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9001 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9002 GrabModeAsync,root_window,target_cursor,CurrentTime);
9003 if (status != GrabSuccess)
9005 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9006 return((Window) NULL);
9012 crop_info->height=0;
9014 target_window=(Window) NULL;
9019 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9020 (void) XDrawRectangle(display,root_window,annotate_context,
9021 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9022 (unsigned int) crop_info->height-1);
9024 Allow another event.
9026 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9027 (void) XWindowEvent(display,root_window,ButtonPressMask |
9028 ButtonReleaseMask | ButtonMotionMask,&event);
9029 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9030 (void) XDrawRectangle(display,root_window,annotate_context,
9031 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9032 (unsigned int) crop_info->height-1);
9037 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9038 event.xbutton.x,event.xbutton.y);
9039 if (target_window == (Window) NULL)
9040 target_window=root_window;
9041 x_offset=event.xbutton.x_root;
9042 y_offset=event.xbutton.y_root;
9043 crop_info->x=x_offset;
9044 crop_info->y=y_offset;
9046 crop_info->height=0;
9058 Discard pending button motion events.
9060 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9061 crop_info->x=event.xmotion.x;
9062 crop_info->y=event.xmotion.y;
9064 Check boundary conditions.
9066 if ((int) crop_info->x < x_offset)
9067 crop_info->width=(unsigned int) (x_offset-crop_info->x);
9070 crop_info->width=(unsigned int) (crop_info->x-x_offset);
9071 crop_info->x=x_offset;
9073 if ((int) crop_info->y < y_offset)
9074 crop_info->height=(unsigned int) (y_offset-crop_info->y);
9077 crop_info->height=(unsigned int) (crop_info->y-y_offset);
9078 crop_info->y=y_offset;
9084 } while ((target_window == (Window) NULL) || (presses > 0));
9085 (void) XUngrabPointer(display,CurrentTime);
9086 (void) XFreeCursor(display,target_cursor);
9087 (void) XFreeGC(display,annotate_context);
9088 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9091 crop_info->height=0;
9093 if ((crop_info->width != 0) && (crop_info->height != 0))
9094 target_window=root_window;
9095 return(target_window);
9099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9103 % X S e t C u r s o r S t a t e %
9107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9109 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9110 % reset to their default.
9112 % The format of the XXSetCursorState method is:
9114 % XSetCursorState(display,windows,const MagickStatusType state)
9116 % A description of each parameter follows:
9118 % o display: Specifies a connection to an X server; returned from
9121 % o windows: Specifies a pointer to a XWindows structure.
9123 % o state: An unsigned integer greater than 0 sets the cursor state
9124 % to busy, otherwise the cursor are reset to their default.
9127 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9128 const MagickStatusType state)
9130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9131 assert(display != (Display *) NULL);
9132 assert(windows != (XWindows *) NULL);
9135 (void) XCheckDefineCursor(display,windows->image.id,
9136 windows->image.busy_cursor);
9137 (void) XCheckDefineCursor(display,windows->pan.id,
9138 windows->pan.busy_cursor);
9139 (void) XCheckDefineCursor(display,windows->magnify.id,
9140 windows->magnify.busy_cursor);
9141 (void) XCheckDefineCursor(display,windows->command.id,
9142 windows->command.busy_cursor);
9146 (void) XCheckDefineCursor(display,windows->image.id,
9147 windows->image.cursor);
9148 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9149 (void) XCheckDefineCursor(display,windows->magnify.id,
9150 windows->magnify.cursor);
9151 (void) XCheckDefineCursor(display,windows->command.id,
9152 windows->command.cursor);
9153 (void) XCheckDefineCursor(display,windows->command.id,
9154 windows->widget.cursor);
9155 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9157 windows->info.mapped=MagickFalse;
9161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9165 % X S e t W i n d o w s %
9169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9171 % XSetWindows() sets the X windows structure if the windows info is specified.
9172 % Otherwise the current windows structure is returned.
9174 % The format of the XSetWindows method is:
9176 % XWindows *XSetWindows(XWindows *windows_info)
9178 % A description of each parameter follows:
9180 % o windows_info: Initialize the Windows structure with this information.
9183 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9186 *windows = (XWindows *) NULL;
9188 if (windows_info != (XWindows *) ~0)
9190 windows=(XWindows *) RelinquishMagickMemory(windows);
9191 windows=windows_info;
9196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9200 % X U s e r P r e f e r e n c e s %
9204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9206 % XUserPreferences() saves the preferences in a configuration file in the
9207 % users' home directory.
9209 % The format of the XUserPreferences method is:
9211 % void XUserPreferences(XResourceInfo *resource_info)
9213 % A description of each parameter follows:
9215 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9218 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9220 #if defined(X11_PREFERENCES_PATH)
9222 cache[MaxTextExtent],
9223 filename[MaxTextExtent],
9224 specifier[MaxTextExtent];
9231 preferences_database;
9234 Save user preferences to the client configuration file.
9236 assert(resource_info != (XResourceInfo *) NULL);
9237 client_name=GetClientName();
9238 preferences_database=XrmGetStringDatabase("");
9239 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9240 value=resource_info->backdrop ? "True" : "False";
9241 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9242 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9243 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9244 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9245 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9247 value=resource_info->confirm_exit ? "True" : "False";
9248 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9249 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9251 value=resource_info->confirm_edit ? "True" : "False";
9252 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9253 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9255 value=resource_info->display_warnings ? "True" : "False";
9256 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9257 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9258 value=resource_info->quantize_info->dither ? "True" : "False";
9259 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9260 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9262 value=resource_info->gamma_correct ? "True" : "False";
9263 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9264 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9265 (void) FormatMagickString(cache,MaxTextExtent,"%lu",
9266 resource_info->undo_cache);
9267 XrmPutStringResource(&preferences_database,specifier,cache);
9268 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9269 value=resource_info->use_pixmap ? "True" : "False";
9270 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9271 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9272 X11_PREFERENCES_PATH,client_name);
9273 ExpandFilename(filename);
9274 XrmPutFileDatabase(preferences_database,filename);
9279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9283 % X V i s u a l C l a s s N a m e %
9287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9289 % XVisualClassName() returns the visual class name as a character string.
9291 % The format of the XVisualClassName method is:
9293 % char *XVisualClassName(const int visual_class)
9295 % A description of each parameter follows:
9297 % o visual_type: XVisualClassName returns the visual class as a character
9300 % o class: Specifies the visual class.
9303 static const char *XVisualClassName(const int visual_class)
9305 switch (visual_class)
9307 case StaticGray: return("StaticGray");
9308 case GrayScale: return("GrayScale");
9309 case StaticColor: return("StaticColor");
9310 case PseudoColor: return("PseudoColor");
9311 case TrueColor: return("TrueColor");
9312 case DirectColor: return("DirectColor");
9314 return("unknown visual class");
9318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9328 % XWarning() displays a warning reason in a Notice widget.
9330 % The format of the XWarning method is:
9332 % void XWarning(const unsigned int warning,const char *reason,
9333 % const char *description)
9335 % A description of each parameter follows:
9337 % o warning: Specifies the numeric warning category.
9339 % o reason: Specifies the reason to display before terminating the
9342 % o description: Specifies any description to the reason.
9345 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9346 const char *reason,const char *description)
9349 text[MaxTextExtent];
9354 if (reason == (char *) NULL)
9356 (void) CopyMagickString(text,reason,MaxTextExtent);
9357 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9358 windows=XSetWindows((XWindows *) ~0);
9359 XNoticeWidget(windows->display,windows,text,(char *) description);
9363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9367 % X W i n d o w B y I D %
9371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9373 % XWindowByID() locates a child window with a given ID. If not window with
9374 % the given name is found, 0 is returned. Only the window specified and its
9375 % subwindows are searched.
9377 % The format of the XWindowByID function is:
9379 % child=XWindowByID(display,window,id)
9381 % A description of each parameter follows:
9383 % o child: XWindowByID returns the window with the specified
9384 % id. If no windows are found, XWindowByID returns 0.
9386 % o display: Specifies a pointer to the Display structure; returned from
9389 % o id: Specifies the id of the window to locate.
9392 MagickExport Window XWindowByID(Display *display,const Window root_window,
9393 const unsigned long id)
9412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9413 assert(display != (Display *) NULL);
9414 assert(root_window != (Window) NULL);
9416 return(XSelectWindow(display,&rectangle_info));
9417 if (root_window == id)
9419 status=XQueryTree(display,root_window,&child,&child,&children,
9421 if (status == False)
9422 return((Window) NULL);
9423 window=(Window) NULL;
9424 for (i=0; i < (int) number_children; i++)
9427 Search each child and their children.
9429 window=XWindowByID(display,children[i],id);
9430 if (window != (Window) NULL)
9433 if (children != (Window *) NULL)
9434 (void) XFree((void *) children);
9439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9443 % X W i n d o w B y N a m e %
9447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9449 % XWindowByName() locates a window with a given name on a display. If no
9450 % window with the given name is found, 0 is returned. If more than one window
9451 % has the given name, the first one is returned. Only root and its children
9454 % The format of the XWindowByName function is:
9456 % window=XWindowByName(display,root_window,name)
9458 % A description of each parameter follows:
9460 % o window: XWindowByName returns the window id.
9462 % o display: Specifies a pointer to the Display structure; returned from
9465 % o root_window: Specifies the id of the root window.
9467 % o name: Specifies the name of the window to locate.
9470 MagickExport Window XWindowByName(Display *display,const Window root_window,
9490 assert(display != (Display *) NULL);
9491 assert(root_window != (Window) NULL);
9492 assert(name != (char *) NULL);
9493 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9494 if (XGetWMName(display,root_window,&window_name) != 0)
9495 if (LocaleCompare((char *) window_name.value,name) == 0)
9496 return(root_window);
9497 status=XQueryTree(display,root_window,&child,&child,&children,
9499 if (status == False)
9500 return((Window) NULL);
9501 window=(Window) NULL;
9502 for (i=0; i < (int) number_children; i++)
9505 Search each child and their children.
9507 window=XWindowByName(display,children[i],name);
9508 if (window != (Window) NULL)
9511 if (children != (Window *) NULL)
9512 (void) XFree((void *) children);
9517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9521 % X W i n d o w B y P r o p e r y %
9525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9527 % XWindowByProperty() locates a child window with a given property. If not
9528 % window with the given name is found, 0 is returned. If more than one window
9529 % has the given property, the first one is returned. Only the window
9530 % specified and its subwindows are searched.
9532 % The format of the XWindowByProperty function is:
9534 % child=XWindowByProperty(display,window,property)
9536 % A description of each parameter follows:
9538 % o child: XWindowByProperty returns the window id with the specified
9539 % property. If no windows are found, XWindowByProperty returns 0.
9541 % o display: Specifies a pointer to the Display structure; returned from
9544 % o property: Specifies the property of the window to locate.
9547 MagickExport Window XWindowByProperty(Display *display,const Window window,
9548 const Atom property)
9576 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9577 assert(display != (Display *) NULL);
9578 assert(window != (Window) NULL);
9579 assert(property != (Atom) NULL);
9580 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9581 if (status == False)
9582 return((Window) NULL);
9584 child=(Window) NULL;
9585 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9587 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9588 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9590 (void) XFree((void *) data);
9591 if ((status == Success) && (type != (Atom) NULL))
9594 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9595 child=XWindowByProperty(display,children[i],property);
9596 if (children != (Window *) NULL)
9597 (void) XFree((void *) children);
9603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9607 % X I m p o r t I m a g e %
9611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9613 % XImportImage() reads an image from an X window.
9615 % The format of the XImportImage method is:
9617 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9619 % A description of each parameter follows:
9621 % o image_info: the image info..
9623 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9626 MagickExport Image *XImportImage(const ImageInfo *image_info,
9627 XImportInfo *ximage_info)
9629 assert(image_info != (const ImageInfo *) NULL);
9630 assert(image_info->signature == MagickSignature);
9631 if (image_info->debug != MagickFalse)
9632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9633 image_info->filename);
9634 assert(ximage_info != (XImportInfo *) NULL);
9635 return((Image *) NULL);
9640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9644 + X C o m p o n e n t G e n e s i s %
9648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9650 % XComponentGenesis() instantiates the X component.
9652 % The format of the XComponentGenesis method is:
9654 % MagickBooleanType XComponentGenesis(void)
9657 MagickExport MagickBooleanType XComponentGenesis(void)
9663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9667 % X G e t I m p o r t I n f o %
9671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9673 % XGetImportInfo() initializes the XImportInfo structure.
9675 % The format of the XGetImportInfo method is:
9677 % void XGetImportInfo(XImportInfo *ximage_info)
9679 % A description of each parameter follows:
9681 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9684 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9686 assert(ximage_info != (XImportInfo *) NULL);
9687 ximage_info->frame=MagickFalse;
9688 ximage_info->borders=MagickFalse;
9689 ximage_info->screen=MagickFalse;
9690 ximage_info->descend=MagickTrue;
9691 ximage_info->silent=MagickFalse;