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 ((window->immutable == MagickFalse) &&
5850 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5853 size[MaxTextExtent];
5861 image_info=AcquireImageInfo();
5862 (void) CopyMagickString(image_info->filename,
5863 resource_info->image_info->texture != (char *) NULL ?
5864 resource_info->image_info->texture : "pattern:checkerboard",
5866 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
5868 image_info->size=ConstantString(size);
5869 pattern=ReadImage(image_info,&image->exception);
5870 image_info=DestroyImageInfo(image_info);
5871 if (pattern != (Image *) NULL)
5873 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5874 if (canvas != (Image *) NULL)
5875 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5876 pattern=DestroyImage(pattern);
5879 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5880 ximage->bits_per_pixel) >> 3));
5881 map_info=window->map_info;
5882 pixels=window->pixel_info->pixels;
5883 q=(unsigned char *) ximage->data;
5885 if (ximage->format == XYBitmap)
5887 register unsigned short
5895 Convert canvas to big-endian bitmap.
5897 background=(unsigned char)
5898 (XPixelIntensity(&window->pixel_info->foreground_color) <
5899 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5900 foreground=(unsigned char)
5901 (XPixelIntensity(&window->pixel_info->background_color) <
5902 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5903 polarity=(unsigned short) ((PixelIntensityToQuantum(
5904 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5905 if (canvas->colors == 2)
5906 polarity=PixelIntensity(&canvas->colormap[0]) <
5907 PixelIntensity(&canvas->colormap[1]);
5908 for (y=0; y < (int) canvas->rows; y++)
5910 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5911 if (p == (const PixelPacket *) NULL)
5913 indexes=GetVirtualIndexQueue(canvas);
5916 for (x=0; x < (int) canvas->columns; x++)
5919 if (indexes[x] == (IndexPacket) polarity)
5937 if (window->pixel_info->colors != 0)
5938 switch (ximage->bits_per_pixel)
5942 register unsigned int
5946 Convert to 2 bit color-mapped X canvas.
5948 for (y=0; y < (int) canvas->rows; y++)
5950 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5951 if (p == (const PixelPacket *) NULL)
5953 indexes=GetVirtualIndexQueue(canvas);
5955 for (x=0; x < (int) canvas->columns; x++)
5957 pixel=pixels[(long) indexes[x]] & 0x0f;
5962 *q=(unsigned char) pixel;
5968 *q|=(unsigned char) (pixel << 2);
5974 *q|=(unsigned char) (pixel << 4);
5980 *q|=(unsigned char) (pixel << 6);
5993 register unsigned int
5997 Convert to 4 bit color-mapped X canvas.
5999 for (y=0; y < (int) canvas->rows; y++)
6001 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6002 if (p == (const PixelPacket *) NULL)
6004 indexes=GetVirtualIndexQueue(canvas);
6006 for (x=0; x < (int) canvas->columns; x++)
6008 pixel=pixels[(long) indexes[x]] & 0xf;
6013 *q=(unsigned char) pixel;
6019 *q|=(unsigned char) (pixel << 4);
6034 Convert to 8 bit color-mapped X canvas.
6036 if (resource_info->color_recovery &&
6037 resource_info->quantize_info->dither)
6039 XDitherImage(canvas,ximage);
6042 for (y=0; y < (int) canvas->rows; y++)
6044 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6045 if (p == (const PixelPacket *) NULL)
6047 indexes=GetVirtualIndexQueue(canvas);
6048 for (x=0; x < (int) canvas->columns; x++)
6050 pixel=pixels[(long) indexes[x]];
6051 *q++=(unsigned char) pixel;
6062 register unsigned int
6066 channel[sizeof(unsigned long)];
6069 Convert to multi-byte color-mapped X canvas.
6071 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6072 for (y=0; y < (int) canvas->rows; y++)
6074 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6075 if (p == (const PixelPacket *) NULL)
6077 indexes=GetVirtualIndexQueue(canvas);
6078 for (x=0; x < (int) canvas->columns; x++)
6080 pixel=pixels[(long) indexes[x]];
6081 for (k=0; k < (int) bytes_per_pixel; k++)
6083 channel[k]=(unsigned char) pixel;
6086 for (k=0; k < (int) bytes_per_pixel; k++)
6095 switch (ximage->bits_per_pixel)
6099 register unsigned int
6103 Convert to contiguous 2 bit continuous-tone X canvas.
6105 for (y=0; y < (int) canvas->rows; y++)
6108 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6109 if (p == (const PixelPacket *) NULL)
6111 for (x=0; x < (int) canvas->columns; x++)
6113 pixel=XGammaPixel(map_info,p);
6119 *q=(unsigned char) pixel;
6125 *q|=(unsigned char) (pixel << 2);
6131 *q|=(unsigned char) (pixel << 4);
6137 *q|=(unsigned char) (pixel << 6);
6151 register unsigned int
6155 Convert to contiguous 4 bit continuous-tone X canvas.
6157 for (y=0; y < (int) canvas->rows; y++)
6159 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6160 if (p == (const PixelPacket *) NULL)
6163 for (x=0; x < (int) canvas->columns; x++)
6165 pixel=XGammaPixel(map_info,p);
6171 *q=(unsigned char) pixel;
6177 *q|=(unsigned char) (pixel << 4);
6193 Convert to contiguous 8 bit continuous-tone X canvas.
6195 if (resource_info->color_recovery &&
6196 resource_info->quantize_info->dither)
6198 XDitherImage(canvas,ximage);
6201 for (y=0; y < (int) canvas->rows; y++)
6203 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6204 if (p == (const PixelPacket *) NULL)
6206 for (x=0; x < (int) canvas->columns; x++)
6208 pixel=XGammaPixel(map_info,p);
6209 *q++=(unsigned char) pixel;
6218 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6219 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6220 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6221 (map_info->blue_mult == 1))
6224 Convert to 32 bit continuous-tone X canvas.
6226 for (y=0; y < (int) canvas->rows; y++)
6228 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6229 &canvas->exception);
6230 if (p == (const PixelPacket *) NULL)
6232 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6233 (blue_gamma != 1.0))
6236 Gamma correct canvas.
6238 for (x=(int) canvas->columns-1; x >= 0; x--)
6240 *q++=ScaleQuantumToChar(XBlueGamma(
6241 GetBluePixelComponent(p)));
6242 *q++=ScaleQuantumToChar(XGreenGamma(
6243 GetGreenPixelComponent(p)));
6244 *q++=ScaleQuantumToChar(XRedGamma(
6245 GetRedPixelComponent(p)));
6251 for (x=(int) canvas->columns-1; x >= 0; x--)
6253 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6254 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6255 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6262 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6263 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6264 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6265 (map_info->blue_mult == 65536L))
6268 Convert to 32 bit continuous-tone X canvas.
6270 for (y=0; y < (int) canvas->rows; y++)
6272 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6273 &canvas->exception);
6274 if (p == (const PixelPacket *) NULL)
6276 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6277 (blue_gamma != 1.0))
6280 Gamma correct canvas.
6282 for (x=(int) canvas->columns-1; x >= 0; x--)
6284 *q++=ScaleQuantumToChar(XRedGamma(
6285 GetRedPixelComponent(p)));
6286 *q++=ScaleQuantumToChar(XGreenGamma(
6287 GetGreenPixelComponent(p)));
6288 *q++=ScaleQuantumToChar(XBlueGamma(
6289 GetBluePixelComponent(p)));
6295 for (x=(int) canvas->columns-1; x >= 0; x--)
6297 *q++=ScaleQuantumToChar((Quantum)
6298 GetRedPixelComponent(p));
6299 *q++=ScaleQuantumToChar((Quantum)
6300 GetGreenPixelComponent(p));
6301 *q++=ScaleQuantumToChar((Quantum)
6302 GetBluePixelComponent(p));
6313 register unsigned int
6317 channel[sizeof(unsigned long)];
6320 Convert to multi-byte continuous-tone X canvas.
6322 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6323 for (y=0; y < (int) canvas->rows; y++)
6325 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6326 &canvas->exception);
6327 if (p == (PixelPacket *) NULL)
6329 for (x=0; x < (long) canvas->columns; x++)
6331 pixel=XGammaPixel(map_info,p);
6332 for (k=0; k < (int) bytes_per_pixel; k++)
6334 channel[k]=(unsigned char) pixel;
6337 for (k=0; k < (int) bytes_per_pixel; k++)
6347 if (matte_image != (XImage *) NULL)
6350 Initialize matte canvas.
6352 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6353 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6354 q=(unsigned char *) matte_image->data;
6355 for (y=0; y < (int) canvas->rows; y++)
6357 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6358 if (p == (const PixelPacket *) NULL)
6362 for (x=(int) canvas->columns-1; x >= 0; x--)
6365 if (p->opacity > (long) (QuantumRange/2))
6381 if (canvas != image)
6382 canvas=DestroyImage(canvas);
6386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6390 + X M a k e I m a g e M S B F i r s t %
6394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6396 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6397 % image pixels are copied in most-significant bit and byte first order. The
6398 % server's scanline pad is also respected. Rather than using one or two
6399 % general cases, many special cases are found here to help speed up the image
6402 % The format of the XMakeImageMSBFirst method is:
6404 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6406 % A description of each parameter follows:
6408 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6410 % o window: Specifies a pointer to a XWindowInfo structure.
6412 % o image: the image.
6414 % o ximage: Specifies a pointer to a XImage structure; returned from
6417 % o matte_image: Specifies a pointer to a XImage structure; returned from
6421 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6422 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6433 register const IndexPacket
6436 register const PixelPacket
6439 register unsigned char
6456 assert(resource_info != (XResourceInfo *) NULL);
6457 assert(window != (XWindowInfo *) NULL);
6458 assert(image != (Image *) NULL);
6459 if (image->debug != MagickFalse)
6460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6462 if ((window->immutable != MagickFalse) &&
6463 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6466 size[MaxTextExtent];
6474 image_info=AcquireImageInfo();
6475 (void) CopyMagickString(image_info->filename,
6476 resource_info->image_info->texture != (char *) NULL ?
6477 resource_info->image_info->texture : "pattern:checkerboard",
6479 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
6481 image_info->size=ConstantString(size);
6482 pattern=ReadImage(image_info,&image->exception);
6483 image_info=DestroyImageInfo(image_info);
6484 if (pattern != (Image *) NULL)
6486 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6487 if (canvas != (Image *) NULL)
6488 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6489 pattern=DestroyImage(pattern);
6492 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6493 ((ximage->width*ximage->bits_per_pixel) >> 3));
6494 map_info=window->map_info;
6495 pixels=window->pixel_info->pixels;
6496 q=(unsigned char *) ximage->data;
6498 if (ximage->format == XYBitmap)
6500 register unsigned short
6508 Convert canvas to big-endian bitmap.
6510 background=(unsigned char)
6511 (XPixelIntensity(&window->pixel_info->foreground_color) <
6512 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6513 foreground=(unsigned char)
6514 (XPixelIntensity(&window->pixel_info->background_color) <
6515 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6516 polarity=(unsigned short) ((PixelIntensityToQuantum(
6517 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6518 if (canvas->colors == 2)
6519 polarity=PixelIntensity(&canvas->colormap[0]) <
6520 PixelIntensity(&canvas->colormap[1]);
6521 for (y=0; y < (int) canvas->rows; y++)
6523 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6524 if (p == (const PixelPacket *) NULL)
6526 indexes=GetVirtualIndexQueue(canvas);
6529 for (x=(int) canvas->columns-1; x >= 0; x--)
6532 if (indexes[x] == (IndexPacket) polarity)
6550 if (window->pixel_info->colors != 0)
6551 switch (ximage->bits_per_pixel)
6555 register unsigned int
6559 Convert to 2 bit color-mapped X canvas.
6561 for (y=0; y < (int) canvas->rows; y++)
6563 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6564 if (p == (const PixelPacket *) NULL)
6566 indexes=GetVirtualIndexQueue(canvas);
6568 for (x=0; x < (int) canvas->columns; x++)
6570 pixel=pixels[(long) indexes[x]] & 0xf;
6575 *q=(unsigned char) (pixel << 6);
6581 *q|=(unsigned char) (pixel << 4);
6587 *q|=(unsigned char) (pixel << 2);
6593 *q|=(unsigned char) pixel;
6606 register unsigned int
6610 Convert to 4 bit color-mapped X canvas.
6612 for (y=0; y < (int) canvas->rows; y++)
6614 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6615 if (p == (const PixelPacket *) NULL)
6617 indexes=GetVirtualIndexQueue(canvas);
6619 for (x=0; x < (int) canvas->columns; x++)
6621 pixel=pixels[(long) indexes[x]] & 0xf;
6626 *q=(unsigned char) (pixel << 4);
6632 *q|=(unsigned char) pixel;
6647 Convert to 8 bit color-mapped X canvas.
6649 if (resource_info->color_recovery &&
6650 resource_info->quantize_info->dither)
6652 XDitherImage(canvas,ximage);
6655 for (y=0; y < (int) canvas->rows; y++)
6657 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6658 if (p == (const PixelPacket *) NULL)
6660 indexes=GetVirtualIndexQueue(canvas);
6661 for (x=0; x < (int) canvas->columns; x++)
6663 pixel=pixels[(long) indexes[x]];
6664 *q++=(unsigned char) pixel;
6675 register unsigned int
6679 channel[sizeof(unsigned long)];
6682 Convert to 8 bit color-mapped X canvas.
6684 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6685 for (y=0; y < (int) canvas->rows; y++)
6687 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6688 if (p == (const PixelPacket *) NULL)
6690 indexes=GetVirtualIndexQueue(canvas);
6691 for (x=0; x < (int) canvas->columns; x++)
6693 pixel=pixels[(long) indexes[x]];
6694 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6696 channel[k]=(unsigned char) pixel;
6699 for (k=0; k < (int) bytes_per_pixel; k++)
6708 switch (ximage->bits_per_pixel)
6712 register unsigned int
6716 Convert to 4 bit continuous-tone X canvas.
6718 for (y=0; y < (int) canvas->rows; y++)
6720 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6721 if (p == (const PixelPacket *) NULL)
6724 for (x=(int) canvas->columns-1; x >= 0; x--)
6726 pixel=XGammaPixel(map_info,p);
6732 *q=(unsigned char) (pixel << 6);
6738 *q|=(unsigned char) (pixel << 4);
6744 *q|=(unsigned char) (pixel << 2);
6750 *q|=(unsigned char) pixel;
6764 register unsigned int
6768 Convert to 4 bit continuous-tone X canvas.
6770 for (y=0; y < (int) canvas->rows; y++)
6772 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6773 if (p == (const PixelPacket *) NULL)
6776 for (x=(int) canvas->columns-1; x >= 0; x--)
6778 pixel=XGammaPixel(map_info,p);
6784 *q=(unsigned char) (pixel << 4);
6790 *q|=(unsigned char) pixel;
6806 Convert to 8 bit continuous-tone X canvas.
6808 if (resource_info->color_recovery &&
6809 resource_info->quantize_info->dither)
6811 XDitherImage(canvas,ximage);
6814 for (y=0; y < (int) canvas->rows; y++)
6816 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6817 if (p == (const PixelPacket *) NULL)
6819 for (x=(int) canvas->columns-1; x >= 0; x--)
6821 pixel=XGammaPixel(map_info,p);
6822 *q++=(unsigned char) pixel;
6831 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6832 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6833 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6834 (map_info->blue_mult == 1))
6837 Convert to 32 bit continuous-tone X canvas.
6839 for (y=0; y < (int) canvas->rows; y++)
6841 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6842 &canvas->exception);
6843 if (p == (const PixelPacket *) NULL)
6845 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6846 (blue_gamma != 1.0))
6849 Gamma correct canvas.
6851 for (x=(int) canvas->columns-1; x >= 0; x--)
6854 *q++=ScaleQuantumToChar(XRedGamma(
6855 GetRedPixelComponent(p)));
6856 *q++=ScaleQuantumToChar(XGreenGamma(
6857 GetGreenPixelComponent(p)));
6858 *q++=ScaleQuantumToChar(XBlueGamma(
6859 GetBluePixelComponent(p)));
6864 for (x=(int) canvas->columns-1; x >= 0; x--)
6867 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6868 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6869 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6875 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6876 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6877 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6878 (map_info->blue_mult == 65536L))
6881 Convert to 32 bit continuous-tone X canvas.
6883 for (y=0; y < (int) canvas->rows; y++)
6885 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6886 &canvas->exception);
6887 if (p == (const PixelPacket *) NULL)
6889 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6890 (blue_gamma != 1.0))
6893 Gamma correct canvas.
6895 for (x=(int) canvas->columns-1; x >= 0; x--)
6898 *q++=ScaleQuantumToChar(XBlueGamma(
6899 GetBluePixelComponent(p)));
6900 *q++=ScaleQuantumToChar(XGreenGamma(
6901 GetGreenPixelComponent(p)));
6902 *q++=ScaleQuantumToChar(XRedGamma(
6903 GetRedPixelComponent(p)));
6908 for (x=(int) canvas->columns-1; x >= 0; x--)
6911 *q++=ScaleQuantumToChar((Quantum)
6912 GetBluePixelComponent(p));
6913 *q++=ScaleQuantumToChar((Quantum)
6914 GetGreenPixelComponent(p));
6915 *q++=ScaleQuantumToChar((Quantum)
6916 GetRedPixelComponent(p));
6926 register unsigned int
6930 channel[sizeof(unsigned long)];
6933 Convert to multi-byte continuous-tone X canvas.
6935 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6936 for (y=0; y < (int) canvas->rows; y++)
6938 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6939 &canvas->exception);
6940 if (p == (const PixelPacket *) NULL)
6942 for (x=(int) canvas->columns-1; x >= 0; x--)
6944 pixel=XGammaPixel(map_info,p);
6945 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6947 channel[k]=(unsigned char) pixel;
6950 for (k=0; k < (int) bytes_per_pixel; k++)
6960 if (matte_image != (XImage *) NULL)
6963 Initialize matte canvas.
6965 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6966 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6967 q=(unsigned char *) matte_image->data;
6968 for (y=0; y < (int) canvas->rows; y++)
6970 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6971 if (p == (const PixelPacket *) NULL)
6975 for (x=(int) canvas->columns-1; x >= 0; x--)
6978 if (p->opacity > (long) (QuantumRange/2))
6994 if (canvas != image)
6995 canvas=DestroyImage(canvas);
6999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7003 % X M a k e M a g n i f y I m a g e %
7007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7009 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7011 % The format of the XMakeMagnifyImage method is:
7013 % void XMakeMagnifyImage(display,windows)
7015 % A description of each parameter follows:
7017 % o display: Specifies a connection to an X server; returned from
7020 % o windows: Specifies a pointer to a XWindows structure.
7023 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7026 tuple[MaxTextExtent];
7043 register unsigned char
7048 previous_magnify = 0;
7066 Check boundary conditions.
7068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7069 assert(display != (Display *) NULL);
7070 assert(windows != (XWindows *) NULL);
7072 for (n=1; n < (long) windows->magnify.data; n++)
7074 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7076 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7078 while (magnify > windows->magnify.width)
7080 while (magnify > windows->magnify.height)
7082 if (magnify != previous_magnify)
7091 New magnify factor: update magnify window name.
7094 while ((1 << i) <= (int) magnify)
7096 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7098 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7099 if (status != False)
7101 XSetWMName(display,windows->magnify.id,&window_name);
7102 XSetWMIconName(display,windows->magnify.id,&window_name);
7103 (void) XFree((void *) window_name.value);
7106 previous_magnify=magnify;
7107 ximage=windows->image.ximage;
7108 width=(unsigned int) windows->magnify.ximage->width;
7109 height=(unsigned int) windows->magnify.ximage->height;
7110 if ((windows->magnify.x < 0) ||
7111 (windows->magnify.x >= windows->image.ximage->width))
7112 windows->magnify.x=windows->image.ximage->width >> 1;
7113 x=windows->magnify.x-((width/magnify) >> 1);
7117 if (x > (int) (ximage->width-(width/magnify)))
7118 x=ximage->width-width/magnify;
7119 if ((windows->magnify.y < 0) ||
7120 (windows->magnify.y >= windows->image.ximage->height))
7121 windows->magnify.y=windows->image.ximage->height >> 1;
7122 y=windows->magnify.y-((height/magnify) >> 1);
7126 if (y > (int) (ximage->height-(height/magnify)))
7127 y=ximage->height-height/magnify;
7128 q=(unsigned char *) windows->magnify.ximage->data;
7129 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7130 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7131 if (ximage->bits_per_pixel < 8)
7133 register unsigned char
7140 register unsigned int
7146 pixel_info=windows->magnify.pixel_info;
7147 switch (ximage->bitmap_bit_order)
7152 Magnify little-endian bitmap.
7156 if (ximage->format == XYBitmap)
7158 background=(unsigned char)
7159 (XPixelIntensity(&pixel_info->foreground_color) <
7160 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7161 foreground=(unsigned char)
7162 (XPixelIntensity(&pixel_info->background_color) <
7163 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7164 if (windows->magnify.depth > 1)
7165 Swap(background,foreground);
7167 for (i=0; i < (long) height; i+=magnify)
7170 Propogate pixel magnify rows.
7172 for (j=0; j < magnify; j++)
7174 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7175 ((x*ximage->bits_per_pixel) >> 3);
7176 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7179 for (k=0; k < width; k+=magnify)
7182 Propogate pixel magnify columns.
7184 for (l=0; l < magnify; l++)
7187 Propogate each bit plane.
7189 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7192 if (*p & (0x01 << (p_bit+plane)))
7205 p_bit+=ximage->bits_per_pixel;
7212 *q=byte >> (8-q_bit);
7224 Magnify big-endian bitmap.
7228 if (ximage->format == XYBitmap)
7230 background=(unsigned char)
7231 (XPixelIntensity(&pixel_info->foreground_color) <
7232 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7233 foreground=(unsigned char)
7234 (XPixelIntensity(&pixel_info->background_color) <
7235 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7236 if (windows->magnify.depth > 1)
7237 Swap(background,foreground);
7239 for (i=0; i < (long) height; i+=magnify)
7242 Propogate pixel magnify rows.
7244 for (j=0; j < magnify; j++)
7246 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7247 ((x*ximage->bits_per_pixel) >> 3);
7248 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7251 for (k=0; k < width; k+=magnify)
7254 Propogate pixel magnify columns.
7256 for (l=0; l < magnify; l++)
7259 Propogate each bit plane.
7261 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7264 if (*p & (0x80 >> (p_bit+plane)))
7277 p_bit+=ximage->bits_per_pixel;
7284 *q=byte << (8-q_bit);
7295 switch (ximage->bits_per_pixel)
7301 Magnify 8 bit X image.
7303 for (i=0; i < (long) height; i+=magnify)
7306 Propogate pixel magnify rows.
7308 for (j=0; j < magnify; j++)
7310 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7311 ((x*ximage->bits_per_pixel) >> 3);
7312 for (k=0; k < width; k+=magnify)
7315 Propogate pixel magnify columns.
7317 for (l=0; l < magnify; l++)
7329 register unsigned int
7334 Magnify multi-byte X image.
7336 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7337 for (i=0; i < (long) height; i+=magnify)
7340 Propogate pixel magnify rows.
7342 for (j=0; j < magnify; j++)
7344 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7345 ((x*ximage->bits_per_pixel) >> 3);
7346 for (k=0; k < width; k+=magnify)
7349 Propogate pixel magnify columns.
7351 for (l=0; l < magnify; l++)
7352 for (m=0; m < bytes_per_pixel; m++)
7364 Copy X image to magnify pixmap.
7366 x=windows->magnify.x-((width/magnify) >> 1);
7368 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7370 if (x > (int) (ximage->width-(width/magnify)))
7371 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7374 y=windows->magnify.y-((height/magnify) >> 1);
7376 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7378 if (y > (int) (ximage->height-(height/magnify)))
7379 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7382 if ((x != 0) || (y != 0))
7383 (void) XFillRectangle(display,windows->magnify.pixmap,
7384 windows->magnify.annotate_context,0,0,width,height);
7385 (void) XPutImage(display,windows->magnify.pixmap,
7386 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7388 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7389 (magnify <= (height >> 1))))
7395 Highlight center pixel.
7397 highlight_info.x=(long) windows->magnify.width >> 1;
7398 highlight_info.y=(long) windows->magnify.height >> 1;
7399 highlight_info.width=magnify;
7400 highlight_info.height=magnify;
7401 (void) XDrawRectangle(display,windows->magnify.pixmap,
7402 windows->magnify.highlight_context,(int) highlight_info.x,
7403 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7404 (unsigned int) highlight_info.height-1);
7406 (void) XDrawRectangle(display,windows->magnify.pixmap,
7407 windows->magnify.annotate_context,(int) highlight_info.x+1,
7408 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7409 (unsigned int) highlight_info.height-3);
7412 Show center pixel color.
7414 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7415 windows->magnify.y,&pixel,&windows->image.image->exception);
7416 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7417 windows->magnify.x,windows->magnify.y);
7418 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7419 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7420 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7421 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7422 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7423 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7424 if (pixel.colorspace == CMYKColorspace)
7426 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7427 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7429 if (pixel.matte != MagickFalse)
7431 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7432 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7434 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7435 height=(unsigned int) windows->magnify.font_info->ascent+
7436 windows->magnify.font_info->descent;
7437 x=windows->magnify.font_info->max_bounds.width >> 1;
7438 y=windows->magnify.font_info->ascent+(height >> 2);
7439 (void) XDrawImageString(display,windows->magnify.pixmap,
7440 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7441 GetColorTuple(&pixel,MagickTrue,tuple);
7443 (void) XDrawImageString(display,windows->magnify.pixmap,
7444 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7445 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7446 &windows->image.image->exception);
7448 (void) XDrawImageString(display,windows->magnify.pixmap,
7449 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7451 Refresh magnify window.
7453 magnify_window=windows->magnify;
7456 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7464 % X M a k e P i x m a p %
7468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7470 % XMakePixmap() creates an X11 pixmap.
7472 % The format of the XMakePixmap method is:
7474 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7475 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7476 % XPixelInfo *pixel)
7478 % A description of each parameter follows:
7480 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7482 % o display: Specifies a connection to an X server; returned from
7485 % o window: Specifies a pointer to a XWindowInfo structure.
7488 static MagickBooleanType XMakePixmap(Display *display,
7489 const XResourceInfo *resource_info,XWindowInfo *window)
7495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7496 assert(display != (Display *) NULL);
7497 assert(resource_info != (XResourceInfo *) NULL);
7498 assert(window != (XWindowInfo *) NULL);
7499 if (window->pixmap != (Pixmap) NULL)
7502 Destroy previous X pixmap.
7504 (void) XFreePixmap(display,window->pixmap);
7505 window->pixmap=(Pixmap) NULL;
7507 if (window->use_pixmap == MagickFalse)
7508 return(MagickFalse);
7509 if (window->ximage == (XImage *) NULL)
7510 return(MagickFalse);
7512 Display busy cursor.
7514 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7515 (void) XFlush(display);
7519 width=(unsigned int) window->ximage->width;
7520 height=(unsigned int) window->ximage->height;
7521 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7522 if (window->pixmap == (Pixmap) NULL)
7525 Unable to allocate pixmap.
7527 (void) XCheckDefineCursor(display,window->id,window->cursor);
7528 return(MagickFalse);
7531 Copy X image to pixmap.
7533 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7534 if (window->shared_memory)
7535 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7536 window->ximage,0,0,0,0,width,height,MagickTrue);
7538 if (window->shared_memory == MagickFalse)
7539 (void) XPutImage(display,window->pixmap,window->annotate_context,
7540 window->ximage,0,0,0,0,width,height);
7541 if (IsEventLogging())
7543 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7544 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7550 (void) XCheckDefineCursor(display,window->id,window->cursor);
7555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7559 % X M a k e S t a n d a r d C o l o r m a p %
7563 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7565 % XMakeStandardColormap() creates an X11 Standard Colormap.
7567 % The format of the XMakeStandardColormap method is:
7569 % XMakeStandardColormap(display,visual_info,resource_info,image,
7572 % A description of each parameter follows:
7574 % o display: Specifies a connection to an X server; returned from
7577 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7578 % returned from XGetVisualInfo.
7580 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7582 % o image: the image.
7584 % o map_info: If a Standard Colormap type is specified, this structure is
7585 % initialized with info from the Standard Colormap.
7587 % o pixel: Specifies a pointer to a XPixelInfo structure.
7591 #if defined(__cplusplus) || defined(c_plusplus)
7595 static inline MagickRealType DiversityPixelIntensity(
7596 const DiversityPacket *pixel)
7601 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7605 static int IntensityCompare(const void *x,const void *y)
7614 color_1=(DiversityPacket *) x;
7615 color_2=(DiversityPacket *) y;
7616 diversity=(int) (DiversityPixelIntensity(color_2)-
7617 DiversityPixelIntensity(color_1));
7621 static int PopularityCompare(const void *x,const void *y)
7627 color_1=(DiversityPacket *) x;
7628 color_2=(DiversityPacket *) y;
7629 return((int) color_2->count-(int) color_1->count);
7632 #if defined(__cplusplus) || defined(c_plusplus)
7636 static inline Quantum ScaleXToQuantum(const unsigned long x,
7637 const unsigned long scale)
7639 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7642 MagickExport void XMakeStandardColormap(Display *display,
7643 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7644 XStandardColormap *map_info,XPixelInfo *pixel)
7652 register IndexPacket
7673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7674 assert(display != (Display *) NULL);
7675 assert(visual_info != (XVisualInfo *) NULL);
7676 assert(map_info != (XStandardColormap *) NULL);
7677 assert(resource_info != (XResourceInfo *) NULL);
7678 assert(pixel != (XPixelInfo *) NULL);
7679 exception=(&image->exception);
7680 if (resource_info->map_type != (char *) NULL)
7683 Standard Colormap is already defined (i.e. xstdcmap).
7685 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7687 number_colors=(unsigned int) (map_info->base_pixel+
7688 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7689 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7690 if ((image->matte == MagickFalse) &&
7691 (resource_info->color_recovery == MagickFalse) &&
7692 resource_info->quantize_info->dither &&
7693 (number_colors < MaxColormapSize))
7698 register PixelPacket
7702 Improve image appearance with error diffusion.
7704 affinity_image=AcquireImage((ImageInfo *) NULL);
7705 if (affinity_image == (Image *) NULL)
7706 ThrowXWindowFatalException(ResourceLimitFatalError,
7707 "UnableToDitherImage",image->filename);
7708 affinity_image->columns=number_colors;
7709 affinity_image->rows=1;
7711 Initialize colormap image.
7713 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7715 if (q != (PixelPacket *) NULL)
7717 for (i=0; i < (long) number_colors; i++)
7720 if (map_info->red_max != 0)
7721 q->red=ScaleXToQuantum((unsigned long) (i/
7722 map_info->red_mult),map_info->red_max);
7723 q->green=(Quantum) 0;
7724 if (map_info->green_max != 0)
7725 q->green=ScaleXToQuantum((unsigned long) ((i/
7726 map_info->green_mult) % (map_info->green_max+1)),
7727 map_info->green_max);
7728 q->blue=(Quantum) 0;
7729 if (map_info->blue_max != 0)
7730 q->blue=ScaleXToQuantum((unsigned long) (i %
7731 map_info->green_mult),map_info->blue_max);
7732 q->opacity=(Quantum) TransparentOpacity;
7735 (void) SyncAuthenticPixels(affinity_image,exception);
7736 (void) RemapImage(resource_info->quantize_info,image,
7739 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7741 (void) SetImageStorageClass(image,DirectClass);
7742 affinity_image=DestroyImage(affinity_image);
7744 if (IsEventLogging())
7746 (void) LogMagickEvent(X11Event,GetMagickModule(),
7747 "Standard Colormap:");
7748 (void) LogMagickEvent(X11Event,GetMagickModule(),
7749 " colormap id: 0x%lx",map_info->colormap);
7750 (void) LogMagickEvent(X11Event,GetMagickModule(),
7751 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7752 map_info->green_max,map_info->blue_max);
7753 (void) LogMagickEvent(X11Event,GetMagickModule(),
7754 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7755 map_info->green_mult,map_info->blue_mult);
7759 if ((visual_info->klass != DirectColor) &&
7760 (visual_info->klass != TrueColor))
7761 if ((image->storage_class == DirectClass) ||
7762 ((int) image->colors > visual_info->colormap_size))
7768 Image has more colors than the visual supports.
7770 quantize_info=(*resource_info->quantize_info);
7771 quantize_info.number_colors=(unsigned long) visual_info->colormap_size;
7772 (void) QuantizeImage(&quantize_info,image);
7775 Free previous and create new colormap.
7777 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7778 colormap=XDefaultColormap(display,visual_info->screen);
7779 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7780 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7781 visual_info->visual,visual_info->klass == DirectColor ?
7782 AllocAll : AllocNone);
7783 if (colormap == (Colormap) NULL)
7784 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7787 Initialize the map and pixel info structures.
7789 XGetMapInfo(visual_info,colormap,map_info);
7790 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7792 Allocating colors in server colormap is based on visual class.
7794 switch (visual_info->klass)
7800 Define Standard Colormap for StaticGray or StaticColor visual.
7802 number_colors=image->colors;
7803 colors=(XColor *) AcquireQuantumMemory((size_t)
7804 visual_info->colormap_size,sizeof(*colors));
7805 if (colors == (XColor *) NULL)
7806 ThrowXWindowFatalException(ResourceLimitFatalError,
7807 "UnableToCreateColormap",image->filename);
7809 color.flags=(char) (DoRed | DoGreen | DoBlue);
7810 for (i=0; i < (long) image->colors; i++)
7812 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7813 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7814 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7815 if (visual_info->klass != StaticColor)
7817 gray_value=(unsigned short) XPixelIntensity(&color);
7818 color.red=gray_value;
7819 color.green=gray_value;
7820 color.blue=gray_value;
7822 status=XAllocColor(display,colormap,&color);
7823 if (status == False)
7825 colormap=XCopyColormapAndFree(display,colormap);
7826 (void) XAllocColor(display,colormap,&color);
7828 pixel->pixels[i]=color.pixel;
7840 Define Standard Colormap for GrayScale or PseudoColor visual.
7842 number_colors=image->colors;
7843 colors=(XColor *) AcquireQuantumMemory((size_t)
7844 visual_info->colormap_size,sizeof(*colors));
7845 if (colors == (XColor *) NULL)
7846 ThrowXWindowFatalException(ResourceLimitFatalError,
7847 "UnableToCreateColormap",image->filename);
7849 Preallocate our GUI colors.
7851 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7852 (void) XAllocColor(display,colormap,&pixel->background_color);
7853 (void) XAllocColor(display,colormap,&pixel->border_color);
7854 (void) XAllocColor(display,colormap,&pixel->matte_color);
7855 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7856 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7857 (void) XAllocColor(display,colormap,&pixel->depth_color);
7858 (void) XAllocColor(display,colormap,&pixel->trough_color);
7859 for (i=0; i < MaxNumberPens; i++)
7860 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7862 Determine if image colors will "fit" into X server colormap.
7864 colormap_type=resource_info->colormap;
7865 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7866 NULL,0,pixel->pixels,(unsigned int) image->colors);
7867 if (status != False)
7868 colormap_type=PrivateColormap;
7869 if (colormap_type == SharedColormap)
7887 Define Standard colormap for shared GrayScale or PseudoColor visual.
7889 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7890 sizeof(*diversity));
7891 if (diversity == (DiversityPacket *) NULL)
7892 ThrowXWindowFatalException(ResourceLimitFatalError,
7893 "UnableToCreateColormap",image->filename);
7894 for (i=0; i < (long) image->colors; i++)
7896 diversity[i].red=image->colormap[i].red;
7897 diversity[i].green=image->colormap[i].green;
7898 diversity[i].blue=image->colormap[i].blue;
7899 diversity[i].index=(unsigned short) i;
7900 diversity[i].count=0;
7902 for (y=0; y < (int) image->rows; y++)
7907 register PixelPacket
7910 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7911 if (q == (PixelPacket *) NULL)
7913 indexes=GetAuthenticIndexQueue(image);
7914 for (x=(long) image->columns-1; x >= 0; x--)
7915 diversity[(long) indexes[x]].count++;
7918 Sort colors by decreasing intensity.
7920 qsort((void *) diversity,image->colors,sizeof(*diversity),
7922 for (i=0; i < (long) image->colors; )
7924 diversity[i].count<<=4; /* increase this colors popularity */
7925 i+=MagickMax((long) (image->colors >> 4),2);
7927 diversity[image->colors-1].count<<=4;
7928 qsort((void *) diversity,image->colors,sizeof(*diversity),
7934 color.flags=(char) (DoRed | DoGreen | DoBlue);
7935 for (i=0; i < (long) image->colors; i++)
7937 index=diversity[i].index;
7939 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7941 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7943 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7944 if (visual_info->klass != PseudoColor)
7946 gray_value=(unsigned short) XPixelIntensity(&color);
7947 color.red=gray_value;
7948 color.green=gray_value;
7949 color.blue=gray_value;
7951 status=XAllocColor(display,colormap,&color);
7952 if (status == False)
7954 pixel->pixels[index]=color.pixel;
7958 Read X server colormap.
7960 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7961 visual_info->colormap_size,sizeof(*server_colors));
7962 if (server_colors == (XColor *) NULL)
7963 ThrowXWindowFatalException(ResourceLimitFatalError,
7964 "UnableToCreateColormap",image->filename);
7965 for (x=visual_info->colormap_size-1; x >= 0; x--)
7966 server_colors[x].pixel=(unsigned long) x;
7967 (void) XQueryColors(display,colormap,server_colors,
7968 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7970 Select remaining colors from X server colormap.
7972 for (; i < (long) image->colors; i++)
7974 index=diversity[i].index;
7976 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7978 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7980 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7981 if (visual_info->klass != PseudoColor)
7983 gray_value=(unsigned short) XPixelIntensity(&color);
7984 color.red=gray_value;
7985 color.green=gray_value;
7986 color.blue=gray_value;
7988 XBestPixel(display,colormap,server_colors,(unsigned int)
7989 visual_info->colormap_size,&color);
7990 pixel->pixels[index]=color.pixel;
7993 if ((int) image->colors < visual_info->colormap_size)
7996 Fill up colors array-- more choices for pen colors.
7998 retain_colors=MagickMin((unsigned int)
7999 (visual_info->colormap_size-image->colors),256);
8000 for (i=0; i < (long) retain_colors; i++)
8001 *p++=server_colors[i];
8002 number_colors+=retain_colors;
8004 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8005 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8009 Define Standard colormap for private GrayScale or PseudoColor visual.
8011 if (status == False)
8014 Not enough colormap entries in the colormap-- Create a new colormap.
8016 colormap=XCreateColormap(display,
8017 XRootWindow(display,visual_info->screen),visual_info->visual,
8019 if (colormap == (Colormap) NULL)
8020 ThrowXWindowFatalException(ResourceLimitFatalError,
8021 "UnableToCreateColormap",image->filename);
8022 map_info->colormap=colormap;
8023 if ((int) image->colors < visual_info->colormap_size)
8026 Retain colors from the default colormap to help lessens the
8027 effects of colormap flashing.
8029 retain_colors=MagickMin((unsigned int)
8030 (visual_info->colormap_size-image->colors),256);
8031 p=colors+image->colors;
8032 for (i=0; i < (long) retain_colors; i++)
8034 p->pixel=(unsigned long) i;
8037 (void) XQueryColors(display,
8038 XDefaultColormap(display,visual_info->screen),
8039 colors+image->colors,(int) retain_colors);
8041 Transfer colors from default to private colormap.
8043 (void) XAllocColorCells(display,colormap,MagickFalse,
8044 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8046 p=colors+image->colors;
8047 for (i=0; i < (long) retain_colors; i++)
8049 p->pixel=pixel->pixels[i];
8052 (void) XStoreColors(display,colormap,colors+image->colors,
8053 (int) retain_colors);
8054 number_colors+=retain_colors;
8056 (void) XAllocColorCells(display,colormap,MagickFalse,
8057 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8061 Store the image colormap.
8064 color.flags=(char) (DoRed | DoGreen | DoBlue);
8065 for (i=0; i < (long) image->colors; i++)
8067 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8068 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8069 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8070 if (visual_info->klass != PseudoColor)
8072 gray_value=(unsigned short) XPixelIntensity(&color);
8073 color.red=gray_value;
8074 color.green=gray_value;
8075 color.blue=gray_value;
8077 color.pixel=pixel->pixels[i];
8080 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8091 Define Standard Colormap for TrueColor or DirectColor visual.
8093 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8094 (map_info->green_max*map_info->green_mult)+
8095 (map_info->blue_max*map_info->blue_mult)+1);
8096 linear_colormap=(number_colors > 4096) ||
8097 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8098 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8099 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8100 MagickTrue : MagickFalse;
8101 if (linear_colormap != MagickFalse)
8102 number_colors=(unsigned long) visual_info->colormap_size;
8104 Allocate color array.
8106 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8107 if (colors == (XColor *) NULL)
8108 ThrowXWindowFatalException(ResourceLimitFatalError,
8109 "UnableToCreateColormap",image->filename);
8111 Initialize linear color ramp.
8114 color.flags=(char) (DoRed | DoGreen | DoBlue);
8115 if (linear_colormap != MagickFalse)
8116 for (i=0; i < (long) number_colors; i++)
8118 color.blue=(unsigned short) 0;
8119 if (map_info->blue_max != 0)
8120 color.blue=(unsigned short) ((unsigned long)
8121 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8122 color.green=color.blue;
8123 color.red=color.blue;
8124 color.pixel=XStandardPixel(map_info,&color);
8128 for (i=0; i < (long) number_colors; i++)
8130 color.red=(unsigned short) 0;
8131 if (map_info->red_max != 0)
8132 color.red=(unsigned short) ((unsigned long)
8133 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8134 color.green=(unsigned int) 0;
8135 if (map_info->green_max != 0)
8136 color.green=(unsigned short) ((unsigned long)
8137 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8138 map_info->green_max));
8139 color.blue=(unsigned short) 0;
8140 if (map_info->blue_max != 0)
8141 color.blue=(unsigned short) ((unsigned long)
8142 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8143 color.pixel=XStandardPixel(map_info,&color);
8146 if ((visual_info->klass == DirectColor) &&
8147 (colormap != XDefaultColormap(display,visual_info->screen)))
8148 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8150 for (i=0; i < (long) number_colors; i++)
8151 (void) XAllocColor(display,colormap,&colors[i]);
8155 if ((visual_info->klass != DirectColor) &&
8156 (visual_info->klass != TrueColor))
8159 Set foreground, background, border, etc. pixels.
8161 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8162 &pixel->foreground_color);
8163 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8164 &pixel->background_color);
8165 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8168 Foreground and background colors must differ.
8170 pixel->background_color.red=(~pixel->foreground_color.red);
8171 pixel->background_color.green=
8172 (~pixel->foreground_color.green);
8173 pixel->background_color.blue=
8174 (~pixel->foreground_color.blue);
8175 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8176 &pixel->background_color);
8178 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8179 &pixel->border_color);
8180 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8181 &pixel->matte_color);
8182 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8183 &pixel->highlight_color);
8184 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8185 &pixel->shadow_color);
8186 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8187 &pixel->depth_color);
8188 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8189 &pixel->trough_color);
8190 for (i=0; i < MaxNumberPens; i++)
8192 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8193 &pixel->pen_colors[i]);
8194 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8196 pixel->colors=image->colors+MaxNumberPens;
8198 colors=(XColor *) RelinquishMagickMemory(colors);
8199 if (IsEventLogging())
8201 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8202 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8203 map_info->colormap);
8204 (void) LogMagickEvent(X11Event,GetMagickModule(),
8205 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8206 map_info->green_max,map_info->blue_max);
8207 (void) LogMagickEvent(X11Event,GetMagickModule(),
8208 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8209 map_info->green_mult,map_info->blue_mult);
8214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8218 % X M a k e W i n d o w %
8222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8224 % XMakeWindow() creates an X11 window.
8226 % The format of the XMakeWindow method is:
8228 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8229 % XClassHint *class_hint,XWMHints *manager_hints,
8230 % XWindowInfo *window_info)
8232 % A description of each parameter follows:
8234 % o display: Specifies a connection to an X server; returned from
8237 % o parent: Specifies the parent window_info.
8239 % o argv: Specifies the application's argument list.
8241 % o argc: Specifies the number of arguments.
8243 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8245 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8247 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8250 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8251 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8252 XWindowInfo *window_info)
8254 #define MinWindowSize 64
8262 static XTextProperty
8273 Set window info hints.
8275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8276 assert(display != (Display *) NULL);
8277 assert(window_info != (XWindowInfo *) NULL);
8278 size_hints=XAllocSizeHints();
8279 if (size_hints == (XSizeHints *) NULL)
8280 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8281 size_hints->flags=(long) window_info->flags;
8282 size_hints->x=window_info->x;
8283 size_hints->y=window_info->y;
8284 size_hints->width=(int) window_info->width;
8285 size_hints->height=(int) window_info->height;
8286 if (window_info->immutable != MagickFalse)
8289 Window size cannot be changed.
8291 size_hints->min_width=size_hints->width;
8292 size_hints->min_height=size_hints->height;
8293 size_hints->max_width=size_hints->width;
8294 size_hints->max_height=size_hints->height;
8295 size_hints->flags|=PMinSize;
8296 size_hints->flags|=PMaxSize;
8301 Window size can be changed.
8303 size_hints->min_width=(int) window_info->min_width;
8304 size_hints->min_height=(int) window_info->min_height;
8305 size_hints->flags|=PResizeInc;
8306 size_hints->width_inc=(int) window_info->width_inc;
8307 size_hints->height_inc=(int) window_info->height_inc;
8308 #if !defined(PRE_R4_ICCCM)
8309 size_hints->flags|=PBaseSize;
8310 size_hints->base_width=size_hints->width_inc;
8311 size_hints->base_height=size_hints->height_inc;
8314 gravity=NorthWestGravity;
8315 if (window_info->geometry != (char *) NULL)
8318 default_geometry[MaxTextExtent],
8319 geometry[MaxTextExtent];
8328 User specified geometry.
8330 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8331 size_hints->width,size_hints->height);
8332 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8334 while (strlen(p) != 0)
8336 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8339 (void) CopyMagickString(p,p+1,MaxTextExtent);
8341 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8342 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8343 &size_hints->width,&size_hints->height,&gravity);
8344 if ((flags & WidthValue) && (flags & HeightValue))
8345 size_hints->flags|=USSize;
8346 if ((flags & XValue) && (flags & YValue))
8348 size_hints->flags|=USPosition;
8349 window_info->x=size_hints->x;
8350 window_info->y=size_hints->y;
8353 #if !defined(PRE_R4_ICCCM)
8354 size_hints->win_gravity=gravity;
8355 size_hints->flags|=PWinGravity;
8357 if (window_info->id == (Window) NULL)
8358 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8359 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8360 window_info->border_width,(int) window_info->depth,InputOutput,
8361 window_info->visual,window_info->mask,&window_info->attributes);
8374 Window already exists; change relevant attributes.
8376 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8377 &window_info->attributes);
8378 mask=ConfigureNotify;
8379 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8380 window_changes.x=window_info->x;
8381 window_changes.y=window_info->y;
8382 window_changes.width=(int) window_info->width;
8383 window_changes.height=(int) window_info->height;
8384 mask=(MagickStatusType) (CWWidth | CWHeight);
8385 if (window_info->flags & USPosition)
8387 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8388 mask,&window_changes);
8390 if (window_info->id == (Window) NULL)
8391 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8393 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8394 if (status == False)
8395 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8397 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8398 if (status == False)
8399 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8400 window_info->icon_name);
8401 if (window_info->icon_geometry != (char *) NULL)
8409 User specified icon geometry.
8411 size_hints->flags|=USPosition;
8412 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8413 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8414 &manager_hints->icon_y,&width,&height,&gravity);
8415 if ((flags & XValue) && (flags & YValue))
8416 manager_hints->flags|=IconPositionHint;
8418 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8419 size_hints,manager_hints,class_hint);
8420 if (window_name.value != (void *) NULL)
8422 (void) XFree((void *) window_name.value);
8423 window_name.value=(unsigned char *) NULL;
8424 window_name.nitems=0;
8426 if (icon_name.value != (void *) NULL)
8428 (void) XFree((void *) icon_name.value);
8429 icon_name.value=(unsigned char *) NULL;
8432 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8433 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8434 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8435 (void) XFree((void *) size_hints);
8436 if (window_info->shape != MagickFalse)
8438 #if defined(MAGICKCORE_HAVE_SHAPE)
8444 Can we apply a non-rectangular shaping mask?
8448 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8449 window_info->shape=MagickFalse;
8451 window_info->shape=MagickFalse;
8454 if (window_info->shared_memory)
8456 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8458 Can we use shared memory with this window?
8460 if (XShmQueryExtension(display) == 0)
8461 window_info->shared_memory=MagickFalse;
8463 window_info->shared_memory=MagickFalse;
8466 window_info->image=NewImageList();
8467 window_info->destroy=MagickFalse;
8471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8475 % X M a g i c k P r o g r e s s M o n i t o r %
8479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8481 % XMagickProgressMonitor() displays the progress a task is making in
8482 % completing a task.
8484 % The format of the XMagickProgressMonitor method is:
8486 % void XMagickProgressMonitor(const char *task,
8487 % const MagickOffsetType quantum,const MagickSizeType span,
8488 % void *client_data)
8490 % A description of each parameter follows:
8492 % o task: Identifies the task in progress.
8494 % o quantum: Specifies the quantum position within the span which represents
8495 % how much progress has been made in completing a task.
8497 % o span: Specifies the span relative to completing a task.
8499 % o client_data: Pointer to any client data.
8503 static const char *GetLocaleMonitorMessage(const char *text)
8506 message[MaxTextExtent],
8515 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8517 if (p != (char *) NULL)
8519 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8520 locale_message=GetLocaleMessage(message);
8521 if (locale_message == message)
8523 return(locale_message);
8526 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8527 const MagickOffsetType quantum,const MagickSizeType span,
8528 void *magick_unused(client_data))
8533 windows=XSetWindows((XWindows *) ~0);
8534 if (windows == (XWindows *) NULL)
8536 if (windows->info.mapped != MagickFalse)
8537 XProgressMonitorWidget(windows->display,windows,
8538 GetLocaleMonitorMessage(tag),quantum,span);
8543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8547 % X Q u e r y C o l o r D a t a b a s e %
8551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8553 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8556 % The format of the XQueryColorDatabase method is:
8558 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8560 % A description of each parameter follows:
8562 % o target: Specifies the color to lookup in the X color database.
8564 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8565 % color is returned as this value.
8568 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8575 *display = (Display *) NULL;
8584 Initialize color return value.
8586 assert(color != (XColor *) NULL);
8590 color->flags=(char) (DoRed | DoGreen | DoBlue);
8591 if ((target == (char *) NULL) || (*target == '\0'))
8592 target="#ffffffffffff";
8594 Let the X server define the color for us.
8596 if (display == (Display *) NULL)
8597 display=XOpenDisplay((char *) NULL);
8598 if (display == (Display *) NULL)
8600 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8601 return(MagickFalse);
8603 colormap=XDefaultColormap(display,XDefaultScreen(display));
8604 status=XParseColor(display,colormap,(char *) target,&xcolor);
8605 if (status == False)
8606 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8609 color->red=xcolor.red;
8610 color->green=xcolor.green;
8611 color->blue=xcolor.blue;
8612 color->flags=xcolor.flags;
8614 return(status != False ? MagickTrue : MagickFalse);
8618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8622 % X Q u e r y P o s i t i o n %
8626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8628 % XQueryPosition() gets the pointer coordinates relative to a window.
8630 % The format of the XQueryPosition method is:
8632 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8634 % A description of each parameter follows:
8636 % o display: Specifies a connection to an X server; returned from
8639 % o window: Specifies a pointer to a Window.
8641 % o x: Return the x coordinate of the pointer relative to the origin of the
8644 % o y: Return the y coordinate of the pointer relative to the origin of the
8648 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8660 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8661 assert(display != (Display *) NULL);
8662 assert(window != (Window) NULL);
8663 assert(x != (int *) NULL);
8664 assert(y != (int *) NULL);
8665 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8674 % X R e f r e s h W i n d o w %
8678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8680 % XRefreshWindow() refreshes an image in a X window.
8682 % The format of the XRefreshWindow method is:
8684 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8685 % const XEvent *event)
8687 % A description of each parameter follows:
8689 % o display: Specifies a connection to an X server; returned from
8692 % o window: Specifies a pointer to a XWindowInfo structure.
8694 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8695 % the entire image is refreshed.
8698 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8699 const XEvent *event)
8709 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8710 assert(display != (Display *) NULL);
8711 assert(window != (XWindowInfo *) NULL);
8712 if (window->ximage == (XImage *) NULL)
8714 if (event != (XEvent *) NULL)
8717 Determine geometry from expose event.
8721 width=(unsigned int) event->xexpose.width;
8722 height=(unsigned int) event->xexpose.height;
8730 Refresh entire window; discard outstanding expose events.
8734 width=window->width;
8735 height=window->height;
8736 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8737 if (window->matte_pixmap != (Pixmap) NULL)
8739 #if defined(MAGICKCORE_HAVE_SHAPE)
8740 if (window->shape != MagickFalse)
8741 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8742 window->matte_pixmap,ShapeSet);
8747 Check boundary conditions.
8749 if ((window->ximage->width-(x+window->x)) < (int) width)
8750 width=(unsigned int) (window->ximage->width-(x+window->x));
8751 if ((window->ximage->height-(y+window->y)) < (int) height)
8752 height=(unsigned int) (window->ximage->height-(y+window->y));
8756 if (window->matte_pixmap != (Pixmap) NULL)
8757 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8758 if (window->pixmap != (Pixmap) NULL)
8760 if (window->depth > 1)
8761 (void) XCopyArea(display,window->pixmap,window->id,
8762 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8764 (void) XCopyPlane(display,window->pixmap,window->id,
8765 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8770 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8771 if (window->shared_memory)
8772 (void) XShmPutImage(display,window->id,window->annotate_context,
8773 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8775 if (window->shared_memory == MagickFalse)
8776 (void) XPutImage(display,window->id,window->annotate_context,
8777 window->ximage,x+window->x,y+window->y,x,y,width,height);
8779 if (window->matte_pixmap != (Pixmap) NULL)
8780 (void) XSetClipMask(display,window->annotate_context,None);
8781 (void) XFlush(display);
8785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8789 % X R e m o t e C o m m a n d %
8793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8795 % XRemoteCommand() forces a remote display(1) to display the specified
8798 % The format of the XRemoteCommand method is:
8800 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8801 % const char *filename)
8803 % A description of each parameter follows:
8805 % o display: Specifies a connection to an X server; returned from
8808 % o window: Specifies the name or id of an X window.
8810 % o filename: the name of the image filename to display.
8813 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8814 const char *window,const char *filename)
8823 assert(filename != (char *) NULL);
8824 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8825 if (display == (Display *) NULL)
8826 display=XOpenDisplay((char *) NULL);
8827 if (display == (Display *) NULL)
8829 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8830 return(MagickFalse);
8832 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8833 remote_window=(Window) NULL;
8834 root_window=XRootWindow(display,XDefaultScreen(display));
8835 if (window != (char *) NULL)
8838 Search window hierarchy and identify any clients by name or ID.
8840 if (isdigit((unsigned char) *window) != 0)
8841 remote_window=XWindowByID(display,root_window,(Window)
8842 strtol((char *) window,(char **) NULL,0));
8843 if (remote_window == (Window) NULL)
8844 remote_window=XWindowByName(display,root_window,window);
8846 if (remote_window == (Window) NULL)
8847 remote_window=XWindowByProperty(display,root_window,remote_atom);
8848 if (remote_window == (Window) NULL)
8850 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8852 return(MagickFalse);
8855 Send remote command.
8857 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8858 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8859 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8860 (void) XSync(display,MagickFalse);
8865 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8869 % X R e t a i n W i n d o w C o l o r s %
8873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8875 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8876 % the colors associated with an image displayed on the window.
8878 % The format of the XRetainWindowColors method is:
8880 % void XRetainWindowColors(Display *display,const Window window)
8882 % A description of each parameter follows:
8884 % o display: Specifies a connection to an X server; returned from
8887 % o window: Specifies a pointer to a XWindowInfo structure.
8890 MagickExport void XRetainWindowColors(Display *display,const Window window)
8899 Put property on the window.
8901 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8902 assert(display != (Display *) NULL);
8903 assert(window != (Window) NULL);
8904 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8905 if (property == (Atom) NULL)
8907 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8911 pixmap=XCreatePixmap(display,window,1,1,1);
8912 if (pixmap == (Pixmap) NULL)
8914 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8917 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8918 (unsigned char *) &pixmap,1);
8919 (void) XSetCloseDownMode(display,RetainPermanent);
8923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8927 % X S e l e c t W i n d o w %
8931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8933 % XSelectWindow() allows a user to select a window using the mouse. If the
8934 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8935 % is returned in the crop_info structure.
8937 % The format of the XSelectWindow function is:
8939 % target_window=XSelectWindow(display,crop_info)
8941 % A description of each parameter follows:
8943 % o window: XSelectWindow returns the window id.
8945 % o display: Specifies a pointer to the Display structure; returned from
8948 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8949 % contains the extents of any cropping rectangle.
8952 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8954 #define MinimumCropArea (unsigned int) 9
8981 Initialize graphic context.
8983 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8984 assert(display != (Display *) NULL);
8985 assert(crop_info != (RectangleInfo *) NULL);
8986 root_window=XRootWindow(display,XDefaultScreen(display));
8987 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8988 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8989 context_values.function=GXinvert;
8990 context_values.plane_mask=
8991 context_values.background ^ context_values.foreground;
8992 context_values.subwindow_mode=IncludeInferiors;
8993 annotate_context=XCreateGC(display,root_window,(unsigned long) (GCBackground |
8994 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8995 if (annotate_context == (GC) NULL)
8996 return(MagickFalse);
8998 Grab the pointer using target cursor.
9000 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9001 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9002 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9003 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9004 GrabModeAsync,root_window,target_cursor,CurrentTime);
9005 if (status != GrabSuccess)
9007 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9008 return((Window) NULL);
9014 crop_info->height=0;
9016 target_window=(Window) NULL;
9021 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9022 (void) XDrawRectangle(display,root_window,annotate_context,
9023 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9024 (unsigned int) crop_info->height-1);
9026 Allow another event.
9028 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9029 (void) XWindowEvent(display,root_window,ButtonPressMask |
9030 ButtonReleaseMask | ButtonMotionMask,&event);
9031 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9032 (void) XDrawRectangle(display,root_window,annotate_context,
9033 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9034 (unsigned int) crop_info->height-1);
9039 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9040 event.xbutton.x,event.xbutton.y);
9041 if (target_window == (Window) NULL)
9042 target_window=root_window;
9043 x_offset=event.xbutton.x_root;
9044 y_offset=event.xbutton.y_root;
9045 crop_info->x=x_offset;
9046 crop_info->y=y_offset;
9048 crop_info->height=0;
9060 Discard pending button motion events.
9062 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9063 crop_info->x=event.xmotion.x;
9064 crop_info->y=event.xmotion.y;
9066 Check boundary conditions.
9068 if ((int) crop_info->x < x_offset)
9069 crop_info->width=(unsigned int) (x_offset-crop_info->x);
9072 crop_info->width=(unsigned int) (crop_info->x-x_offset);
9073 crop_info->x=x_offset;
9075 if ((int) crop_info->y < y_offset)
9076 crop_info->height=(unsigned int) (y_offset-crop_info->y);
9079 crop_info->height=(unsigned int) (crop_info->y-y_offset);
9080 crop_info->y=y_offset;
9086 } while ((target_window == (Window) NULL) || (presses > 0));
9087 (void) XUngrabPointer(display,CurrentTime);
9088 (void) XFreeCursor(display,target_cursor);
9089 (void) XFreeGC(display,annotate_context);
9090 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9093 crop_info->height=0;
9095 if ((crop_info->width != 0) && (crop_info->height != 0))
9096 target_window=root_window;
9097 return(target_window);
9101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9105 % X S e t C u r s o r S t a t e %
9109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9111 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9112 % reset to their default.
9114 % The format of the XXSetCursorState method is:
9116 % XSetCursorState(display,windows,const MagickStatusType state)
9118 % A description of each parameter follows:
9120 % o display: Specifies a connection to an X server; returned from
9123 % o windows: Specifies a pointer to a XWindows structure.
9125 % o state: An unsigned integer greater than 0 sets the cursor state
9126 % to busy, otherwise the cursor are reset to their default.
9129 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9130 const MagickStatusType state)
9132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9133 assert(display != (Display *) NULL);
9134 assert(windows != (XWindows *) NULL);
9137 (void) XCheckDefineCursor(display,windows->image.id,
9138 windows->image.busy_cursor);
9139 (void) XCheckDefineCursor(display,windows->pan.id,
9140 windows->pan.busy_cursor);
9141 (void) XCheckDefineCursor(display,windows->magnify.id,
9142 windows->magnify.busy_cursor);
9143 (void) XCheckDefineCursor(display,windows->command.id,
9144 windows->command.busy_cursor);
9148 (void) XCheckDefineCursor(display,windows->image.id,
9149 windows->image.cursor);
9150 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9151 (void) XCheckDefineCursor(display,windows->magnify.id,
9152 windows->magnify.cursor);
9153 (void) XCheckDefineCursor(display,windows->command.id,
9154 windows->command.cursor);
9155 (void) XCheckDefineCursor(display,windows->command.id,
9156 windows->widget.cursor);
9157 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9159 windows->info.mapped=MagickFalse;
9163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9167 % X S e t W i n d o w s %
9171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9173 % XSetWindows() sets the X windows structure if the windows info is specified.
9174 % Otherwise the current windows structure is returned.
9176 % The format of the XSetWindows method is:
9178 % XWindows *XSetWindows(XWindows *windows_info)
9180 % A description of each parameter follows:
9182 % o windows_info: Initialize the Windows structure with this information.
9185 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9188 *windows = (XWindows *) NULL;
9190 if (windows_info != (XWindows *) ~0)
9192 windows=(XWindows *) RelinquishMagickMemory(windows);
9193 windows=windows_info;
9198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9202 % X U s e r P r e f e r e n c e s %
9206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9208 % XUserPreferences() saves the preferences in a configuration file in the
9209 % users' home directory.
9211 % The format of the XUserPreferences method is:
9213 % void XUserPreferences(XResourceInfo *resource_info)
9215 % A description of each parameter follows:
9217 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9220 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9222 #if defined(X11_PREFERENCES_PATH)
9224 cache[MaxTextExtent],
9225 filename[MaxTextExtent],
9226 specifier[MaxTextExtent];
9233 preferences_database;
9236 Save user preferences to the client configuration file.
9238 assert(resource_info != (XResourceInfo *) NULL);
9239 client_name=GetClientName();
9240 preferences_database=XrmGetStringDatabase("");
9241 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9242 value=resource_info->backdrop ? "True" : "False";
9243 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9244 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9245 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9246 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9247 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9249 value=resource_info->confirm_exit ? "True" : "False";
9250 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9251 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9253 value=resource_info->confirm_edit ? "True" : "False";
9254 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9255 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9257 value=resource_info->display_warnings ? "True" : "False";
9258 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9259 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9260 value=resource_info->quantize_info->dither ? "True" : "False";
9261 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9262 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9264 value=resource_info->gamma_correct ? "True" : "False";
9265 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9266 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9267 (void) FormatMagickString(cache,MaxTextExtent,"%lu",
9268 resource_info->undo_cache);
9269 XrmPutStringResource(&preferences_database,specifier,cache);
9270 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9271 value=resource_info->use_pixmap ? "True" : "False";
9272 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9273 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9274 X11_PREFERENCES_PATH,client_name);
9275 ExpandFilename(filename);
9276 XrmPutFileDatabase(preferences_database,filename);
9281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9285 % X V i s u a l C l a s s N a m e %
9289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9291 % XVisualClassName() returns the visual class name as a character string.
9293 % The format of the XVisualClassName method is:
9295 % char *XVisualClassName(const int visual_class)
9297 % A description of each parameter follows:
9299 % o visual_type: XVisualClassName returns the visual class as a character
9302 % o class: Specifies the visual class.
9305 static const char *XVisualClassName(const int visual_class)
9307 switch (visual_class)
9309 case StaticGray: return("StaticGray");
9310 case GrayScale: return("GrayScale");
9311 case StaticColor: return("StaticColor");
9312 case PseudoColor: return("PseudoColor");
9313 case TrueColor: return("TrueColor");
9314 case DirectColor: return("DirectColor");
9316 return("unknown visual class");
9320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9330 % XWarning() displays a warning reason in a Notice widget.
9332 % The format of the XWarning method is:
9334 % void XWarning(const unsigned int warning,const char *reason,
9335 % const char *description)
9337 % A description of each parameter follows:
9339 % o warning: Specifies the numeric warning category.
9341 % o reason: Specifies the reason to display before terminating the
9344 % o description: Specifies any description to the reason.
9347 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9348 const char *reason,const char *description)
9351 text[MaxTextExtent];
9356 if (reason == (char *) NULL)
9358 (void) CopyMagickString(text,reason,MaxTextExtent);
9359 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9360 windows=XSetWindows((XWindows *) ~0);
9361 XNoticeWidget(windows->display,windows,text,(char *) description);
9365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9369 % X W i n d o w B y I D %
9373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9375 % XWindowByID() locates a child window with a given ID. If not window with
9376 % the given name is found, 0 is returned. Only the window specified and its
9377 % subwindows are searched.
9379 % The format of the XWindowByID function is:
9381 % child=XWindowByID(display,window,id)
9383 % A description of each parameter follows:
9385 % o child: XWindowByID returns the window with the specified
9386 % id. If no windows are found, XWindowByID returns 0.
9388 % o display: Specifies a pointer to the Display structure; returned from
9391 % o id: Specifies the id of the window to locate.
9394 MagickExport Window XWindowByID(Display *display,const Window root_window,
9395 const unsigned long id)
9414 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9415 assert(display != (Display *) NULL);
9416 assert(root_window != (Window) NULL);
9418 return(XSelectWindow(display,&rectangle_info));
9419 if (root_window == id)
9421 status=XQueryTree(display,root_window,&child,&child,&children,
9423 if (status == False)
9424 return((Window) NULL);
9425 window=(Window) NULL;
9426 for (i=0; i < (int) number_children; i++)
9429 Search each child and their children.
9431 window=XWindowByID(display,children[i],id);
9432 if (window != (Window) NULL)
9435 if (children != (Window *) NULL)
9436 (void) XFree((void *) children);
9441 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9445 % X W i n d o w B y N a m e %
9449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9451 % XWindowByName() locates a window with a given name on a display. If no
9452 % window with the given name is found, 0 is returned. If more than one window
9453 % has the given name, the first one is returned. Only root and its children
9456 % The format of the XWindowByName function is:
9458 % window=XWindowByName(display,root_window,name)
9460 % A description of each parameter follows:
9462 % o window: XWindowByName returns the window id.
9464 % o display: Specifies a pointer to the Display structure; returned from
9467 % o root_window: Specifies the id of the root window.
9469 % o name: Specifies the name of the window to locate.
9472 MagickExport Window XWindowByName(Display *display,const Window root_window,
9492 assert(display != (Display *) NULL);
9493 assert(root_window != (Window) NULL);
9494 assert(name != (char *) NULL);
9495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9496 if (XGetWMName(display,root_window,&window_name) != 0)
9497 if (LocaleCompare((char *) window_name.value,name) == 0)
9498 return(root_window);
9499 status=XQueryTree(display,root_window,&child,&child,&children,
9501 if (status == False)
9502 return((Window) NULL);
9503 window=(Window) NULL;
9504 for (i=0; i < (int) number_children; i++)
9507 Search each child and their children.
9509 window=XWindowByName(display,children[i],name);
9510 if (window != (Window) NULL)
9513 if (children != (Window *) NULL)
9514 (void) XFree((void *) children);
9519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9523 % X W i n d o w B y P r o p e r y %
9527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9529 % XWindowByProperty() locates a child window with a given property. If not
9530 % window with the given name is found, 0 is returned. If more than one window
9531 % has the given property, the first one is returned. Only the window
9532 % specified and its subwindows are searched.
9534 % The format of the XWindowByProperty function is:
9536 % child=XWindowByProperty(display,window,property)
9538 % A description of each parameter follows:
9540 % o child: XWindowByProperty returns the window id with the specified
9541 % property. If no windows are found, XWindowByProperty returns 0.
9543 % o display: Specifies a pointer to the Display structure; returned from
9546 % o property: Specifies the property of the window to locate.
9549 MagickExport Window XWindowByProperty(Display *display,const Window window,
9550 const Atom property)
9578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9579 assert(display != (Display *) NULL);
9580 assert(window != (Window) NULL);
9581 assert(property != (Atom) NULL);
9582 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9583 if (status == False)
9584 return((Window) NULL);
9586 child=(Window) NULL;
9587 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9589 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9590 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9592 (void) XFree((void *) data);
9593 if ((status == Success) && (type != (Atom) NULL))
9596 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9597 child=XWindowByProperty(display,children[i],property);
9598 if (children != (Window *) NULL)
9599 (void) XFree((void *) children);
9605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9609 % X I m p o r t I m a g e %
9613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9615 % XImportImage() reads an image from an X window.
9617 % The format of the XImportImage method is:
9619 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9621 % A description of each parameter follows:
9623 % o image_info: the image info..
9625 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9628 MagickExport Image *XImportImage(const ImageInfo *image_info,
9629 XImportInfo *ximage_info)
9631 assert(image_info != (const ImageInfo *) NULL);
9632 assert(image_info->signature == MagickSignature);
9633 if (image_info->debug != MagickFalse)
9634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9635 image_info->filename);
9636 assert(ximage_info != (XImportInfo *) NULL);
9637 return((Image *) NULL);
9642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9646 + X C o m p o n e n t G e n e s i s %
9650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9652 % XComponentGenesis() instantiates the X component.
9654 % The format of the XComponentGenesis method is:
9656 % MagickBooleanType XComponentGenesis(void)
9659 MagickExport MagickBooleanType XComponentGenesis(void)
9665 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9669 % X G e t I m p o r t I n f o %
9673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9675 % XGetImportInfo() initializes the XImportInfo structure.
9677 % The format of the XGetImportInfo method is:
9679 % void XGetImportInfo(XImportInfo *ximage_info)
9681 % A description of each parameter follows:
9683 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9686 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9688 assert(ximage_info != (XImportInfo *) NULL);
9689 ximage_info->frame=MagickFalse;
9690 ximage_info->borders=MagickFalse;
9691 ximage_info->screen=MagickFalse;
9692 ximage_info->descend=MagickTrue;
9693 ximage_info->silent=MagickFalse;