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) RoundToQuantum(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) RoundToQuantum(green_gamma == 1.0 ? (double) \
116 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
118 #define XRedGamma(color) RoundToQuantum(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 q->opacity=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).
713 static char **FontToList(char *font)
728 if (font == (char *) NULL)
729 return((char **) NULL);
731 Convert string to an ASCII list.
734 for (p=font; *p != '\0'; p++)
735 if ((*p == ':') || (*p == ';') || (*p == ','))
737 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
738 if (fontlist == (char **) NULL)
740 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
742 return((char **) NULL);
745 for (i=0; i < (int) fonts; i++)
747 for (q=p; *q != '\0'; q++)
748 if ((*q == ':') || (*q == ';') || (*q == ','))
750 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
751 sizeof(*fontlist[i]));
752 if (fontlist[i] == (char *) NULL)
754 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
756 return((char **) NULL);
758 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
761 fontlist[i]=(char *) NULL;
765 MagickExport XFontStruct *XBestFont(Display *display,
766 const XResourceInfo *resource_info,const MagickBooleanType text_font)
771 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
772 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
773 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
774 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
775 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
776 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
783 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
784 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
785 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
799 font_info=(XFontStruct *) NULL;
800 font_name=resource_info->font;
801 if (text_font != MagickFalse)
802 font_name=resource_info->text_font;
803 if ((font_name != (char *) NULL) && (*font_name != '\0'))
812 Load preferred font specified in the X resource database.
814 fontlist=FontToList(font_name);
815 if (fontlist != (char **) NULL)
817 for (i=0; fontlist[i] != (char *) NULL; i++)
819 if (font_info == (XFontStruct *) NULL)
820 font_info=XLoadQueryFont(display,fontlist[i]);
821 fontlist[i]=DestroyString(fontlist[i]);
823 fontlist=(char **) RelinquishMagickMemory(fontlist);
825 if (font_info == (XFontStruct *) NULL)
826 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
829 Load fonts from list of fonts until one is found.
832 if (text_font != MagickFalse)
834 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
836 while (*p != (char *) NULL)
838 if (font_info != (XFontStruct *) NULL)
840 font_info=XLoadQueryFont(display,(char *) *p);
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 % X B e s t I c o n S i z e %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
858 % size that maintains the aspect ratio of the image. If the window manager
859 % has preferred icon sizes, one of the preferred sizes is used.
861 % The format of the XBestIconSize method is:
863 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
865 % A description of each parameter follows:
867 % o display: Specifies a connection to an X server; returned from
870 % o image: the image.
873 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
897 Determine if the window manager has specified preferred icon sizes.
899 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
900 assert(display != (Display *) NULL);
901 assert(window != (XWindowInfo *) NULL);
902 assert(image != (Image *) NULL);
903 window->width=MaxIconSize;
904 window->height=MaxIconSize;
905 icon_size=(XIconSize *) NULL;
907 root_window=XRootWindow(display,window->screen);
908 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
909 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
911 if (icon_size == (XIconSize *) NULL)
914 Window manager does not restrict icon size.
916 icon_size=XAllocIconSize();
917 if (icon_size == (XIconSize *) NULL)
919 ThrowXWindowFatalException(ResourceLimitError,
920 "MemoryAllocationFailed",image->filename);
923 icon_size->min_width=1;
924 icon_size->max_width=MaxIconSize;
925 icon_size->min_height=1;
926 icon_size->max_height=MaxIconSize;
927 icon_size->width_inc=1;
928 icon_size->height_inc=1;
931 Determine aspect ratio of image.
933 width=(unsigned int) image->columns;
934 height=(unsigned int) image->rows;
936 if (window->crop_geometry)
937 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
939 Look for an icon size that maintains the aspect ratio of image.
941 scale_factor=(MagickRealType) icon_size->max_width/width;
942 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
943 scale_factor=(MagickRealType) icon_size->max_height/height;
944 icon_width=(unsigned int) icon_size->min_width;
945 while ((int) icon_width < icon_size->max_width)
947 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
949 icon_width+=icon_size->width_inc;
951 icon_height=(unsigned int) icon_size->min_height;
952 while ((int) icon_height < icon_size->max_height)
954 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
956 icon_height+=icon_size->height_inc;
958 (void) XFree((void *) icon_size);
959 window->width=icon_width;
960 window->height=icon_height;
964 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
968 % X B e s t P i x e l %
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974 % XBestPixel() returns a pixel from an array of pixels that is closest to the
975 % requested color. If the color array is NULL, the colors are obtained from
978 % The format of the XBestPixel method is:
980 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
981 % unsigned int number_colors,XColor *color)
983 % A description of each parameter follows:
985 % o pixel: XBestPixel returns the pixel value closest to the requested
988 % o display: Specifies a connection to an X server; returned from
991 % o colormap: Specifies the ID of the X server colormap.
993 % o colors: Specifies an array of XColor structures.
995 % o number_colors: Specifies the number of XColor structures in the
996 % color definition array.
998 % o color: Specifies the desired RGB value to find in the colors array.
1001 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1002 XColor *colors,unsigned int number_colors,XColor *color)
1013 register MagickRealType
1024 Find closest representation for the requested RGB color.
1026 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1027 assert(display != (Display *) NULL);
1028 assert(color != (XColor *) NULL);
1029 status=XAllocColor(display,colormap,color);
1030 if (status != False)
1032 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1033 if (query_server != MagickFalse)
1036 Read X server colormap.
1038 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1039 if (colors == (XColor *) NULL)
1041 ThrowXWindowFatalException(ResourceLimitError,
1042 "MemoryAllocationFailed","...");
1045 for (i=0; i < (int) number_colors; i++)
1046 colors[i].pixel=(unsigned long) i;
1047 if (number_colors > 256)
1049 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1051 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1054 for (i=0; i < (int) number_colors; i++)
1056 pixel.red=colors[i].red-(MagickRealType) color->red;
1057 distance=pixel.red*pixel.red;
1058 if (distance > min_distance)
1060 pixel.green=colors[i].green-(MagickRealType) color->green;
1061 distance+=pixel.green*pixel.green;
1062 if (distance > min_distance)
1064 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1065 distance+=pixel.blue*pixel.blue;
1066 if (distance > min_distance)
1068 min_distance=distance;
1069 color->pixel=colors[i].pixel;
1072 (void) XAllocColor(display,colormap,&colors[j]);
1073 if (query_server != MagickFalse)
1074 colors=(XColor *) RelinquishMagickMemory(colors);
1078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % X B e s t V i s u a l I n f o %
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % XBestVisualInfo() returns visual information for a visual that is the "best"
1089 % the server supports. "Best" is defined as:
1091 % 1. Restrict the visual list to those supported by the default screen.
1093 % 2. If a visual type is specified, restrict the visual list to those of
1096 % 3. If a map type is specified, choose the visual that matches the id
1097 % specified by the Standard Colormap.
1099 % 4 From the list of visuals, choose one that can display the most
1100 % simultaneous colors. If more than one visual can display the same
1101 % number of simultaneous colors, one is chosen based on a rank.
1103 % The format of the XBestVisualInfo method is:
1105 % XVisualInfo *XBestVisualInfo(Display *display,
1106 % XStandardColormap *map_info,XResourceInfo *resource_info)
1108 % A description of each parameter follows:
1110 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1113 % o display: Specifies a connection to an X server; returned from
1116 % o map_info: If map_type is specified, this structure is initialized
1117 % with info from the Standard Colormap.
1119 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1123 static inline int MagickMax(const int x,const int y)
1130 static inline unsigned long MagickMin(const unsigned int x,
1131 const unsigned int y)
1138 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1139 XStandardColormap *map_info,XResourceInfo *resource_info)
1141 #define MaxStandardColormaps 7
1142 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1143 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1144 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1145 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1168 Restrict visual search by screen number.
1170 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1171 assert(display != (Display *) NULL);
1172 assert(map_info != (XStandardColormap *) NULL);
1173 assert(resource_info != (XResourceInfo *) NULL);
1174 map_type=resource_info->map_type;
1175 visual_type=resource_info->visual_type;
1176 visual_mask=VisualScreenMask;
1177 visual_template.screen=XDefaultScreen(display);
1178 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1179 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1180 if (resource_info->colors <= (1UL << (unsigned long) visual_template.depth))
1181 visual_mask|=VisualDepthMask;
1182 if (visual_type != (char *) NULL)
1185 Restrict visual search by class or visual id.
1187 if (LocaleCompare("staticgray",visual_type) == 0)
1189 visual_mask|=VisualClassMask;
1190 visual_template.klass=StaticGray;
1193 if (LocaleCompare("grayscale",visual_type) == 0)
1195 visual_mask|=VisualClassMask;
1196 visual_template.klass=GrayScale;
1199 if (LocaleCompare("staticcolor",visual_type) == 0)
1201 visual_mask|=VisualClassMask;
1202 visual_template.klass=StaticColor;
1205 if (LocaleCompare("pseudocolor",visual_type) == 0)
1207 visual_mask|=VisualClassMask;
1208 visual_template.klass=PseudoColor;
1211 if (LocaleCompare("truecolor",visual_type) == 0)
1213 visual_mask|=VisualClassMask;
1214 visual_template.klass=TrueColor;
1217 if (LocaleCompare("directcolor",visual_type) == 0)
1219 visual_mask|=VisualClassMask;
1220 visual_template.klass=DirectColor;
1223 if (LocaleCompare("default",visual_type) == 0)
1225 visual_mask|=VisualIDMask;
1226 visual_template.visualid=XVisualIDFromVisual(
1227 XDefaultVisual(display,XDefaultScreen(display)));
1230 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1232 visual_mask|=VisualIDMask;
1233 visual_template.visualid=
1234 strtol(visual_type,(char **) NULL,0);
1237 ThrowXWindowFatalException(XServerError,
1238 "UnrecognizedVisualSpecifier",visual_type);
1241 Get all visuals that meet our criteria so far.
1244 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1246 visual_mask=VisualScreenMask | VisualIDMask;
1247 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1250 Failed to get visual; try using the default visual.
1252 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1254 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1255 XDefaultScreen(display)));
1256 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1258 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1259 return((XVisualInfo *) NULL);
1260 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1261 XVisualClassName(visual_list->klass));
1263 resource_info->color_recovery=MagickFalse;
1264 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1270 map_name[MaxTextExtent];
1286 Choose a visual associated with a standard colormap.
1288 root_window=XRootWindow(display,XDefaultScreen(display));
1290 if (LocaleCompare(map_type,"list") != 0)
1293 User specified Standard Colormap.
1295 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1296 "RGB_%s_MAP",map_type);
1297 LocaleUpper(map_name);
1298 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1299 if (map_property != (Atom) NULL)
1300 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1306 *colormap[MaxStandardColormaps]=
1308 "_HP_RGB_SMOOTH_MAP_LIST",
1318 Choose a standard colormap from a list.
1320 for (i=0; i < MaxStandardColormaps; i++)
1322 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1323 if (map_property == (Atom) NULL)
1325 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1327 if (status != False)
1330 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1332 if (status == False)
1334 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1336 return((XVisualInfo *) NULL);
1339 Search all Standard Colormaps and visuals for ids that match.
1341 *map_info=map_list[0];
1342 #if !defined(PRE_R4_ICCCM)
1343 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1344 for (i=0; i < number_maps; i++)
1345 for (j=0; j < number_visuals; j++)
1346 if (map_list[i].visualid ==
1347 XVisualIDFromVisual(visual_list[j].visual))
1349 *map_info=map_list[i];
1350 visual_template.visualid=XVisualIDFromVisual(
1351 visual_list[j].visual);
1354 if (map_info->visualid != visual_template.visualid)
1356 ThrowXWindowFatalException(XServerError,
1357 "UnableToMatchVisualToStandardColormap",map_type);
1358 return((XVisualInfo *) NULL);
1361 if (map_info->colormap == (Colormap) NULL)
1363 ThrowXWindowFatalException(XServerError,
1364 "StandardColormapIsNotInitialized",map_type);
1365 return((XVisualInfo *) NULL);
1367 (void) XFree((void *) map_list);
1371 static const unsigned int
1386 Pick one visual that displays the most simultaneous colors.
1388 visual_info=visual_list;
1390 for (i=1; i < number_visuals; i++)
1393 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1396 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1397 if (rank[p->klass] > rank[visual_info->klass])
1400 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1402 (void) XFree((void *) visual_list);
1404 Retrieve only one visual by its screen & id number.
1406 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1408 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1409 return((XVisualInfo *) NULL);
1410 return(visual_info);
1414 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418 % X C h e c k D e f i n e C u r s o r %
1422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1424 % XCheckDefineCursor() prevents cursor changes on the root window.
1426 % The format of the XXCheckDefineCursor method is:
1428 % XCheckDefineCursor(display,window,cursor)
1430 % A description of each parameter follows:
1432 % o display: Specifies a connection to an X server; returned from
1435 % o window: the window.
1437 % o cursor: the cursor.
1440 MagickExport int XCheckDefineCursor(Display *display,Window window,
1443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1444 assert(display != (Display *) NULL);
1445 if (window == XRootWindow(display,XDefaultScreen(display)))
1447 return(XDefineCursor(display,window,cursor));
1451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1455 % X C h e c k R e f r e s h W i n d o w s %
1459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 % XCheckRefreshWindows() checks the X server for exposure events for a
1462 % particular window and updates the areassociated with the exposure event.
1464 % The format of the XCheckRefreshWindows method is:
1466 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1468 % A description of each parameter follows:
1470 % o display: Specifies a connection to an X server; returned from
1473 % o windows: Specifies a pointer to a XWindows structure.
1476 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1485 assert(display != (Display *) NULL);
1486 assert(windows != (XWindows *) NULL);
1487 XDelay(display,SuspendTime);
1488 id=windows->command.id;
1489 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1490 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1491 id=windows->image.id;
1492 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1493 XRefreshWindow(display,&windows->image,&event);
1494 XDelay(display,SuspendTime << 1);
1495 id=windows->command.id;
1496 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1497 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1498 id=windows->image.id;
1499 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1500 XRefreshWindow(display,&windows->image,&event);
1504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1508 % X C l i e n t M e s s a g e %
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1515 % initialized with a particular protocol type and atom.
1517 % The format of the XClientMessage function is:
1519 % XClientMessage(display,window,protocol,reason,timestamp)
1521 % A description of each parameter follows:
1523 % o display: Specifies a pointer to the Display structure; returned from
1526 % o window: Specifies a pointer to a Window structure.
1528 % o protocol: Specifies an atom value.
1530 % o reason: Specifies an atom value which is the reason to send.
1532 % o timestamp: Specifies a value of type Time.
1535 MagickExport void XClientMessage(Display *display,const Window window,
1536 const Atom protocol,const Atom reason,const Time timestamp)
1541 assert(display != (Display *) NULL);
1542 client_event.type=ClientMessage;
1543 client_event.window=window;
1544 client_event.message_type=protocol;
1545 client_event.format=32;
1546 client_event.data.l[0]=(long) reason;
1547 client_event.data.l[1]=(long) timestamp;
1548 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1556 + X C l i e n t W i n d o w %
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 % XClientWindow() finds a window, at or below the specified window, which has
1563 % a WM_STATE property. If such a window is found, it is returned, otherwise
1564 % the argument window is returned.
1566 % The format of the XClientWindow function is:
1568 % client_window=XClientWindow(display,target_window)
1570 % A description of each parameter follows:
1572 % o client_window: XClientWindow returns a window, at or below the specified
1573 % window, which has a WM_STATE property otherwise the argument
1574 % target_window is returned.
1576 % o display: Specifies a pointer to the Display structure; returned from
1579 % o target_window: Specifies the window to find a WM_STATE property.
1582 static Window XClientWindow(Display *display,Window target_window)
1604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1605 assert(display != (Display *) NULL);
1606 state=XInternAtom(display,"WM_STATE",MagickTrue);
1607 if (state == (Atom) NULL)
1608 return(target_window);
1610 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1611 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1612 if ((status == Success) && (type != (Atom) NULL))
1613 return(target_window);
1614 client_window=XWindowByProperty(display,target_window,state);
1615 if (client_window == (Window) NULL)
1616 return(target_window);
1617 return(client_window);
1621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625 + X C o m p o n e n t T e r m i n u s %
1629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1631 % XComponentTerminus() destroys the module component.
1633 % The format of the XComponentTerminus method is:
1635 % XComponentTerminus(void)
1638 MagickExport void XComponentTerminus(void)
1640 DestroyXResources();
1644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 % X C o n f i g u r e I m a g e C o l o r m a p %
1652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654 % XConfigureImageColormap() creates a new X colormap.
1656 % The format of the XConfigureImageColormap method is:
1658 % void XConfigureImageColormap(Display *display,
1659 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1661 % A description of each parameter follows:
1663 % o display: Specifies a connection to an X server; returned from
1666 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1668 % o windows: Specifies a pointer to a XWindows structure.
1670 % o image: the image.
1673 MagickExport void XConfigureImageColormap(Display *display,
1674 XResourceInfo *resource_info,XWindows *windows,Image *image)
1680 Make standard colormap.
1682 XSetCursorState(display,windows,MagickTrue);
1683 XCheckRefreshWindows(display,windows);
1684 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1685 windows->map_info,windows->pixel_info);
1686 colormap=windows->map_info->colormap;
1687 (void) XSetWindowColormap(display,windows->image.id,colormap);
1688 (void) XSetWindowColormap(display,windows->command.id,colormap);
1689 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1690 if (windows->magnify.mapped != MagickFalse)
1691 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1692 if (windows->pan.mapped != MagickFalse)
1693 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1694 XSetCursorState(display,windows,MagickFalse);
1695 XClientMessage(display,windows->image.id,windows->im_protocols,
1696 windows->im_update_colormap,CurrentTime);
1700 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1704 % X C o n s t r a i n W i n d o w P o s i t i o n %
1708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1710 % XConstrainWindowPosition() assures a window is positioned within the X
1711 % server boundaries.
1713 % The format of the XConstrainWindowPosition method is:
1715 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1717 % A description of each parameter follows:
1719 % o display: Specifies a pointer to the Display structure; returned from
1722 % o window_info: Specifies a pointer to a XWindowInfo structure.
1725 MagickExport void XConstrainWindowPosition(Display *display,
1726 XWindowInfo *window_info)
1731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1732 assert(display != (Display *) NULL);
1733 assert(window_info != (XWindowInfo *) NULL);
1734 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1735 if (window_info->x < 0)
1738 if (window_info->x > (int) limit)
1739 window_info->x=(int) limit;
1740 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1741 if (window_info->y < 0)
1744 if (window_info->y > limit)
1745 window_info->y=limit;
1749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1759 % XDelay() suspends program execution for the number of milliseconds
1762 % The format of the Delay method is:
1764 % void XDelay(Display *display,const unsigned long milliseconds)
1766 % A description of each parameter follows:
1768 % o display: Specifies a pointer to the Display structure; returned from
1771 % o milliseconds: Specifies the number of milliseconds to delay before
1775 MagickExport void XDelay(Display *display,const unsigned long milliseconds)
1777 assert(display != (Display *) NULL);
1778 (void) XFlush(display);
1779 if (milliseconds == 0)
1781 #if defined(__WINDOWS__)
1782 Sleep(milliseconds);
1788 timer=milliseconds/1000.0;
1791 #elif defined(MAGICKCORE_HAVE_USLEEP)
1792 usleep(1000*milliseconds);
1793 #elif defined(MAGICKCORE_HAVE_SELECT)
1798 timer.tv_sec=(long) milliseconds/1000;
1799 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1800 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1802 #elif defined(MAGICKCORE_HAVE_POLL)
1803 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1804 #elif defined(__BEOS__)
1805 snooze(1000*milliseconds);
1807 # error "Time delay method not defined."
1812 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1816 % X D e s t r o y R e s o u r c e I n f o %
1820 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1822 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1825 % The format of the XDestroyResourceInfo method is:
1827 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1829 % A description of each parameter follows:
1831 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1834 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1836 if (resource_info->image_geometry != (char *) NULL)
1837 resource_info->image_geometry=(char *)
1838 RelinquishMagickMemory(resource_info->image_geometry);
1839 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1840 resource_info->quantize_info=DestroyQuantizeInfo(
1841 resource_info->quantize_info);
1842 if (resource_info->client_name != (char *) NULL)
1843 resource_info->client_name=(char *)
1844 RelinquishMagickMemory(resource_info->client_name);
1845 if (resource_info->name != (char *) NULL)
1846 resource_info->name=DestroyString(resource_info->name);
1847 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 % X D e s t r o y W i n d o w C o l o r s %
1859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861 % XDestroyWindowColors() frees X11 color resources previously saved on a
1862 % window by XRetainWindowColors or programs like xsetroot.
1864 % The format of the XDestroyWindowColors method is:
1866 % void XDestroyWindowColors(Display *display,Window window)
1868 % A description of each parameter follows:
1870 % o display: Specifies a connection to an X server; returned from
1873 % o window: Specifies a pointer to a Window structure.
1876 MagickExport void XDestroyWindowColors(Display *display,Window window)
1896 If there are previous resources on the root window, destroy them.
1898 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1899 assert(display != (Display *) NULL);
1900 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1901 if (property == (Atom) NULL)
1903 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1907 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1908 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1909 if (status != Success)
1911 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1913 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1914 (void) XDeleteProperty(display,window,property);
1917 (void) XFree((void *) data);
1921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1925 % X D i s p l a y I m a g e I n f o %
1929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1931 % XDisplayImageInfo() displays information about an X image.
1933 % The format of the XDisplayImageInfo method is:
1935 % void XDisplayImageInfo(Display *display,
1936 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1939 % A description of each parameter follows:
1941 % o display: Specifies a connection to an X server; returned from
1944 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1946 % o windows: Specifies a pointer to a XWindows structure.
1948 % o undo_image: the undo image.
1950 % o image: the image.
1953 MagickExport void XDisplayImageInfo(Display *display,
1954 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1958 filename[MaxTextExtent],
1981 Write info about the X server to a file.
1983 assert(display != (Display *) NULL);
1984 assert(resource_info != (XResourceInfo *) NULL);
1985 assert(windows != (XWindows *) NULL);
1986 assert(image != (Image *) NULL);
1988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1990 unique_file=AcquireUniqueFileResource(filename);
1991 if (unique_file != -1)
1992 file=fdopen(unique_file,"w");
1993 if ((unique_file == -1) || (file == (FILE *) NULL))
1995 XNoticeWidget(display,windows,"Unable to display image info",filename);
1998 if (resource_info->gamma_correct != MagickFalse)
1999 if (resource_info->display_gamma != (char *) NULL)
2000 (void) fprintf(file,"Display\n gamma: %s\n\n",
2001 resource_info->display_gamma);
2003 Write info about the X image to a file.
2005 (void) fprintf(file,"X\n visual: %s\n",
2006 XVisualClassName((int) windows->image.storage_class));
2007 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
2008 if (windows->visual_info->colormap_size != 0)
2009 (void) fprintf(file," colormap size: %d\n",
2010 windows->visual_info->colormap_size);
2011 if (resource_info->colormap== SharedColormap)
2012 (void) fprintf(file," colormap type: Shared\n");
2014 (void) fprintf(file," colormap type: Private\n");
2015 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
2016 windows->image.ximage->height);
2017 if (windows->image.crop_geometry != (char *) NULL)
2018 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
2019 if (windows->image.pixmap == (Pixmap) NULL)
2020 (void) fprintf(file," type: X Image\n");
2022 (void) fprintf(file," type: Pixmap\n");
2023 if (windows->image.shape != MagickFalse)
2024 (void) fprintf(file," non-rectangular shape: True\n");
2026 (void) fprintf(file," non-rectangular shape: False\n");
2027 if (windows->image.shared_memory != MagickFalse)
2028 (void) fprintf(file," shared memory: True\n");
2030 (void) fprintf(file," shared memory: False\n");
2031 (void) fprintf(file,"\n");
2032 if (resource_info->font != (char *) NULL)
2033 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2034 if (resource_info->text_font != (char *) NULL)
2035 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2037 Write info about the undo cache to a file.
2040 for (levels=0; undo_image != (Image *) NULL; levels++)
2042 number_pixels=undo_image->list->columns*undo_image->list->rows;
2043 bytes+=number_pixels*sizeof(PixelPacket);
2044 undo_image=GetPreviousImageInList(undo_image);
2046 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2047 (void) fprintf(file," bytes: %lumb\n",(unsigned long)
2048 (bytes+(1 << 19)) >> 20);
2049 (void) fprintf(file," limit: %lumb\n\n",resource_info->undo_cache);
2051 Write info about the image to a file.
2053 (void) IdentifyImage(image,file,MagickTrue);
2054 (void) fclose(file);
2055 text=FileToString(filename,~0,&image->exception);
2056 (void) RelinquishUniqueFileResource(filename);
2057 if (text == (char *) NULL)
2059 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2060 "UnableToDisplayImageInfo");
2063 textlist=StringToList(text);
2064 if (textlist != (char **) NULL)
2067 title[MaxTextExtent];
2070 Display information about the image in the Text View widget.
2072 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2073 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2075 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2076 (char const **) textlist);
2077 for (i=0; textlist[i] != (char *) NULL; i++)
2078 textlist[i]=DestroyString(textlist[i]);
2079 textlist=(char **) RelinquishMagickMemory(textlist);
2081 text=DestroyString(text);
2085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2089 + X D i t h e r I m a g e %
2093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2095 % XDitherImage() dithers the reference image as required by the HP Color
2096 % Recovery algorithm. The color values are quantized to 3 bits of red and
2097 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2098 % standard colormap.
2100 % The format of the XDitherImage method is:
2102 % void XDitherImage(Image *image,XImage *ximage)
2104 % A description of each parameter follows:
2106 % o image: the image.
2108 % o ximage: Specifies a pointer to a XImage structure; returned from
2113 static void XDitherImage(Image *image,XImage *ximage)
2115 static const short int
2118 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2119 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2121 dither_green[2][16]=
2123 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2124 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2128 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2129 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2144 register const PixelPacket
2155 register unsigned long
2164 Allocate and initialize dither maps.
2166 for (i=0; i < 2; i++)
2167 for (j=0; j < 16; j++)
2169 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2171 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2172 sizeof(*green_map));
2173 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2175 if ((red_map[i][j] == (unsigned char *) NULL) ||
2176 (green_map[i][j] == (unsigned char *) NULL) ||
2177 (blue_map[i][j] == (unsigned char *) NULL))
2179 ThrowXWindowFatalException(ResourceLimitError,
2180 "MemoryAllocationFailed",image->filename);
2185 Initialize dither tables.
2187 for (i=0; i < 2; i++)
2188 for (j=0; j < 16; j++)
2189 for (x=0; x < 256; x++)
2194 value+=dither_red[i][j];
2195 red_map[i][j][x]=(unsigned char)
2196 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2200 value+=dither_green[i][j];
2201 green_map[i][j][x]=(unsigned char)
2202 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2206 value+=((unsigned long) dither_blue[i][j] << 1);
2207 blue_map[i][j][x]=(unsigned char)
2208 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2213 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2214 ((unsigned long) (ximage->width*ximage->bits_per_pixel) >> 3));
2218 for (y=0; y < (int) image->rows; y++)
2220 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2221 if (p == (const PixelPacket *) NULL)
2223 for (x=0; x < (int) image->columns; x++)
2225 color.red=RoundToQuantum((MagickRealType) (red_map[i][j][(int)
2226 ScaleQuantumToChar(p->red)] << 8));
2227 color.green=RoundToQuantum((MagickRealType) (green_map[i][j][(int)
2228 ScaleQuantumToChar(p->green)] << 8));
2229 color.blue=RoundToQuantum((MagickRealType) (blue_map[i][j][(int)
2230 ScaleQuantumToChar(p->blue)] << 8));
2231 pixel=(unsigned long) (((unsigned long) color.red & 0xe0) |
2232 (((unsigned long) color.green & 0xe0) >> 3) |
2233 (((unsigned long) color.blue & 0xc0) >> 6));
2246 Free allocated memory.
2248 for (i=0; i < 2; i++)
2249 for (j=0; j < 16; j++)
2251 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2252 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2253 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2262 % X D r a w I m a g e %
2266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2268 % XDrawImage() draws a line on the image.
2270 % The format of the XDrawImage method is:
2272 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2274 % A description of each parameter follows:
2276 % o display: Specifies a connection to an X server; returned from
2279 % o pixel: Specifies a pointer to a XPixelInfo structure.
2281 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2283 % o image: the image.
2286 MagickExport MagickBooleanType XDrawImage(Display *display,
2287 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2323 Initialize drawd image.
2325 assert(display != (Display *) NULL);
2326 assert(pixel != (XPixelInfo *) NULL);
2327 assert(draw_info != (XDrawInfo *) NULL);
2328 assert(image != (Image *) NULL);
2329 if (image->debug != MagickFalse)
2330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2332 Initialize drawd pixmap.
2334 root_window=XRootWindow(display,XDefaultScreen(display));
2335 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2336 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2337 draw_info->height,depth);
2338 if (draw_pixmap == (Pixmap) NULL)
2339 return(MagickFalse);
2341 Initialize graphics info.
2343 context_values.background=(unsigned long) (~0);
2344 context_values.foreground=0;
2345 context_values.line_width=(int) draw_info->line_width;
2346 draw_context=XCreateGC(display,root_window,(unsigned long)
2347 (GCBackground | GCForeground | GCLineWidth),&context_values);
2348 if (draw_context == (GC) NULL)
2349 return(MagickFalse);
2353 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2356 Draw line to pixmap.
2358 (void) XSetBackground(display,draw_context,0);
2359 (void) XSetForeground(display,draw_context,(unsigned long) (~0));
2360 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2361 (void) XSetStipple(display,draw_context,draw_info->stipple);
2362 switch (draw_info->element)
2367 (void) XDrawLines(display,draw_pixmap,draw_context,
2368 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2374 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2375 draw_info->line_info.y1,draw_info->line_info.x2,
2376 draw_info->line_info.y2);
2379 case RectangleElement:
2381 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2382 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2383 (unsigned int) draw_info->rectangle_info.width,
2384 (unsigned int) draw_info->rectangle_info.height);
2387 case FillRectangleElement:
2389 (void) XFillRectangle(display,draw_pixmap,draw_context,
2390 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2391 (unsigned int) draw_info->rectangle_info.width,
2392 (unsigned int) draw_info->rectangle_info.height);
2396 case EllipseElement:
2398 (void) XDrawArc(display,draw_pixmap,draw_context,
2399 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2400 (unsigned int) draw_info->rectangle_info.width,
2401 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2404 case FillCircleElement:
2405 case FillEllipseElement:
2407 (void) XFillArc(display,draw_pixmap,draw_context,
2408 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2409 (unsigned int) draw_info->rectangle_info.width,
2410 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2413 case PolygonElement:
2418 coordinate_info=draw_info->coordinate_info;
2419 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2420 (int) draw_info->number_coordinates,CoordModeOrigin);
2421 (void) XDrawLine(display,draw_pixmap,draw_context,
2422 coordinate_info[draw_info->number_coordinates-1].x,
2423 coordinate_info[draw_info->number_coordinates-1].y,
2424 coordinate_info[0].x,coordinate_info[0].y);
2427 case FillPolygonElement:
2429 (void) XFillPolygon(display,draw_pixmap,draw_context,
2430 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2435 (void) XFreeGC(display,draw_context);
2439 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2440 draw_info->height,AllPlanes,ZPixmap);
2441 if (draw_ximage == (XImage *) NULL)
2442 return(MagickFalse);
2443 (void) XFreePixmap(display,draw_pixmap);
2445 Initialize draw image.
2447 draw_image=AcquireImage((ImageInfo *) NULL);
2448 if (draw_image == (Image *) NULL)
2449 return(MagickFalse);
2450 draw_image->columns=draw_info->width;
2451 draw_image->rows=draw_info->height;
2453 Transfer drawn X image to image.
2455 width=(unsigned int) image->columns;
2456 height=(unsigned int) image->rows;
2459 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2460 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2462 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2463 return(MagickFalse);
2464 draw_image->matte=MagickTrue;
2465 exception=(&image->exception);
2466 for (y=0; y < (int) draw_image->rows; y++)
2471 register PixelPacket
2474 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2475 if (q == (PixelPacket *) NULL)
2477 for (x=0; x < (long) draw_image->columns; x++)
2479 if (XGetPixel(draw_ximage,x,y) == 0)
2482 Set this pixel to the background color.
2484 *q=draw_image->background_color;
2485 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2486 TransparentOpacity : OpaqueOpacity);
2491 Set this pixel to the pen color.
2493 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2494 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2495 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2496 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2497 OpaqueOpacity : TransparentOpacity);
2501 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2504 XDestroyImage(draw_ximage);
2506 Determine draw geometry.
2508 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2509 if ((width != (unsigned int) draw_image->columns) ||
2510 (height != (unsigned int) draw_image->rows))
2513 image_geometry[MaxTextExtent];
2518 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2520 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2522 if (draw_info->degrees != 0.0)
2536 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2537 if (rotate_image == (Image *) NULL)
2538 return(MagickFalse);
2539 draw_image=DestroyImage(draw_image);
2540 draw_image=rotate_image;
2542 Annotation is relative to the degree of rotation.
2544 normalized_degrees=draw_info->degrees;
2545 while (normalized_degrees < -45.0)
2546 normalized_degrees+=360.0;
2547 for (rotations=0; normalized_degrees > 45.0; rotations++)
2548 normalized_degrees-=90.0;
2549 switch (rotations % 4)
2559 x=x-(int) draw_image->columns/2;
2560 y=y+(int) draw_image->columns/2;
2568 x=x-(int) draw_image->columns;
2576 x=x-(int) draw_image->columns/2;
2577 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2583 Composite text onto the image.
2585 for (y=0; y < (int) draw_image->rows; y++)
2590 register PixelPacket
2593 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2594 if (q == (PixelPacket *) NULL)
2596 for (x=0; x < (long) draw_image->columns; x++)
2598 if (q->opacity != (Quantum) TransparentOpacity)
2599 q->opacity=OpaqueOpacity;
2602 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2605 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2606 if (draw_info->stencil == TransparentStencil)
2607 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2611 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2614 draw_image=DestroyImage(draw_image);
2619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2629 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2630 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2631 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2634 % The format of the XError function is:
2636 % XError(display,error)
2638 % A description of each parameter follows:
2640 % o display: Specifies a pointer to the Display structure; returned from
2643 % o error: Specifies the error event.
2647 #if defined(__cplusplus) || defined(c_plusplus)
2651 MagickExport int XError(Display *display,XErrorEvent *error)
2653 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2654 assert(display != (Display *) NULL);
2655 assert(error != (XErrorEvent *) NULL);
2656 xerror_alert=MagickTrue;
2657 switch (error->request_code)
2661 if ((int) error->error_code == BadDrawable)
2662 return(MagickFalse);
2665 case X_GetWindowAttributes:
2668 if ((int) error->error_code == BadWindow)
2669 return(MagickFalse);
2674 if ((int) error->error_code == BadValue)
2675 return(MagickFalse);
2682 #if defined(__cplusplus) || defined(c_plusplus)
2687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2691 % X F r e e R e s o u r c e s %
2695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2697 % XFreeResources() frees X11 resources.
2699 % The format of the XFreeResources method is:
2701 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2702 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2703 % XResourceInfo *resource_info,XWindowInfo *window_info)
2704 % resource_info,window_info)
2706 % A description of each parameter follows:
2708 % o display: Specifies a connection to an X server; returned from
2711 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2712 % returned from XGetVisualInfo.
2714 % o map_info: If map_type is specified, this structure is initialized
2715 % with info from the Standard Colormap.
2717 % o pixel: Specifies a pointer to a XPixelInfo structure.
2719 % o font_info: Specifies a pointer to a XFontStruct structure.
2721 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2723 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2726 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2727 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2728 XResourceInfo *resource_info,XWindowInfo *window_info)
2730 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2731 assert(display != (Display *) NULL);
2732 assert(resource_info != (XResourceInfo *) NULL);
2733 if (window_info != (XWindowInfo *) NULL)
2738 if (window_info->ximage != (XImage *) NULL)
2739 XDestroyImage(window_info->ximage);
2740 if (window_info->id != (Window) NULL)
2743 Free destroy window and free cursors.
2745 if (window_info->id != XRootWindow(display,visual_info->screen))
2746 (void) XDestroyWindow(display,window_info->id);
2747 if (window_info->annotate_context != (GC) NULL)
2748 (void) XFreeGC(display,window_info->annotate_context);
2749 if (window_info->highlight_context != (GC) NULL)
2750 (void) XFreeGC(display,window_info->highlight_context);
2751 if (window_info->widget_context != (GC) NULL)
2752 (void) XFreeGC(display,window_info->widget_context);
2753 if (window_info->cursor != (Cursor) NULL)
2754 (void) XFreeCursor(display,window_info->cursor);
2755 window_info->cursor=(Cursor) NULL;
2756 if (window_info->busy_cursor != (Cursor) NULL)
2757 (void) XFreeCursor(display,window_info->busy_cursor);
2758 window_info->busy_cursor=(Cursor) NULL;
2764 if (font_info != (XFontStruct *) NULL)
2765 (void) XFreeFont(display,font_info);
2766 if (map_info != (XStandardColormap *) NULL)
2769 Free X Standard Colormap.
2771 if (resource_info->map_type == (char *) NULL)
2772 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2773 (void) XFree((void *) map_info);
2778 if (visual_info != (XVisualInfo *) NULL)
2779 (void) XFree((void *) visual_info);
2780 if (resource_info->close_server != MagickFalse)
2781 (void) XCloseDisplay(display);
2785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2789 % X F r e e S t a n d a r d C o l o r m a p %
2793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2795 % XFreeStandardColormap() frees an X11 colormap.
2797 % The format of the XFreeStandardColormap method is:
2799 % void XFreeStandardColormap(Display *display,
2800 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2801 % XPixelInfo *pixel)
2803 % A description of each parameter follows:
2805 % o display: Specifies a connection to an X server; returned from
2808 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2809 % returned from XGetVisualInfo.
2811 % o map_info: If map_type is specified, this structure is initialized
2812 % with info from the Standard Colormap.
2814 % o pixel: Specifies a pointer to a XPixelInfo structure.
2817 MagickExport void XFreeStandardColormap(Display *display,
2818 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2824 assert(display != (Display *) NULL);
2825 assert(visual_info != (XVisualInfo *) NULL);
2826 assert(map_info != (XStandardColormap *) NULL);
2827 (void) XFlush(display);
2828 if (map_info->colormap != (Colormap) NULL)
2830 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2831 (void) XFreeColormap(display,map_info->colormap);
2833 if (pixel != (XPixelInfo *) NULL)
2834 if ((visual_info->klass != TrueColor) &&
2835 (visual_info->klass != DirectColor))
2836 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2837 (int) pixel->colors,0);
2839 map_info->colormap=(Colormap) NULL;
2840 if (pixel != (XPixelInfo *) NULL)
2842 if (pixel->pixels != (unsigned long *) NULL)
2843 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2844 pixel->pixels=(unsigned long *) NULL;
2849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2853 % X G e t A n n o t a t e I n f o %
2857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2859 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2861 % The format of the XGetAnnotateInfo method is:
2863 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2865 % A description of each parameter follows:
2867 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2870 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2873 Initialize annotate structure.
2875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2876 assert(annotate_info != (XAnnotateInfo *) NULL);
2879 annotate_info->width=0;
2880 annotate_info->height=0;
2881 annotate_info->stencil=ForegroundStencil;
2882 annotate_info->degrees=0.0;
2883 annotate_info->font_info=(XFontStruct *) NULL;
2884 annotate_info->text=(char *) NULL;
2885 *annotate_info->geometry='\0';
2886 annotate_info->previous=(XAnnotateInfo *) NULL;
2887 annotate_info->next=(XAnnotateInfo *) NULL;
2888 (void) XSupportsLocale();
2889 (void) XSetLocaleModifiers("");
2893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2897 % X G e t M a p I n f o %
2901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2903 % XGetMapInfo() initializes the XStandardColormap structure.
2905 % The format of the XStandardColormap method is:
2907 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2908 % XStandardColormap *map_info)
2910 % A description of each parameter follows:
2912 % o colormap: Specifies the ID of the X server colormap.
2914 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2915 % returned from XGetVisualInfo.
2917 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2920 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2921 const Colormap colormap,XStandardColormap *map_info)
2924 Initialize map info.
2926 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2927 assert(visual_info != (XVisualInfo *) NULL);
2928 assert(map_info != (XStandardColormap *) NULL);
2929 map_info->colormap=colormap;
2930 map_info->red_max=visual_info->red_mask;
2931 map_info->red_mult=(unsigned long) (map_info->red_max != 0 ? 1 : 0);
2932 if (map_info->red_max != 0)
2933 while ((map_info->red_max & 0x01) == 0)
2935 map_info->red_max>>=1;
2936 map_info->red_mult<<=1;
2938 map_info->green_max=visual_info->green_mask;
2939 map_info->green_mult=(unsigned long) (map_info->green_max != 0 ? 1 : 0);
2940 if (map_info->green_max != 0)
2941 while ((map_info->green_max & 0x01) == 0)
2943 map_info->green_max>>=1;
2944 map_info->green_mult<<=1;
2946 map_info->blue_max=visual_info->blue_mask;
2947 map_info->blue_mult=(unsigned long) (map_info->blue_max != 0 ? 1 : 0);
2948 if (map_info->blue_max != 0)
2949 while ((map_info->blue_max & 0x01) == 0)
2951 map_info->blue_max>>=1;
2952 map_info->blue_mult<<=1;
2954 map_info->base_pixel=0;
2958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2962 % X G e t P i x e l I n f o %
2966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2968 % XGetPixelPacket() initializes the PixelPacket structure.
2970 % The format of the XGetPixelPacket method is:
2972 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2973 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2974 % Image *image,XPixelInfo *pixel)
2977 % A description of each parameter follows:
2979 % o display: Specifies a connection to an X server; returned from
2982 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2983 % returned from XGetVisualInfo.
2985 % o map_info: If map_type is specified, this structure is initialized
2986 % with info from the Standard Colormap.
2988 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2990 % o image: the image.
2992 % o pixel: Specifies a pointer to a XPixelInfo structure.
2995 MagickExport void XGetPixelPacket(Display *display,
2996 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2997 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3000 *PenColors[MaxNumberPens]=
3002 "#000000000000", /* black */
3003 "#00000000ffff", /* blue */
3004 "#0000ffffffff", /* cyan */
3005 "#0000ffff0000", /* green */
3006 "#bdbdbdbdbdbd", /* gray */
3007 "#ffff00000000", /* red */
3008 "#ffff0000ffff", /* magenta */
3009 "#ffffffff0000", /* yellow */
3010 "#ffffffffffff", /* white */
3011 "#bdbdbdbdbdbd", /* gray */
3012 "#bdbdbdbdbdbd" /* gray */
3028 Initialize pixel info.
3030 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3031 assert(display != (Display *) NULL);
3032 assert(visual_info != (XVisualInfo *) NULL);
3033 assert(map_info != (XStandardColormap *) NULL);
3034 assert(resource_info != (XResourceInfo *) NULL);
3035 assert(pixel != (XPixelInfo *) NULL);
3037 if (image != (Image *) NULL)
3038 if (image->storage_class == PseudoClass)
3039 pixel->colors=image->colors;
3040 packets=(unsigned int)
3041 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3042 if (pixel->pixels != (unsigned long *) NULL)
3043 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3044 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3045 sizeof(pixel->pixels));
3046 if (pixel->pixels == (unsigned long *) NULL)
3047 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3050 Set foreground color.
3052 colormap=map_info->colormap;
3053 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3054 &pixel->foreground_color);
3055 status=XParseColor(display,colormap,resource_info->foreground_color,
3056 &pixel->foreground_color);
3057 if (status == False)
3058 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3059 resource_info->foreground_color);
3060 pixel->foreground_color.pixel=
3061 XStandardPixel(map_info,&pixel->foreground_color);
3062 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3064 Set background color.
3066 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3067 status=XParseColor(display,colormap,resource_info->background_color,
3068 &pixel->background_color);
3069 if (status == False)
3070 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3071 resource_info->background_color);
3072 pixel->background_color.pixel=
3073 XStandardPixel(map_info,&pixel->background_color);
3074 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3078 (void) XParseColor(display,colormap,(char *) BorderColor,
3079 &pixel->border_color);
3080 status=XParseColor(display,colormap,resource_info->border_color,
3081 &pixel->border_color);
3082 if (status == False)
3083 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3084 resource_info->border_color);
3085 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3086 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3090 pixel->matte_color=pixel->background_color;
3091 if (resource_info->matte_color != (char *) NULL)
3094 Matte color is specified as a X resource or command line argument.
3096 status=XParseColor(display,colormap,resource_info->matte_color,
3097 &pixel->matte_color);
3098 if (status == False)
3099 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3100 resource_info->matte_color);
3101 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3102 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3105 Set highlight color.
3107 pixel->highlight_color.red=(unsigned short) ((
3108 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3109 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3110 pixel->highlight_color.green=(unsigned short) ((
3111 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3112 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3113 pixel->highlight_color.blue=(unsigned short) ((
3114 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3115 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3116 pixel->highlight_color.pixel=
3117 XStandardPixel(map_info,&pixel->highlight_color);
3118 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3122 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3123 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3124 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3125 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3126 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3127 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3128 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3129 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3133 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3134 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3135 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3136 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3137 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3138 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3139 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3140 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3144 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3145 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3146 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3147 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3148 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3149 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3150 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3151 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3155 for (i=0; i < MaxNumberPens; i++)
3157 (void) XParseColor(display,colormap,(char *) PenColors[i],
3158 &pixel->pen_colors[i]);
3159 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3160 &pixel->pen_colors[i]);
3161 if (status == False)
3162 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3163 resource_info->pen_colors[i]);
3164 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3165 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3167 pixel->box_color=pixel->background_color;
3168 pixel->pen_color=pixel->foreground_color;
3171 if (image != (Image *) NULL)
3173 if ((resource_info->gamma_correct != MagickFalse) &&
3174 (image->gamma != 0.0))
3183 Initialize map relative to display and image gamma.
3185 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3186 red_gamma=geometry_info.rho;
3187 green_gamma=geometry_info.sigma;
3188 if ((flags & SigmaValue) == 0)
3189 green_gamma=red_gamma;
3190 blue_gamma=geometry_info.xi;
3191 if ((flags & XiValue) == 0)
3192 blue_gamma=red_gamma;
3193 red_gamma*=image->gamma;
3194 green_gamma*=image->gamma;
3195 blue_gamma*=image->gamma;
3197 if (image->storage_class == PseudoClass)
3200 Initialize pixel array for images of type PseudoClass.
3202 for (i=0; i < (long) image->colors; i++)
3204 XGammaPixel(map_info,image->colormap+i);
3205 for (i=0; i < MaxNumberPens; i++)
3206 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3207 pixel->colors+=MaxNumberPens;
3213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3217 % X G e t R e s o u r c e C l a s s %
3221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3223 % XGetResourceClass() queries the X server for the specified resource name or
3224 % class. If the resource name or class is not defined in the database, the
3225 % supplied default value is returned.
3227 % The format of the XGetResourceClass method is:
3229 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3230 % const char *keyword,char *resource_default)
3232 % A description of each parameter follows:
3234 % o database: Specifies a resource database; returned from
3235 % XrmGetStringDatabase.
3237 % o client_name: Specifies the application name used to retrieve resource
3238 % info from the X server database.
3240 % o keyword: Specifies the keyword of the value being retrieved.
3242 % o resource_default: Specifies the default value to return if the query
3243 % fails to find the specified keyword/class.
3246 MagickExport char *XGetResourceClass(XrmDatabase database,
3247 const char *client_name,const char *keyword,char *resource_default)
3250 resource_class[MaxTextExtent],
3251 resource_name[MaxTextExtent];
3262 if (database == (XrmDatabase) NULL)
3263 return(resource_default);
3264 *resource_name='\0';
3265 *resource_class='\0';
3266 if (keyword != (char *) NULL)
3273 Initialize resource keyword and class.
3275 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3276 client_name,keyword);
3277 c=(int) (*client_name);
3278 if ((c >= XK_a) && (c <= XK_z))
3281 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3282 c-=(XK_agrave-XK_Agrave);
3284 if ((c >= XK_oslash) && (c <= XK_thorn))
3285 c-=(XK_oslash-XK_Ooblique);
3287 if ((k >= XK_a) && (k <= XK_z))
3290 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3291 k-=(XK_agrave-XK_Agrave);
3293 if ((k >= XK_oslash) && (k <= XK_thorn))
3294 k-=(XK_oslash-XK_Ooblique);
3295 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3296 client_name+1,k,keyword+1);
3298 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3300 if (status == False)
3301 return(resource_default);
3302 return(resource_value.addr);
3306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3310 % X G e t R e s o u r c e D a t a b a s e %
3314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3316 % XGetResourceDatabase() creates a new resource database and initializes it.
3318 % The format of the XGetResourceDatabase method is:
3320 % XrmDatabase XGetResourceDatabase(Display *display,
3321 % const char *client_name)
3323 % A description of each parameter follows:
3325 % o database: XGetResourceDatabase() returns the database after it is
3328 % o display: Specifies a connection to an X server; returned from
3331 % o client_name: Specifies the application name used to retrieve resource
3332 % info from the X server database.
3335 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3336 const char *client_name)
3339 filename[MaxTextExtent];
3351 if (display == (Display *) NULL)
3352 return((XrmDatabase) NULL);
3353 assert(client_name != (char *) NULL);
3355 Initialize resource database.
3358 (void) XGetDefault(display,(char *) client_name,"dummy");
3359 resource_database=XrmGetDatabase(display);
3361 Combine application database.
3363 if (client_name != (char *) NULL)
3366 Get basename of client.
3368 p=client_name+(strlen(client_name)-1);
3369 while ((p > client_name) && (*p != '/'))
3374 c=(int) (*client_name);
3375 if ((c >= XK_a) && (c <= XK_z))
3378 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3379 c-=(XK_agrave-XK_Agrave);
3381 if ((c >= XK_oslash) && (c <= XK_thorn))
3382 c-=(XK_oslash-XK_Ooblique);
3383 #if defined(X11_APPLICATION_PATH)
3384 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3385 X11_APPLICATION_PATH,c,client_name+1);
3386 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3388 if (XResourceManagerString(display) != (char *) NULL)
3391 Combine server database.
3393 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3394 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3397 Merge user preferences database.
3399 #if defined(X11_PREFERENCES_PATH)
3400 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3401 X11_PREFERENCES_PATH,client_name);
3402 ExpandFilename(filename);
3403 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3405 return(resource_database);
3409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3413 % X G e t R e s o u r c e I n f o %
3417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3419 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3421 % The format of the XGetResourceInfo method is:
3423 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3424 % const char *client_name,XResourceInfo *resource_info)
3426 % A description of each parameter follows:
3428 % o image_info: the image info.
3430 % o database: Specifies a resource database; returned from
3431 % XrmGetStringDatabase.
3433 % o client_name: Specifies the application name used to retrieve
3434 % resource info from the X server database.
3436 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3439 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3440 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3447 Initialize resource info fields.
3449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3450 assert(resource_info != (XResourceInfo *) NULL);
3451 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3452 resource_info->resource_database=database;
3453 resource_info->image_info=(ImageInfo *) image_info;
3454 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3455 XMagickProgressMonitor,(void *) NULL);
3456 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3457 resource_info->close_server=MagickTrue;
3458 resource_info->client_name=AcquireString(client_name);
3459 resource_value=XGetResourceClass(database,client_name,"backdrop",
3461 resource_info->backdrop=IsMagickTrue(resource_value);
3462 resource_info->background_color=XGetResourceInstance(database,client_name,
3463 "background",(char *) "#d6d6d6d6d6d6");
3464 resource_info->border_color=XGetResourceInstance(database,client_name,
3465 "borderColor",BorderColor);
3466 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3468 resource_info->border_width=(unsigned int) StringToLong(resource_value);
3469 resource_value=XGetResourceClass(database,client_name,"colormap",
3471 resource_info->colormap=UndefinedColormap;
3472 if (LocaleCompare("private",resource_value) == 0)
3473 resource_info->colormap=PrivateColormap;
3474 if (LocaleCompare("shared",resource_value) == 0)
3475 resource_info->colormap=SharedColormap;
3476 if (resource_info->colormap == UndefinedColormap)
3477 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3479 resource_value=XGetResourceClass(database,client_name,
3480 "colorRecovery",(char *) "False");
3481 resource_info->color_recovery=IsMagickTrue(resource_value);
3482 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3484 resource_info->confirm_exit=IsMagickTrue(resource_value);
3485 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3487 resource_info->confirm_edit=IsMagickTrue(resource_value);
3488 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3489 resource_info->delay=(unsigned int) StringToLong(resource_value);
3490 resource_info->display_gamma=XGetResourceClass(database,client_name,
3491 "displayGamma",(char *) "2.2");
3492 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3494 resource_info->display_warnings=IsMagickTrue(resource_value);
3495 resource_info->font=XGetResourceClass(database,client_name,"font",
3497 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3498 resource_info->font);
3499 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3501 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3502 (char *) "variable");
3503 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3505 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3507 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3508 (char *) "7x13bold");
3509 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3510 (char *) "8x13bold");
3511 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3512 (char *) "9x15bold");
3513 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3515 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3517 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3519 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3521 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3522 "foreground",ForegroundColor);
3523 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3525 resource_info->gamma_correct=IsMagickTrue(resource_value);
3526 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3527 client_name,"geometry",(char *) NULL));
3528 resource_value=XGetResourceClass(database,client_name,"gravity",
3530 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3531 MagickFalse,resource_value);
3532 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3533 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3534 "iconGeometry",(char *) NULL);
3535 resource_value=XGetResourceClass(database,client_name,"iconic",
3537 resource_info->iconic=IsMagickTrue(resource_value);
3538 resource_value=XGetResourceClass(database,client_name,"immutable",
3539 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3541 resource_info->immutable=IsMagickTrue(resource_value);
3542 resource_value=XGetResourceClass(database,client_name,"magnify",
3544 resource_info->magnify=(unsigned int) StringToLong(resource_value);
3545 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3547 resource_info->matte_color=XGetResourceInstance(database,client_name,
3548 "mattecolor",(char *) NULL);
3549 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3550 "name",(char *) NULL));
3551 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3553 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3555 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3557 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3559 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3561 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3563 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3564 (char *) "magenta");
3565 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3567 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3569 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3571 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3573 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3574 resource_info->pause=(unsigned int) StringToLong(resource_value);
3575 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3576 resource_info->quantum=StringToLong(resource_value);
3577 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3578 "font",(char *) "fixed");
3579 resource_info->text_font=XGetResourceClass(database,client_name,
3580 "textFontList",resource_info->text_font);
3581 resource_info->title=XGetResourceClass(database,client_name,"title",
3583 resource_value=XGetResourceClass(database,client_name,"undoCache",
3585 resource_info->undo_cache=(unsigned int) StringToLong(resource_value);
3586 resource_value=XGetResourceClass(database,client_name,"update",
3588 resource_info->update=IsMagickTrue(resource_value);
3589 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3591 resource_info->use_pixmap=IsMagickTrue(resource_value);
3592 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3594 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3595 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3597 resource_info->window_group=XGetResourceClass(database,client_name,
3598 "windowGroup",(char *) NULL);
3599 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3601 resource_info->write_filename=XGetResourceClass(database,client_name,
3602 "writeFilename",(char *) NULL);
3606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3610 % X G e t R e s o u r c e I n s t a n c e %
3614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3616 % XGetResourceInstance() queries the X server for the specified resource name.
3617 % If the resource name is not defined in the database, the supplied default
3618 % value is returned.
3620 % The format of the XGetResourceInstance method is:
3622 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3623 % const char *keyword,const char *resource_default)
3625 % A description of each parameter follows:
3627 % o database: Specifies a resource database; returned from
3628 % XrmGetStringDatabase.
3630 % o client_name: Specifies the application name used to retrieve
3631 % resource info from the X server database.
3633 % o keyword: Specifies the keyword of the value being retrieved.
3635 % o resource_default: Specifies the default value to return if the query
3636 % fails to find the specified keyword/class.
3639 MagickExport char *XGetResourceInstance(XrmDatabase database,
3640 const char *client_name,const char *keyword,const char *resource_default)
3644 resource_name[MaxTextExtent];
3652 if (database == (XrmDatabase) NULL)
3653 return((char *) resource_default);
3654 *resource_name='\0';
3655 if (keyword != (char *) NULL)
3656 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3658 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3660 if (status == False)
3661 return((char *) resource_default);
3662 return(resource_value.addr);
3666 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3670 % X G e t S c r e e n D e n s i t y %
3674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3676 % XGetScreenDensity() returns the density of the X server screen in
3679 % The format of the XGetScreenDensity method is:
3681 % char *XGetScreenDensity(Display *display)
3683 % A description of each parameter follows:
3685 % o density: XGetScreenDensity() returns the density of the X screen in
3688 % o display: Specifies a connection to an X server; returned from
3692 MagickExport char *XGetScreenDensity(Display *display)
3695 density[MaxTextExtent];
3702 Set density as determined by screen size.
3704 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3705 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3706 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3707 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3708 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,y_density);
3709 return(GetPageGeometry(density));
3713 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3717 + X G e t S u b w i n d o w %
3721 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3723 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3724 % pointer and a button press.
3726 % The format of the XGetSubwindow method is:
3728 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3730 % A description of each parameter follows:
3732 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3733 % otherwise the subwindow is returned.
3735 % o display: Specifies a connection to an X server; returned from
3738 % o window: Specifies a pointer to a Window.
3740 % o x: the x coordinate of the pointer relative to the origin of the
3743 % o y: the y coordinate of the pointer relative to the origin of the
3748 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3761 assert(display != (Display *) NULL);
3762 source_window=XRootWindow(display,XDefaultScreen(display));
3763 if (window == (Window) NULL)
3764 return(source_window);
3765 target_window=window;
3768 status=XTranslateCoordinates(display,source_window,window,x,y,
3769 &x_offset,&y_offset,&target_window);
3772 if (target_window == (Window) NULL)
3774 source_window=window;
3775 window=target_window;
3779 if (target_window == (Window) NULL)
3780 target_window=window;
3781 return(target_window);
3785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3789 % X G e t W i n d o w C o l o r %
3793 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3795 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3798 % The format of the XGetWindowColor method is:
3800 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3803 % A description of each parameter follows:
3805 % o display: Specifies a connection to an X server; returned from
3808 % o windows: Specifies a pointer to a XWindows structure.
3810 % o name: the name of the color if found in the X Color Database is
3811 % returned in this character string.
3814 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3815 XWindows *windows,char *name)
3846 Choose a pixel from the X server.
3848 assert(display != (Display *) NULL);
3849 assert(name != (char *) NULL);
3850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3852 target_window=XSelectWindow(display,&crop_info);
3853 if (target_window == (Window) NULL)
3854 return(MagickFalse);
3855 root_window=XRootWindow(display,XDefaultScreen(display));
3856 client_window=target_window;
3857 if (target_window != root_window)
3865 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3866 if (status != False)
3868 client_window=XClientWindow(display,target_window);
3869 target_window=client_window;
3873 Verify window is viewable.
3875 status=XGetWindowAttributes(display,target_window,&window_attributes);
3876 if ((status == False) || (window_attributes.map_state != IsViewable))
3877 return(MagickFalse);
3881 (void) XTranslateCoordinates(display,root_window,target_window,
3882 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3883 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3884 if (ximage == (XImage *) NULL)
3885 return(MagickFalse);
3886 color.pixel=XGetPixel(ximage,0,0);
3887 XDestroyImage(ximage);
3889 Match color against the color database.
3891 (void) XQueryColor(display,window_attributes.colormap,&color);
3892 pixel.red=ScaleShortToQuantum(color.red);
3893 pixel.green=ScaleShortToQuantum(color.green);
3894 pixel.blue=ScaleShortToQuantum(color.blue);
3895 pixel.opacity=OpaqueOpacity;
3896 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3897 &windows->image.image->exception);
3902 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3906 + X G e t W i n d o w I m a g e %
3910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3912 % XGetWindowImage() reads an image from the target X window and returns it.
3913 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3914 % target image with each child image in an optimized fashion. Any child
3915 % window that have the same visual, colormap, and are contained by its parent
3918 % The format of the XGetWindowImage method is:
3920 % Image *XGetWindowImage(Display *display,const Window window,
3921 % const unsigned int borders,const unsigned int level)
3923 % A description of each parameter follows:
3925 % o display: Specifies a connection to an X server; returned from
3928 % o window: Specifies the window to obtain the image from.
3930 % o borders: Specifies whether borders pixels are to be saved with
3933 % o level: Specifies an unsigned integer representing the level of
3934 % decent in the window hierarchy. This value must be zero or one on
3935 % the initial call to XGetWindowImage. A value of zero returns after
3936 % one call. A value of one causes the function to descend the window
3937 % hierarchy and overlay the target image with each subwindow image.
3941 static Image *XGetWindowImage(Display *display,const Window window,
3942 const unsigned int borders,const unsigned int level)
3944 typedef struct _ColormapInfo
3952 struct _ColormapInfo
3956 typedef struct _WindowInfo
3988 register IndexPacket
3995 *colormap_info = (ColormapInfo *) NULL;
4015 Verify window is viewable.
4017 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4018 assert(display != (Display *) NULL);
4019 status=XGetWindowAttributes(display,window,&window_attributes);
4020 if ((status == False) || (window_attributes.map_state != IsViewable))
4021 return((Image *) NULL);
4023 Cropping rectangle is relative to root window.
4025 root_window=XRootWindow(display,XDefaultScreen(display));
4026 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4028 crop_info.x=(long) x_offset;
4029 crop_info.y=(long) y_offset;
4030 crop_info.width=(unsigned long) window_attributes.width;
4031 crop_info.height=(unsigned long) window_attributes.height;
4032 if (borders != MagickFalse)
4035 Include border in image.
4037 crop_info.x-=(long) window_attributes.border_width;
4038 crop_info.y-=(long) window_attributes.border_width;
4039 crop_info.width+=(unsigned long) (window_attributes.border_width << 1);
4040 crop_info.height+=(unsigned long) (window_attributes.border_width << 1);
4043 Crop to root window.
4045 if (crop_info.x < 0)
4047 crop_info.width+=crop_info.x;
4050 if (crop_info.y < 0)
4052 crop_info.height+=crop_info.y;
4055 display_width=XDisplayWidth(display,XDefaultScreen(display));
4056 if ((int) (crop_info.x+crop_info.width) > display_width)
4057 crop_info.width=(unsigned long) (display_width-crop_info.x);
4058 display_height=XDisplayHeight(display,XDefaultScreen(display));
4059 if ((int) (crop_info.y+crop_info.height) > display_height)
4060 crop_info.height=(unsigned long) (display_height-crop_info.y);
4062 Initialize window info attributes.
4064 if (number_windows >= max_windows)
4067 Allocate or resize window info buffer.
4070 if (window_info == (WindowInfo *) NULL)
4071 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4072 sizeof(*window_info));
4074 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4075 max_windows,sizeof(*window_info));
4077 if (window_info == (WindowInfo *) NULL)
4079 ThrowXWindowFatalException(ResourceLimitError,
4080 "MemoryAllocationFailed","...");
4081 return((Image *) NULL);
4083 id=number_windows++;
4084 window_info[id].window=window;
4085 window_info[id].visual=window_attributes.visual;
4086 window_info[id].colormap=window_attributes.colormap;
4087 window_info[id].bounds.x1=(short) crop_info.x;
4088 window_info[id].bounds.y1=(short) crop_info.y;
4089 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4090 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4091 crop_info.x-=x_offset;
4092 crop_info.y-=y_offset;
4093 window_info[id].crop_info=crop_info;
4103 Descend the window hierarchy.
4105 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4106 &children,&number_children);
4107 for (i=0; i < id; i++)
4108 if ((window_info[i].window == window_info[id].parent) &&
4109 (window_info[i].visual == window_info[id].visual) &&
4110 (window_info[i].colormap == window_info[id].colormap))
4112 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4113 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4114 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4115 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4118 Eliminate windows not circumscribed by their parent.
4124 if ((status == True) && (number_children != 0))
4126 for (i=0; i < (int) number_children; i++)
4127 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4128 (void) XFree((void *) children);
4153 register PixelPacket
4156 register unsigned long
4169 Get X image for each window in the list.
4171 image=NewImageList();
4172 for (id=0; id < number_windows; id++)
4175 Does target window intersect top level window?
4178 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4179 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4180 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4181 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4182 MagickTrue : MagickFalse;
4184 Is target window contained by another window with the same colormap?
4186 for (j=0; j < id; j++)
4187 if ((window_info[id].visual == window_info[j].visual) &&
4188 (window_info[id].colormap == window_info[j].colormap))
4190 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4191 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4192 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4193 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4197 if ((window_info[id].visual != window_info[j].visual) ||
4198 (window_info[id].colormap != window_info[j].colormap))
4200 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4201 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4202 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4203 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4206 if (import == MagickFalse)
4211 ximage=XGetImage(display,window_info[id].window,(int)
4212 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4213 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4214 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4215 if (ximage == (XImage *) NULL)
4218 Initialize window colormap.
4221 colors=(XColor *) NULL;
4222 if (window_info[id].colormap != (Colormap) NULL)
4228 Search colormap list for window colormap.
4230 number_colors=(unsigned int) window_info[id].visual->map_entries;
4231 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4232 if (p->colormap == window_info[id].colormap)
4234 if (p == (ColormapInfo *) NULL)
4237 Get the window colormap.
4239 colors=(XColor *) AcquireQuantumMemory(number_colors,
4241 if (colors == (XColor *) NULL)
4243 XDestroyImage(ximage);
4244 return((Image *) NULL);
4246 if ((window_info[id].visual->klass != DirectColor) &&
4247 (window_info[id].visual->klass != TrueColor))
4248 for (i=0; i < (int) number_colors; i++)
4250 colors[i].pixel=(unsigned long) i;
4264 DirectColor or TrueColor visual.
4269 red_bit=window_info[id].visual->red_mask &
4270 (~(window_info[id].visual->red_mask)+1);
4271 green_bit=window_info[id].visual->green_mask &
4272 (~(window_info[id].visual->green_mask)+1);
4273 blue_bit=window_info[id].visual->blue_mask &
4274 (~(window_info[id].visual->blue_mask)+1);
4275 for (i=0; i < (int) number_colors; i++)
4277 colors[i].pixel=red | green | blue;
4280 if (red > window_info[id].visual->red_mask)
4283 if (green > window_info[id].visual->green_mask)
4286 if (blue > window_info[id].visual->blue_mask)
4290 (void) XQueryColors(display,window_info[id].colormap,colors,
4291 (int) number_colors);
4293 Append colormap to colormap list.
4295 p=(ColormapInfo *) AcquireAlignedMemory(1,sizeof(*p));
4296 if (p == (ColormapInfo *) NULL)
4297 return((Image *) NULL);
4298 p->colormap=window_info[id].colormap;
4300 p->next=colormap_info;
4306 Allocate image structure.
4308 composite_image=AcquireImage((ImageInfo *) NULL);
4309 if (composite_image == (Image *) NULL)
4311 XDestroyImage(ximage);
4312 return((Image *) NULL);
4315 Convert X image to MIFF format.
4317 if ((window_info[id].visual->klass != TrueColor) &&
4318 (window_info[id].visual->klass != DirectColor))
4319 composite_image->storage_class=PseudoClass;
4320 composite_image->columns=(unsigned long) ximage->width;
4321 composite_image->rows=(unsigned long) ximage->height;
4322 exception=(&composite_image->exception);
4323 switch (composite_image->storage_class)
4328 register unsigned long
4341 Determine shift and mask for red, green, and blue.
4343 red_mask=window_info[id].visual->red_mask;
4345 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4350 green_mask=window_info[id].visual->green_mask;
4352 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4357 blue_mask=window_info[id].visual->blue_mask;
4359 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4365 Convert X image to DirectClass packets.
4367 if ((number_colors != 0) &&
4368 (window_info[id].visual->klass == DirectColor))
4369 for (y=0; y < (int) composite_image->rows; y++)
4371 q=QueueAuthenticPixels(composite_image,0,y,
4372 composite_image->columns,1,exception);
4373 if (q == (PixelPacket *) NULL)
4375 for (x=0; x < (int) composite_image->columns; x++)
4377 pixel=XGetPixel(ximage,x,y);
4378 index=(pixel >> red_shift) & red_mask;
4379 q->red=ScaleShortToQuantum(colors[index].red);
4380 index=(pixel >> green_shift) & green_mask;
4381 q->green=ScaleShortToQuantum(colors[index].green);
4382 index=(pixel >> blue_shift) & blue_mask;
4383 q->blue=ScaleShortToQuantum(colors[index].blue);
4386 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4390 for (y=0; y < (int) composite_image->rows; y++)
4392 q=QueueAuthenticPixels(composite_image,0,y,
4393 composite_image->columns,1,exception);
4394 if (q == (PixelPacket *) NULL)
4396 for (x=0; x < (int) composite_image->columns; x++)
4398 pixel=XGetPixel(ximage,x,y);
4399 color=(pixel >> red_shift) & red_mask;
4400 color=(65535UL*color)/red_mask;
4401 q->red=ScaleShortToQuantum((unsigned short) color);
4402 color=(pixel >> green_shift) & green_mask;
4403 color=(65535UL*color)/green_mask;
4404 q->green=ScaleShortToQuantum((unsigned short) color);
4405 color=(pixel >> blue_shift) & blue_mask;
4406 color=(65535UL*color)/blue_mask;
4407 q->blue=ScaleShortToQuantum((unsigned short) color);
4410 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4420 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4422 XDestroyImage(ximage);
4423 composite_image=DestroyImage(composite_image);
4424 return((Image *) NULL);
4426 for (i=0; i < (int) composite_image->colors; i++)
4428 composite_image->colormap[colors[i].pixel].red=
4429 ScaleShortToQuantum(colors[i].red);
4430 composite_image->colormap[colors[i].pixel].green=
4431 ScaleShortToQuantum(colors[i].green);
4432 composite_image->colormap[colors[i].pixel].blue=
4433 ScaleShortToQuantum(colors[i].blue);
4436 Convert X image to PseudoClass packets.
4438 for (y=0; y < (int) composite_image->rows; y++)
4440 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4441 if (q == (PixelPacket *) NULL)
4443 indexes=GetAuthenticIndexQueue(composite_image);
4444 for (x=0; x < (int) composite_image->columns; x++)
4446 index=(IndexPacket) XGetPixel(ximage,x,y);
4448 *q++=composite_image->colormap[(long) index];
4450 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4456 XDestroyImage(ximage);
4457 if (image == (Image *) NULL)
4459 image=composite_image;
4463 Composite any children in back-to-front order.
4465 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4466 &x_offset,&y_offset,&child);
4467 x_offset-=(int) crop_info.x;
4470 y_offset-=(int) crop_info.y;
4473 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4477 Relinquish resources.
4479 while (colormap_info != (ColormapInfo *) NULL)
4481 next=colormap_info->next;
4482 colormap_info->colors=(XColor *)
4483 RelinquishMagickMemory(colormap_info->colors);
4484 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4488 Relinquish resources and restore initial state.
4490 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4493 colormap_info=(ColormapInfo *) NULL;
4496 return((Image *) NULL);
4500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4504 % X G e t W i n d o w I n f o %
4508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4510 % XGetWindowInfo() initializes the XWindowInfo structure.
4512 % The format of the XGetWindowInfo method is:
4514 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4515 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4516 % XResourceInfo *resource_info,XWindowInfo *window)
4517 % resource_info,window)
4519 % A description of each parameter follows:
4521 % o display: Specifies a connection to an X server; returned from
4524 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4525 % returned from XGetVisualInfo.
4527 % o map_info: If map_type is specified, this structure is initialized
4528 % with info from the Standard Colormap.
4530 % o pixel: Specifies a pointer to a XPixelInfo structure.
4532 % o font_info: Specifies a pointer to a XFontStruct structure.
4534 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4537 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4538 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4539 XResourceInfo *resource_info,XWindowInfo *window)
4542 Initialize window info.
4544 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4545 assert(display != (Display *) NULL);
4546 assert(visual_info != (XVisualInfo *) NULL);
4547 assert(map_info != (XStandardColormap *) NULL);
4548 assert(pixel != (XPixelInfo *) NULL);
4549 assert(resource_info != (XResourceInfo *) NULL);
4550 assert(window != (XWindowInfo *) NULL);
4551 if (window->id != (Window) NULL)
4553 if (window->cursor != (Cursor) NULL)
4554 (void) XFreeCursor(display,window->cursor);
4555 if (window->busy_cursor != (Cursor) NULL)
4556 (void) XFreeCursor(display,window->busy_cursor);
4557 if (window->highlight_stipple != (Pixmap) NULL)
4558 (void) XFreePixmap(display,window->highlight_stipple);
4559 if (window->shadow_stipple != (Pixmap) NULL)
4560 (void) XFreePixmap(display,window->shadow_stipple);
4561 if (window->name == (char *) NULL)
4562 window->name=AcquireString("");
4563 if (window->icon_name == (char *) NULL)
4564 window->icon_name=AcquireString("");
4569 Initialize these attributes just once.
4571 window->id=(Window) NULL;
4572 if (window->name == (char *) NULL)
4573 window->name=AcquireString("");
4574 if (window->icon_name == (char *) NULL)
4575 window->icon_name=AcquireString("");
4576 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4577 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4578 window->ximage=(XImage *) NULL;
4579 window->matte_image=(XImage *) NULL;
4580 window->pixmap=(Pixmap) NULL;
4581 window->matte_pixmap=(Pixmap) NULL;
4582 window->mapped=MagickFalse;
4583 window->stasis=MagickFalse;
4584 window->shared_memory=MagickTrue;
4585 window->segment_info=(void *) NULL;
4586 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4591 if (window->segment_info == (void *) NULL)
4592 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4593 segment_info=(XShmSegmentInfo *) window->segment_info;
4594 segment_info[0].shmid=(-1);
4595 segment_info[0].shmaddr=(char *) NULL;
4596 segment_info[1].shmid=(-1);
4597 segment_info[1].shmaddr=(char *) NULL;
4602 Initialize these attributes every time function is called.
4604 window->screen=visual_info->screen;
4605 window->root=XRootWindow(display,visual_info->screen);
4606 window->visual=visual_info->visual;
4607 window->storage_class=(unsigned int) visual_info->klass;
4608 window->depth=(unsigned int) visual_info->depth;
4609 window->visual_info=visual_info;
4610 window->map_info=map_info;
4611 window->pixel_info=pixel;
4612 window->font_info=font_info;
4613 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4614 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4615 window->geometry=(char *) NULL;
4616 window->icon_geometry=(char *) NULL;
4617 if (resource_info->icon_geometry != (char *) NULL)
4618 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4619 window->crop_geometry=(char *) NULL;
4620 window->flags=(unsigned long) PSize;
4623 window->min_width=1;
4624 window->min_height=1;
4625 window->width_inc=1;
4626 window->height_inc=1;
4627 window->border_width=resource_info->border_width;
4628 window->annotate_context=pixel->annotate_context;
4629 window->highlight_context=pixel->highlight_context;
4630 window->widget_context=pixel->widget_context;
4631 window->shadow_stipple=(Pixmap) NULL;
4632 window->highlight_stipple=(Pixmap) NULL;
4633 window->use_pixmap=MagickTrue;
4634 window->immutable=MagickFalse;
4635 window->shape=MagickFalse;
4637 window->mask=(unsigned long) (CWBackingStore | CWBackPixel | CWBackPixmap |
4638 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4639 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4640 window->attributes.background_pixel=pixel->background_color.pixel;
4641 window->attributes.background_pixmap=(Pixmap) NULL;
4642 window->attributes.bit_gravity=ForgetGravity;
4643 window->attributes.backing_store=WhenMapped;
4644 window->attributes.save_under=MagickTrue;
4645 window->attributes.border_pixel=pixel->border_color.pixel;
4646 window->attributes.colormap=map_info->colormap;
4647 window->attributes.cursor=window->cursor;
4648 window->attributes.do_not_propagate_mask=NoEventMask;
4649 window->attributes.event_mask=NoEventMask;
4650 window->attributes.override_redirect=MagickFalse;
4651 window->attributes.win_gravity=NorthWestGravity;
4652 window->orphan=MagickFalse;
4656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4660 % X H i g h l i g h t E l l i p s e %
4664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4666 % XHighlightEllipse() puts a border on the X server around a region defined by
4669 % The format of the XHighlightEllipse method is:
4671 % void XHighlightEllipse(Display *display,Window window,
4672 % GC annotate_context,const RectangleInfo *highlight_info)
4674 % A description of each parameter follows:
4676 % o display: Specifies a connection to an X server; returned from
4679 % o window: Specifies a pointer to a Window structure.
4681 % o annotate_context: Specifies a pointer to a GC structure.
4683 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4684 % contains the extents of any highlighting rectangle.
4687 MagickExport void XHighlightEllipse(Display *display,Window window,
4688 GC annotate_context,const RectangleInfo *highlight_info)
4690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4691 assert(display != (Display *) NULL);
4692 assert(window != (Window) NULL);
4693 assert(annotate_context != (GC) NULL);
4694 assert(highlight_info != (RectangleInfo *) NULL);
4695 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4697 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4698 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4699 (unsigned int) highlight_info->height-1,0,360*64);
4700 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4701 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4702 (unsigned int) highlight_info->height-3,0,360*64);
4706 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4710 % X H i g h l i g h t L i n e %
4714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4716 % XHighlightLine() puts a border on the X server around a region defined by
4719 % The format of the XHighlightLine method is:
4721 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4722 % const XSegment *highlight_info)
4724 % A description of each parameter follows:
4726 % o display: Specifies a connection to an X server; returned from
4729 % o window: Specifies a pointer to a Window structure.
4731 % o annotate_context: Specifies a pointer to a GC structure.
4733 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4734 % contains the extents of any highlighting rectangle.
4737 MagickExport void XHighlightLine(Display *display,Window window,
4738 GC annotate_context,const XSegment *highlight_info)
4740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4741 assert(display != (Display *) NULL);
4742 assert(window != (Window) NULL);
4743 assert(annotate_context != (GC) NULL);
4744 assert(highlight_info != (XSegment *) NULL);
4745 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4746 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4750 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4754 % X H i g h l i g h t R e c t a n g l e %
4758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4760 % XHighlightRectangle() puts a border on the X server around a region defined
4761 % by highlight_info.
4763 % The format of the XHighlightRectangle method is:
4765 % void XHighlightRectangle(Display *display,Window window,
4766 % GC annotate_context,const RectangleInfo *highlight_info)
4768 % A description of each parameter follows:
4770 % o display: Specifies a connection to an X server; returned from
4773 % o window: Specifies a pointer to a Window structure.
4775 % o annotate_context: Specifies a pointer to a GC structure.
4777 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4778 % contains the extents of any highlighting rectangle.
4781 MagickExport void XHighlightRectangle(Display *display,Window window,
4782 GC annotate_context,const RectangleInfo *highlight_info)
4784 assert(display != (Display *) NULL);
4785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4786 assert(window != (Window) NULL);
4787 assert(annotate_context != (GC) NULL);
4788 assert(highlight_info != (RectangleInfo *) NULL);
4789 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4791 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4792 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4793 (unsigned int) highlight_info->height-1);
4794 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4795 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4796 (unsigned int) highlight_info->height-3);
4800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4804 % X I m p o r t I m a g e %
4808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4810 % XImportImage() reads an image from an X window.
4812 % The format of the XImportImage method is:
4814 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4816 % A description of each parameter follows:
4818 % o image_info: the image info.
4820 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4823 MagickExport Image *XImportImage(const ImageInfo *image_info,
4824 XImportInfo *ximage_info)
4857 Open X server connection.
4859 assert(image_info != (const ImageInfo *) NULL);
4860 assert(image_info->signature == MagickSignature);
4861 if (image_info->debug != MagickFalse)
4862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4863 image_info->filename);
4864 assert(ximage_info != (XImportInfo *) NULL);
4865 display=XOpenDisplay(image_info->server_name);
4866 if (display == (Display *) NULL)
4868 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4869 XDisplayName(image_info->server_name));
4870 return((Image *) NULL);
4873 Set our forgiving exception handler.
4875 (void) XSetErrorHandler(XError);
4877 Select target window.
4883 root=XRootWindow(display,XDefaultScreen(display));
4884 target=(Window) NULL;
4885 if ((image_info->filename != (char *) NULL) &&
4886 (*image_info->filename != '\0'))
4888 if (LocaleCompare(image_info->filename,"root") == 0)
4893 Select window by ID or name.
4895 if (isdigit((unsigned char) *image_info->filename) != 0)
4896 target=XWindowByID(display,root,(Window)
4897 strtol(image_info->filename,(char **) NULL,0));
4898 if (target == (Window) NULL)
4899 target=XWindowByName(display,root,image_info->filename);
4900 if (target == (Window) NULL)
4901 ThrowXWindowFatalException(XServerError,
4902 "NoWindowWithSpecifiedIDExists",image_info->filename);
4906 If target window is not defined, interactively select one.
4908 prior_target=target;
4909 if (target == (Window) NULL)
4910 target=XSelectWindow(display,&crop_info);
4911 if (target == (Window) NULL)
4912 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4913 image_info->filename);
4914 client=target; /* obsolete */
4920 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4921 if (status != False)
4929 Find window manager frame.
4931 status=XQueryTree(display,target,&root,&parent,&children,&d);
4932 if ((status != False) && (children != (Window *) NULL))
4933 (void) XFree((char *) children);
4934 if ((status == False) || (parent == (Window) NULL) ||
4942 client=XClientWindow(display,target);
4943 if (ximage_info->frame == MagickFalse)
4945 if ((ximage_info->frame == MagickFalse) &&
4946 (prior_target != MagickFalse))
4947 target=prior_target;
4948 XDelay(display,SuspendTime << 4);
4951 if (ximage_info->screen)
4963 Obtain window image directly from screen.
4965 status=XGetWindowAttributes(display,target,&window_attributes);
4966 if (status == False)
4968 ThrowXWindowFatalException(XServerError,
4969 "UnableToReadXWindowAttributes",image_info->filename);
4970 (void) XCloseDisplay(display);
4971 return((Image *) NULL);
4973 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4976 crop_info.width=(unsigned long) window_attributes.width;
4977 crop_info.height=(unsigned long) window_attributes.height;
4978 if (ximage_info->borders)
4981 Include border in image.
4983 crop_info.x-=window_attributes.border_width;
4984 crop_info.y-=window_attributes.border_width;
4985 crop_info.width+=window_attributes.border_width << 1;
4986 crop_info.height+=window_attributes.border_width << 1;
4991 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4994 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4995 if ((status == True) && (number_windows > 0))
4997 ximage_info->descend=MagickTrue;
4998 (void) XFree ((char *) children);
5000 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5001 if (number_colormaps > 0)
5003 if (number_colormaps > 1)
5004 ximage_info->descend=MagickTrue;
5005 (void) XFree((char *) colormaps);
5008 Alert the user not to alter the screen.
5010 if (ximage_info->silent == MagickFalse)
5011 (void) XBell(display,0);
5013 Get image by window id.
5015 (void) XGrabServer(display);
5016 image=XGetWindowImage(display,target,ximage_info->borders,
5017 ximage_info->descend ? 1U : 0U);
5018 (void) XUngrabServer(display);
5019 if (image == (Image *) NULL)
5020 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5021 image_info->filename)
5024 (void) CopyMagickString(image->filename,image_info->filename,
5026 if ((crop_info.width != 0) && (crop_info.height != 0))
5033 Crop image as defined by the cropping rectangle.
5035 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5036 if (clone_image != (Image *) NULL)
5038 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5039 if (crop_image != (Image *) NULL)
5041 image=DestroyImage(image);
5046 status=XGetWMName(display,target,&window_name);
5049 if ((image_info->filename != (char *) NULL) &&
5050 (*image_info->filename == '\0'))
5051 (void) CopyMagickString(image->filename,(char *) window_name.value,
5052 (size_t) window_name.nitems+1);
5053 (void) XFree((void *) window_name.value);
5056 if (ximage_info->silent == MagickFalse)
5059 Alert the user we're done.
5061 (void) XBell(display,0);
5062 (void) XBell(display,0);
5064 (void) XCloseDisplay(display);
5069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5073 % X I n i t i a l i z e W i n d o w s %
5077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5079 % XInitializeWindows() initializes the XWindows structure.
5081 % The format of the XInitializeWindows method is:
5083 % XWindows *XInitializeWindows(Display *display,
5084 % XResourceInfo *resource_info)
5086 % A description of each parameter follows:
5088 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5090 % o display: Specifies a connection to an X server; returned from
5093 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5096 MagickExport XWindows *XInitializeWindows(Display *display,
5097 XResourceInfo *resource_info)
5106 Allocate windows structure.
5108 windows=(XWindows *) AcquireAlignedMemory(1,sizeof(*windows));
5109 if (windows == (XWindows *) NULL)
5111 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5113 return((XWindows *) NULL);
5115 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5116 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5117 sizeof(*windows->pixel_info));
5118 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5119 sizeof(*windows->icon_pixel));
5120 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5121 sizeof(*windows->icon_resources));
5122 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5123 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5124 (windows->icon_resources == (XResourceInfo *) NULL))
5126 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5128 return((XWindows *) NULL);
5131 Initialize windows structure.
5133 windows->display=display;
5134 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5135 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5136 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5137 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5138 windows->im_remote_command=
5139 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5140 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5141 windows->im_update_colormap=
5142 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5143 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5144 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5145 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5146 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5147 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5148 #if defined(__WINDOWS__)
5149 (void) XSynchronize(display,IsWindows95());
5151 if (IsEventLogging())
5153 (void) XSynchronize(display,MagickTrue);
5154 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5155 GetMagickVersion((unsigned long *) NULL));
5156 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5157 (void) LogMagickEvent(X11Event,GetMagickModule(),
5158 " Window Manager: 0x%lx",windows->wm_protocols);
5159 (void) LogMagickEvent(X11Event,GetMagickModule(),
5160 " delete window: 0x%lx",windows->wm_delete_window);
5161 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5162 windows->wm_take_focus);
5163 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5164 windows->im_protocols);
5165 (void) LogMagickEvent(X11Event,GetMagickModule(),
5166 " remote command: 0x%lx",windows->im_remote_command);
5167 (void) LogMagickEvent(X11Event,GetMagickModule(),
5168 " update widget: 0x%lx",windows->im_update_widget);
5169 (void) LogMagickEvent(X11Event,GetMagickModule(),
5170 " update colormap: 0x%lx",windows->im_update_colormap);
5171 (void) LogMagickEvent(X11Event,GetMagickModule(),
5172 " former image: 0x%lx",windows->im_former_image);
5173 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5174 windows->im_next_image);
5175 (void) LogMagickEvent(X11Event,GetMagickModule(),
5176 " retain colors: 0x%lx",windows->im_retain_colors);
5177 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5179 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5180 windows->dnd_protocols);
5183 Allocate standard colormap.
5185 windows->map_info=XAllocStandardColormap();
5186 windows->icon_map=XAllocStandardColormap();
5187 if ((windows->map_info == (XStandardColormap *) NULL) ||
5188 (windows->icon_map == (XStandardColormap *) NULL))
5189 ThrowXWindowFatalException(ResourceLimitFatalError,
5190 "MemoryAllocationFailed","...");
5191 windows->map_info->colormap=(Colormap) NULL;
5192 windows->icon_map->colormap=(Colormap) NULL;
5193 windows->pixel_info->pixels=(unsigned long *) NULL;
5194 windows->pixel_info->annotate_context=(GC) NULL;
5195 windows->pixel_info->highlight_context=(GC) NULL;
5196 windows->pixel_info->widget_context=(GC) NULL;
5197 windows->font_info=(XFontStruct *) NULL;
5198 windows->icon_pixel->annotate_context=(GC) NULL;
5199 windows->icon_pixel->pixels=(unsigned long *) NULL;
5203 *windows->icon_resources=(*resource_info);
5204 windows->icon_resources->visual_type=(char *) "default";
5205 windows->icon_resources->colormap=SharedColormap;
5206 windows->visual_info=
5207 XBestVisualInfo(display,windows->map_info,resource_info);
5208 windows->icon_visual=
5209 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5210 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5211 (windows->icon_visual == (XVisualInfo *) NULL))
5212 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5213 resource_info->visual_type);
5214 if (IsEventLogging())
5216 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5217 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5218 windows->visual_info->visualid);
5219 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5220 XVisualClassName(windows->visual_info->klass));
5221 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5222 windows->visual_info->depth);
5223 (void) LogMagickEvent(X11Event,GetMagickModule(),
5224 " size of colormap: %d entries",windows->visual_info->colormap_size);
5225 (void) LogMagickEvent(X11Event,GetMagickModule(),
5226 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5227 windows->visual_info->red_mask,windows->visual_info->green_mask,
5228 windows->visual_info->blue_mask);
5229 (void) LogMagickEvent(X11Event,GetMagickModule(),
5230 " significant bits in color: %d bits",
5231 windows->visual_info->bits_per_rgb);
5234 Allocate class and manager hints.
5236 windows->class_hints=XAllocClassHint();
5237 windows->manager_hints=XAllocWMHints();
5238 if ((windows->class_hints == (XClassHint *) NULL) ||
5239 (windows->manager_hints == (XWMHints *) NULL))
5240 ThrowXWindowFatalException(ResourceLimitFatalError,
5241 "MemoryAllocationFailed","...");
5243 Determine group leader if we have one.
5245 root_window=XRootWindow(display,windows->visual_info->screen);
5246 windows->group_leader.id=(Window) NULL;
5247 if (resource_info->window_group != (char *) NULL)
5249 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5250 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5251 strtol((char *) resource_info->window_group,(char **) NULL,0));
5252 if (windows->group_leader.id == (Window) NULL)
5253 windows->group_leader.id=
5254 XWindowByName(display,root_window,resource_info->window_group);
5260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5264 % X M a k e C u r s o r %
5268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5270 % XMakeCursor() creates a crosshairs X11 cursor.
5272 % The format of the XMakeCursor method is:
5274 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5275 % char *background_color,char *foreground_color)
5277 % A description of each parameter follows:
5279 % o display: Specifies a connection to an X server; returned from
5282 % o window: Specifies the ID of the window for which the cursor is
5285 % o colormap: Specifies the ID of the colormap from which the background
5286 % and foreground color will be retrieved.
5288 % o background_color: Specifies the color to use for the cursor background.
5290 % o foreground_color: Specifies the color to use for the cursor foreground.
5293 MagickExport Cursor XMakeCursor(Display *display,Window window,
5294 Colormap colormap,char *background_color,char *foreground_color)
5296 #define scope_height 17
5297 #define scope_x_hot 8
5298 #define scope_y_hot 8
5299 #define scope_width 17
5301 static const unsigned char
5304 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5305 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5306 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5307 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5308 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5312 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5313 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5314 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5315 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5316 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5330 assert(display != (Display *) NULL);
5331 assert(window != (Window) NULL);
5332 assert(colormap != (Colormap) NULL);
5333 assert(background_color != (char *) NULL);
5334 assert(foreground_color != (char *) NULL);
5335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5336 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5338 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5339 scope_width,scope_height);
5340 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5342 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5343 return((Cursor) NULL);
5345 (void) XParseColor(display,colormap,background_color,&background);
5346 (void) XParseColor(display,colormap,foreground_color,&foreground);
5347 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5348 scope_x_hot,scope_y_hot);
5349 (void) XFreePixmap(display,source);
5350 (void) XFreePixmap(display,mask);
5355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5359 % X M a k e I m a g e %
5363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5365 % XMakeImage() creates an X11 image. If the image size differs from the X11
5366 % image size, the image is first resized.
5368 % The format of the XMakeImage method is:
5370 % MagickBooleanType XMakeImage(Display *display,
5371 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5372 % unsigned int width,unsigned int height)
5374 % A description of each parameter follows:
5376 % o display: Specifies a connection to an X server; returned from
5379 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5381 % o window: Specifies a pointer to a XWindowInfo structure.
5383 % o image: the image.
5385 % o width: Specifies the width in pixels of the rectangular area to
5388 % o height: Specifies the height in pixels of the rectangular area to
5392 MagickExport MagickBooleanType XMakeImage(Display *display,
5393 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5394 unsigned int width,unsigned int height)
5396 #define CheckOverflowException(length,width,height) \
5397 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5410 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5411 assert(display != (Display *) NULL);
5412 assert(resource_info != (XResourceInfo *) NULL);
5413 assert(window != (XWindowInfo *) NULL);
5415 assert(height != 0);
5416 if ((window->width == 0) || (window->height == 0))
5417 return(MagickFalse);
5419 Apply user transforms to the image.
5421 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5422 (void) XFlush(display);
5423 depth=(int) window->depth;
5424 if (window->destroy)
5425 window->image=DestroyImage(window->image);
5426 window->image=image;
5427 window->destroy=MagickFalse;
5428 if (window->image != (Image *) NULL)
5430 if (window->crop_geometry != (char *) NULL)
5441 window->image->page.x=0;
5442 window->image->page.y=0;
5443 (void) ParsePageGeometry(window->image,window->crop_geometry,
5444 &crop_info,&image->exception);
5445 crop_image=CropImage(window->image,&crop_info,&image->exception);
5446 if (crop_image != (Image *) NULL)
5448 if (window->image != image)
5449 window->image=DestroyImage(window->image);
5450 window->image=crop_image;
5451 window->destroy=MagickTrue;
5454 if ((width != (unsigned int) window->image->columns) ||
5455 (height != (unsigned int) window->image->rows))
5463 resize_image=NewImageList();
5464 if (window->pixel_info->colors != 0)
5465 resize_image=SampleImage(window->image,width,height,
5468 resize_image=ThumbnailImage(window->image,width,height,
5470 if (resize_image != (Image *) NULL)
5472 if (window->image != image)
5473 window->image=DestroyImage(window->image);
5474 window->image=resize_image;
5475 window->destroy=MagickTrue;
5478 width=(unsigned int) window->image->columns;
5479 assert((unsigned long) width == window->image->columns);
5480 height=(unsigned int) window->image->rows;
5481 assert((unsigned long) height == window->image->rows);
5486 ximage=(XImage *) NULL;
5487 format=(depth == 1) ? XYBitmap : ZPixmap;
5488 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5489 if (window->shared_memory != MagickFalse)
5494 segment_info=(XShmSegmentInfo *) window->segment_info;
5495 segment_info[1].shmid=(-1);
5496 segment_info[1].shmaddr=(char *) NULL;
5497 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5498 (char *) NULL,&segment_info[1],width,height);
5499 if (ximage == (XImage *) NULL)
5500 window->shared_memory=MagickFalse;
5501 length=(size_t) ximage->bytes_per_line*ximage->height;
5502 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5503 window->shared_memory=MagickFalse;
5504 if (window->shared_memory != MagickFalse)
5505 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5506 if (window->shared_memory != MagickFalse)
5507 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5508 if (segment_info[1].shmid < 0)
5509 window->shared_memory=MagickFalse;
5510 if (window->shared_memory != MagickFalse)
5511 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5514 if (ximage != (XImage *) NULL)
5515 XDestroyImage(ximage);
5516 ximage=(XImage *) NULL;
5517 if (segment_info[1].shmaddr)
5519 (void) shmdt(segment_info[1].shmaddr);
5520 segment_info[1].shmaddr=(char *) NULL;
5522 if (segment_info[1].shmid >= 0)
5524 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5525 segment_info[1].shmid=(-1);
5531 Allocate X image pixel data.
5533 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5534 if (window->shared_memory)
5542 (void) XSync(display,MagickFalse);
5543 xerror_alert=MagickFalse;
5544 segment_info=(XShmSegmentInfo *) window->segment_info;
5545 ximage->data=segment_info[1].shmaddr;
5546 segment_info[1].readOnly=MagickFalse;
5547 status=XShmAttach(display,&segment_info[1]);
5548 if (status != False)
5549 (void) XSync(display,MagickFalse);
5550 if ((status == False) || (xerror_alert != MagickFalse))
5552 window->shared_memory=MagickFalse;
5553 if (status != False)
5554 XShmDetach(display,&segment_info[1]);
5555 if (ximage != (XImage *) NULL)
5558 XDestroyImage(ximage);
5559 ximage=(XImage *) NULL;
5561 if (segment_info[1].shmid >= 0)
5563 if (segment_info[1].shmaddr != NULL)
5564 (void) shmdt(segment_info[1].shmaddr);
5565 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5566 segment_info[1].shmid=(-1);
5567 segment_info[1].shmaddr=(char *) NULL;
5572 if (window->shared_memory == MagickFalse)
5573 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5574 (char *) NULL,width,height,XBitmapPad(display),0);
5575 if (ximage == (XImage *) NULL)
5578 Unable to create X image.
5580 (void) XCheckDefineCursor(display,window->id,window->cursor);
5581 return(MagickFalse);
5583 length=(size_t) ximage->bytes_per_line*ximage->height;
5584 if (IsEventLogging())
5586 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5587 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5588 ximage->width,ximage->height);
5589 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5591 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5592 ximage->byte_order);
5593 (void) LogMagickEvent(X11Event,GetMagickModule(),
5594 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5595 ximage->bitmap_bit_order,ximage->bitmap_pad);
5596 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5598 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5599 ximage->bytes_per_line);
5600 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5601 ximage->bits_per_pixel);
5602 (void) LogMagickEvent(X11Event,GetMagickModule(),
5603 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5604 ximage->green_mask,ximage->blue_mask);
5606 if (window->shared_memory == MagickFalse)
5608 if (ximage->format != XYBitmap)
5609 ximage->data=(char *) AcquireQuantumMemory((size_t)
5610 ximage->bytes_per_line,(size_t) ximage->height);
5612 ximage->data=(char *) AcquireQuantumMemory((size_t)
5613 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5615 if (ximage->data == (char *) NULL)
5618 Unable to allocate pixel data.
5620 XDestroyImage(ximage);
5621 ximage=(XImage *) NULL;
5622 (void) XCheckDefineCursor(display,window->id,window->cursor);
5623 return(MagickFalse);
5625 if (window->ximage != (XImage *) NULL)
5628 Destroy previous X image.
5630 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5631 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5632 if (window->segment_info != (XShmSegmentInfo *) NULL)
5637 segment_info=(XShmSegmentInfo *) window->segment_info;
5638 if (segment_info[0].shmid >= 0)
5640 (void) XSync(display,MagickFalse);
5641 (void) XShmDetach(display,&segment_info[0]);
5642 (void) XSync(display,MagickFalse);
5643 if (segment_info[0].shmaddr != (char *) NULL)
5644 (void) shmdt(segment_info[0].shmaddr);
5645 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5646 segment_info[0].shmid=(-1);
5647 segment_info[0].shmaddr=(char *) NULL;
5648 window->ximage->data=(char *) NULL;
5652 if (window->ximage->data != (char *) NULL)
5653 free(window->ximage->data);
5654 window->ximage->data=(char *) NULL;
5655 XDestroyImage(window->ximage);
5656 window->ximage=(XImage *) NULL;
5658 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5659 if (window->segment_info != (XShmSegmentInfo *) NULL)
5664 segment_info=(XShmSegmentInfo *) window->segment_info;
5665 segment_info[0]=segment_info[1];
5668 window->ximage=ximage;
5669 matte_image=(XImage *) NULL;
5670 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5671 if ((window->image->matte != MagickFalse) &&
5672 ((long) width <= XDisplayWidth(display,window->screen)) &&
5673 ((long) height <= XDisplayHeight(display,window->screen)))
5678 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5679 (char *) NULL,width,height,XBitmapPad(display),0);
5680 if (IsEventLogging())
5682 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5683 (void) LogMagickEvent(X11Event,GetMagickModule(),
5684 " width, height: %dx%d",matte_image->width,matte_image->height);
5686 if (matte_image != (XImage *) NULL)
5689 Allocate matte image pixel data.
5691 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5692 matte_image->bytes_per_line*matte_image->depth,
5693 (size_t) matte_image->height);
5694 if (matte_image->data == (char *) NULL)
5696 XDestroyImage(matte_image);
5697 matte_image=(XImage *) NULL;
5701 if (window->matte_image != (XImage *) NULL)
5706 if (window->matte_image->data != (char *) NULL)
5707 free(window->matte_image->data);
5708 window->matte_image->data=(char *) NULL;
5709 XDestroyImage(window->matte_image);
5710 window->matte_image=(XImage *) NULL;
5712 window->matte_image=matte_image;
5713 if (window->matte_pixmap != (Pixmap) NULL)
5715 (void) XFreePixmap(display,window->matte_pixmap);
5716 window->matte_pixmap=(Pixmap) NULL;
5717 #if defined(MAGICKCORE_HAVE_SHAPE)
5718 if (window->shape != MagickFalse)
5719 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5722 window->stasis=MagickFalse;
5724 Convert pixels to X image data.
5726 if (window->image != (Image *) NULL)
5728 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5729 (ximage->bitmap_bit_order == LSBFirst)))
5730 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5733 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5736 if (window->matte_image != (XImage *) NULL)
5739 Create matte pixmap.
5741 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5742 if (window->matte_pixmap != (Pixmap) NULL)
5751 Copy matte image to matte pixmap.
5753 context_values.background=1;
5754 context_values.foreground=0;
5755 graphics_context=XCreateGC(display,window->matte_pixmap,
5756 (unsigned long) (GCBackground | GCForeground),&context_values);
5757 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5758 window->matte_image,0,0,0,0,width,height);
5759 (void) XFreeGC(display,graphics_context);
5760 #if defined(MAGICKCORE_HAVE_SHAPE)
5761 if (window->shape != MagickFalse)
5762 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5763 window->matte_pixmap,ShapeSet);
5767 (void) XMakePixmap(display,resource_info,window);
5771 (void) XCheckDefineCursor(display,window->id,window->cursor);
5776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5780 + X M a k e I m a g e L S B F i r s t %
5784 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5786 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5787 % pixels are copied in least-significant bit and byte first order. The
5788 % server's scanline pad is respected. Rather than using one or two general
5789 % cases, many special cases are found here to help speed up the image
5792 % The format of the XMakeImageLSBFirst method is:
5794 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5796 % A description of each parameter follows:
5798 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5800 % o window: Specifies a pointer to a XWindowInfo structure.
5802 % o image: the image.
5804 % o ximage: Specifies a pointer to a XImage structure; returned from
5807 % o matte_image: Specifies a pointer to a XImage structure; returned from
5811 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5812 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5820 register const IndexPacket
5823 register const PixelPacket
5829 register unsigned char
5846 assert(resource_info != (XResourceInfo *) NULL);
5847 assert(window != (XWindowInfo *) NULL);
5848 assert(image != (Image *) NULL);
5849 if (image->debug != MagickFalse)
5850 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5852 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
5855 size[MaxTextExtent];
5863 image_info=AcquireImageInfo();
5864 (void) CopyMagickString(image_info->filename,
5865 resource_info->image_info->texture != (char *) NULL ?
5866 resource_info->image_info->texture : "pattern:checkerboard",
5868 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
5870 image_info->size=ConstantString(size);
5871 pattern=ReadImage(image_info,&image->exception);
5872 image_info=DestroyImageInfo(image_info);
5873 if (pattern != (Image *) NULL)
5875 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5876 if (canvas != (Image *) NULL)
5877 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5878 pattern=DestroyImage(pattern);
5881 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5882 ximage->bits_per_pixel) >> 3));
5883 map_info=window->map_info;
5884 pixels=window->pixel_info->pixels;
5885 q=(unsigned char *) ximage->data;
5887 if (ximage->format == XYBitmap)
5889 register unsigned short
5897 Convert canvas to big-endian bitmap.
5899 background=(unsigned char)
5900 (XPixelIntensity(&window->pixel_info->foreground_color) <
5901 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5902 foreground=(unsigned char)
5903 (XPixelIntensity(&window->pixel_info->background_color) <
5904 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5905 polarity=(unsigned short) ((PixelIntensityToQuantum(
5906 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5907 if (canvas->colors == 2)
5908 polarity=PixelIntensity(&canvas->colormap[0]) <
5909 PixelIntensity(&canvas->colormap[1]);
5910 for (y=0; y < (int) canvas->rows; y++)
5912 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5913 if (p == (const PixelPacket *) NULL)
5915 indexes=GetVirtualIndexQueue(canvas);
5918 for (x=0; x < (int) canvas->columns; x++)
5921 if (indexes[x] == (IndexPacket) polarity)
5939 if (window->pixel_info->colors != 0)
5940 switch (ximage->bits_per_pixel)
5944 register unsigned int
5948 Convert to 2 bit color-mapped X canvas.
5950 for (y=0; y < (int) canvas->rows; y++)
5952 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5953 if (p == (const PixelPacket *) NULL)
5955 indexes=GetVirtualIndexQueue(canvas);
5957 for (x=0; x < (int) canvas->columns; x++)
5959 pixel=pixels[(long) indexes[x]] & 0x0f;
5964 *q=(unsigned char) pixel;
5970 *q|=(unsigned char) (pixel << 2);
5976 *q|=(unsigned char) (pixel << 4);
5982 *q|=(unsigned char) (pixel << 6);
5995 register unsigned int
5999 Convert to 4 bit color-mapped X canvas.
6001 for (y=0; y < (int) canvas->rows; y++)
6003 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6004 if (p == (const PixelPacket *) NULL)
6006 indexes=GetVirtualIndexQueue(canvas);
6008 for (x=0; x < (int) canvas->columns; x++)
6010 pixel=pixels[(long) indexes[x]] & 0xf;
6015 *q=(unsigned char) pixel;
6021 *q|=(unsigned char) (pixel << 4);
6036 Convert to 8 bit color-mapped X canvas.
6038 if (resource_info->color_recovery &&
6039 resource_info->quantize_info->dither)
6041 XDitherImage(canvas,ximage);
6044 for (y=0; y < (int) canvas->rows; y++)
6046 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6047 if (p == (const PixelPacket *) NULL)
6049 indexes=GetVirtualIndexQueue(canvas);
6050 for (x=0; x < (int) canvas->columns; x++)
6052 pixel=pixels[(long) indexes[x]];
6053 *q++=(unsigned char) pixel;
6064 register unsigned int
6068 channel[sizeof(unsigned long)];
6071 Convert to multi-byte color-mapped X canvas.
6073 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6074 for (y=0; y < (int) canvas->rows; y++)
6076 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6077 if (p == (const PixelPacket *) NULL)
6079 indexes=GetVirtualIndexQueue(canvas);
6080 for (x=0; x < (int) canvas->columns; x++)
6082 pixel=pixels[(long) indexes[x]];
6083 for (k=0; k < (int) bytes_per_pixel; k++)
6085 channel[k]=(unsigned char) pixel;
6088 for (k=0; k < (int) bytes_per_pixel; k++)
6097 switch (ximage->bits_per_pixel)
6101 register unsigned int
6105 Convert to contiguous 2 bit continuous-tone X canvas.
6107 for (y=0; y < (int) canvas->rows; y++)
6110 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6111 if (p == (const PixelPacket *) NULL)
6113 for (x=0; x < (int) canvas->columns; x++)
6115 pixel=XGammaPixel(map_info,p);
6121 *q=(unsigned char) pixel;
6127 *q|=(unsigned char) (pixel << 2);
6133 *q|=(unsigned char) (pixel << 4);
6139 *q|=(unsigned char) (pixel << 6);
6153 register unsigned int
6157 Convert to contiguous 4 bit continuous-tone X canvas.
6159 for (y=0; y < (int) canvas->rows; y++)
6161 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6162 if (p == (const PixelPacket *) NULL)
6165 for (x=0; x < (int) canvas->columns; x++)
6167 pixel=XGammaPixel(map_info,p);
6173 *q=(unsigned char) pixel;
6179 *q|=(unsigned char) (pixel << 4);
6195 Convert to contiguous 8 bit continuous-tone X canvas.
6197 if (resource_info->color_recovery &&
6198 resource_info->quantize_info->dither)
6200 XDitherImage(canvas,ximage);
6203 for (y=0; y < (int) canvas->rows; y++)
6205 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6206 if (p == (const PixelPacket *) NULL)
6208 for (x=0; x < (int) canvas->columns; x++)
6210 pixel=XGammaPixel(map_info,p);
6211 *q++=(unsigned char) pixel;
6220 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6221 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6222 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6223 (map_info->blue_mult == 1))
6226 Convert to 32 bit continuous-tone X canvas.
6228 for (y=0; y < (int) canvas->rows; y++)
6230 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6231 &canvas->exception);
6232 if (p == (const PixelPacket *) NULL)
6234 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6235 (blue_gamma != 1.0))
6238 Gamma correct canvas.
6240 for (x=(int) canvas->columns-1; x >= 0; x--)
6242 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6243 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6244 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6250 for (x=(int) canvas->columns-1; x >= 0; x--)
6252 *q++=ScaleQuantumToChar((Quantum) p->blue);
6253 *q++=ScaleQuantumToChar((Quantum) p->green);
6254 *q++=ScaleQuantumToChar((Quantum) p->red);
6261 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6262 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6263 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6264 (map_info->blue_mult == 65536L))
6267 Convert to 32 bit continuous-tone X canvas.
6269 for (y=0; y < (int) canvas->rows; y++)
6271 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6272 &canvas->exception);
6273 if (p == (const PixelPacket *) NULL)
6275 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6276 (blue_gamma != 1.0))
6279 Gamma correct canvas.
6281 for (x=(int) canvas->columns-1; x >= 0; x--)
6283 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6284 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6285 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6291 for (x=(int) canvas->columns-1; x >= 0; x--)
6293 *q++=ScaleQuantumToChar((Quantum) p->red);
6294 *q++=ScaleQuantumToChar((Quantum) p->green);
6295 *q++=ScaleQuantumToChar((Quantum) p->blue);
6306 register unsigned int
6310 channel[sizeof(unsigned long)];
6313 Convert to multi-byte continuous-tone X canvas.
6315 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6316 for (y=0; y < (int) canvas->rows; y++)
6318 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6319 &canvas->exception);
6320 if (p == (PixelPacket *) NULL)
6322 for (x=0; x < (long) canvas->columns; x++)
6324 pixel=XGammaPixel(map_info,p);
6325 for (k=0; k < (int) bytes_per_pixel; k++)
6327 channel[k]=(unsigned char) pixel;
6330 for (k=0; k < (int) bytes_per_pixel; k++)
6340 if (matte_image != (XImage *) NULL)
6343 Initialize matte canvas.
6345 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6346 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6347 q=(unsigned char *) matte_image->data;
6348 for (y=0; y < (int) canvas->rows; y++)
6350 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6351 if (p == (const PixelPacket *) NULL)
6355 for (x=(int) canvas->columns-1; x >= 0; x--)
6358 if (p->opacity > (long) (QuantumRange/2))
6374 if (canvas != image)
6375 canvas=DestroyImage(canvas);
6379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6383 + X M a k e I m a g e M S B F i r s t %
6387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6389 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6390 % image pixels are copied in most-significant bit and byte first order. The
6391 % server's scanline pad is also respected. Rather than using one or two
6392 % general cases, many special cases are found here to help speed up the image
6395 % The format of the XMakeImageMSBFirst method is:
6397 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6399 % A description of each parameter follows:
6401 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6403 % o window: Specifies a pointer to a XWindowInfo structure.
6405 % o image: the image.
6407 % o ximage: Specifies a pointer to a XImage structure; returned from
6410 % o matte_image: Specifies a pointer to a XImage structure; returned from
6415 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6416 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6427 register const IndexPacket
6430 register const PixelPacket
6433 register unsigned char
6450 assert(resource_info != (XResourceInfo *) NULL);
6451 assert(window != (XWindowInfo *) NULL);
6452 assert(image != (Image *) NULL);
6453 if (image->debug != MagickFalse)
6454 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6456 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
6459 size[MaxTextExtent];
6467 image_info=AcquireImageInfo();
6468 (void) CopyMagickString(image_info->filename,
6469 resource_info->image_info->texture != (char *) NULL ?
6470 resource_info->image_info->texture : "pattern:checkerboard",
6472 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
6474 image_info->size=ConstantString(size);
6475 pattern=ReadImage(image_info,&image->exception);
6476 image_info=DestroyImageInfo(image_info);
6477 if (pattern != (Image *) NULL)
6479 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6480 if (canvas != (Image *) NULL)
6481 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6482 pattern=DestroyImage(pattern);
6485 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6486 ((ximage->width*ximage->bits_per_pixel) >> 3));
6487 map_info=window->map_info;
6488 pixels=window->pixel_info->pixels;
6489 q=(unsigned char *) ximage->data;
6491 if (ximage->format == XYBitmap)
6493 register unsigned short
6501 Convert canvas to big-endian bitmap.
6503 background=(unsigned char)
6504 (XPixelIntensity(&window->pixel_info->foreground_color) <
6505 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6506 foreground=(unsigned char)
6507 (XPixelIntensity(&window->pixel_info->background_color) <
6508 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6509 polarity=(unsigned short) ((PixelIntensityToQuantum(
6510 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6511 if (canvas->colors == 2)
6512 polarity=PixelIntensity(&canvas->colormap[0]) <
6513 PixelIntensity(&canvas->colormap[1]);
6514 for (y=0; y < (int) canvas->rows; y++)
6516 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6517 if (p == (const PixelPacket *) NULL)
6519 indexes=GetVirtualIndexQueue(canvas);
6522 for (x=(int) canvas->columns-1; x >= 0; x--)
6525 if (indexes[x] == (IndexPacket) polarity)
6543 if (window->pixel_info->colors != 0)
6544 switch (ximage->bits_per_pixel)
6548 register unsigned int
6552 Convert to 2 bit color-mapped X canvas.
6554 for (y=0; y < (int) canvas->rows; y++)
6556 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6557 if (p == (const PixelPacket *) NULL)
6559 indexes=GetVirtualIndexQueue(canvas);
6561 for (x=0; x < (int) canvas->columns; x++)
6563 pixel=pixels[(long) indexes[x]] & 0xf;
6568 *q=(unsigned char) (pixel << 6);
6574 *q|=(unsigned char) (pixel << 4);
6580 *q|=(unsigned char) (pixel << 2);
6586 *q|=(unsigned char) pixel;
6599 register unsigned int
6603 Convert to 4 bit color-mapped X canvas.
6605 for (y=0; y < (int) canvas->rows; y++)
6607 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6608 if (p == (const PixelPacket *) NULL)
6610 indexes=GetVirtualIndexQueue(canvas);
6612 for (x=0; x < (int) canvas->columns; x++)
6614 pixel=pixels[(long) indexes[x]] & 0xf;
6619 *q=(unsigned char) (pixel << 4);
6625 *q|=(unsigned char) pixel;
6640 Convert to 8 bit color-mapped X canvas.
6642 if (resource_info->color_recovery &&
6643 resource_info->quantize_info->dither)
6645 XDitherImage(canvas,ximage);
6648 for (y=0; y < (int) canvas->rows; y++)
6650 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6651 if (p == (const PixelPacket *) NULL)
6653 indexes=GetVirtualIndexQueue(canvas);
6654 for (x=0; x < (int) canvas->columns; x++)
6656 pixel=pixels[(long) indexes[x]];
6657 *q++=(unsigned char) pixel;
6668 register unsigned int
6672 channel[sizeof(unsigned long)];
6675 Convert to 8 bit color-mapped X canvas.
6677 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6678 for (y=0; y < (int) canvas->rows; y++)
6680 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6681 if (p == (const PixelPacket *) NULL)
6683 indexes=GetVirtualIndexQueue(canvas);
6684 for (x=0; x < (int) canvas->columns; x++)
6686 pixel=pixels[(long) indexes[x]];
6687 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6689 channel[k]=(unsigned char) pixel;
6692 for (k=0; k < (int) bytes_per_pixel; k++)
6701 switch (ximage->bits_per_pixel)
6705 register unsigned int
6709 Convert to 4 bit continuous-tone X canvas.
6711 for (y=0; y < (int) canvas->rows; y++)
6713 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6714 if (p == (const PixelPacket *) NULL)
6717 for (x=(int) canvas->columns-1; x >= 0; x--)
6719 pixel=XGammaPixel(map_info,p);
6725 *q=(unsigned char) (pixel << 6);
6731 *q|=(unsigned char) (pixel << 4);
6737 *q|=(unsigned char) (pixel << 2);
6743 *q|=(unsigned char) pixel;
6757 register unsigned int
6761 Convert to 4 bit continuous-tone X canvas.
6763 for (y=0; y < (int) canvas->rows; y++)
6765 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6766 if (p == (const PixelPacket *) NULL)
6769 for (x=(int) canvas->columns-1; x >= 0; x--)
6771 pixel=XGammaPixel(map_info,p);
6777 *q=(unsigned char) (pixel << 4);
6783 *q|=(unsigned char) pixel;
6799 Convert to 8 bit continuous-tone X canvas.
6801 if (resource_info->color_recovery &&
6802 resource_info->quantize_info->dither)
6804 XDitherImage(canvas,ximage);
6807 for (y=0; y < (int) canvas->rows; y++)
6809 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6810 if (p == (const PixelPacket *) NULL)
6812 for (x=(int) canvas->columns-1; x >= 0; x--)
6814 pixel=XGammaPixel(map_info,p);
6815 *q++=(unsigned char) pixel;
6824 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6825 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6826 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6827 (map_info->blue_mult == 1))
6830 Convert to 32 bit continuous-tone X canvas.
6832 for (y=0; y < (int) canvas->rows; y++)
6834 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6835 &canvas->exception);
6836 if (p == (const PixelPacket *) NULL)
6838 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6839 (blue_gamma != 1.0))
6842 Gamma correct canvas.
6844 for (x=(int) canvas->columns-1; x >= 0; x--)
6847 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6848 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6849 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6854 for (x=(int) canvas->columns-1; x >= 0; x--)
6857 *q++=ScaleQuantumToChar((Quantum) p->red);
6858 *q++=ScaleQuantumToChar((Quantum) p->green);
6859 *q++=ScaleQuantumToChar((Quantum) p->blue);
6865 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6866 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6867 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6868 (map_info->blue_mult == 65536L))
6871 Convert to 32 bit continuous-tone X canvas.
6873 for (y=0; y < (int) canvas->rows; y++)
6875 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6876 &canvas->exception);
6877 if (p == (const PixelPacket *) NULL)
6879 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6880 (blue_gamma != 1.0))
6883 Gamma correct canvas.
6885 for (x=(int) canvas->columns-1; x >= 0; x--)
6888 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6889 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6890 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6895 for (x=(int) canvas->columns-1; x >= 0; x--)
6898 *q++=ScaleQuantumToChar((Quantum) p->blue);
6899 *q++=ScaleQuantumToChar((Quantum) p->green);
6900 *q++=ScaleQuantumToChar((Quantum) p->red);
6910 register unsigned int
6914 channel[sizeof(unsigned long)];
6917 Convert to multi-byte continuous-tone X canvas.
6919 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6920 for (y=0; y < (int) canvas->rows; y++)
6922 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6923 &canvas->exception);
6924 if (p == (const PixelPacket *) NULL)
6926 for (x=(int) canvas->columns-1; x >= 0; x--)
6928 pixel=XGammaPixel(map_info,p);
6929 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6931 channel[k]=(unsigned char) pixel;
6934 for (k=0; k < (int) bytes_per_pixel; k++)
6944 if (matte_image != (XImage *) NULL)
6947 Initialize matte canvas.
6949 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6950 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6951 q=(unsigned char *) matte_image->data;
6952 for (y=0; y < (int) canvas->rows; y++)
6954 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6955 if (p == (const PixelPacket *) NULL)
6959 for (x=(int) canvas->columns-1; x >= 0; x--)
6962 if (p->opacity > (long) (QuantumRange/2))
6978 if (canvas != image)
6979 canvas=DestroyImage(canvas);
6983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6987 % X M a k e M a g n i f y I m a g e %
6991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6993 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
6995 % The format of the XMakeMagnifyImage method is:
6997 % void XMakeMagnifyImage(display,windows)
6999 % A description of each parameter follows:
7001 % o display: Specifies a connection to an X server; returned from
7004 % o windows: Specifies a pointer to a XWindows structure.
7007 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7010 tuple[MaxTextExtent];
7027 register unsigned char
7032 previous_magnify = 0;
7050 Check boundary conditions.
7052 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7053 assert(display != (Display *) NULL);
7054 assert(windows != (XWindows *) NULL);
7056 for (n=1; n < (long) windows->magnify.data; n++)
7058 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7060 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7062 while (magnify > windows->magnify.width)
7064 while (magnify > windows->magnify.height)
7066 if (magnify != previous_magnify)
7075 New magnify factor: update magnify window name.
7078 while ((1 << i) <= (int) magnify)
7080 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7082 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7083 if (status != False)
7085 XSetWMName(display,windows->magnify.id,&window_name);
7086 XSetWMIconName(display,windows->magnify.id,&window_name);
7087 (void) XFree((void *) window_name.value);
7090 previous_magnify=magnify;
7091 ximage=windows->image.ximage;
7092 width=(unsigned int) windows->magnify.ximage->width;
7093 height=(unsigned int) windows->magnify.ximage->height;
7094 if ((windows->magnify.x < 0) ||
7095 (windows->magnify.x >= windows->image.ximage->width))
7096 windows->magnify.x=windows->image.ximage->width >> 1;
7097 x=windows->magnify.x-((width/magnify) >> 1);
7101 if (x > (int) (ximage->width-(width/magnify)))
7102 x=ximage->width-width/magnify;
7103 if ((windows->magnify.y < 0) ||
7104 (windows->magnify.y >= windows->image.ximage->height))
7105 windows->magnify.y=windows->image.ximage->height >> 1;
7106 y=windows->magnify.y-((height/magnify) >> 1);
7110 if (y > (int) (ximage->height-(height/magnify)))
7111 y=ximage->height-height/magnify;
7112 q=(unsigned char *) windows->magnify.ximage->data;
7113 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7114 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7115 if (ximage->bits_per_pixel < 8)
7117 register unsigned char
7124 register unsigned int
7130 pixel_info=windows->magnify.pixel_info;
7131 switch (ximage->bitmap_bit_order)
7136 Magnify little-endian bitmap.
7140 if (ximage->format == XYBitmap)
7142 background=(unsigned char)
7143 (XPixelIntensity(&pixel_info->foreground_color) <
7144 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7145 foreground=(unsigned char)
7146 (XPixelIntensity(&pixel_info->background_color) <
7147 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7148 if (windows->magnify.depth > 1)
7149 Swap(background,foreground);
7151 for (i=0; i < (long) height; i+=magnify)
7154 Propogate pixel magnify rows.
7156 for (j=0; j < magnify; j++)
7158 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7159 ((x*ximage->bits_per_pixel) >> 3);
7160 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7163 for (k=0; k < width; k+=magnify)
7166 Propogate pixel magnify columns.
7168 for (l=0; l < magnify; l++)
7171 Propogate each bit plane.
7173 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7176 if (*p & (0x01 << (p_bit+plane)))
7189 p_bit+=ximage->bits_per_pixel;
7196 *q=byte >> (8-q_bit);
7208 Magnify big-endian bitmap.
7212 if (ximage->format == XYBitmap)
7214 background=(unsigned char)
7215 (XPixelIntensity(&pixel_info->foreground_color) <
7216 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7217 foreground=(unsigned char)
7218 (XPixelIntensity(&pixel_info->background_color) <
7219 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7220 if (windows->magnify.depth > 1)
7221 Swap(background,foreground);
7223 for (i=0; i < (long) height; i+=magnify)
7226 Propogate pixel magnify rows.
7228 for (j=0; j < magnify; j++)
7230 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7231 ((x*ximage->bits_per_pixel) >> 3);
7232 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7235 for (k=0; k < width; k+=magnify)
7238 Propogate pixel magnify columns.
7240 for (l=0; l < magnify; l++)
7243 Propogate each bit plane.
7245 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7248 if (*p & (0x80 >> (p_bit+plane)))
7261 p_bit+=ximage->bits_per_pixel;
7268 *q=byte << (8-q_bit);
7279 switch (ximage->bits_per_pixel)
7285 Magnify 8 bit X image.
7287 for (i=0; i < (long) height; i+=magnify)
7290 Propogate pixel magnify rows.
7292 for (j=0; j < magnify; j++)
7294 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7295 ((x*ximage->bits_per_pixel) >> 3);
7296 for (k=0; k < width; k+=magnify)
7299 Propogate pixel magnify columns.
7301 for (l=0; l < magnify; l++)
7313 register unsigned int
7318 Magnify multi-byte X image.
7320 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7321 for (i=0; i < (long) height; i+=magnify)
7324 Propogate pixel magnify rows.
7326 for (j=0; j < magnify; j++)
7328 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7329 ((x*ximage->bits_per_pixel) >> 3);
7330 for (k=0; k < width; k+=magnify)
7333 Propogate pixel magnify columns.
7335 for (l=0; l < magnify; l++)
7336 for (m=0; m < bytes_per_pixel; m++)
7348 Copy X image to magnify pixmap.
7350 x=windows->magnify.x-((width/magnify) >> 1);
7352 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7354 if (x > (int) (ximage->width-(width/magnify)))
7355 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7358 y=windows->magnify.y-((height/magnify) >> 1);
7360 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7362 if (y > (int) (ximage->height-(height/magnify)))
7363 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7366 if ((x != 0) || (y != 0))
7367 (void) XFillRectangle(display,windows->magnify.pixmap,
7368 windows->magnify.annotate_context,0,0,width,height);
7369 (void) XPutImage(display,windows->magnify.pixmap,
7370 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7372 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7373 (magnify <= (height >> 1))))
7379 Highlight center pixel.
7381 highlight_info.x=(long) windows->magnify.width >> 1;
7382 highlight_info.y=(long) windows->magnify.height >> 1;
7383 highlight_info.width=magnify;
7384 highlight_info.height=magnify;
7385 (void) XDrawRectangle(display,windows->magnify.pixmap,
7386 windows->magnify.highlight_context,(int) highlight_info.x,
7387 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7388 (unsigned int) highlight_info.height-1);
7390 (void) XDrawRectangle(display,windows->magnify.pixmap,
7391 windows->magnify.annotate_context,(int) highlight_info.x+1,
7392 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7393 (unsigned int) highlight_info.height-3);
7396 Show center pixel color.
7398 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7399 windows->magnify.y,&pixel,&windows->image.image->exception);
7400 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7401 windows->magnify.x,windows->magnify.y);
7402 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7403 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7404 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7405 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7406 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7407 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7408 if (pixel.colorspace == CMYKColorspace)
7410 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7411 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7413 if (pixel.matte != MagickFalse)
7415 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7416 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7418 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7419 height=(unsigned int) windows->magnify.font_info->ascent+
7420 windows->magnify.font_info->descent;
7421 x=windows->magnify.font_info->max_bounds.width >> 1;
7422 y=windows->magnify.font_info->ascent+(height >> 2);
7423 (void) XDrawImageString(display,windows->magnify.pixmap,
7424 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7425 GetColorTuple(&pixel,MagickTrue,tuple);
7427 (void) XDrawImageString(display,windows->magnify.pixmap,
7428 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7429 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7430 &windows->image.image->exception);
7432 (void) XDrawImageString(display,windows->magnify.pixmap,
7433 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7435 Refresh magnify window.
7437 magnify_window=windows->magnify;
7440 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7444 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7448 % X M a k e P i x m a p %
7452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7454 % XMakePixmap() creates an X11 pixmap.
7456 % The format of the XMakePixmap method is:
7458 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7459 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7460 % XPixelInfo *pixel)
7462 % A description of each parameter follows:
7464 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7466 % o display: Specifies a connection to an X server; returned from
7469 % o window: Specifies a pointer to a XWindowInfo structure.
7473 static MagickBooleanType XMakePixmap(Display *display,
7474 const XResourceInfo *resource_info,XWindowInfo *window)
7480 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7481 assert(display != (Display *) NULL);
7482 assert(resource_info != (XResourceInfo *) NULL);
7483 assert(window != (XWindowInfo *) NULL);
7484 if (window->pixmap != (Pixmap) NULL)
7487 Destroy previous X pixmap.
7489 (void) XFreePixmap(display,window->pixmap);
7490 window->pixmap=(Pixmap) NULL;
7492 if (window->use_pixmap == MagickFalse)
7493 return(MagickFalse);
7494 if (window->ximage == (XImage *) NULL)
7495 return(MagickFalse);
7497 Display busy cursor.
7499 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7500 (void) XFlush(display);
7504 width=(unsigned int) window->ximage->width;
7505 height=(unsigned int) window->ximage->height;
7506 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7507 if (window->pixmap == (Pixmap) NULL)
7510 Unable to allocate pixmap.
7512 (void) XCheckDefineCursor(display,window->id,window->cursor);
7513 return(MagickFalse);
7516 Copy X image to pixmap.
7518 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7519 if (window->shared_memory)
7520 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7521 window->ximage,0,0,0,0,width,height,MagickTrue);
7523 if (window->shared_memory == MagickFalse)
7524 (void) XPutImage(display,window->pixmap,window->annotate_context,
7525 window->ximage,0,0,0,0,width,height);
7526 if (IsEventLogging())
7528 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7529 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7535 (void) XCheckDefineCursor(display,window->id,window->cursor);
7540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7544 % X M a k e S t a n d a r d C o l o r m a p %
7548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7550 % XMakeStandardColormap() creates an X11 Standard Colormap.
7552 % The format of the XMakeStandardColormap method is:
7554 % XMakeStandardColormap(display,visual_info,resource_info,image,
7557 % A description of each parameter follows:
7559 % o display: Specifies a connection to an X server; returned from
7562 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7563 % returned from XGetVisualInfo.
7565 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7567 % o image: the image.
7569 % o map_info: If a Standard Colormap type is specified, this structure is
7570 % initialized with info from the Standard Colormap.
7572 % o pixel: Specifies a pointer to a XPixelInfo structure.
7577 #if defined(__cplusplus) || defined(c_plusplus)
7581 static inline MagickRealType DiversityPixelIntensity(
7582 const DiversityPacket *pixel)
7587 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7591 static int IntensityCompare(const void *x,const void *y)
7600 color_1=(DiversityPacket *) x;
7601 color_2=(DiversityPacket *) y;
7602 diversity=(int) (DiversityPixelIntensity(color_2)-
7603 DiversityPixelIntensity(color_1));
7607 static int PopularityCompare(const void *x,const void *y)
7613 color_1=(DiversityPacket *) x;
7614 color_2=(DiversityPacket *) y;
7615 return((int) color_2->count-(int) color_1->count);
7618 #if defined(__cplusplus) || defined(c_plusplus)
7622 static inline Quantum ScaleXToQuantum(const unsigned long x,
7623 const unsigned long scale)
7625 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7628 MagickExport void XMakeStandardColormap(Display *display,
7629 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7630 XStandardColormap *map_info,XPixelInfo *pixel)
7638 register IndexPacket
7659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7660 assert(display != (Display *) NULL);
7661 assert(visual_info != (XVisualInfo *) NULL);
7662 assert(map_info != (XStandardColormap *) NULL);
7663 assert(resource_info != (XResourceInfo *) NULL);
7664 assert(pixel != (XPixelInfo *) NULL);
7665 exception=(&image->exception);
7666 if (resource_info->map_type != (char *) NULL)
7669 Standard Colormap is already defined (i.e. xstdcmap).
7671 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7673 number_colors=(unsigned int) (map_info->base_pixel+
7674 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7675 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7676 if ((image->matte == MagickFalse) &&
7677 (resource_info->color_recovery == MagickFalse) &&
7678 resource_info->quantize_info->dither &&
7679 (number_colors < MaxColormapSize))
7684 register PixelPacket
7688 Improve image appearance with error diffusion.
7690 affinity_image=AcquireImage((ImageInfo *) NULL);
7691 if (affinity_image == (Image *) NULL)
7692 ThrowXWindowFatalException(ResourceLimitFatalError,
7693 "UnableToDitherImage",image->filename);
7694 affinity_image->columns=number_colors;
7695 affinity_image->rows=1;
7697 Initialize colormap image.
7699 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7701 if (q != (PixelPacket *) NULL)
7703 for (i=0; i < (long) number_colors; i++)
7706 if (map_info->red_max != 0)
7707 q->red=ScaleXToQuantum((unsigned long) (i/
7708 map_info->red_mult),map_info->red_max);
7709 q->green=(Quantum) 0;
7710 if (map_info->green_max != 0)
7711 q->green=ScaleXToQuantum((unsigned long) ((i/
7712 map_info->green_mult) % (map_info->green_max+1)),
7713 map_info->green_max);
7714 q->blue=(Quantum) 0;
7715 if (map_info->blue_max != 0)
7716 q->blue=ScaleXToQuantum((unsigned long) (i %
7717 map_info->green_mult),map_info->blue_max);
7718 q->opacity=(Quantum) TransparentOpacity;
7721 (void) SyncAuthenticPixels(affinity_image,exception);
7722 (void) RemapImage(resource_info->quantize_info,image,
7725 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7727 (void) SetImageStorageClass(image,DirectClass);
7728 affinity_image=DestroyImage(affinity_image);
7730 if (IsEventLogging())
7732 (void) LogMagickEvent(X11Event,GetMagickModule(),
7733 "Standard Colormap:");
7734 (void) LogMagickEvent(X11Event,GetMagickModule(),
7735 " colormap id: 0x%lx",map_info->colormap);
7736 (void) LogMagickEvent(X11Event,GetMagickModule(),
7737 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7738 map_info->green_max,map_info->blue_max);
7739 (void) LogMagickEvent(X11Event,GetMagickModule(),
7740 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7741 map_info->green_mult,map_info->blue_mult);
7745 if ((visual_info->klass != DirectColor) &&
7746 (visual_info->klass != TrueColor))
7747 if ((image->storage_class == DirectClass) ||
7748 ((int) image->colors > visual_info->colormap_size))
7754 Image has more colors than the visual supports.
7756 quantize_info=(*resource_info->quantize_info);
7757 quantize_info.number_colors=(unsigned long) visual_info->colormap_size;
7758 (void) QuantizeImage(&quantize_info,image);
7761 Free previous and create new colormap.
7763 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7764 colormap=XDefaultColormap(display,visual_info->screen);
7765 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7766 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7767 visual_info->visual,visual_info->klass == DirectColor ?
7768 AllocAll : AllocNone);
7769 if (colormap == (Colormap) NULL)
7770 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7773 Initialize the map and pixel info structures.
7775 XGetMapInfo(visual_info,colormap,map_info);
7776 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7778 Allocating colors in server colormap is based on visual class.
7780 switch (visual_info->klass)
7786 Define Standard Colormap for StaticGray or StaticColor visual.
7788 number_colors=image->colors;
7789 colors=(XColor *) AcquireQuantumMemory((size_t)
7790 visual_info->colormap_size,sizeof(*colors));
7791 if (colors == (XColor *) NULL)
7792 ThrowXWindowFatalException(ResourceLimitFatalError,
7793 "UnableToCreateColormap",image->filename);
7795 color.flags=(char) (DoRed | DoGreen | DoBlue);
7796 for (i=0; i < (long) image->colors; i++)
7798 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7799 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7800 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7801 if (visual_info->klass != StaticColor)
7803 gray_value=(unsigned short) XPixelIntensity(&color);
7804 color.red=gray_value;
7805 color.green=gray_value;
7806 color.blue=gray_value;
7808 status=XAllocColor(display,colormap,&color);
7809 if (status == False)
7811 colormap=XCopyColormapAndFree(display,colormap);
7812 (void) XAllocColor(display,colormap,&color);
7814 pixel->pixels[i]=color.pixel;
7826 Define Standard Colormap for GrayScale or PseudoColor visual.
7828 number_colors=image->colors;
7829 colors=(XColor *) AcquireQuantumMemory((size_t)
7830 visual_info->colormap_size,sizeof(*colors));
7831 if (colors == (XColor *) NULL)
7832 ThrowXWindowFatalException(ResourceLimitFatalError,
7833 "UnableToCreateColormap",image->filename);
7835 Preallocate our GUI colors.
7837 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7838 (void) XAllocColor(display,colormap,&pixel->background_color);
7839 (void) XAllocColor(display,colormap,&pixel->border_color);
7840 (void) XAllocColor(display,colormap,&pixel->matte_color);
7841 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7842 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7843 (void) XAllocColor(display,colormap,&pixel->depth_color);
7844 (void) XAllocColor(display,colormap,&pixel->trough_color);
7845 for (i=0; i < MaxNumberPens; i++)
7846 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7848 Determine if image colors will "fit" into X server colormap.
7850 colormap_type=resource_info->colormap;
7851 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7852 NULL,0,pixel->pixels,(unsigned int) image->colors);
7853 if (status != False)
7854 colormap_type=PrivateColormap;
7855 if (colormap_type == SharedColormap)
7873 Define Standard colormap for shared GrayScale or PseudoColor visual.
7875 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7876 sizeof(*diversity));
7877 if (diversity == (DiversityPacket *) NULL)
7878 ThrowXWindowFatalException(ResourceLimitFatalError,
7879 "UnableToCreateColormap",image->filename);
7880 for (i=0; i < (long) image->colors; i++)
7882 diversity[i].red=image->colormap[i].red;
7883 diversity[i].green=image->colormap[i].green;
7884 diversity[i].blue=image->colormap[i].blue;
7885 diversity[i].index=(unsigned short) i;
7886 diversity[i].count=0;
7888 for (y=0; y < (int) image->rows; y++)
7893 register PixelPacket
7896 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7897 if (q == (PixelPacket *) NULL)
7899 indexes=GetAuthenticIndexQueue(image);
7900 for (x=(long) image->columns-1; x >= 0; x--)
7901 diversity[(long) indexes[x]].count++;
7904 Sort colors by decreasing intensity.
7906 qsort((void *) diversity,image->colors,sizeof(*diversity),
7908 for (i=0; i < (long) image->colors; )
7910 diversity[i].count<<=4; /* increase this colors popularity */
7911 i+=MagickMax((long) (image->colors >> 4),2);
7913 diversity[image->colors-1].count<<=4;
7914 qsort((void *) diversity,image->colors,sizeof(*diversity),
7920 color.flags=(char) (DoRed | DoGreen | DoBlue);
7921 for (i=0; i < (long) image->colors; i++)
7923 index=diversity[i].index;
7925 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7927 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7929 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7930 if (visual_info->klass != PseudoColor)
7932 gray_value=(unsigned short) XPixelIntensity(&color);
7933 color.red=gray_value;
7934 color.green=gray_value;
7935 color.blue=gray_value;
7937 status=XAllocColor(display,colormap,&color);
7938 if (status == False)
7940 pixel->pixels[index]=color.pixel;
7944 Read X server colormap.
7946 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7947 visual_info->colormap_size,sizeof(*server_colors));
7948 if (server_colors == (XColor *) NULL)
7949 ThrowXWindowFatalException(ResourceLimitFatalError,
7950 "UnableToCreateColormap",image->filename);
7951 for (x=visual_info->colormap_size-1; x >= 0; x--)
7952 server_colors[x].pixel=(unsigned long) x;
7953 (void) XQueryColors(display,colormap,server_colors,
7954 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7956 Select remaining colors from X server colormap.
7958 for (; i < (long) image->colors; i++)
7960 index=diversity[i].index;
7962 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7964 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7966 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7967 if (visual_info->klass != PseudoColor)
7969 gray_value=(unsigned short) XPixelIntensity(&color);
7970 color.red=gray_value;
7971 color.green=gray_value;
7972 color.blue=gray_value;
7974 XBestPixel(display,colormap,server_colors,(unsigned int)
7975 visual_info->colormap_size,&color);
7976 pixel->pixels[index]=color.pixel;
7979 if ((int) image->colors < visual_info->colormap_size)
7982 Fill up colors array-- more choices for pen colors.
7984 retain_colors=MagickMin((unsigned int)
7985 (visual_info->colormap_size-image->colors),256);
7986 for (i=0; i < (long) retain_colors; i++)
7987 *p++=server_colors[i];
7988 number_colors+=retain_colors;
7990 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
7991 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
7995 Define Standard colormap for private GrayScale or PseudoColor visual.
7997 if (status == False)
8000 Not enough colormap entries in the colormap-- Create a new colormap.
8002 colormap=XCreateColormap(display,
8003 XRootWindow(display,visual_info->screen),visual_info->visual,
8005 if (colormap == (Colormap) NULL)
8006 ThrowXWindowFatalException(ResourceLimitFatalError,
8007 "UnableToCreateColormap",image->filename);
8008 map_info->colormap=colormap;
8009 if ((int) image->colors < visual_info->colormap_size)
8012 Retain colors from the default colormap to help lessens the
8013 effects of colormap flashing.
8015 retain_colors=MagickMin((unsigned int)
8016 (visual_info->colormap_size-image->colors),256);
8017 p=colors+image->colors;
8018 for (i=0; i < (long) retain_colors; i++)
8020 p->pixel=(unsigned long) i;
8023 (void) XQueryColors(display,
8024 XDefaultColormap(display,visual_info->screen),
8025 colors+image->colors,(int) retain_colors);
8027 Transfer colors from default to private colormap.
8029 (void) XAllocColorCells(display,colormap,MagickFalse,
8030 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8032 p=colors+image->colors;
8033 for (i=0; i < (long) retain_colors; i++)
8035 p->pixel=pixel->pixels[i];
8038 (void) XStoreColors(display,colormap,colors+image->colors,
8039 (int) retain_colors);
8040 number_colors+=retain_colors;
8042 (void) XAllocColorCells(display,colormap,MagickFalse,
8043 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8047 Store the image colormap.
8050 color.flags=(char) (DoRed | DoGreen | DoBlue);
8051 for (i=0; i < (long) image->colors; i++)
8053 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8054 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8055 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8056 if (visual_info->klass != PseudoColor)
8058 gray_value=(unsigned short) XPixelIntensity(&color);
8059 color.red=gray_value;
8060 color.green=gray_value;
8061 color.blue=gray_value;
8063 color.pixel=pixel->pixels[i];
8066 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8077 Define Standard Colormap for TrueColor or DirectColor visual.
8079 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8080 (map_info->green_max*map_info->green_mult)+
8081 (map_info->blue_max*map_info->blue_mult)+1);
8082 linear_colormap=(number_colors > 4096) ||
8083 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8084 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8085 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8086 MagickTrue : MagickFalse;
8087 if (linear_colormap != MagickFalse)
8088 number_colors=(unsigned long) visual_info->colormap_size;
8090 Allocate color array.
8092 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8093 if (colors == (XColor *) NULL)
8094 ThrowXWindowFatalException(ResourceLimitFatalError,
8095 "UnableToCreateColormap",image->filename);
8097 Initialize linear color ramp.
8100 color.flags=(char) (DoRed | DoGreen | DoBlue);
8101 if (linear_colormap != MagickFalse)
8102 for (i=0; i < (long) number_colors; i++)
8104 color.blue=(unsigned short) 0;
8105 if (map_info->blue_max != 0)
8106 color.blue=(unsigned short) ((unsigned long)
8107 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8108 color.green=color.blue;
8109 color.red=color.blue;
8110 color.pixel=XStandardPixel(map_info,&color);
8114 for (i=0; i < (long) number_colors; i++)
8116 color.red=(unsigned short) 0;
8117 if (map_info->red_max != 0)
8118 color.red=(unsigned short) ((unsigned long)
8119 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8120 color.green=(unsigned int) 0;
8121 if (map_info->green_max != 0)
8122 color.green=(unsigned short) ((unsigned long)
8123 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8124 map_info->green_max));
8125 color.blue=(unsigned short) 0;
8126 if (map_info->blue_max != 0)
8127 color.blue=(unsigned short) ((unsigned long)
8128 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8129 color.pixel=XStandardPixel(map_info,&color);
8132 if ((visual_info->klass == DirectColor) &&
8133 (colormap != XDefaultColormap(display,visual_info->screen)))
8134 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8136 for (i=0; i < (long) number_colors; i++)
8137 (void) XAllocColor(display,colormap,&colors[i]);
8141 if ((visual_info->klass != DirectColor) &&
8142 (visual_info->klass != TrueColor))
8145 Set foreground, background, border, etc. pixels.
8147 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8148 &pixel->foreground_color);
8149 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8150 &pixel->background_color);
8151 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8154 Foreground and background colors must differ.
8156 pixel->background_color.red=(~pixel->foreground_color.red);
8157 pixel->background_color.green=
8158 (~pixel->foreground_color.green);
8159 pixel->background_color.blue=
8160 (~pixel->foreground_color.blue);
8161 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8162 &pixel->background_color);
8164 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8165 &pixel->border_color);
8166 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8167 &pixel->matte_color);
8168 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8169 &pixel->highlight_color);
8170 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8171 &pixel->shadow_color);
8172 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8173 &pixel->depth_color);
8174 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8175 &pixel->trough_color);
8176 for (i=0; i < MaxNumberPens; i++)
8178 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8179 &pixel->pen_colors[i]);
8180 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8182 pixel->colors=image->colors+MaxNumberPens;
8184 colors=(XColor *) RelinquishMagickMemory(colors);
8185 if (IsEventLogging())
8187 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8188 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8189 map_info->colormap);
8190 (void) LogMagickEvent(X11Event,GetMagickModule(),
8191 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8192 map_info->green_max,map_info->blue_max);
8193 (void) LogMagickEvent(X11Event,GetMagickModule(),
8194 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8195 map_info->green_mult,map_info->blue_mult);
8200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8204 % X M a k e W i n d o w %
8208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8210 % XMakeWindow() creates an X11 window.
8212 % The format of the XMakeWindow method is:
8214 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8215 % XClassHint *class_hint,XWMHints *manager_hints,
8216 % XWindowInfo *window_info)
8218 % A description of each parameter follows:
8220 % o display: Specifies a connection to an X server; returned from
8223 % o parent: Specifies the parent window_info.
8225 % o argv: Specifies the application's argument list.
8227 % o argc: Specifies the number of arguments.
8229 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8231 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8233 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8236 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8237 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8238 XWindowInfo *window_info)
8240 #define MinWindowSize 64
8248 static XTextProperty
8259 Set window info hints.
8261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8262 assert(display != (Display *) NULL);
8263 assert(window_info != (XWindowInfo *) NULL);
8264 size_hints=XAllocSizeHints();
8265 if (size_hints == (XSizeHints *) NULL)
8266 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8267 size_hints->flags=(long) window_info->flags;
8268 size_hints->x=window_info->x;
8269 size_hints->y=window_info->y;
8270 size_hints->width=(int) window_info->width;
8271 size_hints->height=(int) window_info->height;
8272 if (window_info->immutable != MagickFalse)
8275 Window size cannot be changed.
8277 size_hints->min_width=size_hints->width;
8278 size_hints->min_height=size_hints->height;
8279 size_hints->max_width=size_hints->width;
8280 size_hints->max_height=size_hints->height;
8281 size_hints->flags|=PMinSize;
8282 size_hints->flags|=PMaxSize;
8287 Window size can be changed.
8289 size_hints->min_width=(int) window_info->min_width;
8290 size_hints->min_height=(int) window_info->min_height;
8291 size_hints->flags|=PResizeInc;
8292 size_hints->width_inc=(int) window_info->width_inc;
8293 size_hints->height_inc=(int) window_info->height_inc;
8294 #if !defined(PRE_R4_ICCCM)
8295 size_hints->flags|=PBaseSize;
8296 size_hints->base_width=size_hints->width_inc;
8297 size_hints->base_height=size_hints->height_inc;
8300 gravity=NorthWestGravity;
8301 if (window_info->geometry != (char *) NULL)
8304 default_geometry[MaxTextExtent],
8305 geometry[MaxTextExtent];
8314 User specified geometry.
8316 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8317 size_hints->width,size_hints->height);
8318 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8320 while (strlen(p) != 0)
8322 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8325 (void) CopyMagickString(p,p+1,MaxTextExtent);
8327 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8328 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8329 &size_hints->width,&size_hints->height,&gravity);
8330 if ((flags & WidthValue) && (flags & HeightValue))
8331 size_hints->flags|=USSize;
8332 if ((flags & XValue) && (flags & YValue))
8334 size_hints->flags|=USPosition;
8335 window_info->x=size_hints->x;
8336 window_info->y=size_hints->y;
8339 #if !defined(PRE_R4_ICCCM)
8340 size_hints->win_gravity=gravity;
8341 size_hints->flags|=PWinGravity;
8343 if (window_info->id == (Window) NULL)
8344 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8345 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8346 window_info->border_width,(int) window_info->depth,InputOutput,
8347 window_info->visual,window_info->mask,&window_info->attributes);
8360 Window already exists; change relevant attributes.
8362 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8363 &window_info->attributes);
8364 mask=ConfigureNotify;
8365 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8366 window_changes.x=window_info->x;
8367 window_changes.y=window_info->y;
8368 window_changes.width=(int) window_info->width;
8369 window_changes.height=(int) window_info->height;
8370 mask=(MagickStatusType) (CWWidth | CWHeight);
8371 if (window_info->flags & USPosition)
8373 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8374 mask,&window_changes);
8376 if (window_info->id == (Window) NULL)
8377 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8379 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8380 if (status == False)
8381 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8383 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8384 if (status == False)
8385 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8386 window_info->icon_name);
8387 if (window_info->icon_geometry != (char *) NULL)
8395 User specified icon geometry.
8397 size_hints->flags|=USPosition;
8398 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8399 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8400 &manager_hints->icon_y,&width,&height,&gravity);
8401 if ((flags & XValue) && (flags & YValue))
8402 manager_hints->flags|=IconPositionHint;
8404 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8405 size_hints,manager_hints,class_hint);
8406 if (window_name.value != (void *) NULL)
8408 (void) XFree((void *) window_name.value);
8409 window_name.value=(unsigned char *) NULL;
8410 window_name.nitems=0;
8412 if (icon_name.value != (void *) NULL)
8414 (void) XFree((void *) icon_name.value);
8415 icon_name.value=(unsigned char *) NULL;
8418 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8419 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8420 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8421 (void) XFree((void *) size_hints);
8422 if (window_info->shape != MagickFalse)
8424 #if defined(MAGICKCORE_HAVE_SHAPE)
8430 Can we apply a non-rectangular shaping mask?
8434 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8435 window_info->shape=MagickFalse;
8437 window_info->shape=MagickFalse;
8440 if (window_info->shared_memory)
8442 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8444 Can we use shared memory with this window?
8446 if (XShmQueryExtension(display) == 0)
8447 window_info->shared_memory=MagickFalse;
8449 window_info->shared_memory=MagickFalse;
8452 window_info->image=NewImageList();
8453 window_info->destroy=MagickFalse;
8457 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8461 % X M a g i c k P r o g r e s s M o n i t o r %
8465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8467 % XMagickProgressMonitor() displays the progress a task is making in
8468 % completing a task.
8470 % The format of the XMagickProgressMonitor method is:
8472 % void XMagickProgressMonitor(const char *task,
8473 % const MagickOffsetType quantum,const MagickSizeType span,
8474 % void *client_data)
8476 % A description of each parameter follows:
8478 % o task: Identifies the task in progress.
8480 % o quantum: Specifies the quantum position within the span which represents
8481 % how much progress has been made in completing a task.
8483 % o span: Specifies the span relative to completing a task.
8485 % o client_data: Pointer to any client data.
8489 static const char *GetLocaleMonitorMessage(const char *text)
8492 message[MaxTextExtent],
8501 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8503 if (p != (char *) NULL)
8505 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8506 locale_message=GetLocaleMessage(message);
8507 if (locale_message == message)
8509 return(locale_message);
8512 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8513 const MagickOffsetType quantum,const MagickSizeType span,
8514 void *magick_unused(client_data))
8519 windows=XSetWindows((XWindows *) ~0);
8520 if (windows == (XWindows *) NULL)
8522 if (windows->info.mapped != MagickFalse)
8523 XProgressMonitorWidget(windows->display,windows,
8524 GetLocaleMonitorMessage(tag),quantum,span);
8529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8533 % X Q u e r y C o l o r D a t a b a s e %
8537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8539 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8542 % The format of the XQueryColorDatabase method is:
8544 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8546 % A description of each parameter follows:
8548 % o target: Specifies the color to lookup in the X color database.
8550 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8551 % color is returned as this value.
8554 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8561 *display = (Display *) NULL;
8570 Initialize color return value.
8572 assert(color != (XColor *) NULL);
8576 color->flags=(char) (DoRed | DoGreen | DoBlue);
8577 if ((target == (char *) NULL) || (*target == '\0'))
8578 target="#ffffffffffff";
8580 Let the X server define the color for us.
8582 if (display == (Display *) NULL)
8583 display=XOpenDisplay((char *) NULL);
8584 if (display == (Display *) NULL)
8586 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8587 return(MagickFalse);
8589 colormap=XDefaultColormap(display,XDefaultScreen(display));
8590 status=XParseColor(display,colormap,(char *) target,&xcolor);
8591 if (status == False)
8592 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8595 color->red=xcolor.red;
8596 color->green=xcolor.green;
8597 color->blue=xcolor.blue;
8598 color->flags=xcolor.flags;
8600 return(status != False ? MagickTrue : MagickFalse);
8604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8608 % X Q u e r y P o s i t i o n %
8612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8614 % XQueryPosition() gets the pointer coordinates relative to a window.
8616 % The format of the XQueryPosition method is:
8618 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8620 % A description of each parameter follows:
8622 % o display: Specifies a connection to an X server; returned from
8625 % o window: Specifies a pointer to a Window.
8627 % o x: Return the x coordinate of the pointer relative to the origin of the
8630 % o y: Return the y coordinate of the pointer relative to the origin of the
8634 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8647 assert(display != (Display *) NULL);
8648 assert(window != (Window) NULL);
8649 assert(x != (int *) NULL);
8650 assert(y != (int *) NULL);
8651 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8660 % X R e f r e s h W i n d o w %
8664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8666 % XRefreshWindow() refreshes an image in a X window.
8668 % The format of the XRefreshWindow method is:
8670 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8671 % const XEvent *event)
8673 % A description of each parameter follows:
8675 % o display: Specifies a connection to an X server; returned from
8678 % o window: Specifies a pointer to a XWindowInfo structure.
8680 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8681 % the entire image is refreshed.
8684 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8685 const XEvent *event)
8695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8696 assert(display != (Display *) NULL);
8697 assert(window != (XWindowInfo *) NULL);
8698 if (window->ximage == (XImage *) NULL)
8700 if (event != (XEvent *) NULL)
8703 Determine geometry from expose event.
8707 width=(unsigned int) event->xexpose.width;
8708 height=(unsigned int) event->xexpose.height;
8716 Refresh entire window; discard outstanding expose events.
8720 width=window->width;
8721 height=window->height;
8722 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8725 Check boundary conditions.
8727 if ((window->ximage->width-(x+window->x)) < (int) width)
8728 width=(unsigned int) (window->ximage->width-(x+window->x));
8729 if ((window->ximage->height-(y+window->y)) < (int) height)
8730 height=(unsigned int) (window->ximage->height-(y+window->y));
8734 if (window->matte_pixmap != (Pixmap) NULL)
8736 #if defined(MAGICKCORE_HAVE_SHAPE)
8737 if (window->shape != MagickFalse)
8738 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8739 window->matte_pixmap,ShapeSet);
8741 (void) XSetClipMask(display,window->annotate_context,
8742 window->matte_pixmap);
8744 if (window->pixmap != (Pixmap) NULL)
8746 if (window->depth > 1)
8747 (void) XCopyArea(display,window->pixmap,window->id,
8748 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8750 (void) XCopyPlane(display,window->pixmap,window->id,
8751 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8756 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8757 if (window->shared_memory)
8758 (void) XShmPutImage(display,window->id,window->annotate_context,
8759 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8761 if (window->shared_memory == MagickFalse)
8762 (void) XPutImage(display,window->id,window->annotate_context,
8763 window->ximage,x+window->x,y+window->y,x,y,width,height);
8765 if (window->matte_pixmap != (Pixmap) NULL)
8766 (void) XSetClipMask(display,window->annotate_context,None);
8767 (void) XFlush(display);
8771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8775 % X R e m o t e C o m m a n d %
8779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8781 % XRemoteCommand() forces a remote display(1) to display the specified
8784 % The format of the XRemoteCommand method is:
8786 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8787 % const char *filename)
8789 % A description of each parameter follows:
8791 % o display: Specifies a connection to an X server; returned from
8794 % o window: Specifies the name or id of an X window.
8796 % o filename: the name of the image filename to display.
8799 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8800 const char *window,const char *filename)
8809 assert(filename != (char *) NULL);
8810 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8811 if (display == (Display *) NULL)
8812 display=XOpenDisplay((char *) NULL);
8813 if (display == (Display *) NULL)
8815 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8816 return(MagickFalse);
8818 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8819 remote_window=(Window) NULL;
8820 root_window=XRootWindow(display,XDefaultScreen(display));
8821 if (window != (char *) NULL)
8824 Search window hierarchy and identify any clients by name or ID.
8826 if (isdigit((unsigned char) *window) != 0)
8827 remote_window=XWindowByID(display,root_window,(Window)
8828 strtol((char *) window,(char **) NULL,0));
8829 if (remote_window == (Window) NULL)
8830 remote_window=XWindowByName(display,root_window,window);
8832 if (remote_window == (Window) NULL)
8833 remote_window=XWindowByProperty(display,root_window,remote_atom);
8834 if (remote_window == (Window) NULL)
8836 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8838 return(MagickFalse);
8841 Send remote command.
8843 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8844 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8845 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8846 (void) XSync(display,MagickFalse);
8851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8855 % X R e t a i n W i n d o w C o l o r s %
8859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8861 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8862 % the colors associated with an image displayed on the window.
8864 % The format of the XRetainWindowColors method is:
8866 % void XRetainWindowColors(Display *display,const Window window)
8868 % A description of each parameter follows:
8870 % o display: Specifies a connection to an X server; returned from
8873 % o window: Specifies a pointer to a XWindowInfo structure.
8876 MagickExport void XRetainWindowColors(Display *display,const Window window)
8885 Put property on the window.
8887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8888 assert(display != (Display *) NULL);
8889 assert(window != (Window) NULL);
8890 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8891 if (property == (Atom) NULL)
8893 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8897 pixmap=XCreatePixmap(display,window,1,1,1);
8898 if (pixmap == (Pixmap) NULL)
8900 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8903 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8904 (unsigned char *) &pixmap,1);
8905 (void) XSetCloseDownMode(display,RetainPermanent);
8909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8913 % X S e l e c t W i n d o w %
8917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8919 % XSelectWindow() allows a user to select a window using the mouse. If the
8920 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8921 % is returned in the crop_info structure.
8923 % The format of the XSelectWindow function is:
8925 % target_window=XSelectWindow(display,crop_info)
8927 % A description of each parameter follows:
8929 % o window: XSelectWindow returns the window id.
8931 % o display: Specifies a pointer to the Display structure; returned from
8934 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8935 % contains the extents of any cropping rectangle.
8939 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8941 #define MinimumCropArea (unsigned int) 9
8968 Initialize graphic context.
8970 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8971 assert(display != (Display *) NULL);
8972 assert(crop_info != (RectangleInfo *) NULL);
8973 root_window=XRootWindow(display,XDefaultScreen(display));
8974 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8975 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8976 context_values.function=GXinvert;
8977 context_values.plane_mask=
8978 context_values.background ^ context_values.foreground;
8979 context_values.subwindow_mode=IncludeInferiors;
8980 annotate_context=XCreateGC(display,root_window,(unsigned long) (GCBackground |
8981 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8982 if (annotate_context == (GC) NULL)
8983 return(MagickFalse);
8985 Grab the pointer using target cursor.
8987 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
8988 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
8989 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
8990 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
8991 GrabModeAsync,root_window,target_cursor,CurrentTime);
8992 if (status != GrabSuccess)
8994 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
8995 return((Window) NULL);
9001 crop_info->height=0;
9003 target_window=(Window) NULL;
9008 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9009 (void) XDrawRectangle(display,root_window,annotate_context,
9010 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9011 (unsigned int) crop_info->height-1);
9013 Allow another event.
9015 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9016 (void) XWindowEvent(display,root_window,ButtonPressMask |
9017 ButtonReleaseMask | ButtonMotionMask,&event);
9018 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9019 (void) XDrawRectangle(display,root_window,annotate_context,
9020 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9021 (unsigned int) crop_info->height-1);
9026 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9027 event.xbutton.x,event.xbutton.y);
9028 if (target_window == (Window) NULL)
9029 target_window=root_window;
9030 x_offset=event.xbutton.x_root;
9031 y_offset=event.xbutton.y_root;
9032 crop_info->x=x_offset;
9033 crop_info->y=y_offset;
9035 crop_info->height=0;
9047 Discard pending button motion events.
9049 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9050 crop_info->x=event.xmotion.x;
9051 crop_info->y=event.xmotion.y;
9053 Check boundary conditions.
9055 if ((int) crop_info->x < x_offset)
9056 crop_info->width=(unsigned int) (x_offset-crop_info->x);
9059 crop_info->width=(unsigned int) (crop_info->x-x_offset);
9060 crop_info->x=x_offset;
9062 if ((int) crop_info->y < y_offset)
9063 crop_info->height=(unsigned int) (y_offset-crop_info->y);
9066 crop_info->height=(unsigned int) (crop_info->y-y_offset);
9067 crop_info->y=y_offset;
9073 } while ((target_window == (Window) NULL) || (presses > 0));
9074 (void) XUngrabPointer(display,CurrentTime);
9075 (void) XFreeCursor(display,target_cursor);
9076 (void) XFreeGC(display,annotate_context);
9077 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9080 crop_info->height=0;
9082 if ((crop_info->width != 0) && (crop_info->height != 0))
9083 target_window=root_window;
9084 return(target_window);
9088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9092 % X S e t C u r s o r S t a t e %
9096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9098 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9099 % reset to their default.
9101 % The format of the XXSetCursorState method is:
9103 % XSetCursorState(display,windows,const MagickStatusType state)
9105 % A description of each parameter follows:
9107 % o display: Specifies a connection to an X server; returned from
9110 % o windows: Specifies a pointer to a XWindows structure.
9112 % o state: An unsigned integer greater than 0 sets the cursor state
9113 % to busy, otherwise the cursor are reset to their default.
9116 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9117 const MagickStatusType state)
9119 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9120 assert(display != (Display *) NULL);
9121 assert(windows != (XWindows *) NULL);
9124 (void) XCheckDefineCursor(display,windows->image.id,
9125 windows->image.busy_cursor);
9126 (void) XCheckDefineCursor(display,windows->pan.id,
9127 windows->pan.busy_cursor);
9128 (void) XCheckDefineCursor(display,windows->magnify.id,
9129 windows->magnify.busy_cursor);
9130 (void) XCheckDefineCursor(display,windows->command.id,
9131 windows->command.busy_cursor);
9135 (void) XCheckDefineCursor(display,windows->image.id,
9136 windows->image.cursor);
9137 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9138 (void) XCheckDefineCursor(display,windows->magnify.id,
9139 windows->magnify.cursor);
9140 (void) XCheckDefineCursor(display,windows->command.id,
9141 windows->command.cursor);
9142 (void) XCheckDefineCursor(display,windows->command.id,
9143 windows->widget.cursor);
9144 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9146 windows->info.mapped=MagickFalse;
9150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9154 % X S e t W i n d o w s %
9158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9160 % XSetWindows() sets the X windows structure if the windows info is specified.
9161 % Otherwise the current windows structure is returned.
9163 % The format of the XSetWindows method is:
9165 % XWindows *XSetWindows(XWindows *windows_info)
9167 % A description of each parameter follows:
9169 % o windows_info: Initialize the Windows structure with this information.
9172 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9175 *windows = (XWindows *) NULL;
9177 if (windows_info != (XWindows *) ~0)
9179 windows=(XWindows *) RelinquishMagickMemory(windows);
9180 windows=windows_info;
9185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9189 % X U s e r P r e f e r e n c e s %
9193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9195 % XUserPreferences() saves the preferences in a configuration file in the
9196 % users' home directory.
9198 % The format of the XUserPreferences method is:
9200 % void XUserPreferences(XResourceInfo *resource_info)
9202 % A description of each parameter follows:
9204 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9207 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9209 #if defined(X11_PREFERENCES_PATH)
9211 cache[MaxTextExtent],
9212 filename[MaxTextExtent],
9213 specifier[MaxTextExtent];
9220 preferences_database;
9223 Save user preferences to the client configuration file.
9225 assert(resource_info != (XResourceInfo *) NULL);
9226 client_name=GetClientName();
9227 preferences_database=XrmGetStringDatabase("");
9228 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9229 value=resource_info->backdrop ? "True" : "False";
9230 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9231 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",client_name);
9232 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9233 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9234 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9236 value=resource_info->confirm_exit ? "True" : "False";
9237 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9238 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9240 value=resource_info->confirm_edit ? "True" : "False";
9241 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9242 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9244 value=resource_info->display_warnings ? "True" : "False";
9245 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9246 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",client_name);
9247 value=resource_info->quantize_info->dither ? "True" : "False";
9248 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9249 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9251 value=resource_info->gamma_correct ? "True" : "False";
9252 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9253 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9254 (void) FormatMagickString(cache,MaxTextExtent,"%lu",
9255 resource_info->undo_cache);
9256 XrmPutStringResource(&preferences_database,specifier,cache);
9257 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9258 value=resource_info->use_pixmap ? "True" : "False";
9259 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9260 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9261 X11_PREFERENCES_PATH,client_name);
9262 ExpandFilename(filename);
9263 XrmPutFileDatabase(preferences_database,filename);
9268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9272 % X V i s u a l C l a s s N a m e %
9276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9278 % XVisualClassName() returns the visual class name as a character string.
9280 % The format of the XVisualClassName method is:
9282 % char *XVisualClassName(const int visual_class)
9284 % A description of each parameter follows:
9286 % o visual_type: XVisualClassName returns the visual class as a character
9289 % o class: Specifies the visual class.
9293 static const char *XVisualClassName(const int visual_class)
9295 switch (visual_class)
9297 case StaticGray: return("StaticGray");
9298 case GrayScale: return("GrayScale");
9299 case StaticColor: return("StaticColor");
9300 case PseudoColor: return("PseudoColor");
9301 case TrueColor: return("TrueColor");
9302 case DirectColor: return("DirectColor");
9304 return("unknown visual class");
9308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9318 % XWarning() displays a warning reason in a Notice widget.
9320 % The format of the XWarning method is:
9322 % void XWarning(const unsigned int warning,const char *reason,
9323 % const char *description)
9325 % A description of each parameter follows:
9327 % o warning: Specifies the numeric warning category.
9329 % o reason: Specifies the reason to display before terminating the
9332 % o description: Specifies any description to the reason.
9335 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9336 const char *reason,const char *description)
9339 text[MaxTextExtent];
9344 if (reason == (char *) NULL)
9346 (void) CopyMagickString(text,reason,MaxTextExtent);
9347 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9348 windows=XSetWindows((XWindows *) ~0);
9349 XNoticeWidget(windows->display,windows,text,(char *) description);
9353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9357 % X W i n d o w B y I D %
9361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9363 % XWindowByID() locates a child window with a given ID. If not window with
9364 % the given name is found, 0 is returned. Only the window specified and its
9365 % subwindows are searched.
9367 % The format of the XWindowByID function is:
9369 % child=XWindowByID(display,window,id)
9371 % A description of each parameter follows:
9373 % o child: XWindowByID returns the window with the specified
9374 % id. If no windows are found, XWindowByID returns 0.
9376 % o display: Specifies a pointer to the Display structure; returned from
9379 % o id: Specifies the id of the window to locate.
9382 MagickExport Window XWindowByID(Display *display,const Window root_window,
9383 const unsigned long id)
9402 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9403 assert(display != (Display *) NULL);
9404 assert(root_window != (Window) NULL);
9406 return(XSelectWindow(display,&rectangle_info));
9407 if (root_window == id)
9409 status=XQueryTree(display,root_window,&child,&child,&children,
9411 if (status == False)
9412 return((Window) NULL);
9413 window=(Window) NULL;
9414 for (i=0; i < (int) number_children; i++)
9417 Search each child and their children.
9419 window=XWindowByID(display,children[i],id);
9420 if (window != (Window) NULL)
9423 if (children != (Window *) NULL)
9424 (void) XFree((void *) children);
9429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9433 % X W i n d o w B y N a m e %
9437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9439 % XWindowByName() locates a window with a given name on a display. If no
9440 % window with the given name is found, 0 is returned. If more than one window
9441 % has the given name, the first one is returned. Only root and its children
9444 % The format of the XWindowByName function is:
9446 % window=XWindowByName(display,root_window,name)
9448 % A description of each parameter follows:
9450 % o window: XWindowByName returns the window id.
9452 % o display: Specifies a pointer to the Display structure; returned from
9455 % o root_window: Specifies the id of the root window.
9457 % o name: Specifies the name of the window to locate.
9460 MagickExport Window XWindowByName(Display *display,const Window root_window,
9480 assert(display != (Display *) NULL);
9481 assert(root_window != (Window) NULL);
9482 assert(name != (char *) NULL);
9483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9484 if (XGetWMName(display,root_window,&window_name) != 0)
9485 if (LocaleCompare((char *) window_name.value,name) == 0)
9486 return(root_window);
9487 status=XQueryTree(display,root_window,&child,&child,&children,
9489 if (status == False)
9490 return((Window) NULL);
9491 window=(Window) NULL;
9492 for (i=0; i < (int) number_children; i++)
9495 Search each child and their children.
9497 window=XWindowByName(display,children[i],name);
9498 if (window != (Window) NULL)
9501 if (children != (Window *) NULL)
9502 (void) XFree((void *) children);
9507 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9511 % X W i n d o w B y P r o p e r y %
9515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9517 % XWindowByProperty() locates a child window with a given property. If not
9518 % window with the given name is found, 0 is returned. If more than one window
9519 % has the given property, the first one is returned. Only the window
9520 % specified and its subwindows are searched.
9522 % The format of the XWindowByProperty function is:
9524 % child=XWindowByProperty(display,window,property)
9526 % A description of each parameter follows:
9528 % o child: XWindowByProperty returns the window id with the specified
9529 % property. If no windows are found, XWindowByProperty returns 0.
9531 % o display: Specifies a pointer to the Display structure; returned from
9534 % o property: Specifies the property of the window to locate.
9537 MagickExport Window XWindowByProperty(Display *display,const Window window,
9538 const Atom property)
9566 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9567 assert(display != (Display *) NULL);
9568 assert(window != (Window) NULL);
9569 assert(property != (Atom) NULL);
9570 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9571 if (status == False)
9572 return((Window) NULL);
9574 child=(Window) NULL;
9575 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9577 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9578 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9580 (void) XFree((void *) data);
9581 if ((status == Success) && (type != (Atom) NULL))
9584 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9585 child=XWindowByProperty(display,children[i],property);
9586 if (children != (Window *) NULL)
9587 (void) XFree((void *) children);
9593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9597 % X I m p o r t I m a g e %
9601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9603 % XImportImage() reads an image from an X window.
9605 % The format of the XImportImage method is:
9607 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9609 % A description of each parameter follows:
9611 % o image_info: the image info..
9613 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9616 MagickExport Image *XImportImage(const ImageInfo *image_info,
9617 XImportInfo *ximage_info)
9619 assert(image_info != (const ImageInfo *) NULL);
9620 assert(image_info->signature == MagickSignature);
9621 if (image_info->debug != MagickFalse)
9622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9623 image_info->filename);
9624 assert(ximage_info != (XImportInfo *) NULL);
9625 return((Image *) NULL);
9630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9634 + X C o m p o n e n t G e n e s i s %
9638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9640 % XComponentGenesis() instantiates the X component.
9642 % The format of the XComponentGenesis method is:
9644 % MagickBooleanType XComponentGenesis(void)
9647 MagickExport MagickBooleanType XComponentGenesis(void)
9653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9657 % X G e t I m p o r t I n f o %
9661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9663 % XGetImportInfo() initializes the XImportInfo structure.
9665 % The format of the XGetImportInfo method is:
9667 % void XGetImportInfo(XImportInfo *ximage_info)
9669 % A description of each parameter follows:
9671 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9674 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9676 assert(ximage_info != (XImportInfo *) NULL);
9677 ximage_info->frame=MagickFalse;
9678 ximage_info->borders=MagickFalse;
9679 ximage_info->screen=MagickFalse;
9680 ximage_info->descend=MagickTrue;
9681 ximage_info->silent=MagickFalse;