2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % X X W W IIIII N N DDDD OOO W W %
7 % X X W W I NN N D D O O W W %
8 % X W W I N N N D D O O W W %
9 % X X W W W I N NN D D O O W W W %
10 % X X W W IIIII N N DDDD OOO W W %
13 % MagickCore X11 Utility Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "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/colormap.h"
51 #include "magick/composite.h"
52 #include "magick/display.h"
53 #include "magick/exception.h"
54 #include "magick/exception-private.h"
55 #include "magick/geometry.h"
56 #include "magick/identify.h"
57 #include "magick/image.h"
58 #include "magick/image-private.h"
59 #include "magick/list.h"
60 #include "magick/locale_.h"
61 #include "magick/log.h"
62 #include "magick/magick.h"
63 #include "magick/memory_.h"
64 #include "magick/monitor.h"
65 #include "magick/option.h"
66 #include "magick/PreRvIcccm.h"
67 #include "magick/quantize.h"
68 #include "magick/quantum.h"
69 #include "magick/quantum-private.h"
70 #include "magick/resource_.h"
71 #include "magick/resize.h"
72 #include "magick/shear.h"
73 #include "magick/statistic.h"
74 #include "magick/string_.h"
75 #include "magick/string-private.h"
76 #include "magick/transform.h"
77 #include "magick/utility.h"
78 #include "magick/widget.h"
79 #include "magick/xwindow.h"
80 #include "magick/xwindow-private.h"
81 #include "magick/version.h"
85 #if defined(MAGICKCORE_X11_DELEGATE)
86 #include <X11/Xproto.h>
87 #include <X11/Xlocale.h>
88 #if defined(MAGICK_HAVE_POLL)
89 # include <sys/poll.h>
91 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
92 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
93 # include <machine/param.h>
97 #include <X11/extensions/XShm.h>
99 #if defined(MAGICKCORE_HAVE_SHAPE)
100 #include <X11/extensions/shape.h>
106 #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
107 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
109 #define XGammaPixel(map,color) (size_t) (map->base_pixel+ \
110 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
112 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
114 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
116 #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
117 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
119 #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
120 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
122 #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
123 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
124 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
125 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
127 #define AccentuateModulate ScaleCharToQuantum(80)
128 #define HighlightModulate ScaleCharToQuantum(125)
129 #define ShadowModulate ScaleCharToQuantum(135)
130 #define DepthModulate ScaleCharToQuantum(185)
131 #define TroughModulate ScaleCharToQuantum(110)
133 #define XLIB_ILLEGAL_ACCESS 1
135 #undef NorthWestGravity
137 #undef NorthEastGravity
141 #undef SouthWestGravity
143 #undef SouthEastGravity
150 #define XFD_SET fd_set
154 Enumeration declarations.
168 Typedef declarations.
170 typedef struct _DiversityPacket
185 Constant declaractions.
187 static MagickBooleanType
188 xerror_alert = MagickFalse;
194 *XVisualClassName(const int);
196 static MagickRealType
201 static MagickBooleanType
202 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
205 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
207 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
211 XSelectWindow(Display *,RectangleInfo *);
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 % D e s t r o y X R e s o u r c e s %
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % DestroyXResources() destroys any X resources.
226 % The format of the DestroyXResources method is:
228 % void DestroyXResources()
230 % A description of each parameter follows:
233 MagickExport void DestroyXResources(void)
242 *magick_windows[MaxXWindows];
248 windows=XSetWindows((XWindows *) ~0);
249 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
252 magick_windows[number_windows++]=(&windows->context);
253 magick_windows[number_windows++]=(&windows->group_leader);
254 magick_windows[number_windows++]=(&windows->backdrop);
255 magick_windows[number_windows++]=(&windows->icon);
256 magick_windows[number_windows++]=(&windows->image);
257 magick_windows[number_windows++]=(&windows->info);
258 magick_windows[number_windows++]=(&windows->magnify);
259 magick_windows[number_windows++]=(&windows->pan);
260 magick_windows[number_windows++]=(&windows->command);
261 magick_windows[number_windows++]=(&windows->widget);
262 magick_windows[number_windows++]=(&windows->popup);
263 magick_windows[number_windows++]=(&windows->context);
264 for (i=0; i < (int) number_windows; i++)
266 if (magick_windows[i]->mapped != MagickFalse)
268 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
269 magick_windows[i]->screen);
270 magick_windows[i]->mapped=MagickFalse;
272 if (magick_windows[i]->name != (char *) NULL)
273 magick_windows[i]->name=(char *)
274 RelinquishMagickMemory(magick_windows[i]->name);
275 if (magick_windows[i]->icon_name != (char *) NULL)
276 magick_windows[i]->icon_name=(char *)
277 RelinquishMagickMemory(magick_windows[i]->icon_name);
278 if (magick_windows[i]->cursor != (Cursor) NULL)
280 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
281 magick_windows[i]->cursor=(Cursor) NULL;
283 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
285 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
286 magick_windows[i]->busy_cursor=(Cursor) NULL;
288 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
290 (void) XFreePixmap(windows->display,
291 magick_windows[i]->highlight_stipple);
292 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
294 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
296 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
297 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
299 if (magick_windows[i]->ximage != (XImage *) NULL)
301 XDestroyImage(magick_windows[i]->ximage);
302 magick_windows[i]->ximage=(XImage *) NULL;
304 if (magick_windows[i]->pixmap != (Pixmap) NULL)
306 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
307 magick_windows[i]->pixmap=(Pixmap) NULL;
309 if (magick_windows[i]->id != (Window) NULL)
311 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
312 magick_windows[i]->id=(Window) NULL;
314 if (magick_windows[i]->destroy != MagickFalse)
316 if (magick_windows[i]->image != (Image *) NULL)
318 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
319 magick_windows[i]->image=NewImageList();
321 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
323 (void) XFreePixmap(windows->display,
324 magick_windows[i]->matte_pixmap);
325 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
328 if (magick_windows[i]->segment_info != (void *) NULL)
330 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
334 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
335 if (segment_info != (XShmSegmentInfo *) NULL)
336 if (segment_info[0].shmid >= 0)
338 if (segment_info[0].shmaddr != NULL)
339 (void) shmdt(segment_info[0].shmaddr);
340 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
341 segment_info[0].shmaddr=NULL;
342 segment_info[0].shmid=(-1);
345 magick_windows[i]->segment_info=(void *)
346 RelinquishMagickMemory(magick_windows[i]->segment_info);
349 windows->icon_resources=(XResourceInfo *)
350 RelinquishMagickMemory(windows->icon_resources);
351 if (windows->icon_pixel != (XPixelInfo *) NULL)
353 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
354 windows->icon_pixel->pixels=(unsigned long *)
355 RelinquishMagickMemory(windows->icon_pixel->pixels);
356 if (windows->icon_pixel->annotate_context != (GC) NULL)
357 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
358 windows->icon_pixel=(XPixelInfo *)
359 RelinquishMagickMemory(windows->icon_pixel);
361 if (windows->pixel_info != (XPixelInfo *) NULL)
363 if (windows->pixel_info->pixels != (unsigned long *) NULL)
364 windows->pixel_info->pixels=(unsigned long *)
365 RelinquishMagickMemory(windows->pixel_info->pixels);
366 if (windows->pixel_info->annotate_context != (GC) NULL)
367 XFreeGC(windows->display,windows->pixel_info->annotate_context);
368 if (windows->pixel_info->widget_context != (GC) NULL)
369 XFreeGC(windows->display,windows->pixel_info->widget_context);
370 if (windows->pixel_info->highlight_context != (GC) NULL)
371 XFreeGC(windows->display,windows->pixel_info->highlight_context);
372 windows->pixel_info=(XPixelInfo *)
373 RelinquishMagickMemory(windows->pixel_info);
375 if (windows->font_info != (XFontStruct *) NULL)
377 XFreeFont(windows->display,windows->font_info);
378 windows->font_info=(XFontStruct *) NULL;
380 if (windows->class_hints != (XClassHint *) NULL)
382 if (windows->class_hints->res_name != (char *) NULL)
383 XFree(windows->class_hints->res_name);
384 if (windows->class_hints->res_class != (char *) NULL)
385 XFree(windows->class_hints->res_class);
386 XFree(windows->class_hints);
387 windows->class_hints=(XClassHint *) NULL;
389 if (windows->manager_hints != (XWMHints *) NULL)
391 XFree(windows->manager_hints);
392 windows->manager_hints=(XWMHints *) NULL;
394 if (windows->map_info != (XStandardColormap *) NULL)
396 XFree(windows->map_info);
397 windows->map_info=(XStandardColormap *) NULL;
399 if (windows->icon_map != (XStandardColormap *) NULL)
401 XFree(windows->icon_map);
402 windows->icon_map=(XStandardColormap *) NULL;
404 if (windows->visual_info != (XVisualInfo *) NULL)
406 XFree(windows->visual_info);
407 windows->visual_info=(XVisualInfo *) NULL;
409 if (windows->icon_visual != (XVisualInfo *) NULL)
411 XFree(windows->icon_visual);
412 windows->icon_visual=(XVisualInfo *) NULL;
414 (void) XSetWindows((XWindows *) NULL);
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 % X A n n o t a t e I m a g e %
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 % XAnnotateImage() annotates the image with text.
430 % The format of the XAnnotateImage method is:
432 % MagickBooleanType XAnnotateImage(Display *display,
433 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
435 % A description of each parameter follows:
437 % o display: Specifies a connection to an X server; returned from
440 % o pixel: Specifies a pointer to a XPixelInfo structure.
442 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
444 % o image: the image.
447 MagickExport MagickBooleanType XAnnotateImage(Display *display,
448 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
487 Initialize annotated image.
489 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
490 assert(display != (Display *) NULL);
491 assert(pixel != (XPixelInfo *) NULL);
492 assert(annotate_info != (XAnnotateInfo *) NULL);
493 assert(image != (Image *) NULL);
495 Initialize annotated pixmap.
497 root_window=XRootWindow(display,XDefaultScreen(display));
498 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
499 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
500 annotate_info->height,depth);
501 if (annotate_pixmap == (Pixmap) NULL)
504 Initialize graphics info.
506 context_values.background=0;
507 context_values.foreground=(size_t) (~0);
508 context_values.font=annotate_info->font_info->fid;
509 annotate_context=XCreateGC(display,root_window,(unsigned long)
510 (GCBackground | GCFont | GCForeground),&context_values);
511 if (annotate_context == (GC) NULL)
516 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
517 (int) annotate_info->font_info->ascent,annotate_info->text,
518 (int) strlen(annotate_info->text));
519 (void) XFreeGC(display,annotate_context);
521 Initialize annotated X image.
523 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
524 annotate_info->height,AllPlanes,ZPixmap);
525 if (annotate_ximage == (XImage *) NULL)
527 (void) XFreePixmap(display,annotate_pixmap);
529 Initialize annotated image.
531 annotate_image=AcquireImage((ImageInfo *) NULL);
532 if (annotate_image == (Image *) NULL)
534 annotate_image->columns=annotate_info->width;
535 annotate_image->rows=annotate_info->height;
537 Transfer annotated X image to image.
539 width=(unsigned int) image->columns;
540 height=(unsigned int) image->rows;
543 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
544 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
545 &annotate_image->background_color,&image->exception);
546 if (annotate_info->stencil == ForegroundStencil)
547 annotate_image->matte=MagickTrue;
548 exception=(&image->exception);
549 annotate_view=AcquireCacheView(annotate_image);
550 for (y=0; y < (int) annotate_image->rows; y++)
558 q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
559 annotate_image->columns,1,exception);
560 if (q == (PixelPacket *) NULL)
562 for (x=0; x < (int) annotate_image->columns; x++)
564 SetOpacityPixelComponent(q,OpaqueOpacity);
565 if (XGetPixel(annotate_ximage,x,y) == 0)
568 Set this pixel to the background color.
570 SetRedPixelComponent(q,ScaleShortToQuantum(pixel->box_color.red));
571 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel->box_color.green));
572 SetBluePixelComponent(q,ScaleShortToQuantum(pixel->box_color.blue));
573 if ((annotate_info->stencil == ForegroundStencil) ||
574 (annotate_info->stencil == OpaqueStencil))
575 SetOpacityPixelComponent(q,TransparentOpacity);
580 Set this pixel to the pen color.
582 SetRedPixelComponent(q,ScaleShortToQuantum(pixel->pen_color.red));
583 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel->pen_color.green));
584 SetBluePixelComponent(q,ScaleShortToQuantum(pixel->pen_color.blue));
585 if (annotate_info->stencil == BackgroundStencil)
586 SetOpacityPixelComponent(q,TransparentOpacity);
590 if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
593 annotate_view=DestroyCacheView(annotate_view);
594 XDestroyImage(annotate_ximage);
596 Determine annotate geometry.
598 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
599 if ((width != (unsigned int) annotate_image->columns) ||
600 (height != (unsigned int) annotate_image->rows))
603 image_geometry[MaxTextExtent];
608 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
610 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
612 if (annotate_info->degrees != 0.0)
627 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
628 if (rotate_image == (Image *) NULL)
630 annotate_image=DestroyImage(annotate_image);
631 annotate_image=rotate_image;
633 Annotation is relative to the degree of rotation.
635 normalized_degrees=annotate_info->degrees;
636 while (normalized_degrees < -45.0)
637 normalized_degrees+=360.0;
638 for (rotations=0; normalized_degrees > 45.0; rotations++)
639 normalized_degrees-=90.0;
640 switch (rotations % 4)
650 x-=(int) annotate_image->columns/2;
651 y+=(int) annotate_image->columns/2;
659 x=x-(int) annotate_image->columns;
667 x=x-(int) annotate_image->columns/2;
668 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
674 Composite text onto the image.
676 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
678 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
679 OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y);
681 annotate_image=DestroyImage(annotate_image);
686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % X B e s t F o n t %
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696 % XBestFont() returns the "best" font. "Best" is defined as a font specified
697 % in the X resource database or a font such that the text width displayed
698 % with the font does not exceed the specified maximum width.
700 % The format of the XBestFont method is:
702 % XFontStruct *XBestFont(Display *display,
703 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
705 % A description of each parameter follows:
707 % o font: XBestFont returns a pointer to a XFontStruct structure.
709 % o display: Specifies a connection to an X server; returned from
712 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
714 % o text_font: True is font should be mono-spaced (typewriter style).
718 static char **FontToList(char *font)
733 if (font == (char *) NULL)
734 return((char **) NULL);
736 Convert string to an ASCII list.
739 for (p=font; *p != '\0'; p++)
740 if ((*p == ':') || (*p == ';') || (*p == ','))
742 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
743 if (fontlist == (char **) NULL)
745 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
747 return((char **) NULL);
750 for (i=0; i < (int) fonts; i++)
752 for (q=p; *q != '\0'; q++)
753 if ((*q == ':') || (*q == ';') || (*q == ','))
755 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
756 sizeof(*fontlist[i]));
757 if (fontlist[i] == (char *) NULL)
759 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
761 return((char **) NULL);
763 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
766 fontlist[i]=(char *) NULL;
770 MagickExport XFontStruct *XBestFont(Display *display,
771 const XResourceInfo *resource_info,const MagickBooleanType text_font)
776 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
777 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
778 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
779 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
780 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
781 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
788 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
789 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
790 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
804 font_info=(XFontStruct *) NULL;
805 font_name=resource_info->font;
806 if (text_font != MagickFalse)
807 font_name=resource_info->text_font;
808 if ((font_name != (char *) NULL) && (*font_name != '\0'))
817 Load preferred font specified in the X resource database.
819 fontlist=FontToList(font_name);
820 if (fontlist != (char **) NULL)
822 for (i=0; fontlist[i] != (char *) NULL; i++)
824 if (font_info == (XFontStruct *) NULL)
825 font_info=XLoadQueryFont(display,fontlist[i]);
826 fontlist[i]=DestroyString(fontlist[i]);
828 fontlist=(char **) RelinquishMagickMemory(fontlist);
830 if (font_info == (XFontStruct *) NULL)
831 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
834 Load fonts from list of fonts until one is found.
837 if (text_font != MagickFalse)
839 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
841 while (*p != (char *) NULL)
843 if (font_info != (XFontStruct *) NULL)
845 font_info=XLoadQueryFont(display,(char *) *p);
852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % X B e s t I c o n S i z e %
860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
863 % size that maintains the aspect ratio of the image. If the window manager
864 % has preferred icon sizes, one of the preferred sizes is used.
866 % The format of the XBestIconSize method is:
868 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
870 % A description of each parameter follows:
872 % o display: Specifies a connection to an X server; returned from
875 % o image: the image.
878 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
902 Determine if the window manager has specified preferred icon sizes.
904 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
905 assert(display != (Display *) NULL);
906 assert(window != (XWindowInfo *) NULL);
907 assert(image != (Image *) NULL);
908 window->width=MaxIconSize;
909 window->height=MaxIconSize;
910 icon_size=(XIconSize *) NULL;
912 root_window=XRootWindow(display,window->screen);
913 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
914 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
916 if (icon_size == (XIconSize *) NULL)
919 Window manager does not restrict icon size.
921 icon_size=XAllocIconSize();
922 if (icon_size == (XIconSize *) NULL)
924 ThrowXWindowFatalException(ResourceLimitError,
925 "MemoryAllocationFailed",image->filename);
928 icon_size->min_width=1;
929 icon_size->max_width=MaxIconSize;
930 icon_size->min_height=1;
931 icon_size->max_height=MaxIconSize;
932 icon_size->width_inc=1;
933 icon_size->height_inc=1;
936 Determine aspect ratio of image.
938 width=(unsigned int) image->columns;
939 height=(unsigned int) image->rows;
941 if (window->crop_geometry)
942 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
944 Look for an icon size that maintains the aspect ratio of image.
946 scale_factor=(MagickRealType) icon_size->max_width/width;
947 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
948 scale_factor=(MagickRealType) icon_size->max_height/height;
949 icon_width=(unsigned int) icon_size->min_width;
950 while ((int) icon_width < icon_size->max_width)
952 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
954 icon_width+=icon_size->width_inc;
956 icon_height=(unsigned int) icon_size->min_height;
957 while ((int) icon_height < icon_size->max_height)
959 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
961 icon_height+=icon_size->height_inc;
963 (void) XFree((void *) icon_size);
964 window->width=icon_width;
965 window->height=icon_height;
969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % X B e s t P i x e l %
977 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % XBestPixel() returns a pixel from an array of pixels that is closest to the
980 % requested color. If the color array is NULL, the colors are obtained from
983 % The format of the XBestPixel method is:
985 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
986 % unsigned int number_colors,XColor *color)
988 % A description of each parameter follows:
990 % o pixel: XBestPixel returns the pixel value closest to the requested
993 % o display: Specifies a connection to an X server; returned from
996 % o colormap: Specifies the ID of the X server colormap.
998 % o colors: Specifies an array of XColor structures.
1000 % o number_colors: Specifies the number of XColor structures in the
1001 % color definition array.
1003 % o color: Specifies the desired RGB value to find in the colors array.
1006 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1007 XColor *colors,unsigned int number_colors,XColor *color)
1018 register MagickRealType
1029 Find closest representation for the requested RGB color.
1031 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1032 assert(display != (Display *) NULL);
1033 assert(color != (XColor *) NULL);
1034 status=XAllocColor(display,colormap,color);
1035 if (status != False)
1037 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1038 if (query_server != MagickFalse)
1041 Read X server colormap.
1043 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1044 if (colors == (XColor *) NULL)
1046 ThrowXWindowFatalException(ResourceLimitError,
1047 "MemoryAllocationFailed","...");
1050 for (i=0; i < (int) number_colors; i++)
1051 colors[i].pixel=(size_t) i;
1052 if (number_colors > 256)
1054 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1056 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1059 for (i=0; i < (int) number_colors; i++)
1061 pixel.red=colors[i].red-(MagickRealType) color->red;
1062 distance=pixel.red*pixel.red;
1063 if (distance > min_distance)
1065 pixel.green=colors[i].green-(MagickRealType) color->green;
1066 distance+=pixel.green*pixel.green;
1067 if (distance > min_distance)
1069 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1070 distance+=pixel.blue*pixel.blue;
1071 if (distance > min_distance)
1073 min_distance=distance;
1074 color->pixel=colors[i].pixel;
1077 (void) XAllocColor(display,colormap,&colors[j]);
1078 if (query_server != MagickFalse)
1079 colors=(XColor *) RelinquishMagickMemory(colors);
1083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % X B e s t V i s u a l I n f o %
1091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1093 % XBestVisualInfo() returns visual information for a visual that is the "best"
1094 % the server supports. "Best" is defined as:
1096 % 1. Restrict the visual list to those supported by the default screen.
1098 % 2. If a visual type is specified, restrict the visual list to those of
1101 % 3. If a map type is specified, choose the visual that matches the id
1102 % specified by the Standard Colormap.
1104 % 4 From the list of visuals, choose one that can display the most
1105 % simultaneous colors. If more than one visual can display the same
1106 % number of simultaneous colors, one is chosen based on a rank.
1108 % The format of the XBestVisualInfo method is:
1110 % XVisualInfo *XBestVisualInfo(Display *display,
1111 % XStandardColormap *map_info,XResourceInfo *resource_info)
1113 % A description of each parameter follows:
1115 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1118 % o display: Specifies a connection to an X server; returned from
1121 % o map_info: If map_type is specified, this structure is initialized
1122 % with info from the Standard Colormap.
1124 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1128 static inline int MagickMax(const int x,const int y)
1135 static inline size_t MagickMin(const unsigned int x,
1136 const unsigned int y)
1143 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1144 XStandardColormap *map_info,XResourceInfo *resource_info)
1146 #define MaxStandardColormaps 7
1147 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1148 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1149 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1150 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1176 Restrict visual search by screen number.
1178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1179 assert(display != (Display *) NULL);
1180 assert(map_info != (XStandardColormap *) NULL);
1181 assert(resource_info != (XResourceInfo *) NULL);
1182 map_type=resource_info->map_type;
1183 visual_type=resource_info->visual_type;
1184 visual_mask=VisualScreenMask;
1185 visual_template.screen=XDefaultScreen(display);
1186 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1188 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1189 if (resource_info->colors <= (one << (size_t) visual_template.depth))
1190 visual_mask|=VisualDepthMask;
1191 if (visual_type != (char *) NULL)
1194 Restrict visual search by class or visual id.
1196 if (LocaleCompare("staticgray",visual_type) == 0)
1198 visual_mask|=VisualClassMask;
1199 visual_template.klass=StaticGray;
1202 if (LocaleCompare("grayscale",visual_type) == 0)
1204 visual_mask|=VisualClassMask;
1205 visual_template.klass=GrayScale;
1208 if (LocaleCompare("staticcolor",visual_type) == 0)
1210 visual_mask|=VisualClassMask;
1211 visual_template.klass=StaticColor;
1214 if (LocaleCompare("pseudocolor",visual_type) == 0)
1216 visual_mask|=VisualClassMask;
1217 visual_template.klass=PseudoColor;
1220 if (LocaleCompare("truecolor",visual_type) == 0)
1222 visual_mask|=VisualClassMask;
1223 visual_template.klass=TrueColor;
1226 if (LocaleCompare("directcolor",visual_type) == 0)
1228 visual_mask|=VisualClassMask;
1229 visual_template.klass=DirectColor;
1232 if (LocaleCompare("default",visual_type) == 0)
1234 visual_mask|=VisualIDMask;
1235 visual_template.visualid=XVisualIDFromVisual(
1236 XDefaultVisual(display,XDefaultScreen(display)));
1239 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1241 visual_mask|=VisualIDMask;
1242 visual_template.visualid=
1243 strtol(visual_type,(char **) NULL,0);
1246 ThrowXWindowFatalException(XServerError,
1247 "UnrecognizedVisualSpecifier",visual_type);
1250 Get all visuals that meet our criteria so far.
1253 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1255 visual_mask=VisualScreenMask | VisualIDMask;
1256 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1259 Failed to get visual; try using the default visual.
1261 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1263 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1264 XDefaultScreen(display)));
1265 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1267 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1268 return((XVisualInfo *) NULL);
1269 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1270 XVisualClassName(visual_list->klass));
1272 resource_info->color_recovery=MagickFalse;
1273 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1279 map_name[MaxTextExtent];
1295 Choose a visual associated with a standard colormap.
1297 root_window=XRootWindow(display,XDefaultScreen(display));
1299 if (LocaleCompare(map_type,"list") != 0)
1302 User specified Standard Colormap.
1304 (void) FormatLocaleString((char *) map_name,MaxTextExtent,
1305 "RGB_%s_MAP",map_type);
1306 LocaleUpper(map_name);
1307 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1308 if (map_property != (Atom) NULL)
1309 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1315 *colormap[MaxStandardColormaps]=
1317 "_HP_RGB_SMOOTH_MAP_LIST",
1327 Choose a standard colormap from a list.
1329 for (i=0; i < MaxStandardColormaps; i++)
1331 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1332 if (map_property == (Atom) NULL)
1334 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1336 if (status != False)
1339 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1341 if (status == False)
1343 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1345 return((XVisualInfo *) NULL);
1348 Search all Standard Colormaps and visuals for ids that match.
1350 *map_info=map_list[0];
1351 #if !defined(PRE_R4_ICCCM)
1352 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1353 for (i=0; i < number_maps; i++)
1354 for (j=0; j < number_visuals; j++)
1355 if (map_list[i].visualid ==
1356 XVisualIDFromVisual(visual_list[j].visual))
1358 *map_info=map_list[i];
1359 visual_template.visualid=XVisualIDFromVisual(
1360 visual_list[j].visual);
1363 if (map_info->visualid != visual_template.visualid)
1365 ThrowXWindowFatalException(XServerError,
1366 "UnableToMatchVisualToStandardColormap",map_type);
1367 return((XVisualInfo *) NULL);
1370 if (map_info->colormap == (Colormap) NULL)
1372 ThrowXWindowFatalException(XServerError,
1373 "StandardColormapIsNotInitialized",map_type);
1374 return((XVisualInfo *) NULL);
1376 (void) XFree((void *) map_list);
1380 static const unsigned int
1395 Pick one visual that displays the most simultaneous colors.
1397 visual_info=visual_list;
1399 for (i=1; i < number_visuals; i++)
1402 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1405 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1406 if (rank[p->klass] > rank[visual_info->klass])
1409 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1411 (void) XFree((void *) visual_list);
1413 Retrieve only one visual by its screen & id number.
1415 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1417 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1418 return((XVisualInfo *) NULL);
1419 return(visual_info);
1423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1427 % X C h e c k D e f i n e C u r s o r %
1431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1433 % XCheckDefineCursor() prevents cursor changes on the root window.
1435 % The format of the XXCheckDefineCursor method is:
1437 % XCheckDefineCursor(display,window,cursor)
1439 % A description of each parameter follows:
1441 % o display: Specifies a connection to an X server; returned from
1444 % o window: the window.
1446 % o cursor: the cursor.
1449 MagickExport int XCheckDefineCursor(Display *display,Window window,
1452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1453 assert(display != (Display *) NULL);
1454 if (window == XRootWindow(display,XDefaultScreen(display)))
1456 return(XDefineCursor(display,window,cursor));
1460 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 % X C h e c k R e f r e s h W i n d o w s %
1468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1470 % XCheckRefreshWindows() checks the X server for exposure events for a
1471 % particular window and updates the areassociated with the exposure event.
1473 % The format of the XCheckRefreshWindows method is:
1475 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1477 % A description of each parameter follows:
1479 % o display: Specifies a connection to an X server; returned from
1482 % o windows: Specifies a pointer to a XWindows structure.
1485 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1493 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1494 assert(display != (Display *) NULL);
1495 assert(windows != (XWindows *) NULL);
1496 XDelay(display,SuspendTime);
1497 id=windows->command.id;
1498 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1499 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1500 id=windows->image.id;
1501 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1502 XRefreshWindow(display,&windows->image,&event);
1503 XDelay(display,SuspendTime << 1);
1504 id=windows->command.id;
1505 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1506 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1507 id=windows->image.id;
1508 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1509 XRefreshWindow(display,&windows->image,&event);
1513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1517 % X C l i e n t M e s s a g e %
1521 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1524 % initialized with a particular protocol type and atom.
1526 % The format of the XClientMessage function is:
1528 % XClientMessage(display,window,protocol,reason,timestamp)
1530 % A description of each parameter follows:
1532 % o display: Specifies a pointer to the Display structure; returned from
1535 % o window: Specifies a pointer to a Window structure.
1537 % o protocol: Specifies an atom value.
1539 % o reason: Specifies an atom value which is the reason to send.
1541 % o timestamp: Specifies a value of type Time.
1544 MagickExport void XClientMessage(Display *display,const Window window,
1545 const Atom protocol,const Atom reason,const Time timestamp)
1550 assert(display != (Display *) NULL);
1551 client_event.type=ClientMessage;
1552 client_event.window=window;
1553 client_event.message_type=protocol;
1554 client_event.format=32;
1555 client_event.data.l[0]=(long) reason;
1556 client_event.data.l[1]=(long) timestamp;
1557 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565 + X C l i e n t W i n d o w %
1569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1571 % XClientWindow() finds a window, at or below the specified window, which has
1572 % a WM_STATE property. If such a window is found, it is returned, otherwise
1573 % the argument window is returned.
1575 % The format of the XClientWindow function is:
1577 % client_window=XClientWindow(display,target_window)
1579 % A description of each parameter follows:
1581 % o client_window: XClientWindow returns a window, at or below the specified
1582 % window, which has a WM_STATE property otherwise the argument
1583 % target_window is returned.
1585 % o display: Specifies a pointer to the Display structure; returned from
1588 % o target_window: Specifies the window to find a WM_STATE property.
1591 static Window XClientWindow(Display *display,Window target_window)
1613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1614 assert(display != (Display *) NULL);
1615 state=XInternAtom(display,"WM_STATE",MagickTrue);
1616 if (state == (Atom) NULL)
1617 return(target_window);
1619 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1620 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1621 if ((status == Success) && (type != (Atom) NULL))
1622 return(target_window);
1623 client_window=XWindowByProperty(display,target_window,state);
1624 if (client_window == (Window) NULL)
1625 return(target_window);
1626 return(client_window);
1630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1634 + X C o m p o n e n t T e r m i n u s %
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1640 % XComponentTerminus() destroys the module component.
1642 % The format of the XComponentTerminus method is:
1644 % XComponentTerminus(void)
1647 MagickExport void XComponentTerminus(void)
1649 DestroyXResources();
1653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1657 % X C o n f i g u r e I m a g e C o l o r m a p %
1661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1663 % XConfigureImageColormap() creates a new X colormap.
1665 % The format of the XConfigureImageColormap method is:
1667 % void XConfigureImageColormap(Display *display,
1668 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1670 % A description of each parameter follows:
1672 % o display: Specifies a connection to an X server; returned from
1675 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1677 % o windows: Specifies a pointer to a XWindows structure.
1679 % o image: the image.
1682 MagickExport void XConfigureImageColormap(Display *display,
1683 XResourceInfo *resource_info,XWindows *windows,Image *image)
1689 Make standard colormap.
1691 XSetCursorState(display,windows,MagickTrue);
1692 XCheckRefreshWindows(display,windows);
1693 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1694 windows->map_info,windows->pixel_info);
1695 colormap=windows->map_info->colormap;
1696 (void) XSetWindowColormap(display,windows->image.id,colormap);
1697 (void) XSetWindowColormap(display,windows->command.id,colormap);
1698 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1699 if (windows->magnify.mapped != MagickFalse)
1700 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1701 if (windows->pan.mapped != MagickFalse)
1702 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1703 XSetCursorState(display,windows,MagickFalse);
1704 XClientMessage(display,windows->image.id,windows->im_protocols,
1705 windows->im_update_colormap,CurrentTime);
1709 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1713 % X C o n s t r a i n W i n d o w P o s i t i o n %
1717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1719 % XConstrainWindowPosition() assures a window is positioned within the X
1720 % server boundaries.
1722 % The format of the XConstrainWindowPosition method is:
1724 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1726 % A description of each parameter follows:
1728 % o display: Specifies a pointer to the Display structure; returned from
1731 % o window_info: Specifies a pointer to a XWindowInfo structure.
1734 MagickExport void XConstrainWindowPosition(Display *display,
1735 XWindowInfo *window_info)
1740 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1741 assert(display != (Display *) NULL);
1742 assert(window_info != (XWindowInfo *) NULL);
1743 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1744 if (window_info->x < 0)
1747 if (window_info->x > (int) limit)
1748 window_info->x=(int) limit;
1749 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1750 if (window_info->y < 0)
1753 if (window_info->y > limit)
1754 window_info->y=limit;
1758 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1768 % XDelay() suspends program execution for the number of milliseconds
1771 % The format of the Delay method is:
1773 % void XDelay(Display *display,const size_t milliseconds)
1775 % A description of each parameter follows:
1777 % o display: Specifies a pointer to the Display structure; returned from
1780 % o milliseconds: Specifies the number of milliseconds to delay before
1784 MagickExport void XDelay(Display *display,const size_t milliseconds)
1786 assert(display != (Display *) NULL);
1787 (void) XFlush(display);
1788 MagickDelay(milliseconds);
1792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1796 % X D e s t r o y R e s o u r c e I n f o %
1800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1802 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1805 % The format of the XDestroyResourceInfo method is:
1807 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1809 % A description of each parameter follows:
1811 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1814 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1816 if (resource_info->image_geometry != (char *) NULL)
1817 resource_info->image_geometry=(char *)
1818 RelinquishMagickMemory(resource_info->image_geometry);
1819 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1820 resource_info->quantize_info=DestroyQuantizeInfo(
1821 resource_info->quantize_info);
1822 if (resource_info->client_name != (char *) NULL)
1823 resource_info->client_name=(char *)
1824 RelinquishMagickMemory(resource_info->client_name);
1825 if (resource_info->name != (char *) NULL)
1826 resource_info->name=DestroyString(resource_info->name);
1827 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1835 % X D e s t r o y W i n d o w C o l o r s %
1839 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1841 % XDestroyWindowColors() frees X11 color resources previously saved on a
1842 % window by XRetainWindowColors or programs like xsetroot.
1844 % The format of the XDestroyWindowColors method is:
1846 % void XDestroyWindowColors(Display *display,Window window)
1848 % A description of each parameter follows:
1850 % o display: Specifies a connection to an X server; returned from
1853 % o window: Specifies a pointer to a Window structure.
1856 MagickExport void XDestroyWindowColors(Display *display,Window window)
1876 If there are previous resources on the root window, destroy them.
1878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1879 assert(display != (Display *) NULL);
1880 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1881 if (property == (Atom) NULL)
1883 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1887 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1888 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1889 if (status != Success)
1891 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1893 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1894 (void) XDeleteProperty(display,window,property);
1897 (void) XFree((void *) data);
1901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1905 % X D i s p l a y I m a g e I n f o %
1909 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1911 % XDisplayImageInfo() displays information about an X image.
1913 % The format of the XDisplayImageInfo method is:
1915 % void XDisplayImageInfo(Display *display,
1916 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1919 % A description of each parameter follows:
1921 % o display: Specifies a connection to an X server; returned from
1924 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1926 % o windows: Specifies a pointer to a XWindows structure.
1928 % o undo_image: the undo image.
1930 % o image: the image.
1933 MagickExport void XDisplayImageInfo(Display *display,
1934 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1938 filename[MaxTextExtent],
1961 Write info about the X server to a file.
1963 assert(display != (Display *) NULL);
1964 assert(resource_info != (XResourceInfo *) NULL);
1965 assert(windows != (XWindows *) NULL);
1966 assert(image != (Image *) NULL);
1968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1970 unique_file=AcquireUniqueFileResource(filename);
1971 if (unique_file != -1)
1972 file=fdopen(unique_file,"w");
1973 if ((unique_file == -1) || (file == (FILE *) NULL))
1975 XNoticeWidget(display,windows,"Unable to display image info",filename);
1978 if (resource_info->gamma_correct != MagickFalse)
1979 if (resource_info->display_gamma != (char *) NULL)
1980 (void) FormatLocaleFile(file,"Display\n gamma: %s\n\n",
1981 resource_info->display_gamma);
1983 Write info about the X image to a file.
1985 (void) FormatLocaleFile(file,"X\n visual: %s\n",
1986 XVisualClassName((int) windows->image.storage_class));
1987 (void) FormatLocaleFile(file," depth: %d\n",windows->image.ximage->depth);
1988 if (windows->visual_info->colormap_size != 0)
1989 (void) FormatLocaleFile(file," colormap size: %d\n",
1990 windows->visual_info->colormap_size);
1991 if (resource_info->colormap== SharedColormap)
1992 (void) FormatLocaleFile(file," colormap type: Shared\n");
1994 (void) FormatLocaleFile(file," colormap type: Private\n");
1995 (void) FormatLocaleFile(file," geometry: %dx%d\n",
1996 windows->image.ximage->width,windows->image.ximage->height);
1997 if (windows->image.crop_geometry != (char *) NULL)
1998 (void) FormatLocaleFile(file," crop geometry: %s\n",
1999 windows->image.crop_geometry);
2000 if (windows->image.pixmap == (Pixmap) NULL)
2001 (void) FormatLocaleFile(file," type: X Image\n");
2003 (void) FormatLocaleFile(file," type: Pixmap\n");
2004 if (windows->image.shape != MagickFalse)
2005 (void) FormatLocaleFile(file," non-rectangular shape: True\n");
2007 (void) FormatLocaleFile(file," non-rectangular shape: False\n");
2008 if (windows->image.shared_memory != MagickFalse)
2009 (void) FormatLocaleFile(file," shared memory: True\n");
2011 (void) FormatLocaleFile(file," shared memory: False\n");
2012 (void) FormatLocaleFile(file,"\n");
2013 if (resource_info->font != (char *) NULL)
2014 (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
2015 if (resource_info->text_font != (char *) NULL)
2016 (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
2018 Write info about the undo cache to a file.
2021 for (levels=0; undo_image != (Image *) NULL; levels++)
2023 number_pixels=undo_image->list->columns*undo_image->list->rows;
2024 bytes+=number_pixels*sizeof(PixelPacket);
2025 undo_image=GetPreviousImageInList(undo_image);
2027 (void) FormatLocaleFile(file,"Undo Edit Cache\n levels: %u\n",levels);
2028 (void) FormatLocaleFile(file," bytes: %.20gmb\n",(double)
2029 ((bytes+(1 << 19)) >> 20));
2030 (void) FormatLocaleFile(file," limit: %.20gmb\n\n",(double)
2031 resource_info->undo_cache);
2033 Write info about the image to a file.
2035 (void) IdentifyImage(image,file,MagickTrue);
2036 (void) fclose(file);
2037 text=FileToString(filename,~0,&image->exception);
2038 (void) RelinquishUniqueFileResource(filename);
2039 if (text == (char *) NULL)
2041 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2042 "UnableToDisplayImageInfo");
2045 textlist=StringToList(text);
2046 if (textlist != (char **) NULL)
2049 title[MaxTextExtent];
2052 Display information about the image in the Text View widget.
2054 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2055 (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
2057 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2058 (char const **) textlist);
2059 for (i=0; textlist[i] != (char *) NULL; i++)
2060 textlist[i]=DestroyString(textlist[i]);
2061 textlist=(char **) RelinquishMagickMemory(textlist);
2063 text=DestroyString(text);
2067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2071 + X D i t h e r I m a g e %
2075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2077 % XDitherImage() dithers the reference image as required by the HP Color
2078 % Recovery algorithm. The color values are quantized to 3 bits of red and
2079 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2080 % standard colormap.
2082 % The format of the XDitherImage method is:
2084 % void XDitherImage(Image *image,XImage *ximage)
2086 % A description of each parameter follows:
2088 % o image: the image.
2090 % o ximage: Specifies a pointer to a XImage structure; returned from
2094 static void XDitherImage(Image *image,XImage *ximage)
2096 static const short int
2099 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2100 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2102 dither_green[2][16]=
2104 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2105 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2109 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2110 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2126 register const PixelPacket
2146 Allocate and initialize dither maps.
2148 for (i=0; i < 2; i++)
2149 for (j=0; j < 16; j++)
2151 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2153 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2154 sizeof(*green_map));
2155 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2157 if ((red_map[i][j] == (unsigned char *) NULL) ||
2158 (green_map[i][j] == (unsigned char *) NULL) ||
2159 (blue_map[i][j] == (unsigned char *) NULL))
2161 ThrowXWindowFatalException(ResourceLimitError,
2162 "MemoryAllocationFailed",image->filename);
2167 Initialize dither tables.
2169 for (i=0; i < 2; i++)
2170 for (j=0; j < 16; j++)
2171 for (x=0; x < 256; x++)
2176 value+=dither_red[i][j];
2177 red_map[i][j][x]=(unsigned char)
2178 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2182 value+=dither_green[i][j];
2183 green_map[i][j][x]=(unsigned char)
2184 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2188 value+=((size_t) dither_blue[i][j] << 1);
2189 blue_map[i][j][x]=(unsigned char)
2190 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2195 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2196 ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
2200 image_view=AcquireCacheView(image);
2201 for (y=0; y < (int) image->rows; y++)
2203 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
2205 if (p == (const PixelPacket *) NULL)
2207 for (x=0; x < (int) image->columns; x++)
2209 color.red=ClampToQuantum((MagickRealType) (red_map[i][j][(int)
2210 ScaleQuantumToChar(GetRedPixelComponent(p))] << 8));
2211 color.green=ClampToQuantum((MagickRealType) (green_map[i][j][(int)
2212 ScaleQuantumToChar(GetGreenPixelComponent(p))] << 8));
2213 color.blue=ClampToQuantum((MagickRealType) (blue_map[i][j][(int)
2214 ScaleQuantumToChar(GetBluePixelComponent(p))] << 8));
2215 pixel=(size_t) (((size_t) color.red & 0xe0) |
2216 (((size_t) color.green & 0xe0) >> 3) |
2217 (((size_t) color.blue & 0xc0) >> 6));
2229 image_view=DestroyCacheView(image_view);
2231 Free allocated memory.
2233 for (i=0; i < 2; i++)
2234 for (j=0; j < 16; j++)
2236 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2237 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2238 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2247 % X D r a w I m a g e %
2251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2253 % XDrawImage() draws a line on the image.
2255 % The format of the XDrawImage method is:
2257 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2259 % A description of each parameter follows:
2261 % o display: Specifies a connection to an X server; returned from
2264 % o pixel: Specifies a pointer to a XPixelInfo structure.
2266 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2268 % o image: the image.
2271 MagickExport MagickBooleanType XDrawImage(Display *display,
2272 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2311 Initialize drawd image.
2313 assert(display != (Display *) NULL);
2314 assert(pixel != (XPixelInfo *) NULL);
2315 assert(draw_info != (XDrawInfo *) NULL);
2316 assert(image != (Image *) NULL);
2317 if (image->debug != MagickFalse)
2318 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2320 Initialize drawd pixmap.
2322 root_window=XRootWindow(display,XDefaultScreen(display));
2323 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2324 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2325 draw_info->height,depth);
2326 if (draw_pixmap == (Pixmap) NULL)
2327 return(MagickFalse);
2329 Initialize graphics info.
2331 context_values.background=(size_t) (~0);
2332 context_values.foreground=0;
2333 context_values.line_width=(int) draw_info->line_width;
2334 draw_context=XCreateGC(display,root_window,(size_t)
2335 (GCBackground | GCForeground | GCLineWidth),&context_values);
2336 if (draw_context == (GC) NULL)
2337 return(MagickFalse);
2341 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2344 Draw line to pixmap.
2346 (void) XSetBackground(display,draw_context,0);
2347 (void) XSetForeground(display,draw_context,(size_t) (~0));
2348 if (draw_info->stipple != (Pixmap) NULL)
2350 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2351 (void) XSetStipple(display,draw_context,draw_info->stipple);
2353 switch (draw_info->element)
2358 (void) XDrawLines(display,draw_pixmap,draw_context,
2359 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2365 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2366 draw_info->line_info.y1,draw_info->line_info.x2,
2367 draw_info->line_info.y2);
2370 case RectangleElement:
2372 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2373 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2374 (unsigned int) draw_info->rectangle_info.width,
2375 (unsigned int) draw_info->rectangle_info.height);
2378 case FillRectangleElement:
2380 (void) XFillRectangle(display,draw_pixmap,draw_context,
2381 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2382 (unsigned int) draw_info->rectangle_info.width,
2383 (unsigned int) draw_info->rectangle_info.height);
2387 case EllipseElement:
2389 (void) XDrawArc(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,0,360*64);
2395 case FillCircleElement:
2396 case FillEllipseElement:
2398 (void) XFillArc(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 PolygonElement:
2409 coordinate_info=draw_info->coordinate_info;
2410 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2411 (int) draw_info->number_coordinates,CoordModeOrigin);
2412 (void) XDrawLine(display,draw_pixmap,draw_context,
2413 coordinate_info[draw_info->number_coordinates-1].x,
2414 coordinate_info[draw_info->number_coordinates-1].y,
2415 coordinate_info[0].x,coordinate_info[0].y);
2418 case FillPolygonElement:
2420 (void) XFillPolygon(display,draw_pixmap,draw_context,
2421 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2426 (void) XFreeGC(display,draw_context);
2430 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2431 draw_info->height,AllPlanes,ZPixmap);
2432 if (draw_ximage == (XImage *) NULL)
2433 return(MagickFalse);
2434 (void) XFreePixmap(display,draw_pixmap);
2436 Initialize draw image.
2438 draw_image=AcquireImage((ImageInfo *) NULL);
2439 if (draw_image == (Image *) NULL)
2440 return(MagickFalse);
2441 draw_image->columns=draw_info->width;
2442 draw_image->rows=draw_info->height;
2444 Transfer drawn X image to image.
2446 width=(unsigned int) image->columns;
2447 height=(unsigned int) image->rows;
2450 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2451 (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,
2452 &draw_image->background_color,&image->exception);
2453 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2454 return(MagickFalse);
2455 draw_image->matte=MagickTrue;
2456 exception=(&image->exception);
2457 draw_view=AcquireCacheView(draw_image);
2458 for (y=0; y < (int) draw_image->rows; y++)
2463 register PixelPacket
2466 q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2468 if (q == (PixelPacket *) NULL)
2470 for (x=0; x < (int) draw_image->columns; x++)
2472 if (XGetPixel(draw_ximage,x,y) == 0)
2475 Set this pixel to the background color.
2477 *q=draw_image->background_color;
2478 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2479 TransparentOpacity : OpaqueOpacity);
2484 Set this pixel to the pen color.
2486 SetRedPixelComponent(q,ScaleShortToQuantum(pixel->pen_color.red));
2487 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel->pen_color.green));
2488 SetBluePixelComponent(q,ScaleShortToQuantum(pixel->pen_color.blue));
2489 SetOpacityPixelComponent(q,(Quantum) (draw_info->stencil ==
2490 OpaqueStencil ? OpaqueOpacity : TransparentOpacity));
2494 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2497 draw_view=DestroyCacheView(draw_view);
2498 XDestroyImage(draw_ximage);
2500 Determine draw geometry.
2502 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2503 if ((width != (unsigned int) draw_image->columns) ||
2504 (height != (unsigned int) draw_image->rows))
2507 image_geometry[MaxTextExtent];
2512 (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
2514 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2516 if (draw_info->degrees != 0.0)
2530 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2531 if (rotate_image == (Image *) NULL)
2532 return(MagickFalse);
2533 draw_image=DestroyImage(draw_image);
2534 draw_image=rotate_image;
2536 Annotation is relative to the degree of rotation.
2538 normalized_degrees=draw_info->degrees;
2539 while (normalized_degrees < -45.0)
2540 normalized_degrees+=360.0;
2541 for (rotations=0; normalized_degrees > 45.0; rotations++)
2542 normalized_degrees-=90.0;
2543 switch (rotations % 4)
2553 x=x-(int) draw_image->columns/2;
2554 y=y+(int) draw_image->columns/2;
2562 x=x-(int) draw_image->columns;
2570 x=x-(int) draw_image->columns/2;
2571 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2577 Composite text onto the image.
2579 draw_view=AcquireCacheView(draw_image);
2580 for (y=0; y < (int) draw_image->rows; y++)
2585 register PixelPacket
2588 q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2590 if (q == (PixelPacket *) NULL)
2592 for (x=0; x < (int) draw_image->columns; x++)
2594 if (q->opacity != (Quantum) TransparentOpacity)
2595 SetOpacityPixelComponent(q,OpaqueOpacity);
2598 if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
2601 draw_view=DestroyCacheView(draw_view);
2602 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2603 if (draw_info->stencil == TransparentStencil)
2604 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,(ssize_t) x,
2609 (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2613 draw_image=DestroyImage(draw_image);
2618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2628 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2629 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2630 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2633 % The format of the XError function is:
2635 % XError(display,error)
2637 % A description of each parameter follows:
2639 % o display: Specifies a pointer to the Display structure; returned from
2642 % o error: Specifies the error event.
2646 #if defined(__cplusplus) || defined(c_plusplus)
2650 MagickExport int XError(Display *display,XErrorEvent *error)
2652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2653 assert(display != (Display *) NULL);
2654 assert(error != (XErrorEvent *) NULL);
2655 xerror_alert=MagickTrue;
2656 switch (error->request_code)
2660 if ((int) error->error_code == BadDrawable)
2661 return(MagickFalse);
2664 case X_GetWindowAttributes:
2667 if ((int) error->error_code == BadWindow)
2668 return(MagickFalse);
2673 if ((int) error->error_code == BadValue)
2674 return(MagickFalse);
2681 #if defined(__cplusplus) || defined(c_plusplus)
2686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2690 % X F r e e R e s o u r c e s %
2694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2696 % XFreeResources() frees X11 resources.
2698 % The format of the XFreeResources method is:
2700 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2701 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2702 % XResourceInfo *resource_info,XWindowInfo *window_info)
2703 % resource_info,window_info)
2705 % A description of each parameter follows:
2707 % o display: Specifies a connection to an X server; returned from
2710 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2711 % returned from XGetVisualInfo.
2713 % o map_info: If map_type is specified, this structure is initialized
2714 % with info from the Standard Colormap.
2716 % o pixel: Specifies a pointer to a XPixelInfo structure.
2718 % o font_info: Specifies a pointer to a XFontStruct structure.
2720 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2722 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2725 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2726 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2727 XResourceInfo *resource_info,XWindowInfo *window_info)
2729 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2730 assert(display != (Display *) NULL);
2731 assert(resource_info != (XResourceInfo *) NULL);
2732 if (window_info != (XWindowInfo *) NULL)
2737 if (window_info->ximage != (XImage *) NULL)
2738 XDestroyImage(window_info->ximage);
2739 if (window_info->id != (Window) NULL)
2742 Free destroy window and free cursors.
2744 if (window_info->id != XRootWindow(display,visual_info->screen))
2745 (void) XDestroyWindow(display,window_info->id);
2746 if (window_info->annotate_context != (GC) NULL)
2747 (void) XFreeGC(display,window_info->annotate_context);
2748 if (window_info->highlight_context != (GC) NULL)
2749 (void) XFreeGC(display,window_info->highlight_context);
2750 if (window_info->widget_context != (GC) NULL)
2751 (void) XFreeGC(display,window_info->widget_context);
2752 if (window_info->cursor != (Cursor) NULL)
2753 (void) XFreeCursor(display,window_info->cursor);
2754 window_info->cursor=(Cursor) NULL;
2755 if (window_info->busy_cursor != (Cursor) NULL)
2756 (void) XFreeCursor(display,window_info->busy_cursor);
2757 window_info->busy_cursor=(Cursor) NULL;
2763 if (font_info != (XFontStruct *) NULL)
2765 (void) XFreeFont(display,font_info);
2766 font_info=(XFontStruct *) NULL;
2768 if (map_info != (XStandardColormap *) NULL)
2771 Free X Standard Colormap.
2773 if (resource_info->map_type == (char *) NULL)
2774 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2775 (void) XFree((void *) map_info);
2780 if (visual_info != (XVisualInfo *) NULL)
2781 (void) XFree((void *) visual_info);
2782 if (resource_info->close_server != MagickFalse)
2783 (void) XCloseDisplay(display);
2787 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2791 % X F r e e S t a n d a r d C o l o r m a p %
2795 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2797 % XFreeStandardColormap() frees an X11 colormap.
2799 % The format of the XFreeStandardColormap method is:
2801 % void XFreeStandardColormap(Display *display,
2802 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2803 % XPixelInfo *pixel)
2805 % A description of each parameter follows:
2807 % o display: Specifies a connection to an X server; returned from
2810 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2811 % returned from XGetVisualInfo.
2813 % o map_info: If map_type is specified, this structure is initialized
2814 % with info from the Standard Colormap.
2816 % o pixel: Specifies a pointer to a XPixelInfo structure.
2819 MagickExport void XFreeStandardColormap(Display *display,
2820 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2826 assert(display != (Display *) NULL);
2827 assert(visual_info != (XVisualInfo *) NULL);
2828 assert(map_info != (XStandardColormap *) NULL);
2829 (void) XFlush(display);
2830 if (map_info->colormap != (Colormap) NULL)
2832 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2833 (void) XFreeColormap(display,map_info->colormap);
2835 if (pixel != (XPixelInfo *) NULL)
2836 if ((visual_info->klass != TrueColor) &&
2837 (visual_info->klass != DirectColor))
2838 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2839 (int) pixel->colors,0);
2841 map_info->colormap=(Colormap) NULL;
2842 if (pixel != (XPixelInfo *) NULL)
2844 if (pixel->pixels != (unsigned long *) NULL)
2845 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2846 pixel->pixels=(unsigned long *) NULL;
2851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2855 % X G e t A n n o t a t e I n f o %
2859 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2861 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2863 % The format of the XGetAnnotateInfo method is:
2865 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2867 % A description of each parameter follows:
2869 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2872 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2875 Initialize annotate structure.
2877 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2878 assert(annotate_info != (XAnnotateInfo *) NULL);
2881 annotate_info->width=0;
2882 annotate_info->height=0;
2883 annotate_info->stencil=ForegroundStencil;
2884 annotate_info->degrees=0.0;
2885 annotate_info->font_info=(XFontStruct *) NULL;
2886 annotate_info->text=(char *) NULL;
2887 *annotate_info->geometry='\0';
2888 annotate_info->previous=(XAnnotateInfo *) NULL;
2889 annotate_info->next=(XAnnotateInfo *) NULL;
2890 (void) XSupportsLocale();
2891 (void) XSetLocaleModifiers("");
2895 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2899 % X G e t M a p I n f o %
2903 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2905 % XGetMapInfo() initializes the XStandardColormap structure.
2907 % The format of the XStandardColormap method is:
2909 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2910 % XStandardColormap *map_info)
2912 % A description of each parameter follows:
2914 % o colormap: Specifies the ID of the X server colormap.
2916 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2917 % returned from XGetVisualInfo.
2919 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2922 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2923 const Colormap colormap,XStandardColormap *map_info)
2926 Initialize map info.
2928 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2929 assert(visual_info != (XVisualInfo *) NULL);
2930 assert(map_info != (XStandardColormap *) NULL);
2931 map_info->colormap=colormap;
2932 map_info->red_max=visual_info->red_mask;
2933 map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
2934 if (map_info->red_max != 0)
2935 while ((map_info->red_max & 0x01) == 0)
2937 map_info->red_max>>=1;
2938 map_info->red_mult<<=1;
2940 map_info->green_max=visual_info->green_mask;
2941 map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
2942 if (map_info->green_max != 0)
2943 while ((map_info->green_max & 0x01) == 0)
2945 map_info->green_max>>=1;
2946 map_info->green_mult<<=1;
2948 map_info->blue_max=visual_info->blue_mask;
2949 map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
2950 if (map_info->blue_max != 0)
2951 while ((map_info->blue_max & 0x01) == 0)
2953 map_info->blue_max>>=1;
2954 map_info->blue_mult<<=1;
2956 map_info->base_pixel=0;
2960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2964 % X G e t P i x e l I n f o %
2968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2970 % XGetPixelPacket() initializes the PixelPacket structure.
2972 % The format of the XGetPixelPacket method is:
2974 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2975 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2976 % Image *image,XPixelInfo *pixel)
2979 % A description of each parameter follows:
2981 % o display: Specifies a connection to an X server; returned from
2984 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2985 % returned from XGetVisualInfo.
2987 % o map_info: If map_type is specified, this structure is initialized
2988 % with info from the Standard Colormap.
2990 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2992 % o image: the image.
2994 % o pixel: Specifies a pointer to a XPixelInfo structure.
2997 MagickExport void XGetPixelPacket(Display *display,
2998 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2999 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
3002 *PenColors[MaxNumberPens]=
3004 "#000000000000", /* black */
3005 "#00000000ffff", /* blue */
3006 "#0000ffffffff", /* cyan */
3007 "#0000ffff0000", /* green */
3008 "#bdbdbdbdbdbd", /* gray */
3009 "#ffff00000000", /* red */
3010 "#ffff0000ffff", /* magenta */
3011 "#ffffffff0000", /* yellow */
3012 "#ffffffffffff", /* white */
3013 "#bdbdbdbdbdbd", /* gray */
3014 "#bdbdbdbdbdbd" /* gray */
3030 Initialize pixel info.
3032 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3033 assert(display != (Display *) NULL);
3034 assert(visual_info != (XVisualInfo *) NULL);
3035 assert(map_info != (XStandardColormap *) NULL);
3036 assert(resource_info != (XResourceInfo *) NULL);
3037 assert(pixel != (XPixelInfo *) NULL);
3039 if (image != (Image *) NULL)
3040 if (image->storage_class == PseudoClass)
3041 pixel->colors=(ssize_t) image->colors;
3042 packets=(unsigned int)
3043 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3044 if (pixel->pixels != (unsigned long *) NULL)
3045 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3046 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3047 sizeof(pixel->pixels));
3048 if (pixel->pixels == (unsigned long *) NULL)
3049 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3052 Set foreground color.
3054 colormap=map_info->colormap;
3055 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3056 &pixel->foreground_color);
3057 status=XParseColor(display,colormap,resource_info->foreground_color,
3058 &pixel->foreground_color);
3059 if (status == False)
3060 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3061 resource_info->foreground_color);
3062 pixel->foreground_color.pixel=
3063 XStandardPixel(map_info,&pixel->foreground_color);
3064 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3066 Set background color.
3068 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3069 status=XParseColor(display,colormap,resource_info->background_color,
3070 &pixel->background_color);
3071 if (status == False)
3072 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3073 resource_info->background_color);
3074 pixel->background_color.pixel=
3075 XStandardPixel(map_info,&pixel->background_color);
3076 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3080 (void) XParseColor(display,colormap,(char *) BorderColor,
3081 &pixel->border_color);
3082 status=XParseColor(display,colormap,resource_info->border_color,
3083 &pixel->border_color);
3084 if (status == False)
3085 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3086 resource_info->border_color);
3087 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3088 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3092 pixel->matte_color=pixel->background_color;
3093 if (resource_info->matte_color != (char *) NULL)
3096 Matte color is specified as a X resource or command line argument.
3098 status=XParseColor(display,colormap,resource_info->matte_color,
3099 &pixel->matte_color);
3100 if (status == False)
3101 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3102 resource_info->matte_color);
3103 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3104 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3107 Set highlight color.
3109 pixel->highlight_color.red=(unsigned short) ((
3110 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3111 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3112 pixel->highlight_color.green=(unsigned short) ((
3113 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3114 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3115 pixel->highlight_color.blue=(unsigned short) ((
3116 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3117 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3118 pixel->highlight_color.pixel=
3119 XStandardPixel(map_info,&pixel->highlight_color);
3120 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3124 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3125 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3126 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3127 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3128 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3129 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3130 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3131 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3135 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3136 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3137 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3138 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3139 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3140 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3141 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3142 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3146 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3147 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3148 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3149 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3150 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3151 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3152 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3153 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3157 for (i=0; i < MaxNumberPens; i++)
3159 (void) XParseColor(display,colormap,(char *) PenColors[i],
3160 &pixel->pen_colors[i]);
3161 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3162 &pixel->pen_colors[i]);
3163 if (status == False)
3164 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3165 resource_info->pen_colors[i]);
3166 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3167 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3169 pixel->box_color=pixel->background_color;
3170 pixel->pen_color=pixel->foreground_color;
3173 if (image != (Image *) NULL)
3175 if ((resource_info->gamma_correct != MagickFalse) &&
3176 (image->gamma != 0.0))
3185 Initialize map relative to display and image gamma.
3187 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3188 red_gamma=geometry_info.rho;
3189 green_gamma=geometry_info.sigma;
3190 if ((flags & SigmaValue) == 0)
3191 green_gamma=red_gamma;
3192 blue_gamma=geometry_info.xi;
3193 if ((flags & XiValue) == 0)
3194 blue_gamma=red_gamma;
3195 red_gamma*=image->gamma;
3196 green_gamma*=image->gamma;
3197 blue_gamma*=image->gamma;
3199 if (image->storage_class == PseudoClass)
3202 Initialize pixel array for images of type PseudoClass.
3204 for (i=0; i < (ssize_t) image->colors; i++)
3205 pixel->pixels[i]=XGammaPixel(map_info,image->colormap+i);
3206 for (i=0; i < MaxNumberPens; i++)
3207 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3208 pixel->colors+=MaxNumberPens;
3214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3218 % X G e t R e s o u r c e C l a s s %
3222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3224 % XGetResourceClass() queries the X server for the specified resource name or
3225 % class. If the resource name or class is not defined in the database, the
3226 % supplied default value is returned.
3228 % The format of the XGetResourceClass method is:
3230 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3231 % const char *keyword,char *resource_default)
3233 % A description of each parameter follows:
3235 % o database: Specifies a resource database; returned from
3236 % XrmGetStringDatabase.
3238 % o client_name: Specifies the application name used to retrieve resource
3239 % info from the X server database.
3241 % o keyword: Specifies the keyword of the value being retrieved.
3243 % o resource_default: Specifies the default value to return if the query
3244 % fails to find the specified keyword/class.
3247 MagickExport char *XGetResourceClass(XrmDatabase database,
3248 const char *client_name,const char *keyword,char *resource_default)
3251 resource_class[MaxTextExtent],
3252 resource_name[MaxTextExtent];
3263 if (database == (XrmDatabase) NULL)
3264 return(resource_default);
3265 *resource_name='\0';
3266 *resource_class='\0';
3267 if (keyword != (char *) NULL)
3274 Initialize resource keyword and class.
3276 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
3277 client_name,keyword);
3278 c=(int) (*client_name);
3279 if ((c >= XK_a) && (c <= XK_z))
3282 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3283 c-=(XK_agrave-XK_Agrave);
3285 if ((c >= XK_oslash) && (c <= XK_thorn))
3286 c-=(XK_oslash-XK_Ooblique);
3288 if ((k >= XK_a) && (k <= XK_z))
3291 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3292 k-=(XK_agrave-XK_Agrave);
3294 if ((k >= XK_oslash) && (k <= XK_thorn))
3295 k-=(XK_oslash-XK_Ooblique);
3296 (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3297 client_name+1,k,keyword+1);
3299 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3301 if (status == False)
3302 return(resource_default);
3303 return(resource_value.addr);
3307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3311 % X G e t R e s o u r c e D a t a b a s e %
3315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3317 % XGetResourceDatabase() creates a new resource database and initializes it.
3319 % The format of the XGetResourceDatabase method is:
3321 % XrmDatabase XGetResourceDatabase(Display *display,
3322 % const char *client_name)
3324 % A description of each parameter follows:
3326 % o database: XGetResourceDatabase() returns the database after it is
3329 % o display: Specifies a connection to an X server; returned from
3332 % o client_name: Specifies the application name used to retrieve resource
3333 % info from the X server database.
3336 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3337 const char *client_name)
3340 filename[MaxTextExtent];
3352 if (display == (Display *) NULL)
3353 return((XrmDatabase) NULL);
3354 assert(client_name != (char *) NULL);
3356 Initialize resource database.
3359 (void) XGetDefault(display,(char *) client_name,"dummy");
3360 resource_database=XrmGetDatabase(display);
3362 Combine application database.
3364 if (client_name != (char *) NULL)
3367 Get basename of client.
3369 p=client_name+(strlen(client_name)-1);
3370 while ((p > client_name) && (*p != '/'))
3375 c=(int) (*client_name);
3376 if ((c >= XK_a) && (c <= XK_z))
3379 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3380 c-=(XK_agrave-XK_Agrave);
3382 if ((c >= XK_oslash) && (c <= XK_thorn))
3383 c-=(XK_oslash-XK_Ooblique);
3384 #if defined(X11_APPLICATION_PATH)
3385 (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
3386 X11_APPLICATION_PATH,c,client_name+1);
3387 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3389 if (XResourceManagerString(display) != (char *) NULL)
3392 Combine server database.
3394 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3395 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3398 Merge user preferences database.
3400 #if defined(X11_PREFERENCES_PATH)
3401 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
3402 X11_PREFERENCES_PATH,client_name);
3403 ExpandFilename(filename);
3404 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3406 return(resource_database);
3410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3414 % X G e t R e s o u r c e I n f o %
3418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3420 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3422 % The format of the XGetResourceInfo method is:
3424 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3425 % const char *client_name,XResourceInfo *resource_info)
3427 % A description of each parameter follows:
3429 % o image_info: the image info.
3431 % o database: Specifies a resource database; returned from
3432 % XrmGetStringDatabase.
3434 % o client_name: Specifies the application name used to retrieve
3435 % resource info from the X server database.
3437 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3440 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3441 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3448 Initialize resource info fields.
3450 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3451 assert(resource_info != (XResourceInfo *) NULL);
3452 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3453 resource_info->resource_database=database;
3454 resource_info->image_info=(ImageInfo *) image_info;
3455 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3456 XMagickProgressMonitor,(void *) NULL);
3457 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3458 resource_info->close_server=MagickTrue;
3459 resource_info->client_name=AcquireString(client_name);
3460 resource_value=XGetResourceClass(database,client_name,"backdrop",
3462 resource_info->backdrop=IsMagickTrue(resource_value);
3463 resource_info->background_color=XGetResourceInstance(database,client_name,
3464 "background",(char *) "#d6d6d6d6d6d6");
3465 resource_info->border_color=XGetResourceInstance(database,client_name,
3466 "borderColor",BorderColor);
3467 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3469 resource_info->border_width=(unsigned int) StringToUnsignedLong(
3471 resource_value=XGetResourceClass(database,client_name,"colormap",
3473 resource_info->colormap=UndefinedColormap;
3474 if (LocaleCompare("private",resource_value) == 0)
3475 resource_info->colormap=PrivateColormap;
3476 if (LocaleCompare("shared",resource_value) == 0)
3477 resource_info->colormap=SharedColormap;
3478 if (resource_info->colormap == UndefinedColormap)
3479 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3481 resource_value=XGetResourceClass(database,client_name,
3482 "colorRecovery",(char *) "False");
3483 resource_info->color_recovery=IsMagickTrue(resource_value);
3484 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3486 resource_info->confirm_exit=IsMagickTrue(resource_value);
3487 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3489 resource_info->confirm_edit=IsMagickTrue(resource_value);
3490 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3491 resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
3492 resource_info->display_gamma=XGetResourceClass(database,client_name,
3493 "displayGamma",(char *) "2.2");
3494 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3496 resource_info->display_warnings=IsMagickTrue(resource_value);
3497 resource_info->font=XGetResourceClass(database,client_name,"font",
3499 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3500 resource_info->font);
3501 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3503 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3504 (char *) "variable");
3505 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3507 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3509 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3510 (char *) "7x13bold");
3511 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3512 (char *) "8x13bold");
3513 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3514 (char *) "9x15bold");
3515 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3517 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3519 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3521 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3523 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3524 "foreground",ForegroundColor);
3525 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3527 resource_info->gamma_correct=IsMagickTrue(resource_value);
3528 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3529 client_name,"geometry",(char *) NULL));
3530 resource_value=XGetResourceClass(database,client_name,"gravity",
3532 resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3533 MagickFalse,resource_value);
3534 directory=getcwd(resource_info->home_directory,MaxTextExtent);
3536 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3537 "iconGeometry",(char *) NULL);
3538 resource_value=XGetResourceClass(database,client_name,"iconic",
3540 resource_info->iconic=IsMagickTrue(resource_value);
3541 resource_value=XGetResourceClass(database,client_name,"immutable",
3542 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3544 resource_info->immutable=IsMagickTrue(resource_value);
3545 resource_value=XGetResourceClass(database,client_name,"magnify",
3547 resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
3548 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3550 resource_info->matte_color=XGetResourceInstance(database,client_name,
3551 "mattecolor",(char *) NULL);
3552 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3553 "name",(char *) NULL));
3554 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3556 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3558 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3560 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3562 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3564 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3566 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3567 (char *) "magenta");
3568 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3570 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3572 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3574 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3576 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3577 resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
3578 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3579 resource_info->quantum=StringToLong(resource_value);
3580 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3581 "font",(char *) "fixed");
3582 resource_info->text_font=XGetResourceClass(database,client_name,
3583 "textFontList",resource_info->text_font);
3584 resource_info->title=XGetResourceClass(database,client_name,"title",
3586 resource_value=XGetResourceClass(database,client_name,"undoCache",
3588 resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
3589 resource_value=XGetResourceClass(database,client_name,"update",
3591 resource_info->update=IsMagickTrue(resource_value);
3592 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3594 resource_info->use_pixmap=IsMagickTrue(resource_value);
3595 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3597 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3598 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3600 resource_info->window_group=XGetResourceClass(database,client_name,
3601 "windowGroup",(char *) NULL);
3602 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3604 resource_info->write_filename=XGetResourceClass(database,client_name,
3605 "writeFilename",(char *) NULL);
3609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3613 % X G e t R e s o u r c e I n s t a n c e %
3617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3619 % XGetResourceInstance() queries the X server for the specified resource name.
3620 % If the resource name is not defined in the database, the supplied default
3621 % value is returned.
3623 % The format of the XGetResourceInstance method is:
3625 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3626 % const char *keyword,const char *resource_default)
3628 % A description of each parameter follows:
3630 % o database: Specifies a resource database; returned from
3631 % XrmGetStringDatabase.
3633 % o client_name: Specifies the application name used to retrieve
3634 % resource info from the X server database.
3636 % o keyword: Specifies the keyword of the value being retrieved.
3638 % o resource_default: Specifies the default value to return if the query
3639 % fails to find the specified keyword/class.
3642 MagickExport char *XGetResourceInstance(XrmDatabase database,
3643 const char *client_name,const char *keyword,const char *resource_default)
3647 resource_name[MaxTextExtent];
3655 if (database == (XrmDatabase) NULL)
3656 return((char *) resource_default);
3657 *resource_name='\0';
3658 if (keyword != (char *) NULL)
3659 (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",client_name,
3661 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3663 if (status == False)
3664 return((char *) resource_default);
3665 return(resource_value.addr);
3669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3673 % X G e t S c r e e n D e n s i t y %
3677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3679 % XGetScreenDensity() returns the density of the X server screen in
3682 % The format of the XGetScreenDensity method is:
3684 % char *XGetScreenDensity(Display *display)
3686 % A description of each parameter follows:
3688 % o density: XGetScreenDensity() returns the density of the X screen in
3691 % o display: Specifies a connection to an X server; returned from
3695 MagickExport char *XGetScreenDensity(Display *display)
3698 density[MaxTextExtent];
3705 Set density as determined by screen size.
3707 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3708 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3709 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3710 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3711 (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",x_density,
3713 return(GetPageGeometry(density));
3717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3721 + X G e t S u b w i n d o w %
3725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3727 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3728 % pointer and a button press.
3730 % The format of the XGetSubwindow method is:
3732 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3734 % A description of each parameter follows:
3736 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3737 % otherwise the subwindow is returned.
3739 % o display: Specifies a connection to an X server; returned from
3742 % o window: Specifies a pointer to a Window.
3744 % o x: the x coordinate of the pointer relative to the origin of the
3747 % o y: the y coordinate of the pointer relative to the origin of the
3751 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3764 assert(display != (Display *) NULL);
3765 source_window=XRootWindow(display,XDefaultScreen(display));
3766 if (window == (Window) NULL)
3767 return(source_window);
3768 target_window=window;
3771 status=XTranslateCoordinates(display,source_window,window,x,y,
3772 &x_offset,&y_offset,&target_window);
3775 if (target_window == (Window) NULL)
3777 source_window=window;
3778 window=target_window;
3782 if (target_window == (Window) NULL)
3783 target_window=window;
3784 return(target_window);
3788 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3792 % X G e t W i n d o w C o l o r %
3796 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3798 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3801 % The format of the XGetWindowColor method is:
3803 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3806 % A description of each parameter follows:
3808 % o display: Specifies a connection to an X server; returned from
3811 % o windows: Specifies a pointer to a XWindows structure.
3813 % o name: the name of the color if found in the X Color Database is
3814 % returned in this character string.
3817 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3818 XWindows *windows,char *name)
3849 Choose a pixel from the X server.
3851 assert(display != (Display *) NULL);
3852 assert(name != (char *) NULL);
3853 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3855 target_window=XSelectWindow(display,&crop_info);
3856 if (target_window == (Window) NULL)
3857 return(MagickFalse);
3858 root_window=XRootWindow(display,XDefaultScreen(display));
3859 client_window=target_window;
3860 if (target_window != root_window)
3868 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3869 if (status != False)
3871 client_window=XClientWindow(display,target_window);
3872 target_window=client_window;
3876 Verify window is viewable.
3878 status=XGetWindowAttributes(display,target_window,&window_attributes);
3879 if ((status == False) || (window_attributes.map_state != IsViewable))
3880 return(MagickFalse);
3884 (void) XTranslateCoordinates(display,root_window,target_window,
3885 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3886 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3887 if (ximage == (XImage *) NULL)
3888 return(MagickFalse);
3889 color.pixel=XGetPixel(ximage,0,0);
3890 XDestroyImage(ximage);
3892 Match color against the color database.
3894 (void) XQueryColor(display,window_attributes.colormap,&color);
3895 pixel.red=ScaleShortToQuantum(color.red);
3896 pixel.green=ScaleShortToQuantum(color.green);
3897 pixel.blue=ScaleShortToQuantum(color.blue);
3898 pixel.opacity=OpaqueOpacity;
3899 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3900 &windows->image.image->exception);
3905 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3909 + X G e t W i n d o w I m a g e %
3913 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3915 % XGetWindowImage() reads an image from the target X window and returns it.
3916 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3917 % target image with each child image in an optimized fashion. Any child
3918 % window that have the same visual, colormap, and are contained by its parent
3921 % The format of the XGetWindowImage method is:
3923 % Image *XGetWindowImage(Display *display,const Window window,
3924 % const unsigned int borders,const unsigned int level)
3926 % A description of each parameter follows:
3928 % o display: Specifies a connection to an X server; returned from
3931 % o window: Specifies the window to obtain the image from.
3933 % o borders: Specifies whether borders pixels are to be saved with
3936 % o level: Specifies an unsigned integer representing the level of
3937 % decent in the window hierarchy. This value must be zero or one on
3938 % the initial call to XGetWindowImage. A value of zero returns after
3939 % one call. A value of one causes the function to descend the window
3940 % hierarchy and overlay the target image with each subwindow image.
3943 static Image *XGetWindowImage(Display *display,const Window window,
3944 const unsigned int borders,const unsigned int level)
3946 typedef struct _ColormapInfo
3954 struct _ColormapInfo
3958 typedef struct _WindowInfo
3990 register IndexPacket
3997 *colormap_info = (ColormapInfo *) NULL;
4017 Verify window is viewable.
4019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4020 assert(display != (Display *) NULL);
4021 status=XGetWindowAttributes(display,window,&window_attributes);
4022 if ((status == False) || (window_attributes.map_state != IsViewable))
4023 return((Image *) NULL);
4025 Cropping rectangle is relative to root window.
4027 root_window=XRootWindow(display,XDefaultScreen(display));
4028 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4030 crop_info.x=(ssize_t) x_offset;
4031 crop_info.y=(ssize_t) y_offset;
4032 crop_info.width=(size_t) window_attributes.width;
4033 crop_info.height=(size_t) window_attributes.height;
4034 if (borders != MagickFalse)
4037 Include border in image.
4039 crop_info.x-=(ssize_t) window_attributes.border_width;
4040 crop_info.y-=(ssize_t) window_attributes.border_width;
4041 crop_info.width+=(size_t) (window_attributes.border_width << 1);
4042 crop_info.height+=(size_t) (window_attributes.border_width << 1);
4045 Crop to root window.
4047 if (crop_info.x < 0)
4049 crop_info.width+=crop_info.x;
4052 if (crop_info.y < 0)
4054 crop_info.height+=crop_info.y;
4057 display_width=XDisplayWidth(display,XDefaultScreen(display));
4058 if ((int) (crop_info.x+crop_info.width) > display_width)
4059 crop_info.width=(size_t) (display_width-crop_info.x);
4060 display_height=XDisplayHeight(display,XDefaultScreen(display));
4061 if ((int) (crop_info.y+crop_info.height) > display_height)
4062 crop_info.height=(size_t) (display_height-crop_info.y);
4064 Initialize window info attributes.
4066 if (number_windows >= max_windows)
4069 Allocate or resize window info buffer.
4072 if (window_info == (WindowInfo *) NULL)
4073 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4074 sizeof(*window_info));
4076 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4077 max_windows,sizeof(*window_info));
4079 if (window_info == (WindowInfo *) NULL)
4081 ThrowXWindowFatalException(ResourceLimitError,
4082 "MemoryAllocationFailed","...");
4083 return((Image *) NULL);
4085 id=number_windows++;
4086 window_info[id].window=window;
4087 window_info[id].visual=window_attributes.visual;
4088 window_info[id].colormap=window_attributes.colormap;
4089 window_info[id].bounds.x1=(short) crop_info.x;
4090 window_info[id].bounds.y1=(short) crop_info.y;
4091 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4092 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4093 crop_info.x-=x_offset;
4094 crop_info.y-=y_offset;
4095 window_info[id].crop_info=crop_info;
4105 Descend the window hierarchy.
4107 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4108 &children,&number_children);
4109 for (i=0; i < id; i++)
4110 if ((window_info[i].window == window_info[id].parent) &&
4111 (window_info[i].visual == window_info[id].visual) &&
4112 (window_info[i].colormap == window_info[id].colormap))
4114 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4115 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4116 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4117 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4120 Eliminate windows not circumscribed by their parent.
4126 if ((status == True) && (number_children != 0))
4128 for (i=0; i < (int) number_children; i++)
4129 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4130 (void) XFree((void *) children);
4158 register PixelPacket
4174 Get X image for each window in the list.
4176 image=NewImageList();
4177 for (id=0; id < number_windows; id++)
4180 Does target window intersect top level window?
4183 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4184 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4185 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4186 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4187 MagickTrue : MagickFalse;
4189 Is target window contained by another window with the same colormap?
4191 for (j=0; j < id; j++)
4192 if ((window_info[id].visual == window_info[j].visual) &&
4193 (window_info[id].colormap == window_info[j].colormap))
4195 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4196 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4197 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4198 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4202 if ((window_info[id].visual != window_info[j].visual) ||
4203 (window_info[id].colormap != window_info[j].colormap))
4205 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4206 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4207 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4208 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4211 if (import == MagickFalse)
4216 ximage=XGetImage(display,window_info[id].window,(int)
4217 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4218 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4219 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4220 if (ximage == (XImage *) NULL)
4223 Initialize window colormap.
4226 colors=(XColor *) NULL;
4227 if (window_info[id].colormap != (Colormap) NULL)
4233 Search colormap list for window colormap.
4235 number_colors=(unsigned int) window_info[id].visual->map_entries;
4236 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4237 if (p->colormap == window_info[id].colormap)
4239 if (p == (ColormapInfo *) NULL)
4242 Get the window colormap.
4244 colors=(XColor *) AcquireQuantumMemory(number_colors,
4246 if (colors == (XColor *) NULL)
4248 XDestroyImage(ximage);
4249 return((Image *) NULL);
4251 if ((window_info[id].visual->klass != DirectColor) &&
4252 (window_info[id].visual->klass != TrueColor))
4253 for (i=0; i < (int) number_colors; i++)
4255 colors[i].pixel=(size_t) i;
4269 DirectColor or TrueColor visual.
4274 red_bit=window_info[id].visual->red_mask &
4275 (~(window_info[id].visual->red_mask)+1);
4276 green_bit=window_info[id].visual->green_mask &
4277 (~(window_info[id].visual->green_mask)+1);
4278 blue_bit=window_info[id].visual->blue_mask &
4279 (~(window_info[id].visual->blue_mask)+1);
4280 for (i=0; i < (int) number_colors; i++)
4282 colors[i].pixel=(unsigned long) (red | green | blue);
4285 if (red > window_info[id].visual->red_mask)
4288 if (green > window_info[id].visual->green_mask)
4291 if (blue > window_info[id].visual->blue_mask)
4295 (void) XQueryColors(display,window_info[id].colormap,colors,
4296 (int) number_colors);
4298 Append colormap to colormap list.
4300 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4301 if (p == (ColormapInfo *) NULL)
4302 return((Image *) NULL);
4303 p->colormap=window_info[id].colormap;
4305 p->next=colormap_info;
4311 Allocate image structure.
4313 composite_image=AcquireImage((ImageInfo *) NULL);
4314 if (composite_image == (Image *) NULL)
4316 XDestroyImage(ximage);
4317 return((Image *) NULL);
4320 Convert X image to MIFF format.
4322 if ((window_info[id].visual->klass != TrueColor) &&
4323 (window_info[id].visual->klass != DirectColor))
4324 composite_image->storage_class=PseudoClass;
4325 composite_image->columns=(size_t) ximage->width;
4326 composite_image->rows=(size_t) ximage->height;
4327 exception=(&composite_image->exception);
4328 composite_view=AcquireCacheView(composite_image);
4329 switch (composite_image->storage_class)
4347 Determine shift and mask for red, green, and blue.
4349 red_mask=window_info[id].visual->red_mask;
4351 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4356 green_mask=window_info[id].visual->green_mask;
4358 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4363 blue_mask=window_info[id].visual->blue_mask;
4365 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4371 Convert X image to DirectClass packets.
4373 if ((number_colors != 0) &&
4374 (window_info[id].visual->klass == DirectColor))
4375 for (y=0; y < (int) composite_image->rows; y++)
4377 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4378 composite_image->columns,1,exception);
4379 if (q == (PixelPacket *) NULL)
4381 for (x=0; x < (int) composite_image->columns; x++)
4383 pixel=XGetPixel(ximage,x,y);
4384 index=(pixel >> red_shift) & red_mask;
4385 SetRedPixelComponent(q,ScaleShortToQuantum(
4386 colors[index].red));
4387 index=(pixel >> green_shift) & green_mask;
4388 SetGreenPixelComponent(q,ScaleShortToQuantum(
4389 colors[index].green));
4390 index=(pixel >> blue_shift) & blue_mask;
4391 SetBluePixelComponent(q,ScaleShortToQuantum(
4392 colors[index].blue));
4395 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4399 for (y=0; y < (int) composite_image->rows; y++)
4401 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4402 composite_image->columns,1,exception);
4403 if (q == (PixelPacket *) NULL)
4405 for (x=0; x < (int) composite_image->columns; x++)
4407 pixel=XGetPixel(ximage,x,y);
4408 color=(pixel >> red_shift) & red_mask;
4409 color=(65535UL*color)/red_mask;
4410 SetRedPixelComponent(q,ScaleShortToQuantum((unsigned short)
4412 color=(pixel >> green_shift) & green_mask;
4413 color=(65535UL*color)/green_mask;
4414 SetGreenPixelComponent(q,ScaleShortToQuantum((unsigned short)
4416 color=(pixel >> blue_shift) & blue_mask;
4417 color=(65535UL*color)/blue_mask;
4418 SetBluePixelComponent(q,ScaleShortToQuantum((unsigned short)
4422 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4432 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4434 XDestroyImage(ximage);
4435 composite_image=DestroyImage(composite_image);
4436 return((Image *) NULL);
4438 for (i=0; i < (int) composite_image->colors; i++)
4440 composite_image->colormap[colors[i].pixel].red=
4441 ScaleShortToQuantum(colors[i].red);
4442 composite_image->colormap[colors[i].pixel].green=
4443 ScaleShortToQuantum(colors[i].green);
4444 composite_image->colormap[colors[i].pixel].blue=
4445 ScaleShortToQuantum(colors[i].blue);
4448 Convert X image to PseudoClass packets.
4450 for (y=0; y < (int) composite_image->rows; y++)
4452 q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4453 composite_image->columns,1,exception);
4454 if (q == (PixelPacket *) NULL)
4456 indexes=GetCacheViewAuthenticIndexQueue(composite_view);
4457 for (x=0; x < (int) composite_image->columns; x++)
4459 index=(IndexPacket) XGetPixel(ximage,x,y);
4460 SetIndexPixelComponent(indexes+x,index);
4461 SetRGBOPixelComponents(q,composite_image->colormap+(ssize_t)
4465 if (SyncCacheViewAuthenticPixels(composite_view,exception) == MagickFalse)
4471 composite_view=DestroyCacheView(composite_view);
4472 XDestroyImage(ximage);
4473 if (image == (Image *) NULL)
4475 image=composite_image;
4479 Composite any children in back-to-front order.
4481 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4482 &x_offset,&y_offset,&child);
4483 x_offset-=(int) crop_info.x;
4486 y_offset-=(int) crop_info.y;
4489 (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4490 x_offset,(ssize_t) y_offset);
4493 Relinquish resources.
4495 while (colormap_info != (ColormapInfo *) NULL)
4497 next=colormap_info->next;
4498 colormap_info->colors=(XColor *)
4499 RelinquishMagickMemory(colormap_info->colors);
4500 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4504 Relinquish resources and restore initial state.
4506 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4509 colormap_info=(ColormapInfo *) NULL;
4512 return((Image *) NULL);
4516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4520 % X G e t W i n d o w I n f o %
4524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4526 % XGetWindowInfo() initializes the XWindowInfo structure.
4528 % The format of the XGetWindowInfo method is:
4530 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4531 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4532 % XResourceInfo *resource_info,XWindowInfo *window)
4533 % resource_info,window)
4535 % A description of each parameter follows:
4537 % o display: Specifies a connection to an X server; returned from
4540 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4541 % returned from XGetVisualInfo.
4543 % o map_info: If map_type is specified, this structure is initialized
4544 % with info from the Standard Colormap.
4546 % o pixel: Specifies a pointer to a XPixelInfo structure.
4548 % o font_info: Specifies a pointer to a XFontStruct structure.
4550 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4553 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4554 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4555 XResourceInfo *resource_info,XWindowInfo *window)
4558 Initialize window info.
4560 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4561 assert(display != (Display *) NULL);
4562 assert(visual_info != (XVisualInfo *) NULL);
4563 assert(map_info != (XStandardColormap *) NULL);
4564 assert(pixel != (XPixelInfo *) NULL);
4565 assert(resource_info != (XResourceInfo *) NULL);
4566 assert(window != (XWindowInfo *) NULL);
4567 if (window->id != (Window) NULL)
4569 if (window->cursor != (Cursor) NULL)
4570 (void) XFreeCursor(display,window->cursor);
4571 if (window->busy_cursor != (Cursor) NULL)
4572 (void) XFreeCursor(display,window->busy_cursor);
4573 if (window->highlight_stipple != (Pixmap) NULL)
4574 (void) XFreePixmap(display,window->highlight_stipple);
4575 if (window->shadow_stipple != (Pixmap) NULL)
4576 (void) XFreePixmap(display,window->shadow_stipple);
4577 if (window->name == (char *) NULL)
4578 window->name=AcquireString("");
4579 if (window->icon_name == (char *) NULL)
4580 window->icon_name=AcquireString("");
4585 Initialize these attributes just once.
4587 window->id=(Window) NULL;
4588 if (window->name == (char *) NULL)
4589 window->name=AcquireString("");
4590 if (window->icon_name == (char *) NULL)
4591 window->icon_name=AcquireString("");
4592 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4593 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4594 window->ximage=(XImage *) NULL;
4595 window->matte_image=(XImage *) NULL;
4596 window->pixmap=(Pixmap) NULL;
4597 window->matte_pixmap=(Pixmap) NULL;
4598 window->mapped=MagickFalse;
4599 window->stasis=MagickFalse;
4600 window->shared_memory=MagickTrue;
4601 window->segment_info=(void *) NULL;
4602 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4607 if (window->segment_info == (void *) NULL)
4608 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4609 segment_info=(XShmSegmentInfo *) window->segment_info;
4610 segment_info[0].shmid=(-1);
4611 segment_info[0].shmaddr=(char *) NULL;
4612 segment_info[1].shmid=(-1);
4613 segment_info[1].shmaddr=(char *) NULL;
4618 Initialize these attributes every time function is called.
4620 window->screen=visual_info->screen;
4621 window->root=XRootWindow(display,visual_info->screen);
4622 window->visual=visual_info->visual;
4623 window->storage_class=(unsigned int) visual_info->klass;
4624 window->depth=(unsigned int) visual_info->depth;
4625 window->visual_info=visual_info;
4626 window->map_info=map_info;
4627 window->pixel_info=pixel;
4628 window->font_info=font_info;
4629 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4630 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4631 window->geometry=(char *) NULL;
4632 window->icon_geometry=(char *) NULL;
4633 if (resource_info->icon_geometry != (char *) NULL)
4634 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4635 window->crop_geometry=(char *) NULL;
4636 window->flags=(size_t) PSize;
4639 window->min_width=1;
4640 window->min_height=1;
4641 window->width_inc=1;
4642 window->height_inc=1;
4643 window->border_width=resource_info->border_width;
4644 window->annotate_context=pixel->annotate_context;
4645 window->highlight_context=pixel->highlight_context;
4646 window->widget_context=pixel->widget_context;
4647 window->shadow_stipple=(Pixmap) NULL;
4648 window->highlight_stipple=(Pixmap) NULL;
4649 window->use_pixmap=MagickTrue;
4650 window->immutable=MagickFalse;
4651 window->shape=MagickFalse;
4653 window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
4654 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4655 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4656 window->attributes.background_pixel=pixel->background_color.pixel;
4657 window->attributes.background_pixmap=(Pixmap) NULL;
4658 window->attributes.bit_gravity=ForgetGravity;
4659 window->attributes.backing_store=WhenMapped;
4660 window->attributes.save_under=MagickTrue;
4661 window->attributes.border_pixel=pixel->border_color.pixel;
4662 window->attributes.colormap=map_info->colormap;
4663 window->attributes.cursor=window->cursor;
4664 window->attributes.do_not_propagate_mask=NoEventMask;
4665 window->attributes.event_mask=NoEventMask;
4666 window->attributes.override_redirect=MagickFalse;
4667 window->attributes.win_gravity=NorthWestGravity;
4668 window->orphan=MagickFalse;
4672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4676 % X H i g h l i g h t E l l i p s e %
4680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4682 % XHighlightEllipse() puts a border on the X server around a region defined by
4685 % The format of the XHighlightEllipse method is:
4687 % void XHighlightEllipse(Display *display,Window window,
4688 % GC annotate_context,const RectangleInfo *highlight_info)
4690 % A description of each parameter follows:
4692 % o display: Specifies a connection to an X server; returned from
4695 % o window: Specifies a pointer to a Window structure.
4697 % o annotate_context: Specifies a pointer to a GC structure.
4699 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4700 % contains the extents of any highlighting rectangle.
4703 MagickExport void XHighlightEllipse(Display *display,Window window,
4704 GC annotate_context,const RectangleInfo *highlight_info)
4706 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4707 assert(display != (Display *) NULL);
4708 assert(window != (Window) NULL);
4709 assert(annotate_context != (GC) NULL);
4710 assert(highlight_info != (RectangleInfo *) NULL);
4711 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4713 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4714 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4715 (unsigned int) highlight_info->height-1,0,360*64);
4716 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4717 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4718 (unsigned int) highlight_info->height-3,0,360*64);
4722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4726 % X H i g h l i g h t L i n e %
4730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4732 % XHighlightLine() puts a border on the X server around a region defined by
4735 % The format of the XHighlightLine method is:
4737 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4738 % const XSegment *highlight_info)
4740 % A description of each parameter follows:
4742 % o display: Specifies a connection to an X server; returned from
4745 % o window: Specifies a pointer to a Window structure.
4747 % o annotate_context: Specifies a pointer to a GC structure.
4749 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4750 % contains the extents of any highlighting rectangle.
4753 MagickExport void XHighlightLine(Display *display,Window window,
4754 GC annotate_context,const XSegment *highlight_info)
4756 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4757 assert(display != (Display *) NULL);
4758 assert(window != (Window) NULL);
4759 assert(annotate_context != (GC) NULL);
4760 assert(highlight_info != (XSegment *) NULL);
4761 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4762 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4770 % X H i g h l i g h t R e c t a n g l e %
4774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4776 % XHighlightRectangle() puts a border on the X server around a region defined
4777 % by highlight_info.
4779 % The format of the XHighlightRectangle method is:
4781 % void XHighlightRectangle(Display *display,Window window,
4782 % GC annotate_context,const RectangleInfo *highlight_info)
4784 % A description of each parameter follows:
4786 % o display: Specifies a connection to an X server; returned from
4789 % o window: Specifies a pointer to a Window structure.
4791 % o annotate_context: Specifies a pointer to a GC structure.
4793 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4794 % contains the extents of any highlighting rectangle.
4797 MagickExport void XHighlightRectangle(Display *display,Window window,
4798 GC annotate_context,const RectangleInfo *highlight_info)
4800 assert(display != (Display *) NULL);
4801 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4802 assert(window != (Window) NULL);
4803 assert(annotate_context != (GC) NULL);
4804 assert(highlight_info != (RectangleInfo *) NULL);
4805 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4807 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4808 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4809 (unsigned int) highlight_info->height-1);
4810 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4811 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4812 (unsigned int) highlight_info->height-3);
4816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4820 % X I m p o r t I m a g e %
4824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4826 % XImportImage() reads an image from an X window.
4828 % The format of the XImportImage method is:
4830 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4832 % A description of each parameter follows:
4834 % o image_info: the image info.
4836 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4839 MagickExport Image *XImportImage(const ImageInfo *image_info,
4840 XImportInfo *ximage_info)
4873 Open X server connection.
4875 assert(image_info != (const ImageInfo *) NULL);
4876 assert(image_info->signature == MagickSignature);
4877 if (image_info->debug != MagickFalse)
4878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4879 image_info->filename);
4880 assert(ximage_info != (XImportInfo *) NULL);
4881 display=XOpenDisplay(image_info->server_name);
4882 if (display == (Display *) NULL)
4884 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4885 XDisplayName(image_info->server_name));
4886 return((Image *) NULL);
4889 Set our forgiving exception handler.
4891 (void) XSetErrorHandler(XError);
4893 Select target window.
4899 root=XRootWindow(display,XDefaultScreen(display));
4900 target=(Window) NULL;
4901 if ((image_info->filename != (char *) NULL) &&
4902 (*image_info->filename != '\0'))
4904 if (LocaleCompare(image_info->filename,"root") == 0)
4909 Select window by ID or name.
4911 if (isdigit((unsigned char) *image_info->filename) != 0)
4912 target=XWindowByID(display,root,(Window)
4913 strtol(image_info->filename,(char **) NULL,0));
4914 if (target == (Window) NULL)
4915 target=XWindowByName(display,root,image_info->filename);
4916 if (target == (Window) NULL)
4917 ThrowXWindowFatalException(XServerError,
4918 "NoWindowWithSpecifiedIDExists",image_info->filename);
4922 If target window is not defined, interactively select one.
4924 prior_target=target;
4925 if (target == (Window) NULL)
4926 target=XSelectWindow(display,&crop_info);
4927 if (target == (Window) NULL)
4928 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4929 image_info->filename);
4930 client=target; /* obsolete */
4936 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4937 if (status != False)
4945 Find window manager frame.
4947 status=XQueryTree(display,target,&root,&parent,&children,&d);
4948 if ((status != False) && (children != (Window *) NULL))
4949 (void) XFree((char *) children);
4950 if ((status == False) || (parent == (Window) NULL) ||
4958 client=XClientWindow(display,target);
4959 if (ximage_info->frame == MagickFalse)
4961 if ((ximage_info->frame == MagickFalse) &&
4962 (prior_target != MagickFalse))
4963 target=prior_target;
4964 XDelay(display,SuspendTime << 4);
4967 if (ximage_info->screen)
4979 Obtain window image directly from screen.
4981 status=XGetWindowAttributes(display,target,&window_attributes);
4982 if (status == False)
4984 ThrowXWindowFatalException(XServerError,
4985 "UnableToReadXWindowAttributes",image_info->filename);
4986 (void) XCloseDisplay(display);
4987 return((Image *) NULL);
4989 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4990 crop_info.x=(ssize_t) x;
4991 crop_info.y=(ssize_t) y;
4992 crop_info.width=(size_t) window_attributes.width;
4993 crop_info.height=(size_t) window_attributes.height;
4994 if (ximage_info->borders != 0)
4997 Include border in image.
4999 crop_info.x-=window_attributes.border_width;
5000 crop_info.y-=window_attributes.border_width;
5001 crop_info.width+=window_attributes.border_width << 1;
5002 crop_info.height+=window_attributes.border_width << 1;
5007 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
5010 status=XGetWMColormapWindows(display,target,&children,&number_windows);
5011 if ((status == True) && (number_windows > 0))
5013 ximage_info->descend=MagickTrue;
5014 (void) XFree ((char *) children);
5016 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
5017 if (number_colormaps > 0)
5019 if (number_colormaps > 1)
5020 ximage_info->descend=MagickTrue;
5021 (void) XFree((char *) colormaps);
5024 Alert the user not to alter the screen.
5026 if (ximage_info->silent == MagickFalse)
5027 (void) XBell(display,0);
5029 Get image by window id.
5031 (void) XGrabServer(display);
5032 image=XGetWindowImage(display,target,ximage_info->borders,
5033 ximage_info->descend ? 1U : 0U);
5034 (void) XUngrabServer(display);
5035 if (image == (Image *) NULL)
5036 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
5037 image_info->filename)
5040 (void) CopyMagickString(image->filename,image_info->filename,
5042 if ((crop_info.width != 0) && (crop_info.height != 0))
5049 Crop image as defined by the cropping rectangle.
5051 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5052 if (clone_image != (Image *) NULL)
5054 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5055 if (crop_image != (Image *) NULL)
5057 image=DestroyImage(image);
5062 status=XGetWMName(display,target,&window_name);
5065 if ((image_info->filename != (char *) NULL) &&
5066 (*image_info->filename == '\0'))
5067 (void) CopyMagickString(image->filename,(char *) window_name.value,
5068 (size_t) window_name.nitems+1);
5069 (void) XFree((void *) window_name.value);
5072 if (ximage_info->silent == MagickFalse)
5075 Alert the user we're done.
5077 (void) XBell(display,0);
5078 (void) XBell(display,0);
5080 (void) XCloseDisplay(display);
5085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5089 % X I n i t i a l i z e W i n d o w s %
5093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5095 % XInitializeWindows() initializes the XWindows structure.
5097 % The format of the XInitializeWindows method is:
5099 % XWindows *XInitializeWindows(Display *display,
5100 % XResourceInfo *resource_info)
5102 % A description of each parameter follows:
5104 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5106 % o display: Specifies a connection to an X server; returned from
5109 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5112 MagickExport XWindows *XInitializeWindows(Display *display,
5113 XResourceInfo *resource_info)
5122 Allocate windows structure.
5124 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5125 if (windows == (XWindows *) NULL)
5127 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5129 return((XWindows *) NULL);
5131 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5132 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5133 sizeof(*windows->pixel_info));
5134 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5135 sizeof(*windows->icon_pixel));
5136 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5137 sizeof(*windows->icon_resources));
5138 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5139 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5140 (windows->icon_resources == (XResourceInfo *) NULL))
5142 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5144 return((XWindows *) NULL);
5147 Initialize windows structure.
5149 windows->display=display;
5150 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5151 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5152 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5153 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5154 windows->im_remote_command=
5155 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5156 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5157 windows->im_update_colormap=
5158 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5159 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5160 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5161 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5162 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5163 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5164 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
5165 (void) XSynchronize(display,IsWindows95());
5167 if (IsEventLogging())
5169 (void) XSynchronize(display,MagickTrue);
5170 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5171 GetMagickVersion((size_t *) NULL));
5172 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5173 (void) LogMagickEvent(X11Event,GetMagickModule(),
5174 " Window Manager: 0x%lx",windows->wm_protocols);
5175 (void) LogMagickEvent(X11Event,GetMagickModule(),
5176 " delete window: 0x%lx",windows->wm_delete_window);
5177 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5178 windows->wm_take_focus);
5179 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5180 windows->im_protocols);
5181 (void) LogMagickEvent(X11Event,GetMagickModule(),
5182 " remote command: 0x%lx",windows->im_remote_command);
5183 (void) LogMagickEvent(X11Event,GetMagickModule(),
5184 " update widget: 0x%lx",windows->im_update_widget);
5185 (void) LogMagickEvent(X11Event,GetMagickModule(),
5186 " update colormap: 0x%lx",windows->im_update_colormap);
5187 (void) LogMagickEvent(X11Event,GetMagickModule(),
5188 " former image: 0x%lx",windows->im_former_image);
5189 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5190 windows->im_next_image);
5191 (void) LogMagickEvent(X11Event,GetMagickModule(),
5192 " retain colors: 0x%lx",windows->im_retain_colors);
5193 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5195 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5196 windows->dnd_protocols);
5199 Allocate standard colormap.
5201 windows->map_info=XAllocStandardColormap();
5202 windows->icon_map=XAllocStandardColormap();
5203 if ((windows->map_info == (XStandardColormap *) NULL) ||
5204 (windows->icon_map == (XStandardColormap *) NULL))
5205 ThrowXWindowFatalException(ResourceLimitFatalError,
5206 "MemoryAllocationFailed","...");
5207 windows->map_info->colormap=(Colormap) NULL;
5208 windows->icon_map->colormap=(Colormap) NULL;
5209 windows->pixel_info->pixels=(unsigned long *) NULL;
5210 windows->pixel_info->annotate_context=(GC) NULL;
5211 windows->pixel_info->highlight_context=(GC) NULL;
5212 windows->pixel_info->widget_context=(GC) NULL;
5213 windows->font_info=(XFontStruct *) NULL;
5214 windows->icon_pixel->annotate_context=(GC) NULL;
5215 windows->icon_pixel->pixels=(unsigned long *) NULL;
5219 *windows->icon_resources=(*resource_info);
5220 windows->icon_resources->visual_type=(char *) "default";
5221 windows->icon_resources->colormap=SharedColormap;
5222 windows->visual_info=
5223 XBestVisualInfo(display,windows->map_info,resource_info);
5224 windows->icon_visual=
5225 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5226 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5227 (windows->icon_visual == (XVisualInfo *) NULL))
5228 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5229 resource_info->visual_type);
5230 if (IsEventLogging())
5232 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5233 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5234 windows->visual_info->visualid);
5235 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5236 XVisualClassName(windows->visual_info->klass));
5237 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5238 windows->visual_info->depth);
5239 (void) LogMagickEvent(X11Event,GetMagickModule(),
5240 " size of colormap: %d entries",windows->visual_info->colormap_size);
5241 (void) LogMagickEvent(X11Event,GetMagickModule(),
5242 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5243 windows->visual_info->red_mask,windows->visual_info->green_mask,
5244 windows->visual_info->blue_mask);
5245 (void) LogMagickEvent(X11Event,GetMagickModule(),
5246 " significant bits in color: %d bits",
5247 windows->visual_info->bits_per_rgb);
5250 Allocate class and manager hints.
5252 windows->class_hints=XAllocClassHint();
5253 windows->manager_hints=XAllocWMHints();
5254 if ((windows->class_hints == (XClassHint *) NULL) ||
5255 (windows->manager_hints == (XWMHints *) NULL))
5256 ThrowXWindowFatalException(ResourceLimitFatalError,
5257 "MemoryAllocationFailed","...");
5259 Determine group leader if we have one.
5261 root_window=XRootWindow(display,windows->visual_info->screen);
5262 windows->group_leader.id=(Window) NULL;
5263 if (resource_info->window_group != (char *) NULL)
5265 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5266 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5267 strtol((char *) resource_info->window_group,(char **) NULL,0));
5268 if (windows->group_leader.id == (Window) NULL)
5269 windows->group_leader.id=
5270 XWindowByName(display,root_window,resource_info->window_group);
5276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5280 % X M a k e C u r s o r %
5284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5286 % XMakeCursor() creates a crosshairs X11 cursor.
5288 % The format of the XMakeCursor method is:
5290 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5291 % char *background_color,char *foreground_color)
5293 % A description of each parameter follows:
5295 % o display: Specifies a connection to an X server; returned from
5298 % o window: Specifies the ID of the window for which the cursor is
5301 % o colormap: Specifies the ID of the colormap from which the background
5302 % and foreground color will be retrieved.
5304 % o background_color: Specifies the color to use for the cursor background.
5306 % o foreground_color: Specifies the color to use for the cursor foreground.
5309 MagickExport Cursor XMakeCursor(Display *display,Window window,
5310 Colormap colormap,char *background_color,char *foreground_color)
5312 #define scope_height 17
5313 #define scope_x_hot 8
5314 #define scope_y_hot 8
5315 #define scope_width 17
5317 static const unsigned char
5320 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5321 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5322 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5323 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5324 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5328 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5329 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5330 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5331 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5332 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5346 assert(display != (Display *) NULL);
5347 assert(window != (Window) NULL);
5348 assert(colormap != (Colormap) NULL);
5349 assert(background_color != (char *) NULL);
5350 assert(foreground_color != (char *) NULL);
5351 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5352 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5354 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5355 scope_width,scope_height);
5356 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5358 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5359 return((Cursor) NULL);
5361 (void) XParseColor(display,colormap,background_color,&background);
5362 (void) XParseColor(display,colormap,foreground_color,&foreground);
5363 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5364 scope_x_hot,scope_y_hot);
5365 (void) XFreePixmap(display,source);
5366 (void) XFreePixmap(display,mask);
5371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5375 % X M a k e I m a g e %
5379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5381 % XMakeImage() creates an X11 image. If the image size differs from the X11
5382 % image size, the image is first resized.
5384 % The format of the XMakeImage method is:
5386 % MagickBooleanType XMakeImage(Display *display,
5387 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5388 % unsigned int width,unsigned int height)
5390 % A description of each parameter follows:
5392 % o display: Specifies a connection to an X server; returned from
5395 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5397 % o window: Specifies a pointer to a XWindowInfo structure.
5399 % o image: the image.
5401 % o width: Specifies the width in pixels of the rectangular area to
5404 % o height: Specifies the height in pixels of the rectangular area to
5408 MagickExport MagickBooleanType XMakeImage(Display *display,
5409 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5410 unsigned int width,unsigned int height)
5412 #define CheckOverflowException(length,width,height) \
5413 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5427 assert(display != (Display *) NULL);
5428 assert(resource_info != (XResourceInfo *) NULL);
5429 assert(window != (XWindowInfo *) NULL);
5431 assert(height != 0);
5432 if ((window->width == 0) || (window->height == 0))
5433 return(MagickFalse);
5435 Apply user transforms to the image.
5437 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5438 (void) XFlush(display);
5439 depth=(int) window->depth;
5440 if (window->destroy)
5441 window->image=DestroyImage(window->image);
5442 window->image=image;
5443 window->destroy=MagickFalse;
5444 if (window->image != (Image *) NULL)
5446 if (window->crop_geometry != (char *) NULL)
5457 window->image->page.x=0;
5458 window->image->page.y=0;
5459 (void) ParsePageGeometry(window->image,window->crop_geometry,
5460 &crop_info,&image->exception);
5461 crop_image=CropImage(window->image,&crop_info,&image->exception);
5462 if (crop_image != (Image *) NULL)
5464 if (window->image != image)
5465 window->image=DestroyImage(window->image);
5466 window->image=crop_image;
5467 window->destroy=MagickTrue;
5470 if ((width != (unsigned int) window->image->columns) ||
5471 (height != (unsigned int) window->image->rows))
5479 resize_image=NewImageList();
5480 if (window->pixel_info->colors != 0)
5481 resize_image=SampleImage(window->image,width,height,
5484 resize_image=ThumbnailImage(window->image,width,height,
5486 if (resize_image != (Image *) NULL)
5488 if (window->image != image)
5489 window->image=DestroyImage(window->image);
5490 window->image=resize_image;
5491 window->destroy=MagickTrue;
5494 width=(unsigned int) window->image->columns;
5495 assert((size_t) width == window->image->columns);
5496 height=(unsigned int) window->image->rows;
5497 assert((size_t) height == window->image->rows);
5502 ximage=(XImage *) NULL;
5503 format=(depth == 1) ? XYBitmap : ZPixmap;
5504 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5505 if (window->shared_memory != MagickFalse)
5510 segment_info=(XShmSegmentInfo *) window->segment_info;
5511 segment_info[1].shmid=(-1);
5512 segment_info[1].shmaddr=(char *) NULL;
5513 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5514 (char *) NULL,&segment_info[1],width,height);
5515 if (ximage == (XImage *) NULL)
5516 window->shared_memory=MagickFalse;
5517 length=(size_t) ximage->bytes_per_line*ximage->height;
5518 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5519 window->shared_memory=MagickFalse;
5520 if (window->shared_memory != MagickFalse)
5521 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5522 if (window->shared_memory != MagickFalse)
5523 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5524 if (segment_info[1].shmid < 0)
5525 window->shared_memory=MagickFalse;
5526 if (window->shared_memory != MagickFalse)
5527 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5530 if (ximage != (XImage *) NULL)
5531 XDestroyImage(ximage);
5532 ximage=(XImage *) NULL;
5533 if (segment_info[1].shmaddr)
5535 (void) shmdt(segment_info[1].shmaddr);
5536 segment_info[1].shmaddr=(char *) NULL;
5538 if (segment_info[1].shmid >= 0)
5540 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5541 segment_info[1].shmid=(-1);
5547 Allocate X image pixel data.
5549 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5550 if (window->shared_memory)
5558 (void) XSync(display,MagickFalse);
5559 xerror_alert=MagickFalse;
5560 segment_info=(XShmSegmentInfo *) window->segment_info;
5561 ximage->data=segment_info[1].shmaddr;
5562 segment_info[1].readOnly=MagickFalse;
5563 status=XShmAttach(display,&segment_info[1]);
5564 if (status != False)
5565 (void) XSync(display,MagickFalse);
5566 if ((status == False) || (xerror_alert != MagickFalse))
5568 window->shared_memory=MagickFalse;
5569 if (status != False)
5570 XShmDetach(display,&segment_info[1]);
5571 if (ximage != (XImage *) NULL)
5574 XDestroyImage(ximage);
5575 ximage=(XImage *) NULL;
5577 if (segment_info[1].shmid >= 0)
5579 if (segment_info[1].shmaddr != NULL)
5580 (void) shmdt(segment_info[1].shmaddr);
5581 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5582 segment_info[1].shmid=(-1);
5583 segment_info[1].shmaddr=(char *) NULL;
5588 if (window->shared_memory == MagickFalse)
5589 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5590 (char *) NULL,width,height,XBitmapPad(display),0);
5591 if (ximage == (XImage *) NULL)
5594 Unable to create X image.
5596 (void) XCheckDefineCursor(display,window->id,window->cursor);
5597 return(MagickFalse);
5599 length=(size_t) ximage->bytes_per_line*ximage->height;
5600 if (IsEventLogging())
5602 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5603 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5604 ximage->width,ximage->height);
5605 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5607 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5608 ximage->byte_order);
5609 (void) LogMagickEvent(X11Event,GetMagickModule(),
5610 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5611 ximage->bitmap_bit_order,ximage->bitmap_pad);
5612 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5614 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5615 ximage->bytes_per_line);
5616 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5617 ximage->bits_per_pixel);
5618 (void) LogMagickEvent(X11Event,GetMagickModule(),
5619 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5620 ximage->green_mask,ximage->blue_mask);
5622 if (window->shared_memory == MagickFalse)
5624 if (ximage->format != XYBitmap)
5625 ximage->data=(char *) AcquireQuantumMemory((size_t)
5626 ximage->bytes_per_line,(size_t) ximage->height);
5628 ximage->data=(char *) AcquireQuantumMemory((size_t)
5629 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5631 if (ximage->data == (char *) NULL)
5634 Unable to allocate pixel data.
5636 XDestroyImage(ximage);
5637 ximage=(XImage *) NULL;
5638 (void) XCheckDefineCursor(display,window->id,window->cursor);
5639 return(MagickFalse);
5641 if (window->ximage != (XImage *) NULL)
5644 Destroy previous X image.
5646 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5647 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5648 if (window->segment_info != (XShmSegmentInfo *) NULL)
5653 segment_info=(XShmSegmentInfo *) window->segment_info;
5654 if (segment_info[0].shmid >= 0)
5656 (void) XSync(display,MagickFalse);
5657 (void) XShmDetach(display,&segment_info[0]);
5658 (void) XSync(display,MagickFalse);
5659 if (segment_info[0].shmaddr != (char *) NULL)
5660 (void) shmdt(segment_info[0].shmaddr);
5661 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5662 segment_info[0].shmid=(-1);
5663 segment_info[0].shmaddr=(char *) NULL;
5664 window->ximage->data=(char *) NULL;
5668 if (window->ximage->data != (char *) NULL)
5669 free(window->ximage->data);
5670 window->ximage->data=(char *) NULL;
5671 XDestroyImage(window->ximage);
5672 window->ximage=(XImage *) NULL;
5674 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5675 if (window->segment_info != (XShmSegmentInfo *) NULL)
5680 segment_info=(XShmSegmentInfo *) window->segment_info;
5681 segment_info[0]=segment_info[1];
5684 window->ximage=ximage;
5685 matte_image=(XImage *) NULL;
5686 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5687 if ((window->image->matte != MagickFalse) &&
5688 ((int) width <= XDisplayWidth(display,window->screen)) &&
5689 ((int) height <= XDisplayHeight(display,window->screen)))
5694 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5695 (char *) NULL,width,height,XBitmapPad(display),0);
5696 if (IsEventLogging())
5698 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5699 (void) LogMagickEvent(X11Event,GetMagickModule(),
5700 " width, height: %dx%d",matte_image->width,matte_image->height);
5702 if (matte_image != (XImage *) NULL)
5705 Allocate matte image pixel data.
5707 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5708 matte_image->bytes_per_line*matte_image->depth,
5709 (size_t) matte_image->height);
5710 if (matte_image->data == (char *) NULL)
5712 XDestroyImage(matte_image);
5713 matte_image=(XImage *) NULL;
5717 if (window->matte_image != (XImage *) NULL)
5722 if (window->matte_image->data != (char *) NULL)
5723 free(window->matte_image->data);
5724 window->matte_image->data=(char *) NULL;
5725 XDestroyImage(window->matte_image);
5726 window->matte_image=(XImage *) NULL;
5728 window->matte_image=matte_image;
5729 if (window->matte_pixmap != (Pixmap) NULL)
5731 (void) XFreePixmap(display,window->matte_pixmap);
5732 window->matte_pixmap=(Pixmap) NULL;
5733 #if defined(MAGICKCORE_HAVE_SHAPE)
5734 if (window->shape != MagickFalse)
5735 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5738 window->stasis=MagickFalse;
5740 Convert pixels to X image data.
5742 if (window->image != (Image *) NULL)
5744 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5745 (ximage->bitmap_bit_order == LSBFirst)))
5746 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5749 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5752 if (window->matte_image != (XImage *) NULL)
5755 Create matte pixmap.
5757 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5758 if (window->matte_pixmap != (Pixmap) NULL)
5767 Copy matte image to matte pixmap.
5769 context_values.background=1;
5770 context_values.foreground=0;
5771 graphics_context=XCreateGC(display,window->matte_pixmap,
5772 (size_t) (GCBackground | GCForeground),&context_values);
5773 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5774 window->matte_image,0,0,0,0,width,height);
5775 (void) XFreeGC(display,graphics_context);
5776 #if defined(MAGICKCORE_HAVE_SHAPE)
5777 if (window->shape != MagickFalse)
5778 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5779 window->matte_pixmap,ShapeSet);
5783 (void) XMakePixmap(display,resource_info,window);
5787 (void) XCheckDefineCursor(display,window->id,window->cursor);
5792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5796 + X M a k e I m a g e L S B F i r s t %
5800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5802 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5803 % pixels are copied in least-significant bit and byte first order. The
5804 % server's scanline pad is respected. Rather than using one or two general
5805 % cases, many special cases are found here to help speed up the image
5808 % The format of the XMakeImageLSBFirst method is:
5810 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5812 % A description of each parameter follows:
5814 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5816 % o window: Specifies a pointer to a XWindowInfo structure.
5818 % o image: the image.
5820 % o ximage: Specifies a pointer to a XImage structure; returned from
5823 % o matte_image: Specifies a pointer to a XImage structure; returned from
5827 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5828 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5839 register const IndexPacket
5842 register const PixelPacket
5848 register unsigned char
5865 assert(resource_info != (XResourceInfo *) NULL);
5866 assert(window != (XWindowInfo *) NULL);
5867 assert(image != (Image *) NULL);
5868 if (image->debug != MagickFalse)
5869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5871 if ((window->immutable == MagickFalse) &&
5872 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
5875 size[MaxTextExtent];
5883 image_info=AcquireImageInfo();
5884 (void) CopyMagickString(image_info->filename,
5885 resource_info->image_info->texture != (char *) NULL ?
5886 resource_info->image_info->texture : "pattern:checkerboard",
5888 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5889 image->columns,(double) image->rows);
5890 image_info->size=ConstantString(size);
5891 pattern=ReadImage(image_info,&image->exception);
5892 image_info=DestroyImageInfo(image_info);
5893 if (pattern != (Image *) NULL)
5895 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5896 if (canvas != (Image *) NULL)
5897 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5898 pattern=DestroyImage(pattern);
5901 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5902 ximage->bits_per_pixel) >> 3));
5903 map_info=window->map_info;
5904 pixels=window->pixel_info->pixels;
5905 q=(unsigned char *) ximage->data;
5907 canvas_view=AcquireCacheView(canvas);
5908 if (ximage->format == XYBitmap)
5910 register unsigned short
5918 Convert canvas to big-endian bitmap.
5920 background=(unsigned char)
5921 (XPixelIntensity(&window->pixel_info->foreground_color) <
5922 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5923 foreground=(unsigned char)
5924 (XPixelIntensity(&window->pixel_info->background_color) <
5925 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5926 polarity=(unsigned short) ((PixelIntensityToQuantum(
5927 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5928 if (canvas->colors == 2)
5929 polarity=PixelIntensity(&canvas->colormap[0]) <
5930 PixelIntensity(&canvas->colormap[1]);
5931 for (y=0; y < (int) canvas->rows; y++)
5933 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
5934 &canvas->exception);
5935 if (p == (const PixelPacket *) NULL)
5937 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5940 for (x=0; x < (int) canvas->columns; x++)
5943 if (GetIndexPixelComponent(indexes+x) == (IndexPacket) polarity)
5961 if (window->pixel_info->colors != 0)
5962 switch (ximage->bits_per_pixel)
5966 register unsigned int
5970 Convert to 2 bit color-mapped X canvas.
5972 for (y=0; y < (int) canvas->rows; y++)
5974 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
5975 canvas->columns,1,&canvas->exception);
5976 if (p == (const PixelPacket *) NULL)
5978 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
5980 for (x=0; x < (int) canvas->columns; x++)
5982 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)] & 0x0f;
5987 *q=(unsigned char) pixel;
5993 *q|=(unsigned char) (pixel << 2);
5999 *q|=(unsigned char) (pixel << 4);
6005 *q|=(unsigned char) (pixel << 6);
6018 register unsigned int
6022 Convert to 4 bit color-mapped X canvas.
6024 for (y=0; y < (int) canvas->rows; y++)
6026 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6027 canvas->columns,1,&canvas->exception);
6028 if (p == (const PixelPacket *) NULL)
6030 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6032 for (x=0; x < (int) canvas->columns; x++)
6034 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)] & 0xf;
6039 *q=(unsigned char) pixel;
6045 *q|=(unsigned char) (pixel << 4);
6060 Convert to 8 bit color-mapped X canvas.
6062 if (resource_info->color_recovery &&
6063 resource_info->quantize_info->dither)
6065 XDitherImage(canvas,ximage);
6068 for (y=0; y < (int) canvas->rows; y++)
6070 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6071 canvas->columns,1,&canvas->exception);
6072 if (p == (const PixelPacket *) NULL)
6074 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6075 for (x=0; x < (int) canvas->columns; x++)
6077 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)];
6078 *q++=(unsigned char) pixel;
6089 register unsigned int
6093 channel[sizeof(size_t)];
6096 Convert to multi-byte color-mapped X canvas.
6098 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6099 for (y=0; y < (int) canvas->rows; y++)
6101 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6102 canvas->columns,1,&canvas->exception);
6103 if (p == (const PixelPacket *) NULL)
6105 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6106 for (x=0; x < (int) canvas->columns; x++)
6108 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)];
6109 for (k=0; k < (int) bytes_per_pixel; k++)
6111 channel[k]=(unsigned char) pixel;
6114 for (k=0; k < (int) bytes_per_pixel; k++)
6123 switch (ximage->bits_per_pixel)
6127 register unsigned int
6131 Convert to contiguous 2 bit continuous-tone X canvas.
6133 for (y=0; y < (int) canvas->rows; y++)
6136 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6137 canvas->columns,1,&canvas->exception);
6138 if (p == (const PixelPacket *) NULL)
6140 for (x=0; x < (int) canvas->columns; x++)
6142 pixel=XGammaPixel(map_info,p);
6148 *q=(unsigned char) pixel;
6154 *q|=(unsigned char) (pixel << 2);
6160 *q|=(unsigned char) (pixel << 4);
6166 *q|=(unsigned char) (pixel << 6);
6180 register unsigned int
6184 Convert to contiguous 4 bit continuous-tone X canvas.
6186 for (y=0; y < (int) canvas->rows; y++)
6188 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6189 canvas->columns,1,&canvas->exception);
6190 if (p == (const PixelPacket *) NULL)
6193 for (x=0; x < (int) canvas->columns; x++)
6195 pixel=XGammaPixel(map_info,p);
6201 *q=(unsigned char) pixel;
6207 *q|=(unsigned char) (pixel << 4);
6223 Convert to contiguous 8 bit continuous-tone X canvas.
6225 if (resource_info->color_recovery &&
6226 resource_info->quantize_info->dither)
6228 XDitherImage(canvas,ximage);
6231 for (y=0; y < (int) canvas->rows; y++)
6233 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6234 canvas->columns,1,&canvas->exception);
6235 if (p == (const PixelPacket *) NULL)
6237 for (x=0; x < (int) canvas->columns; x++)
6239 pixel=XGammaPixel(map_info,p);
6240 *q++=(unsigned char) pixel;
6249 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6250 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6251 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6252 (map_info->blue_mult == 1))
6255 Convert to 32 bit continuous-tone X canvas.
6257 for (y=0; y < (int) canvas->rows; y++)
6259 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6260 canvas->columns,1,&canvas->exception);
6261 if (p == (const PixelPacket *) NULL)
6263 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6264 (blue_gamma != 1.0))
6267 Gamma correct canvas.
6269 for (x=(int) canvas->columns-1; x >= 0; x--)
6271 *q++=ScaleQuantumToChar(XBlueGamma(
6272 GetBluePixelComponent(p)));
6273 *q++=ScaleQuantumToChar(XGreenGamma(
6274 GetGreenPixelComponent(p)));
6275 *q++=ScaleQuantumToChar(XRedGamma(
6276 GetRedPixelComponent(p)));
6282 for (x=(int) canvas->columns-1; x >= 0; x--)
6284 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6285 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6286 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6293 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6294 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6295 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6296 (map_info->blue_mult == 65536L))
6299 Convert to 32 bit continuous-tone X canvas.
6301 for (y=0; y < (int) canvas->rows; y++)
6303 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6304 canvas->columns,1,&canvas->exception);
6305 if (p == (const PixelPacket *) NULL)
6307 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6308 (blue_gamma != 1.0))
6311 Gamma correct canvas.
6313 for (x=(int) canvas->columns-1; x >= 0; x--)
6315 *q++=ScaleQuantumToChar(XRedGamma(
6316 GetRedPixelComponent(p)));
6317 *q++=ScaleQuantumToChar(XGreenGamma(
6318 GetGreenPixelComponent(p)));
6319 *q++=ScaleQuantumToChar(XBlueGamma(
6320 GetBluePixelComponent(p)));
6326 for (x=(int) canvas->columns-1; x >= 0; x--)
6328 *q++=ScaleQuantumToChar((Quantum)
6329 GetRedPixelComponent(p));
6330 *q++=ScaleQuantumToChar((Quantum)
6331 GetGreenPixelComponent(p));
6332 *q++=ScaleQuantumToChar((Quantum)
6333 GetBluePixelComponent(p));
6344 register unsigned int
6348 channel[sizeof(size_t)];
6351 Convert to multi-byte continuous-tone X canvas.
6353 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6354 for (y=0; y < (int) canvas->rows; y++)
6356 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6357 canvas->columns,1,&canvas->exception);
6358 if (p == (PixelPacket *) NULL)
6360 for (x=0; x < (int) canvas->columns; x++)
6362 pixel=XGammaPixel(map_info,p);
6363 for (k=0; k < (int) bytes_per_pixel; k++)
6365 channel[k]=(unsigned char) pixel;
6368 for (k=0; k < (int) bytes_per_pixel; k++)
6378 if (matte_image != (XImage *) NULL)
6381 Initialize matte canvas.
6383 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6384 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6385 q=(unsigned char *) matte_image->data;
6386 for (y=0; y < (int) canvas->rows; y++)
6388 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6389 &canvas->exception);
6390 if (p == (const PixelPacket *) NULL)
6394 for (x=(int) canvas->columns-1; x >= 0; x--)
6397 if (GetOpacityPixelComponent(p) > (QuantumRange/2))
6413 canvas_view=DestroyCacheView(canvas_view);
6414 if (canvas != image)
6415 canvas=DestroyImage(canvas);
6419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6423 + X M a k e I m a g e M S B F i r s t %
6427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6429 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6430 % image pixels are copied in most-significant bit and byte first order. The
6431 % server's scanline pad is also respected. Rather than using one or two
6432 % general cases, many special cases are found here to help speed up the image
6435 % The format of the XMakeImageMSBFirst method is:
6437 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6439 % A description of each parameter follows:
6441 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6443 % o window: Specifies a pointer to a XWindowInfo structure.
6445 % o image: the image.
6447 % o ximage: Specifies a pointer to a XImage structure; returned from
6450 % o matte_image: Specifies a pointer to a XImage structure; returned from
6454 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6455 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6469 register const IndexPacket
6472 register const PixelPacket
6475 register unsigned char
6492 assert(resource_info != (XResourceInfo *) NULL);
6493 assert(window != (XWindowInfo *) NULL);
6494 assert(image != (Image *) NULL);
6495 if (image->debug != MagickFalse)
6496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6498 if ((window->immutable != MagickFalse) &&
6499 (image->storage_class == DirectClass) && (image->matte != MagickFalse))
6502 size[MaxTextExtent];
6510 image_info=AcquireImageInfo();
6511 (void) CopyMagickString(image_info->filename,
6512 resource_info->image_info->texture != (char *) NULL ?
6513 resource_info->image_info->texture : "pattern:checkerboard",
6515 (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6516 image->columns,(double) image->rows);
6517 image_info->size=ConstantString(size);
6518 pattern=ReadImage(image_info,&image->exception);
6519 image_info=DestroyImageInfo(image_info);
6520 if (pattern != (Image *) NULL)
6522 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6523 if (canvas != (Image *) NULL)
6524 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6525 pattern=DestroyImage(pattern);
6528 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6529 ((ximage->width*ximage->bits_per_pixel) >> 3));
6530 map_info=window->map_info;
6531 pixels=window->pixel_info->pixels;
6532 q=(unsigned char *) ximage->data;
6534 canvas_view=AcquireCacheView(canvas);
6535 if (ximage->format == XYBitmap)
6537 register unsigned short
6545 Convert canvas to big-endian bitmap.
6547 background=(unsigned char)
6548 (XPixelIntensity(&window->pixel_info->foreground_color) <
6549 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6550 foreground=(unsigned char)
6551 (XPixelIntensity(&window->pixel_info->background_color) <
6552 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6553 polarity=(unsigned short) ((PixelIntensityToQuantum(
6554 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6555 if (canvas->colors == 2)
6556 polarity=PixelIntensity(&canvas->colormap[0]) <
6557 PixelIntensity(&canvas->colormap[1]);
6558 for (y=0; y < (int) canvas->rows; y++)
6560 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
6561 &canvas->exception);
6562 if (p == (const PixelPacket *) NULL)
6564 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6567 for (x=(int) canvas->columns-1; x >= 0; x--)
6570 if (GetIndexPixelComponent(indexes+x) == (IndexPacket) polarity)
6588 if (window->pixel_info->colors != 0)
6589 switch (ximage->bits_per_pixel)
6593 register unsigned int
6597 Convert to 2 bit color-mapped X canvas.
6599 for (y=0; y < (int) canvas->rows; y++)
6601 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6602 canvas->columns,1,&canvas->exception);
6603 if (p == (const PixelPacket *) NULL)
6605 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6607 for (x=0; x < (int) canvas->columns; x++)
6609 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)] & 0xf;
6614 *q=(unsigned char) (pixel << 6);
6620 *q|=(unsigned char) (pixel << 4);
6626 *q|=(unsigned char) (pixel << 2);
6632 *q|=(unsigned char) pixel;
6645 register unsigned int
6649 Convert to 4 bit color-mapped X canvas.
6651 for (y=0; y < (int) canvas->rows; y++)
6653 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6654 canvas->columns,1,&canvas->exception);
6655 if (p == (const PixelPacket *) NULL)
6657 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6659 for (x=0; x < (int) canvas->columns; x++)
6661 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)] & 0xf;
6666 *q=(unsigned char) (pixel << 4);
6672 *q|=(unsigned char) pixel;
6687 Convert to 8 bit color-mapped X canvas.
6689 if (resource_info->color_recovery &&
6690 resource_info->quantize_info->dither)
6692 XDitherImage(canvas,ximage);
6695 for (y=0; y < (int) canvas->rows; y++)
6697 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6698 canvas->columns,1,&canvas->exception);
6699 if (p == (const PixelPacket *) NULL)
6701 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6702 for (x=0; x < (int) canvas->columns; x++)
6704 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)];
6705 *q++=(unsigned char) pixel;
6716 register unsigned int
6720 channel[sizeof(size_t)];
6723 Convert to 8 bit color-mapped X canvas.
6725 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6726 for (y=0; y < (int) canvas->rows; y++)
6728 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6729 canvas->columns,1,&canvas->exception);
6730 if (p == (const PixelPacket *) NULL)
6732 indexes=GetCacheViewVirtualIndexQueue(canvas_view);
6733 for (x=0; x < (int) canvas->columns; x++)
6735 pixel=pixels[(ssize_t) GetIndexPixelComponent(indexes+x)];
6736 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6738 channel[k]=(unsigned char) pixel;
6741 for (k=0; k < (int) bytes_per_pixel; k++)
6750 switch (ximage->bits_per_pixel)
6754 register unsigned int
6758 Convert to 4 bit continuous-tone X canvas.
6760 for (y=0; y < (int) canvas->rows; y++)
6762 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6763 canvas->columns,1,&canvas->exception);
6764 if (p == (const PixelPacket *) NULL)
6767 for (x=(int) canvas->columns-1; x >= 0; x--)
6769 pixel=XGammaPixel(map_info,p);
6775 *q=(unsigned char) (pixel << 6);
6781 *q|=(unsigned char) (pixel << 4);
6787 *q|=(unsigned char) (pixel << 2);
6793 *q|=(unsigned char) pixel;
6807 register unsigned int
6811 Convert to 4 bit continuous-tone X canvas.
6813 for (y=0; y < (int) canvas->rows; y++)
6815 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6816 canvas->columns,1,&canvas->exception);
6817 if (p == (const PixelPacket *) NULL)
6820 for (x=(int) canvas->columns-1; x >= 0; x--)
6822 pixel=XGammaPixel(map_info,p);
6828 *q=(unsigned char) (pixel << 4);
6834 *q|=(unsigned char) pixel;
6850 Convert to 8 bit continuous-tone X canvas.
6852 if (resource_info->color_recovery &&
6853 resource_info->quantize_info->dither)
6855 XDitherImage(canvas,ximage);
6858 for (y=0; y < (int) canvas->rows; y++)
6860 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6861 canvas->columns,1,&canvas->exception);
6862 if (p == (const PixelPacket *) NULL)
6864 for (x=(int) canvas->columns-1; x >= 0; x--)
6866 pixel=XGammaPixel(map_info,p);
6867 *q++=(unsigned char) pixel;
6876 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6877 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6878 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6879 (map_info->blue_mult == 1))
6882 Convert to 32 bit continuous-tone X canvas.
6884 for (y=0; y < (int) canvas->rows; y++)
6886 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6887 canvas->columns,1,&canvas->exception);
6888 if (p == (const PixelPacket *) NULL)
6890 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6891 (blue_gamma != 1.0))
6894 Gamma correct canvas.
6896 for (x=(int) canvas->columns-1; x >= 0; x--)
6899 *q++=ScaleQuantumToChar(XRedGamma(
6900 GetRedPixelComponent(p)));
6901 *q++=ScaleQuantumToChar(XGreenGamma(
6902 GetGreenPixelComponent(p)));
6903 *q++=ScaleQuantumToChar(XBlueGamma(
6904 GetBluePixelComponent(p)));
6909 for (x=(int) canvas->columns-1; x >= 0; x--)
6912 *q++=ScaleQuantumToChar((Quantum) GetRedPixelComponent(p));
6913 *q++=ScaleQuantumToChar((Quantum) GetGreenPixelComponent(p));
6914 *q++=ScaleQuantumToChar((Quantum) GetBluePixelComponent(p));
6920 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6921 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6922 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6923 (map_info->blue_mult == 65536L))
6926 Convert to 32 bit continuous-tone X canvas.
6928 for (y=0; y < (int) canvas->rows; y++)
6930 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6931 canvas->columns,1,&canvas->exception);
6932 if (p == (const PixelPacket *) NULL)
6934 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6935 (blue_gamma != 1.0))
6938 Gamma correct canvas.
6940 for (x=(int) canvas->columns-1; x >= 0; x--)
6943 *q++=ScaleQuantumToChar(XBlueGamma(
6944 GetBluePixelComponent(p)));
6945 *q++=ScaleQuantumToChar(XGreenGamma(
6946 GetGreenPixelComponent(p)));
6947 *q++=ScaleQuantumToChar(XRedGamma(
6948 GetRedPixelComponent(p)));
6953 for (x=(int) canvas->columns-1; x >= 0; x--)
6956 *q++=ScaleQuantumToChar((Quantum)
6957 GetBluePixelComponent(p));
6958 *q++=ScaleQuantumToChar((Quantum)
6959 GetGreenPixelComponent(p));
6960 *q++=ScaleQuantumToChar((Quantum)
6961 GetRedPixelComponent(p));
6971 register unsigned int
6975 channel[sizeof(size_t)];
6978 Convert to multi-byte continuous-tone X canvas.
6980 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6981 for (y=0; y < (int) canvas->rows; y++)
6983 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
6984 canvas->columns,1,&canvas->exception);
6985 if (p == (const PixelPacket *) NULL)
6987 for (x=(int) canvas->columns-1; x >= 0; x--)
6989 pixel=XGammaPixel(map_info,p);
6990 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6992 channel[k]=(unsigned char) pixel;
6995 for (k=0; k < (int) bytes_per_pixel; k++)
7005 if (matte_image != (XImage *) NULL)
7008 Initialize matte canvas.
7010 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
7011 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
7012 q=(unsigned char *) matte_image->data;
7013 for (y=0; y < (int) canvas->rows; y++)
7015 p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
7016 &canvas->exception);
7017 if (p == (const PixelPacket *) NULL)
7021 for (x=(int) canvas->columns-1; x >= 0; x--)
7024 if (GetOpacityPixelComponent(p) > (QuantumRange/2))
7040 canvas_view=DestroyCacheView(canvas_view);
7041 if (canvas != image)
7042 canvas=DestroyImage(canvas);
7046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7050 % X M a k e M a g n i f y I m a g e %
7054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7056 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
7058 % The format of the XMakeMagnifyImage method is:
7060 % void XMakeMagnifyImage(display,windows)
7062 % A description of each parameter follows:
7064 % o display: Specifies a connection to an X server; returned from
7067 % o windows: Specifies a pointer to a XWindows structure.
7070 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
7073 tuple[MaxTextExtent];
7087 register unsigned char
7095 previous_magnify = 0;
7113 Check boundary conditions.
7115 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7116 assert(display != (Display *) NULL);
7117 assert(windows != (XWindows *) NULL);
7119 for (n=1; n < (ssize_t) windows->magnify.data; n++)
7121 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7123 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7125 while (magnify > windows->magnify.width)
7127 while (magnify > windows->magnify.height)
7129 if (magnify != previous_magnify)
7138 New magnify factor: update magnify window name.
7141 while ((1 << i) <= (int) magnify)
7143 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7144 "Magnify %.20gX",(double) i);
7145 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7146 if (status != False)
7148 XSetWMName(display,windows->magnify.id,&window_name);
7149 XSetWMIconName(display,windows->magnify.id,&window_name);
7150 (void) XFree((void *) window_name.value);
7153 previous_magnify=magnify;
7154 ximage=windows->image.ximage;
7155 width=(unsigned int) windows->magnify.ximage->width;
7156 height=(unsigned int) windows->magnify.ximage->height;
7157 if ((windows->magnify.x < 0) ||
7158 (windows->magnify.x >= windows->image.ximage->width))
7159 windows->magnify.x=windows->image.ximage->width >> 1;
7160 x=windows->magnify.x-((width/magnify) >> 1);
7164 if (x > (int) (ximage->width-(width/magnify)))
7165 x=ximage->width-width/magnify;
7166 if ((windows->magnify.y < 0) ||
7167 (windows->magnify.y >= windows->image.ximage->height))
7168 windows->magnify.y=windows->image.ximage->height >> 1;
7169 y=windows->magnify.y-((height/magnify) >> 1);
7173 if (y > (int) (ximage->height-(height/magnify)))
7174 y=ximage->height-height/magnify;
7175 q=(unsigned char *) windows->magnify.ximage->data;
7176 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7177 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7178 if (ximage->bits_per_pixel < 8)
7180 register unsigned char
7187 register unsigned int
7193 pixel_info=windows->magnify.pixel_info;
7194 switch (ximage->bitmap_bit_order)
7199 Magnify little-endian bitmap.
7203 if (ximage->format == XYBitmap)
7205 background=(unsigned char)
7206 (XPixelIntensity(&pixel_info->foreground_color) <
7207 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7208 foreground=(unsigned char)
7209 (XPixelIntensity(&pixel_info->background_color) <
7210 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7211 if (windows->magnify.depth > 1)
7212 Swap(background,foreground);
7214 for (i=0; i < (ssize_t) height; i+=magnify)
7217 Propogate pixel magnify rows.
7219 for (j=0; j < magnify; j++)
7221 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7222 ((x*ximage->bits_per_pixel) >> 3);
7223 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7226 for (k=0; k < width; k+=magnify)
7229 Propogate pixel magnify columns.
7231 for (l=0; l < magnify; l++)
7234 Propogate each bit plane.
7236 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7239 if (*p & (0x01 << (p_bit+plane)))
7252 p_bit+=ximage->bits_per_pixel;
7259 *q=byte >> (8-q_bit);
7271 Magnify big-endian bitmap.
7275 if (ximage->format == XYBitmap)
7277 background=(unsigned char)
7278 (XPixelIntensity(&pixel_info->foreground_color) <
7279 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7280 foreground=(unsigned char)
7281 (XPixelIntensity(&pixel_info->background_color) <
7282 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7283 if (windows->magnify.depth > 1)
7284 Swap(background,foreground);
7286 for (i=0; i < (ssize_t) height; i+=magnify)
7289 Propogate pixel magnify rows.
7291 for (j=0; j < magnify; j++)
7293 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7294 ((x*ximage->bits_per_pixel) >> 3);
7295 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7298 for (k=0; k < width; k+=magnify)
7301 Propogate pixel magnify columns.
7303 for (l=0; l < magnify; l++)
7306 Propogate each bit plane.
7308 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7311 if (*p & (0x80 >> (p_bit+plane)))
7324 p_bit+=ximage->bits_per_pixel;
7331 *q=byte << (8-q_bit);
7342 switch (ximage->bits_per_pixel)
7348 Magnify 8 bit X image.
7350 for (i=0; i < (ssize_t) height; i+=magnify)
7353 Propogate pixel magnify rows.
7355 for (j=0; j < magnify; j++)
7357 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7358 ((x*ximage->bits_per_pixel) >> 3);
7359 for (k=0; k < width; k+=magnify)
7362 Propogate pixel magnify columns.
7364 for (l=0; l < magnify; l++)
7376 register unsigned int
7381 Magnify multi-byte X image.
7383 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7384 for (i=0; i < (ssize_t) height; i+=magnify)
7387 Propogate pixel magnify rows.
7389 for (j=0; j < magnify; j++)
7391 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7392 ((x*ximage->bits_per_pixel) >> 3);
7393 for (k=0; k < width; k+=magnify)
7396 Propogate pixel magnify columns.
7398 for (l=0; l < magnify; l++)
7399 for (m=0; m < bytes_per_pixel; m++)
7411 Copy X image to magnify pixmap.
7413 x=windows->magnify.x-((width/magnify) >> 1);
7415 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7417 if (x > (int) (ximage->width-(width/magnify)))
7418 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7421 y=windows->magnify.y-((height/magnify) >> 1);
7423 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7425 if (y > (int) (ximage->height-(height/magnify)))
7426 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7429 if ((x != 0) || (y != 0))
7430 (void) XFillRectangle(display,windows->magnify.pixmap,
7431 windows->magnify.annotate_context,0,0,width,height);
7432 (void) XPutImage(display,windows->magnify.pixmap,
7433 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7435 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7436 (magnify <= (height >> 1))))
7442 Highlight center pixel.
7444 highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7445 highlight_info.y=(ssize_t) windows->magnify.height >> 1;
7446 highlight_info.width=magnify;
7447 highlight_info.height=magnify;
7448 (void) XDrawRectangle(display,windows->magnify.pixmap,
7449 windows->magnify.highlight_context,(int) highlight_info.x,
7450 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7451 (unsigned int) highlight_info.height-1);
7453 (void) XDrawRectangle(display,windows->magnify.pixmap,
7454 windows->magnify.annotate_context,(int) highlight_info.x+1,
7455 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7456 (unsigned int) highlight_info.height-3);
7459 Show center pixel color.
7461 (void) GetOneVirtualMagickPixel(windows->image.image,(ssize_t)
7462 windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,
7463 &windows->image.image->exception);
7464 (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
7465 windows->magnify.x,windows->magnify.y);
7466 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7467 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7468 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7469 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7470 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7471 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7472 if (pixel.colorspace == CMYKColorspace)
7474 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7475 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7477 if (pixel.matte != MagickFalse)
7479 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7480 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7482 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7483 height=(unsigned int) windows->magnify.font_info->ascent+
7484 windows->magnify.font_info->descent;
7485 x=windows->magnify.font_info->max_bounds.width >> 1;
7486 y=windows->magnify.font_info->ascent+(height >> 2);
7487 (void) XDrawImageString(display,windows->magnify.pixmap,
7488 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7489 GetColorTuple(&pixel,MagickTrue,tuple);
7491 (void) XDrawImageString(display,windows->magnify.pixmap,
7492 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7493 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7494 &windows->image.image->exception);
7496 (void) XDrawImageString(display,windows->magnify.pixmap,
7497 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7499 Refresh magnify window.
7501 magnify_window=windows->magnify;
7504 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7508 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7512 % X M a k e P i x m a p %
7516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7518 % XMakePixmap() creates an X11 pixmap.
7520 % The format of the XMakePixmap method is:
7522 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7523 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7524 % XPixelInfo *pixel)
7526 % A description of each parameter follows:
7528 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7530 % o display: Specifies a connection to an X server; returned from
7533 % o window: Specifies a pointer to a XWindowInfo structure.
7536 static MagickBooleanType XMakePixmap(Display *display,
7537 const XResourceInfo *resource_info,XWindowInfo *window)
7543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7544 assert(display != (Display *) NULL);
7545 assert(resource_info != (XResourceInfo *) NULL);
7546 assert(window != (XWindowInfo *) NULL);
7547 if (window->pixmap != (Pixmap) NULL)
7550 Destroy previous X pixmap.
7552 (void) XFreePixmap(display,window->pixmap);
7553 window->pixmap=(Pixmap) NULL;
7555 if (window->use_pixmap == MagickFalse)
7556 return(MagickFalse);
7557 if (window->ximage == (XImage *) NULL)
7558 return(MagickFalse);
7560 Display busy cursor.
7562 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7563 (void) XFlush(display);
7567 width=(unsigned int) window->ximage->width;
7568 height=(unsigned int) window->ximage->height;
7569 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7570 if (window->pixmap == (Pixmap) NULL)
7573 Unable to allocate pixmap.
7575 (void) XCheckDefineCursor(display,window->id,window->cursor);
7576 return(MagickFalse);
7579 Copy X image to pixmap.
7581 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7582 if (window->shared_memory)
7583 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7584 window->ximage,0,0,0,0,width,height,MagickTrue);
7586 if (window->shared_memory == MagickFalse)
7587 (void) XPutImage(display,window->pixmap,window->annotate_context,
7588 window->ximage,0,0,0,0,width,height);
7589 if (IsEventLogging())
7591 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7592 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7598 (void) XCheckDefineCursor(display,window->id,window->cursor);
7603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7607 % X M a k e S t a n d a r d C o l o r m a p %
7611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7613 % XMakeStandardColormap() creates an X11 Standard Colormap.
7615 % The format of the XMakeStandardColormap method is:
7617 % XMakeStandardColormap(display,visual_info,resource_info,image,
7620 % A description of each parameter follows:
7622 % o display: Specifies a connection to an X server; returned from
7625 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7626 % returned from XGetVisualInfo.
7628 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7630 % o image: the image.
7632 % o map_info: If a Standard Colormap type is specified, this structure is
7633 % initialized with info from the Standard Colormap.
7635 % o pixel: Specifies a pointer to a XPixelInfo structure.
7639 #if defined(__cplusplus) || defined(c_plusplus)
7643 static inline MagickRealType DiversityPixelIntensity(
7644 const DiversityPacket *pixel)
7649 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7653 static int IntensityCompare(const void *x,const void *y)
7662 color_1=(DiversityPacket *) x;
7663 color_2=(DiversityPacket *) y;
7664 diversity=(int) (DiversityPixelIntensity(color_2)-
7665 DiversityPixelIntensity(color_1));
7669 static int PopularityCompare(const void *x,const void *y)
7675 color_1=(DiversityPacket *) x;
7676 color_2=(DiversityPacket *) y;
7677 return((int) color_2->count-(int) color_1->count);
7680 #if defined(__cplusplus) || defined(c_plusplus)
7684 static inline Quantum ScaleXToQuantum(const size_t x,
7687 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7690 MagickExport void XMakeStandardColormap(Display *display,
7691 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7692 XStandardColormap *map_info,XPixelInfo *pixel)
7700 register IndexPacket
7721 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7722 assert(display != (Display *) NULL);
7723 assert(visual_info != (XVisualInfo *) NULL);
7724 assert(map_info != (XStandardColormap *) NULL);
7725 assert(resource_info != (XResourceInfo *) NULL);
7726 assert(pixel != (XPixelInfo *) NULL);
7727 exception=(&image->exception);
7728 if (resource_info->map_type != (char *) NULL)
7731 Standard Colormap is already defined (i.e. xstdcmap).
7733 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7735 number_colors=(unsigned int) (map_info->base_pixel+
7736 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7737 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7738 if ((image->matte == MagickFalse) &&
7739 (resource_info->color_recovery == MagickFalse) &&
7740 resource_info->quantize_info->dither &&
7741 (number_colors < MaxColormapSize))
7746 register PixelPacket
7750 Improve image appearance with error diffusion.
7752 affinity_image=AcquireImage((ImageInfo *) NULL);
7753 if (affinity_image == (Image *) NULL)
7754 ThrowXWindowFatalException(ResourceLimitFatalError,
7755 "UnableToDitherImage",image->filename);
7756 affinity_image->columns=number_colors;
7757 affinity_image->rows=1;
7759 Initialize colormap image.
7761 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7763 if (q != (PixelPacket *) NULL)
7765 for (i=0; i < (ssize_t) number_colors; i++)
7767 SetRedPixelComponent(q,0);
7768 if (map_info->red_max != 0)
7769 SetRedPixelComponent(q,ScaleXToQuantum((size_t) (i/
7770 map_info->red_mult),map_info->red_max));
7771 SetGreenPixelComponent(q,0);
7772 if (map_info->green_max != 0)
7773 SetGreenPixelComponent(q,ScaleXToQuantum((size_t) ((i/
7774 map_info->green_mult) % (map_info->green_max+1)),
7775 map_info->green_max));
7776 SetBluePixelComponent(q,0);
7777 if (map_info->blue_max != 0)
7778 SetBluePixelComponent(q,ScaleXToQuantum((size_t) (i %
7779 map_info->green_mult),map_info->blue_max));
7780 SetOpacityPixelComponent(q,TransparentOpacity);
7783 (void) SyncAuthenticPixels(affinity_image,exception);
7784 (void) RemapImage(resource_info->quantize_info,image,
7787 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7789 (void) SetImageStorageClass(image,DirectClass);
7790 affinity_image=DestroyImage(affinity_image);
7792 if (IsEventLogging())
7794 (void) LogMagickEvent(X11Event,GetMagickModule(),
7795 "Standard Colormap:");
7796 (void) LogMagickEvent(X11Event,GetMagickModule(),
7797 " colormap id: 0x%lx",map_info->colormap);
7798 (void) LogMagickEvent(X11Event,GetMagickModule(),
7799 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7800 map_info->green_max,map_info->blue_max);
7801 (void) LogMagickEvent(X11Event,GetMagickModule(),
7802 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7803 map_info->green_mult,map_info->blue_mult);
7807 if ((visual_info->klass != DirectColor) &&
7808 (visual_info->klass != TrueColor))
7809 if ((image->storage_class == DirectClass) ||
7810 ((int) image->colors > visual_info->colormap_size))
7816 Image has more colors than the visual supports.
7818 quantize_info=(*resource_info->quantize_info);
7819 quantize_info.number_colors=(size_t) visual_info->colormap_size;
7820 (void) QuantizeImage(&quantize_info,image);
7823 Free previous and create new colormap.
7825 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7826 colormap=XDefaultColormap(display,visual_info->screen);
7827 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7828 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7829 visual_info->visual,visual_info->klass == DirectColor ?
7830 AllocAll : AllocNone);
7831 if (colormap == (Colormap) NULL)
7832 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7835 Initialize the map and pixel info structures.
7837 XGetMapInfo(visual_info,colormap,map_info);
7838 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7840 Allocating colors in server colormap is based on visual class.
7842 switch (visual_info->klass)
7848 Define Standard Colormap for StaticGray or StaticColor visual.
7850 number_colors=image->colors;
7851 colors=(XColor *) AcquireQuantumMemory((size_t)
7852 visual_info->colormap_size,sizeof(*colors));
7853 if (colors == (XColor *) NULL)
7854 ThrowXWindowFatalException(ResourceLimitFatalError,
7855 "UnableToCreateColormap",image->filename);
7857 color.flags=(char) (DoRed | DoGreen | DoBlue);
7858 for (i=0; i < (ssize_t) image->colors; i++)
7860 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7861 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7862 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7863 if (visual_info->klass != StaticColor)
7865 gray_value=(unsigned short) XPixelIntensity(&color);
7866 color.red=gray_value;
7867 color.green=gray_value;
7868 color.blue=gray_value;
7870 status=XAllocColor(display,colormap,&color);
7871 if (status == False)
7873 colormap=XCopyColormapAndFree(display,colormap);
7874 (void) XAllocColor(display,colormap,&color);
7876 pixel->pixels[i]=color.pixel;
7888 Define Standard Colormap for GrayScale or PseudoColor visual.
7890 number_colors=image->colors;
7891 colors=(XColor *) AcquireQuantumMemory((size_t)
7892 visual_info->colormap_size,sizeof(*colors));
7893 if (colors == (XColor *) NULL)
7894 ThrowXWindowFatalException(ResourceLimitFatalError,
7895 "UnableToCreateColormap",image->filename);
7897 Preallocate our GUI colors.
7899 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7900 (void) XAllocColor(display,colormap,&pixel->background_color);
7901 (void) XAllocColor(display,colormap,&pixel->border_color);
7902 (void) XAllocColor(display,colormap,&pixel->matte_color);
7903 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7904 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7905 (void) XAllocColor(display,colormap,&pixel->depth_color);
7906 (void) XAllocColor(display,colormap,&pixel->trough_color);
7907 for (i=0; i < MaxNumberPens; i++)
7908 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7910 Determine if image colors will "fit" into X server colormap.
7912 colormap_type=resource_info->colormap;
7913 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7914 NULL,0,pixel->pixels,(unsigned int) image->colors);
7915 if (status != False)
7916 colormap_type=PrivateColormap;
7917 if (colormap_type == SharedColormap)
7938 Define Standard colormap for shared GrayScale or PseudoColor visual.
7940 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7941 sizeof(*diversity));
7942 if (diversity == (DiversityPacket *) NULL)
7943 ThrowXWindowFatalException(ResourceLimitFatalError,
7944 "UnableToCreateColormap",image->filename);
7945 for (i=0; i < (ssize_t) image->colors; i++)
7947 diversity[i].red=image->colormap[i].red;
7948 diversity[i].green=image->colormap[i].green;
7949 diversity[i].blue=image->colormap[i].blue;
7950 diversity[i].index=(unsigned short) i;
7951 diversity[i].count=0;
7953 image_view=AcquireCacheView(image);
7954 for (y=0; y < (int) image->rows; y++)
7959 register const PixelPacket
7962 p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7963 image->columns,1,exception);
7964 if (p == (const PixelPacket *) NULL)
7966 indexes=GetCacheViewAuthenticIndexQueue(image_view);
7967 for (x=(int) image->columns-1; x >= 0; x--)
7968 diversity[(ssize_t) GetIndexPixelComponent(indexes+x)].count++;
7970 image_view=DestroyCacheView(image_view);
7972 Sort colors by decreasing intensity.
7974 qsort((void *) diversity,image->colors,sizeof(*diversity),
7976 for (i=0; i < (ssize_t) image->colors; )
7978 diversity[i].count<<=4; /* increase this colors popularity */
7979 i+=MagickMax((int) (image->colors >> 4),2);
7981 diversity[image->colors-1].count<<=4;
7982 qsort((void *) diversity,image->colors,sizeof(*diversity),
7988 color.flags=(char) (DoRed | DoGreen | DoBlue);
7989 for (i=0; i < (ssize_t) image->colors; i++)
7991 index=diversity[i].index;
7993 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7995 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7997 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7998 if (visual_info->klass != PseudoColor)
8000 gray_value=(unsigned short) XPixelIntensity(&color);
8001 color.red=gray_value;
8002 color.green=gray_value;
8003 color.blue=gray_value;
8005 status=XAllocColor(display,colormap,&color);
8006 if (status == False)
8008 pixel->pixels[index]=color.pixel;
8012 Read X server colormap.
8014 server_colors=(XColor *) AcquireQuantumMemory((size_t)
8015 visual_info->colormap_size,sizeof(*server_colors));
8016 if (server_colors == (XColor *) NULL)
8017 ThrowXWindowFatalException(ResourceLimitFatalError,
8018 "UnableToCreateColormap",image->filename);
8019 for (x=visual_info->colormap_size-1; x >= 0; x--)
8020 server_colors[x].pixel=(size_t) x;
8021 (void) XQueryColors(display,colormap,server_colors,
8022 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
8024 Select remaining colors from X server colormap.
8026 for (; i < (ssize_t) image->colors; i++)
8028 index=diversity[i].index;
8030 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
8032 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
8034 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
8035 if (visual_info->klass != PseudoColor)
8037 gray_value=(unsigned short) XPixelIntensity(&color);
8038 color.red=gray_value;
8039 color.green=gray_value;
8040 color.blue=gray_value;
8042 XBestPixel(display,colormap,server_colors,(unsigned int)
8043 visual_info->colormap_size,&color);
8044 pixel->pixels[index]=color.pixel;
8047 if ((int) image->colors < visual_info->colormap_size)
8050 Fill up colors array-- more choices for pen colors.
8052 retain_colors=MagickMin((unsigned int)
8053 (visual_info->colormap_size-image->colors),256);
8054 for (i=0; i < (ssize_t) retain_colors; i++)
8055 *p++=server_colors[i];
8056 number_colors+=retain_colors;
8058 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
8059 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
8063 Define Standard colormap for private GrayScale or PseudoColor visual.
8065 if (status == False)
8068 Not enough colormap entries in the colormap-- Create a new colormap.
8070 colormap=XCreateColormap(display,
8071 XRootWindow(display,visual_info->screen),visual_info->visual,
8073 if (colormap == (Colormap) NULL)
8074 ThrowXWindowFatalException(ResourceLimitFatalError,
8075 "UnableToCreateColormap",image->filename);
8076 map_info->colormap=colormap;
8077 if ((int) image->colors < visual_info->colormap_size)
8080 Retain colors from the default colormap to help lessens the
8081 effects of colormap flashing.
8083 retain_colors=MagickMin((unsigned int)
8084 (visual_info->colormap_size-image->colors),256);
8085 p=colors+image->colors;
8086 for (i=0; i < (ssize_t) retain_colors; i++)
8088 p->pixel=(unsigned long) i;
8091 (void) XQueryColors(display,
8092 XDefaultColormap(display,visual_info->screen),
8093 colors+image->colors,(int) retain_colors);
8095 Transfer colors from default to private colormap.
8097 (void) XAllocColorCells(display,colormap,MagickFalse,
8098 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8100 p=colors+image->colors;
8101 for (i=0; i < (ssize_t) retain_colors; i++)
8103 p->pixel=pixel->pixels[i];
8106 (void) XStoreColors(display,colormap,colors+image->colors,
8107 (int) retain_colors);
8108 number_colors+=retain_colors;
8110 (void) XAllocColorCells(display,colormap,MagickFalse,
8111 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8115 Store the image colormap.
8118 color.flags=(char) (DoRed | DoGreen | DoBlue);
8119 for (i=0; i < (ssize_t) image->colors; i++)
8121 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8122 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8123 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8124 if (visual_info->klass != PseudoColor)
8126 gray_value=(unsigned short) XPixelIntensity(&color);
8127 color.red=gray_value;
8128 color.green=gray_value;
8129 color.blue=gray_value;
8131 color.pixel=pixel->pixels[i];
8134 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8145 Define Standard Colormap for TrueColor or DirectColor visual.
8147 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8148 (map_info->green_max*map_info->green_mult)+
8149 (map_info->blue_max*map_info->blue_mult)+1);
8150 linear_colormap=(number_colors > 4096) ||
8151 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8152 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8153 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8154 MagickTrue : MagickFalse;
8155 if (linear_colormap != MagickFalse)
8156 number_colors=(size_t) visual_info->colormap_size;
8158 Allocate color array.
8160 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8161 if (colors == (XColor *) NULL)
8162 ThrowXWindowFatalException(ResourceLimitFatalError,
8163 "UnableToCreateColormap",image->filename);
8165 Initialize linear color ramp.
8168 color.flags=(char) (DoRed | DoGreen | DoBlue);
8169 if (linear_colormap != MagickFalse)
8170 for (i=0; i < (ssize_t) number_colors; i++)
8172 color.blue=(unsigned short) 0;
8173 if (map_info->blue_max != 0)
8174 color.blue=(unsigned short) ((size_t)
8175 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8176 color.green=color.blue;
8177 color.red=color.blue;
8178 color.pixel=XStandardPixel(map_info,&color);
8182 for (i=0; i < (ssize_t) number_colors; i++)
8184 color.red=(unsigned short) 0;
8185 if (map_info->red_max != 0)
8186 color.red=(unsigned short) ((size_t)
8187 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8188 color.green=(unsigned int) 0;
8189 if (map_info->green_max != 0)
8190 color.green=(unsigned short) ((size_t)
8191 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8192 map_info->green_max));
8193 color.blue=(unsigned short) 0;
8194 if (map_info->blue_max != 0)
8195 color.blue=(unsigned short) ((size_t)
8196 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8197 color.pixel=XStandardPixel(map_info,&color);
8200 if ((visual_info->klass == DirectColor) &&
8201 (colormap != XDefaultColormap(display,visual_info->screen)))
8202 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8204 for (i=0; i < (ssize_t) number_colors; i++)
8205 (void) XAllocColor(display,colormap,&colors[i]);
8209 if ((visual_info->klass != DirectColor) &&
8210 (visual_info->klass != TrueColor))
8213 Set foreground, background, border, etc. pixels.
8215 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8216 &pixel->foreground_color);
8217 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8218 &pixel->background_color);
8219 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8222 Foreground and background colors must differ.
8224 pixel->background_color.red=(~pixel->foreground_color.red);
8225 pixel->background_color.green=
8226 (~pixel->foreground_color.green);
8227 pixel->background_color.blue=
8228 (~pixel->foreground_color.blue);
8229 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8230 &pixel->background_color);
8232 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8233 &pixel->border_color);
8234 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8235 &pixel->matte_color);
8236 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8237 &pixel->highlight_color);
8238 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8239 &pixel->shadow_color);
8240 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8241 &pixel->depth_color);
8242 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8243 &pixel->trough_color);
8244 for (i=0; i < MaxNumberPens; i++)
8246 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8247 &pixel->pen_colors[i]);
8248 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8250 pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
8252 colors=(XColor *) RelinquishMagickMemory(colors);
8253 if (IsEventLogging())
8255 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8256 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8257 map_info->colormap);
8258 (void) LogMagickEvent(X11Event,GetMagickModule(),
8259 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8260 map_info->green_max,map_info->blue_max);
8261 (void) LogMagickEvent(X11Event,GetMagickModule(),
8262 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8263 map_info->green_mult,map_info->blue_mult);
8268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8272 % X M a k e W i n d o w %
8276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8278 % XMakeWindow() creates an X11 window.
8280 % The format of the XMakeWindow method is:
8282 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8283 % XClassHint *class_hint,XWMHints *manager_hints,
8284 % XWindowInfo *window_info)
8286 % A description of each parameter follows:
8288 % o display: Specifies a connection to an X server; returned from
8291 % o parent: Specifies the parent window_info.
8293 % o argv: Specifies the application's argument list.
8295 % o argc: Specifies the number of arguments.
8297 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8299 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8301 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8304 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8305 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8306 XWindowInfo *window_info)
8308 #define MinWindowSize 64
8316 static XTextProperty
8327 Set window info hints.
8329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8330 assert(display != (Display *) NULL);
8331 assert(window_info != (XWindowInfo *) NULL);
8332 size_hints=XAllocSizeHints();
8333 if (size_hints == (XSizeHints *) NULL)
8334 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8335 size_hints->flags=(int) window_info->flags;
8336 size_hints->x=window_info->x;
8337 size_hints->y=window_info->y;
8338 size_hints->width=(int) window_info->width;
8339 size_hints->height=(int) window_info->height;
8340 if (window_info->immutable != MagickFalse)
8343 Window size cannot be changed.
8345 size_hints->min_width=size_hints->width;
8346 size_hints->min_height=size_hints->height;
8347 size_hints->max_width=size_hints->width;
8348 size_hints->max_height=size_hints->height;
8349 size_hints->flags|=PMinSize;
8350 size_hints->flags|=PMaxSize;
8355 Window size can be changed.
8357 size_hints->min_width=(int) window_info->min_width;
8358 size_hints->min_height=(int) window_info->min_height;
8359 size_hints->flags|=PResizeInc;
8360 size_hints->width_inc=(int) window_info->width_inc;
8361 size_hints->height_inc=(int) window_info->height_inc;
8362 #if !defined(PRE_R4_ICCCM)
8363 size_hints->flags|=PBaseSize;
8364 size_hints->base_width=size_hints->width_inc;
8365 size_hints->base_height=size_hints->height_inc;
8368 gravity=NorthWestGravity;
8369 if (window_info->geometry != (char *) NULL)
8372 default_geometry[MaxTextExtent],
8373 geometry[MaxTextExtent];
8382 User specified geometry.
8384 (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
8385 size_hints->width,size_hints->height);
8386 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8388 while (strlen(p) != 0)
8390 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8393 (void) CopyMagickString(p,p+1,MaxTextExtent);
8395 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8396 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8397 &size_hints->width,&size_hints->height,&gravity);
8398 if ((flags & WidthValue) && (flags & HeightValue))
8399 size_hints->flags|=USSize;
8400 if ((flags & XValue) && (flags & YValue))
8402 size_hints->flags|=USPosition;
8403 window_info->x=size_hints->x;
8404 window_info->y=size_hints->y;
8407 #if !defined(PRE_R4_ICCCM)
8408 size_hints->win_gravity=gravity;
8409 size_hints->flags|=PWinGravity;
8411 if (window_info->id == (Window) NULL)
8412 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8413 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8414 window_info->border_width,(int) window_info->depth,InputOutput,
8415 window_info->visual,(unsigned long) window_info->mask,
8416 &window_info->attributes);
8429 Window already exists; change relevant attributes.
8431 (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8432 window_info->mask,&window_info->attributes);
8433 mask=ConfigureNotify;
8434 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8435 window_changes.x=window_info->x;
8436 window_changes.y=window_info->y;
8437 window_changes.width=(int) window_info->width;
8438 window_changes.height=(int) window_info->height;
8439 mask=(MagickStatusType) (CWWidth | CWHeight);
8440 if (window_info->flags & USPosition)
8442 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8443 mask,&window_changes);
8445 if (window_info->id == (Window) NULL)
8446 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8448 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8449 if (status == False)
8450 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8452 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8453 if (status == False)
8454 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8455 window_info->icon_name);
8456 if (window_info->icon_geometry != (char *) NULL)
8464 User specified icon geometry.
8466 size_hints->flags|=USPosition;
8467 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8468 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8469 &manager_hints->icon_y,&width,&height,&gravity);
8470 if ((flags & XValue) && (flags & YValue))
8471 manager_hints->flags|=IconPositionHint;
8473 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8474 size_hints,manager_hints,class_hint);
8475 if (window_name.value != (void *) NULL)
8477 (void) XFree((void *) window_name.value);
8478 window_name.value=(unsigned char *) NULL;
8479 window_name.nitems=0;
8481 if (icon_name.value != (void *) NULL)
8483 (void) XFree((void *) icon_name.value);
8484 icon_name.value=(unsigned char *) NULL;
8487 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8488 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8489 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8490 (void) XFree((void *) size_hints);
8491 if (window_info->shape != MagickFalse)
8493 #if defined(MAGICKCORE_HAVE_SHAPE)
8499 Can we apply a non-rectangular shaping mask?
8503 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8504 window_info->shape=MagickFalse;
8506 window_info->shape=MagickFalse;
8509 if (window_info->shared_memory)
8511 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8513 Can we use shared memory with this window?
8515 if (XShmQueryExtension(display) == 0)
8516 window_info->shared_memory=MagickFalse;
8518 window_info->shared_memory=MagickFalse;
8521 window_info->image=NewImageList();
8522 window_info->destroy=MagickFalse;
8526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8530 % X M a g i c k P r o g r e s s M o n i t o r %
8534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8536 % XMagickProgressMonitor() displays the progress a task is making in
8537 % completing a task.
8539 % The format of the XMagickProgressMonitor method is:
8541 % void XMagickProgressMonitor(const char *task,
8542 % const MagickOffsetType quantum,const MagickSizeType span,
8543 % void *client_data)
8545 % A description of each parameter follows:
8547 % o task: Identifies the task in progress.
8549 % o quantum: Specifies the quantum position within the span which represents
8550 % how much progress has been made in completing a task.
8552 % o span: Specifies the span relative to completing a task.
8554 % o client_data: Pointer to any client data.
8558 static const char *GetLocaleMonitorMessage(const char *text)
8561 message[MaxTextExtent],
8570 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8572 if (p != (char *) NULL)
8574 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
8575 locale_message=GetLocaleMessage(message);
8576 if (locale_message == message)
8578 return(locale_message);
8581 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8582 const MagickOffsetType quantum,const MagickSizeType span,
8583 void *magick_unused(client_data))
8588 windows=XSetWindows((XWindows *) ~0);
8589 if (windows == (XWindows *) NULL)
8591 if (windows->info.mapped != MagickFalse)
8592 XProgressMonitorWidget(windows->display,windows,
8593 GetLocaleMonitorMessage(tag),quantum,span);
8598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8602 % X Q u e r y C o l o r D a t a b a s e %
8606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8608 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8611 % The format of the XQueryColorDatabase method is:
8613 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8615 % A description of each parameter follows:
8617 % o target: Specifies the color to lookup in the X color database.
8619 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8620 % color is returned as this value.
8623 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8630 *display = (Display *) NULL;
8639 Initialize color return value.
8641 assert(color != (XColor *) NULL);
8645 color->flags=(char) (DoRed | DoGreen | DoBlue);
8646 if ((target == (char *) NULL) || (*target == '\0'))
8647 target="#ffffffffffff";
8649 Let the X server define the color for us.
8651 if (display == (Display *) NULL)
8652 display=XOpenDisplay((char *) NULL);
8653 if (display == (Display *) NULL)
8655 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8656 return(MagickFalse);
8658 colormap=XDefaultColormap(display,XDefaultScreen(display));
8659 status=XParseColor(display,colormap,(char *) target,&xcolor);
8660 if (status == False)
8661 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8664 color->red=xcolor.red;
8665 color->green=xcolor.green;
8666 color->blue=xcolor.blue;
8667 color->flags=xcolor.flags;
8669 return(status != False ? MagickTrue : MagickFalse);
8673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8677 % X Q u e r y P o s i t i o n %
8681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8683 % XQueryPosition() gets the pointer coordinates relative to a window.
8685 % The format of the XQueryPosition method is:
8687 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8689 % A description of each parameter follows:
8691 % o display: Specifies a connection to an X server; returned from
8694 % o window: Specifies a pointer to a Window.
8696 % o x: Return the x coordinate of the pointer relative to the origin of the
8699 % o y: Return the y coordinate of the pointer relative to the origin of the
8703 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8715 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8716 assert(display != (Display *) NULL);
8717 assert(window != (Window) NULL);
8718 assert(x != (int *) NULL);
8719 assert(y != (int *) NULL);
8720 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8729 % X R e f r e s h W i n d o w %
8733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8735 % XRefreshWindow() refreshes an image in a X window.
8737 % The format of the XRefreshWindow method is:
8739 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8740 % const XEvent *event)
8742 % A description of each parameter follows:
8744 % o display: Specifies a connection to an X server; returned from
8747 % o window: Specifies a pointer to a XWindowInfo structure.
8749 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8750 % the entire image is refreshed.
8753 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8754 const XEvent *event)
8764 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8765 assert(display != (Display *) NULL);
8766 assert(window != (XWindowInfo *) NULL);
8767 if (window->ximage == (XImage *) NULL)
8769 if (event != (XEvent *) NULL)
8772 Determine geometry from expose event.
8776 width=(unsigned int) event->xexpose.width;
8777 height=(unsigned int) event->xexpose.height;
8785 Refresh entire window; discard outstanding expose events.
8789 width=window->width;
8790 height=window->height;
8791 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8792 if (window->matte_pixmap != (Pixmap) NULL)
8794 #if defined(MAGICKCORE_HAVE_SHAPE)
8795 if (window->shape != MagickFalse)
8796 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8797 window->matte_pixmap,ShapeSet);
8802 Check boundary conditions.
8804 if ((window->ximage->width-(x+window->x)) < (int) width)
8805 width=(unsigned int) (window->ximage->width-(x+window->x));
8806 if ((window->ximage->height-(y+window->y)) < (int) height)
8807 height=(unsigned int) (window->ximage->height-(y+window->y));
8811 if (window->matte_pixmap != (Pixmap) NULL)
8812 (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
8813 if (window->pixmap != (Pixmap) NULL)
8815 if (window->depth > 1)
8816 (void) XCopyArea(display,window->pixmap,window->id,
8817 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8819 (void) XCopyPlane(display,window->pixmap,window->id,
8820 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8825 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8826 if (window->shared_memory)
8827 (void) XShmPutImage(display,window->id,window->annotate_context,
8828 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8830 if (window->shared_memory == MagickFalse)
8831 (void) XPutImage(display,window->id,window->annotate_context,
8832 window->ximage,x+window->x,y+window->y,x,y,width,height);
8834 if (window->matte_pixmap != (Pixmap) NULL)
8835 (void) XSetClipMask(display,window->annotate_context,None);
8836 (void) XFlush(display);
8840 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8844 % X R e m o t e C o m m a n d %
8848 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8850 % XRemoteCommand() forces a remote display(1) to display the specified
8853 % The format of the XRemoteCommand method is:
8855 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8856 % const char *filename)
8858 % A description of each parameter follows:
8860 % o display: Specifies a connection to an X server; returned from
8863 % o window: Specifies the name or id of an X window.
8865 % o filename: the name of the image filename to display.
8868 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8869 const char *window,const char *filename)
8878 assert(filename != (char *) NULL);
8879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8880 if (display == (Display *) NULL)
8881 display=XOpenDisplay((char *) NULL);
8882 if (display == (Display *) NULL)
8884 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8885 return(MagickFalse);
8887 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8888 remote_window=(Window) NULL;
8889 root_window=XRootWindow(display,XDefaultScreen(display));
8890 if (window != (char *) NULL)
8893 Search window hierarchy and identify any clients by name or ID.
8895 if (isdigit((unsigned char) *window) != 0)
8896 remote_window=XWindowByID(display,root_window,(Window)
8897 strtol((char *) window,(char **) NULL,0));
8898 if (remote_window == (Window) NULL)
8899 remote_window=XWindowByName(display,root_window,window);
8901 if (remote_window == (Window) NULL)
8902 remote_window=XWindowByProperty(display,root_window,remote_atom);
8903 if (remote_window == (Window) NULL)
8905 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8907 return(MagickFalse);
8910 Send remote command.
8912 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8913 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8914 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8915 (void) XSync(display,MagickFalse);
8920 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8924 % X R e t a i n W i n d o w C o l o r s %
8928 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8930 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8931 % the colors associated with an image displayed on the window.
8933 % The format of the XRetainWindowColors method is:
8935 % void XRetainWindowColors(Display *display,const Window window)
8937 % A description of each parameter follows:
8939 % o display: Specifies a connection to an X server; returned from
8942 % o window: Specifies a pointer to a XWindowInfo structure.
8945 MagickExport void XRetainWindowColors(Display *display,const Window window)
8954 Put property on the window.
8956 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8957 assert(display != (Display *) NULL);
8958 assert(window != (Window) NULL);
8959 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8960 if (property == (Atom) NULL)
8962 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8966 pixmap=XCreatePixmap(display,window,1,1,1);
8967 if (pixmap == (Pixmap) NULL)
8969 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8972 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8973 (unsigned char *) &pixmap,1);
8974 (void) XSetCloseDownMode(display,RetainPermanent);
8978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8982 % X S e l e c t W i n d o w %
8986 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8988 % XSelectWindow() allows a user to select a window using the mouse. If the
8989 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8990 % is returned in the crop_info structure.
8992 % The format of the XSelectWindow function is:
8994 % target_window=XSelectWindow(display,crop_info)
8996 % A description of each parameter follows:
8998 % o window: XSelectWindow returns the window id.
9000 % o display: Specifies a pointer to the Display structure; returned from
9003 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
9004 % contains the extents of any cropping rectangle.
9007 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
9009 #define MinimumCropArea (unsigned int) 9
9036 Initialize graphic context.
9038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9039 assert(display != (Display *) NULL);
9040 assert(crop_info != (RectangleInfo *) NULL);
9041 root_window=XRootWindow(display,XDefaultScreen(display));
9042 context_values.background=XBlackPixel(display,XDefaultScreen(display));
9043 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
9044 context_values.function=GXinvert;
9045 context_values.plane_mask=
9046 context_values.background ^ context_values.foreground;
9047 context_values.subwindow_mode=IncludeInferiors;
9048 annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
9049 GCForeground | GCFunction | GCSubwindowMode),&context_values);
9050 if (annotate_context == (GC) NULL)
9051 return(MagickFalse);
9053 Grab the pointer using target cursor.
9055 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
9056 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
9057 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
9058 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
9059 GrabModeAsync,root_window,target_cursor,CurrentTime);
9060 if (status != GrabSuccess)
9062 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
9063 return((Window) NULL);
9069 crop_info->height=0;
9071 target_window=(Window) NULL;
9076 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9077 (void) XDrawRectangle(display,root_window,annotate_context,
9078 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9079 (unsigned int) crop_info->height-1);
9081 Allow another event.
9083 (void) XAllowEvents(display,SyncPointer,CurrentTime);
9084 (void) XWindowEvent(display,root_window,ButtonPressMask |
9085 ButtonReleaseMask | ButtonMotionMask,&event);
9086 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
9087 (void) XDrawRectangle(display,root_window,annotate_context,
9088 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
9089 (unsigned int) crop_info->height-1);
9094 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9095 event.xbutton.x,event.xbutton.y);
9096 if (target_window == (Window) NULL)
9097 target_window=root_window;
9098 x_offset=event.xbutton.x_root;
9099 y_offset=event.xbutton.y_root;
9100 crop_info->x=(ssize_t) x_offset;
9101 crop_info->y=(ssize_t) y_offset;
9103 crop_info->height=0;
9115 Discard pending button motion events.
9117 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9118 crop_info->x=(ssize_t) event.xmotion.x;
9119 crop_info->y=(ssize_t) event.xmotion.y;
9121 Check boundary conditions.
9123 if ((int) crop_info->x < x_offset)
9124 crop_info->width=(size_t) (x_offset-crop_info->x);
9127 crop_info->width=(size_t) (crop_info->x-x_offset);
9128 crop_info->x=(ssize_t) x_offset;
9130 if ((int) crop_info->y < y_offset)
9131 crop_info->height=(size_t) (y_offset-crop_info->y);
9134 crop_info->height=(size_t) (crop_info->y-y_offset);
9135 crop_info->y=(ssize_t) y_offset;
9141 } while ((target_window == (Window) NULL) || (presses > 0));
9142 (void) XUngrabPointer(display,CurrentTime);
9143 (void) XFreeCursor(display,target_cursor);
9144 (void) XFreeGC(display,annotate_context);
9145 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9148 crop_info->height=0;
9150 if ((crop_info->width != 0) && (crop_info->height != 0))
9151 target_window=root_window;
9152 return(target_window);
9156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9160 % X S e t C u r s o r S t a t e %
9164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9166 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9167 % reset to their default.
9169 % The format of the XXSetCursorState method is:
9171 % XSetCursorState(display,windows,const MagickStatusType state)
9173 % A description of each parameter follows:
9175 % o display: Specifies a connection to an X server; returned from
9178 % o windows: Specifies a pointer to a XWindows structure.
9180 % o state: An unsigned integer greater than 0 sets the cursor state
9181 % to busy, otherwise the cursor are reset to their default.
9184 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9185 const MagickStatusType state)
9187 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9188 assert(display != (Display *) NULL);
9189 assert(windows != (XWindows *) NULL);
9192 (void) XCheckDefineCursor(display,windows->image.id,
9193 windows->image.busy_cursor);
9194 (void) XCheckDefineCursor(display,windows->pan.id,
9195 windows->pan.busy_cursor);
9196 (void) XCheckDefineCursor(display,windows->magnify.id,
9197 windows->magnify.busy_cursor);
9198 (void) XCheckDefineCursor(display,windows->command.id,
9199 windows->command.busy_cursor);
9203 (void) XCheckDefineCursor(display,windows->image.id,
9204 windows->image.cursor);
9205 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9206 (void) XCheckDefineCursor(display,windows->magnify.id,
9207 windows->magnify.cursor);
9208 (void) XCheckDefineCursor(display,windows->command.id,
9209 windows->command.cursor);
9210 (void) XCheckDefineCursor(display,windows->command.id,
9211 windows->widget.cursor);
9212 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9214 windows->info.mapped=MagickFalse;
9218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9222 % X S e t W i n d o w s %
9226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9228 % XSetWindows() sets the X windows structure if the windows info is specified.
9229 % Otherwise the current windows structure is returned.
9231 % The format of the XSetWindows method is:
9233 % XWindows *XSetWindows(XWindows *windows_info)
9235 % A description of each parameter follows:
9237 % o windows_info: Initialize the Windows structure with this information.
9240 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9243 *windows = (XWindows *) NULL;
9245 if (windows_info != (XWindows *) ~0)
9247 windows=(XWindows *) RelinquishMagickMemory(windows);
9248 windows=windows_info;
9253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9257 % X U s e r P r e f e r e n c e s %
9261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9263 % XUserPreferences() saves the preferences in a configuration file in the
9264 % users' home directory.
9266 % The format of the XUserPreferences method is:
9268 % void XUserPreferences(XResourceInfo *resource_info)
9270 % A description of each parameter follows:
9272 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9275 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9277 #if defined(X11_PREFERENCES_PATH)
9279 cache[MaxTextExtent],
9280 filename[MaxTextExtent],
9281 specifier[MaxTextExtent];
9288 preferences_database;
9291 Save user preferences to the client configuration file.
9293 assert(resource_info != (XResourceInfo *) NULL);
9294 client_name=GetClientName();
9295 preferences_database=XrmGetStringDatabase("");
9296 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
9297 value=resource_info->backdrop ? "True" : "False";
9298 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9299 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
9300 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9301 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9302 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9304 value=resource_info->confirm_exit ? "True" : "False";
9305 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9306 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9308 value=resource_info->confirm_edit ? "True" : "False";
9309 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9310 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9312 value=resource_info->display_warnings ? "True" : "False";
9313 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9314 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
9315 value=resource_info->quantize_info->dither ? "True" : "False";
9316 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9317 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9319 value=resource_info->gamma_correct ? "True" : "False";
9320 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9321 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9322 (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
9323 resource_info->undo_cache);
9324 XrmPutStringResource(&preferences_database,specifier,cache);
9325 (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
9326 value=resource_info->use_pixmap ? "True" : "False";
9327 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9328 (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9329 X11_PREFERENCES_PATH,client_name);
9330 ExpandFilename(filename);
9331 XrmPutFileDatabase(preferences_database,filename);
9336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9340 % X V i s u a l C l a s s N a m e %
9344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9346 % XVisualClassName() returns the visual class name as a character string.
9348 % The format of the XVisualClassName method is:
9350 % char *XVisualClassName(const int visual_class)
9352 % A description of each parameter follows:
9354 % o visual_type: XVisualClassName returns the visual class as a character
9357 % o class: Specifies the visual class.
9360 static const char *XVisualClassName(const int visual_class)
9362 switch (visual_class)
9364 case StaticGray: return("StaticGray");
9365 case GrayScale: return("GrayScale");
9366 case StaticColor: return("StaticColor");
9367 case PseudoColor: return("PseudoColor");
9368 case TrueColor: return("TrueColor");
9369 case DirectColor: return("DirectColor");
9371 return("unknown visual class");
9375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9385 % XWarning() displays a warning reason in a Notice widget.
9387 % The format of the XWarning method is:
9389 % void XWarning(const unsigned int warning,const char *reason,
9390 % const char *description)
9392 % A description of each parameter follows:
9394 % o warning: Specifies the numeric warning category.
9396 % o reason: Specifies the reason to display before terminating the
9399 % o description: Specifies any description to the reason.
9402 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9403 const char *reason,const char *description)
9406 text[MaxTextExtent];
9411 if (reason == (char *) NULL)
9413 (void) CopyMagickString(text,reason,MaxTextExtent);
9414 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9415 windows=XSetWindows((XWindows *) ~0);
9416 XNoticeWidget(windows->display,windows,text,(char *) description);
9420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9424 % X W i n d o w B y I D %
9428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9430 % XWindowByID() locates a child window with a given ID. If not window with
9431 % the given name is found, 0 is returned. Only the window specified and its
9432 % subwindows are searched.
9434 % The format of the XWindowByID function is:
9436 % child=XWindowByID(display,window,id)
9438 % A description of each parameter follows:
9440 % o child: XWindowByID returns the window with the specified
9441 % id. If no windows are found, XWindowByID returns 0.
9443 % o display: Specifies a pointer to the Display structure; returned from
9446 % o id: Specifies the id of the window to locate.
9449 MagickExport Window XWindowByID(Display *display,const Window root_window,
9469 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9470 assert(display != (Display *) NULL);
9471 assert(root_window != (Window) NULL);
9473 return(XSelectWindow(display,&rectangle_info));
9474 if (root_window == id)
9475 return(root_window);
9476 status=XQueryTree(display,root_window,&child,&child,&children,
9478 if (status == False)
9479 return((Window) NULL);
9480 window=(Window) NULL;
9481 for (i=0; i < (int) number_children; i++)
9484 Search each child and their children.
9486 window=XWindowByID(display,children[i],id);
9487 if (window != (Window) NULL)
9490 if (children != (Window *) NULL)
9491 (void) XFree((void *) children);
9496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9500 % X W i n d o w B y N a m e %
9504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9506 % XWindowByName() locates a window with a given name on a display. If no
9507 % window with the given name is found, 0 is returned. If more than one window
9508 % has the given name, the first one is returned. Only root and its children
9511 % The format of the XWindowByName function is:
9513 % window=XWindowByName(display,root_window,name)
9515 % A description of each parameter follows:
9517 % o window: XWindowByName returns the window id.
9519 % o display: Specifies a pointer to the Display structure; returned from
9522 % o root_window: Specifies the id of the root window.
9524 % o name: Specifies the name of the window to locate.
9527 MagickExport Window XWindowByName(Display *display,const Window root_window,
9547 assert(display != (Display *) NULL);
9548 assert(root_window != (Window) NULL);
9549 assert(name != (char *) NULL);
9550 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9551 if (XGetWMName(display,root_window,&window_name) != 0)
9552 if (LocaleCompare((char *) window_name.value,name) == 0)
9553 return(root_window);
9554 status=XQueryTree(display,root_window,&child,&child,&children,
9556 if (status == False)
9557 return((Window) NULL);
9558 window=(Window) NULL;
9559 for (i=0; i < (int) number_children; i++)
9562 Search each child and their children.
9564 window=XWindowByName(display,children[i],name);
9565 if (window != (Window) NULL)
9568 if (children != (Window *) NULL)
9569 (void) XFree((void *) children);
9574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9578 % X W i n d o w B y P r o p e r y %
9582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9584 % XWindowByProperty() locates a child window with a given property. If not
9585 % window with the given name is found, 0 is returned. If more than one window
9586 % has the given property, the first one is returned. Only the window
9587 % specified and its subwindows are searched.
9589 % The format of the XWindowByProperty function is:
9591 % child=XWindowByProperty(display,window,property)
9593 % A description of each parameter follows:
9595 % o child: XWindowByProperty returns the window id with the specified
9596 % property. If no windows are found, XWindowByProperty returns 0.
9598 % o display: Specifies a pointer to the Display structure; returned from
9601 % o property: Specifies the property of the window to locate.
9604 MagickExport Window XWindowByProperty(Display *display,const Window window,
9605 const Atom property)
9633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9634 assert(display != (Display *) NULL);
9635 assert(window != (Window) NULL);
9636 assert(property != (Atom) NULL);
9637 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9638 if (status == False)
9639 return((Window) NULL);
9641 child=(Window) NULL;
9642 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9644 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9645 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9647 (void) XFree((void *) data);
9648 if ((status == Success) && (type != (Atom) NULL))
9651 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9652 child=XWindowByProperty(display,children[i],property);
9653 if (children != (Window *) NULL)
9654 (void) XFree((void *) children);
9660 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9664 % X I m p o r t I m a g e %
9668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9670 % XImportImage() reads an image from an X window.
9672 % The format of the XImportImage method is:
9674 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9676 % A description of each parameter follows:
9678 % o image_info: the image info..
9680 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9683 MagickExport Image *XImportImage(const ImageInfo *image_info,
9684 XImportInfo *ximage_info)
9686 assert(image_info != (const ImageInfo *) NULL);
9687 assert(image_info->signature == MagickSignature);
9688 if (image_info->debug != MagickFalse)
9689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9690 image_info->filename);
9691 assert(ximage_info != (XImportInfo *) NULL);
9692 return((Image *) NULL);
9697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9701 + X C o m p o n e n t G e n e s i s %
9705 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9707 % XComponentGenesis() instantiates the X component.
9709 % The format of the XComponentGenesis method is:
9711 % MagickBooleanType XComponentGenesis(void)
9714 MagickExport MagickBooleanType XComponentGenesis(void)
9720 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9724 % X G e t I m p o r t I n f o %
9728 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9730 % XGetImportInfo() initializes the XImportInfo structure.
9732 % The format of the XGetImportInfo method is:
9734 % void XGetImportInfo(XImportInfo *ximage_info)
9736 % A description of each parameter follows:
9738 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9741 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9743 assert(ximage_info != (XImportInfo *) NULL);
9744 ximage_info->frame=MagickFalse;
9745 ximage_info->borders=MagickFalse;
9746 ximage_info->screen=MagickFalse;
9747 ximage_info->descend=MagickTrue;
9748 ximage_info->silent=MagickFalse;