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-2009 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/animate.h"
44 #include "magick/artifact.h"
45 #include "magick/blob.h"
46 #include "magick/cache.h"
47 #include "magick/client.h"
48 #include "magick/color.h"
49 #include "magick/color-private.h"
50 #include "magick/composite.h"
51 #include "magick/display.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/geometry.h"
55 #include "magick/identify.h"
56 #include "magick/image.h"
57 #include "magick/image-private.h"
58 #include "magick/list.h"
59 #include "magick/locale_.h"
60 #include "magick/log.h"
61 #include "magick/magick.h"
62 #include "magick/memory_.h"
63 #include "magick/monitor.h"
64 #include "magick/option.h"
65 #include "magick/PreRvIcccm.h"
66 #include "magick/quantize.h"
67 #include "magick/quantum.h"
68 #include "magick/quantum-private.h"
69 #include "magick/resource_.h"
70 #include "magick/resize.h"
71 #include "magick/shear.h"
72 #include "magick/statistic.h"
73 #include "magick/string_.h"
74 #include "magick/transform.h"
75 #include "magick/utility.h"
76 #include "magick/widget.h"
77 #include "magick/xwindow.h"
78 #include "magick/xwindow-private.h"
79 #include "magick/version.h"
83 #if defined(MAGICKCORE_X11_DELEGATE)
84 #include <X11/Xproto.h>
85 #include <X11/Xlocale.h>
86 #if defined(MAGICK_HAVE_POLL)
87 # include <sys/poll.h>
89 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
90 #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
91 # include <machine/param.h>
95 #include <X11/extensions/XShm.h>
97 #if defined(MAGICKCORE_HAVE_SHAPE)
98 #include <X11/extensions/shape.h>
104 #define XBlueGamma(color) RoundToQuantum(blue_gamma == 1.0 ? (double) \
105 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
107 #define XGammaPixel(map,color) (unsigned long) (map->base_pixel+ \
108 ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
110 ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
112 ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
114 #define XGreenGamma(color) RoundToQuantum(green_gamma == 1.0 ? (double) \
115 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
117 #define XRedGamma(color) RoundToQuantum(red_gamma == 1.0 ? (double) \
118 (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
120 #define XStandardPixel(map,color) (unsigned long) (map->base_pixel+ \
121 (((color)->red*map->red_max/65535L)*map->red_mult)+ \
122 (((color)->green*map->green_max/65535L)*map->green_mult)+ \
123 (((color)->blue*map->blue_max/65535L)*map->blue_mult))
125 #define AccentuateModulate ScaleCharToQuantum(80)
126 #define HighlightModulate ScaleCharToQuantum(125)
127 #define ShadowModulate ScaleCharToQuantum(135)
128 #define DepthModulate ScaleCharToQuantum(185)
129 #define TroughModulate ScaleCharToQuantum(110)
131 #define XLIB_ILLEGAL_ACCESS 1
133 #undef NorthWestGravity
135 #undef NorthEastGravity
139 #undef SouthWestGravity
141 #undef SouthEastGravity
148 #define XFD_SET fd_set
152 Enumeration declarations.
166 Typedef declarations.
168 typedef struct _DiversityPacket
183 Constant declaractions.
185 static MagickBooleanType
186 xerror_alert = MagickFalse;
192 *XVisualClassName(const int);
194 static MagickRealType
199 static MagickBooleanType
200 XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
203 XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
205 XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
209 XSelectWindow(Display *,RectangleInfo *);
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 % D e s t r o y X R e s o u r c e s %
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 % DestroyXResources() destroys any X resources.
224 % The format of the DestroyXResources method is:
226 % void DestroyXResources()
228 % A description of each parameter follows:
231 MagickExport void DestroyXResources(void)
240 *magick_windows[MaxXWindows];
246 windows=XSetWindows((XWindows *) ~0);
247 if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
250 magick_windows[number_windows++]=(&windows->context);
251 magick_windows[number_windows++]=(&windows->group_leader);
252 magick_windows[number_windows++]=(&windows->backdrop);
253 magick_windows[number_windows++]=(&windows->icon);
254 magick_windows[number_windows++]=(&windows->image);
255 magick_windows[number_windows++]=(&windows->info);
256 magick_windows[number_windows++]=(&windows->magnify);
257 magick_windows[number_windows++]=(&windows->pan);
258 magick_windows[number_windows++]=(&windows->command);
259 magick_windows[number_windows++]=(&windows->widget);
260 magick_windows[number_windows++]=(&windows->popup);
261 magick_windows[number_windows++]=(&windows->context);
262 for (i=0; i < (int) number_windows; i++)
264 if (magick_windows[i]->mapped != MagickFalse)
266 (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
267 magick_windows[i]->screen);
268 magick_windows[i]->mapped=MagickFalse;
270 if (magick_windows[i]->name != (char *) NULL)
271 magick_windows[i]->name=(char *)
272 RelinquishMagickMemory(magick_windows[i]->name);
273 if (magick_windows[i]->icon_name != (char *) NULL)
274 magick_windows[i]->icon_name=(char *)
275 RelinquishMagickMemory(magick_windows[i]->icon_name);
276 if (magick_windows[i]->cursor != (Cursor) NULL)
278 (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
279 magick_windows[i]->cursor=(Cursor) NULL;
281 if (magick_windows[i]->busy_cursor != (Cursor) NULL)
283 (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
284 magick_windows[i]->busy_cursor=(Cursor) NULL;
286 if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
288 (void) XFreePixmap(windows->display,
289 magick_windows[i]->highlight_stipple);
290 magick_windows[i]->highlight_stipple=(Pixmap) NULL;
292 if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
294 (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
295 magick_windows[i]->shadow_stipple=(Pixmap) NULL;
297 if (magick_windows[i]->ximage != (XImage *) NULL)
299 XDestroyImage(magick_windows[i]->ximage);
300 magick_windows[i]->ximage=(XImage *) NULL;
302 if (magick_windows[i]->pixmap != (Pixmap) NULL)
304 (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
305 magick_windows[i]->pixmap=(Pixmap) NULL;
307 if (magick_windows[i]->id != (Window) NULL)
309 (void) XDestroyWindow(windows->display,magick_windows[i]->id);
310 magick_windows[i]->id=(Window) NULL;
312 if (magick_windows[i]->destroy != MagickFalse)
314 if (magick_windows[i]->image != (Image *) NULL)
316 magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
317 magick_windows[i]->image=NewImageList();
319 if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
321 (void) XFreePixmap(windows->display,
322 magick_windows[i]->matte_pixmap);
323 magick_windows[i]->matte_pixmap=(Pixmap) NULL;
326 if (magick_windows[i]->segment_info != (void *) NULL)
328 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
332 segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
333 if (segment_info != (XShmSegmentInfo *) NULL)
334 if (segment_info[0].shmid >= 0)
336 if (segment_info[0].shmaddr != NULL)
337 (void) shmdt(segment_info[0].shmaddr);
338 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
339 segment_info[0].shmaddr=NULL;
340 segment_info[0].shmid=(-1);
343 magick_windows[i]->segment_info=(void *)
344 RelinquishMagickMemory(magick_windows[i]->segment_info);
347 windows->icon_resources=(XResourceInfo *)
348 RelinquishMagickMemory(windows->icon_resources);
349 if (windows->icon_pixel != (XPixelInfo *) NULL)
351 if (windows->icon_pixel->pixels != (unsigned long *) NULL)
352 windows->icon_pixel->pixels=(unsigned long *)
353 RelinquishMagickMemory(windows->icon_pixel->pixels);
354 if (windows->icon_pixel->annotate_context != (GC) NULL)
355 XFreeGC(windows->display,windows->icon_pixel->annotate_context);
356 windows->icon_pixel=(XPixelInfo *)
357 RelinquishMagickMemory(windows->icon_pixel);
359 if (windows->pixel_info != (XPixelInfo *) NULL)
361 if (windows->pixel_info->pixels != (unsigned long *) NULL)
362 windows->pixel_info->pixels=(unsigned long *)
363 RelinquishMagickMemory(windows->pixel_info->pixels);
364 if (windows->pixel_info->annotate_context != (GC) NULL)
365 XFreeGC(windows->display,windows->pixel_info->annotate_context);
366 if (windows->pixel_info->widget_context != (GC) NULL)
367 XFreeGC(windows->display,windows->pixel_info->widget_context);
368 if (windows->pixel_info->highlight_context != (GC) NULL)
369 XFreeGC(windows->display,windows->pixel_info->highlight_context);
370 windows->pixel_info=(XPixelInfo *)
371 RelinquishMagickMemory(windows->pixel_info);
373 if (windows->font_info != (XFontStruct *) NULL)
375 XFreeFont(windows->display,windows->font_info);
376 windows->font_info=(XFontStruct *) NULL;
378 if (windows->class_hints != (XClassHint *) NULL)
380 if (windows->class_hints->res_name != (char *) NULL)
381 XFree(windows->class_hints->res_name);
382 if (windows->class_hints->res_class != (char *) NULL)
383 XFree(windows->class_hints->res_class);
384 XFree(windows->class_hints);
385 windows->class_hints=(XClassHint *) NULL;
387 if (windows->manager_hints != (XWMHints *) NULL)
389 XFree(windows->manager_hints);
390 windows->manager_hints=(XWMHints *) NULL;
392 if (windows->map_info != (XStandardColormap *) NULL)
394 XFree(windows->map_info);
395 windows->map_info=(XStandardColormap *) NULL;
397 if (windows->icon_map != (XStandardColormap *) NULL)
399 XFree(windows->icon_map);
400 windows->icon_map=(XStandardColormap *) NULL;
402 if (windows->visual_info != (XVisualInfo *) NULL)
404 XFree(windows->visual_info);
405 windows->visual_info=(XVisualInfo *) NULL;
407 if (windows->icon_visual != (XVisualInfo *) NULL)
409 XFree(windows->icon_visual);
410 windows->icon_visual=(XVisualInfo *) NULL;
412 (void) XSetWindows((XWindows *) NULL);
416 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 % X A n n o t a t e I m a g e %
424 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 % XAnnotateImage() annotates the image with text.
428 % The format of the XAnnotateImage method is:
430 % MagickBooleanType XAnnotateImage(Display *display,
431 % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
433 % A description of each parameter follows:
435 % o display: Specifies a connection to an X server; returned from
438 % o pixel: Specifies a pointer to a XPixelInfo structure.
440 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
442 % o image: the image.
445 MagickExport MagickBooleanType XAnnotateImage(Display *display,
446 const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image)
482 Initialize annotated image.
484 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
485 assert(display != (Display *) NULL);
486 assert(pixel != (XPixelInfo *) NULL);
487 assert(annotate_info != (XAnnotateInfo *) NULL);
488 assert(image != (Image *) NULL);
490 Initialize annotated pixmap.
492 root_window=XRootWindow(display,XDefaultScreen(display));
493 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
494 annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
495 annotate_info->height,depth);
496 if (annotate_pixmap == (Pixmap) NULL)
499 Initialize graphics info.
501 context_values.background=0;
502 context_values.foreground=(unsigned long) (~0);
503 context_values.font=annotate_info->font_info->fid;
504 annotate_context=XCreateGC(display,root_window,(unsigned long)
505 GCBackground | GCFont | GCForeground,&context_values);
506 if (annotate_context == (GC) NULL)
511 (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
512 (int) annotate_info->font_info->ascent,annotate_info->text,
513 (int) strlen(annotate_info->text));
514 (void) XFreeGC(display,annotate_context);
516 Initialize annotated X image.
518 annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
519 annotate_info->height,AllPlanes,ZPixmap);
520 if (annotate_ximage == (XImage *) NULL)
522 (void) XFreePixmap(display,annotate_pixmap);
524 Initialize annotated image.
526 annotate_image=AcquireImage((ImageInfo *) NULL);
527 if (annotate_image == (Image *) NULL)
529 annotate_image->columns=annotate_info->width;
530 annotate_image->rows=annotate_info->height;
532 Transfer annotated X image to image.
534 width=(unsigned int) image->columns;
535 height=(unsigned int) image->rows;
538 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
539 (void) GetOneVirtualPixel(image,x,y,&annotate_image->background_color,
541 if (annotate_info->stencil == ForegroundStencil)
542 annotate_image->matte=MagickTrue;
543 exception=(&image->exception);
544 for (y=0; y < (int) annotate_image->rows; y++)
552 q=GetAuthenticPixels(annotate_image,0,y,annotate_image->columns,1,
554 if (q == (PixelPacket *) NULL)
556 for (x=0; x < (long) annotate_image->columns; x++)
558 q->opacity=OpaqueOpacity;
559 if (XGetPixel(annotate_ximage,x,y) == 0)
562 Set this pixel to the background color.
564 q->red=ScaleShortToQuantum(pixel->box_color.red);
565 q->green=ScaleShortToQuantum(pixel->box_color.green);
566 q->blue=ScaleShortToQuantum(pixel->box_color.blue);
567 if ((annotate_info->stencil == ForegroundStencil) ||
568 (annotate_info->stencil == OpaqueStencil))
569 q->opacity=(Quantum) TransparentOpacity;
574 Set this pixel to the pen color.
576 q->red=ScaleShortToQuantum(pixel->pen_color.red);
577 q->green=ScaleShortToQuantum(pixel->pen_color.green);
578 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
579 if (annotate_info->stencil == BackgroundStencil)
580 q->opacity=(Quantum) TransparentOpacity;
584 if (SyncAuthenticPixels(annotate_image,exception) == MagickFalse)
587 XDestroyImage(annotate_ximage);
589 Determine annotate geometry.
591 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
592 if ((width != (unsigned int) annotate_image->columns) ||
593 (height != (unsigned int) annotate_image->rows))
596 image_geometry[MaxTextExtent];
601 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
603 (void) TransformImage(&annotate_image,(char *) NULL,image_geometry);
605 if (annotate_info->degrees != 0.0)
620 RotateImage(annotate_image,annotate_info->degrees,&image->exception);
621 if (rotate_image == (Image *) NULL)
623 annotate_image=DestroyImage(annotate_image);
624 annotate_image=rotate_image;
626 Annotation is relative to the degree of rotation.
628 normalized_degrees=annotate_info->degrees;
629 while (normalized_degrees < -45.0)
630 normalized_degrees+=360.0;
631 for (rotations=0; normalized_degrees > 45.0; rotations++)
632 normalized_degrees-=90.0;
633 switch (rotations % 4)
643 x-=(int) annotate_image->columns/2;
644 y+=(int) annotate_image->columns/2;
652 x=x-(int) annotate_image->columns;
660 x=x-(int) annotate_image->columns/2;
661 y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
667 Composite text onto the image.
669 (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
671 (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
672 OverCompositeOp : CopyCompositeOp,annotate_image,x,y);
674 annotate_image=DestroyImage(annotate_image);
679 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683 % X B e s t F o n t %
687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 % XBestFont() returns the "best" font. "Best" is defined as a font specified
690 % in the X resource database or a font such that the text width displayed
691 % with the font does not exceed the specified maximum width.
693 % The format of the XBestFont method is:
695 % XFontStruct *XBestFont(Display *display,
696 % const XResourceInfo *resource_info,const MagickBooleanType text_font)
698 % A description of each parameter follows:
700 % o font: XBestFont returns a pointer to a XFontStruct structure.
702 % o display: Specifies a connection to an X server; returned from
705 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
707 % o text_font: True is font should be mono-spaced (typewriter style).
712 static char **FontToList(char *font)
727 if (font == (char *) NULL)
728 return((char **) NULL);
730 Convert string to an ASCII list.
733 for (p=font; *p != '\0'; p++)
734 if ((*p == ':') || (*p == ';') || (*p == ','))
736 fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
737 if (fontlist == (char **) NULL)
739 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
741 return((char **) NULL);
744 for (i=0; i < (int) fonts; i++)
746 for (q=p; *q != '\0'; q++)
747 if ((*q == ':') || (*q == ';') || (*q == ','))
749 fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
750 sizeof(*fontlist[i]));
751 if (fontlist[i] == (char *) NULL)
753 ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
755 return((char **) NULL);
757 (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
760 fontlist[i]=(char *) NULL;
764 MagickExport XFontStruct *XBestFont(Display *display,
765 const XResourceInfo *resource_info,const MagickBooleanType text_font)
770 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
771 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
772 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
773 "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
774 "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
775 "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
782 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
783 "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
784 "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
798 font_info=(XFontStruct *) NULL;
799 font_name=resource_info->font;
800 if (text_font != MagickFalse)
801 font_name=resource_info->text_font;
802 if ((font_name != (char *) NULL) && (*font_name != '\0'))
811 Load preferred font specified in the X resource database.
813 fontlist=FontToList(font_name);
814 if (fontlist != (char **) NULL)
816 for (i=0; fontlist[i] != (char *) NULL; i++)
818 if (font_info == (XFontStruct *) NULL)
819 font_info=XLoadQueryFont(display,fontlist[i]);
820 fontlist[i]=DestroyString(fontlist[i]);
822 fontlist=(char **) RelinquishMagickMemory(fontlist);
824 if (font_info == (XFontStruct *) NULL)
825 ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
828 Load fonts from list of fonts until one is found.
831 if (text_font != MagickFalse)
833 if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
835 while (*p != (char *) NULL)
837 if (font_info != (XFontStruct *) NULL)
839 font_info=XLoadQueryFont(display,(char *) *p);
846 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850 % X B e s t I c o n S i z e %
854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
856 % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
857 % size that maintains the aspect ratio of the image. If the window manager
858 % has preferred icon sizes, one of the preferred sizes is used.
860 % The format of the XBestIconSize method is:
862 % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
864 % A description of each parameter follows:
866 % o display: Specifies a connection to an X server; returned from
869 % o image: the image.
872 MagickExport void XBestIconSize(Display *display,XWindowInfo *window,
896 Determine if the window manager has specified preferred icon sizes.
898 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
899 assert(display != (Display *) NULL);
900 assert(window != (XWindowInfo *) NULL);
901 assert(image != (Image *) NULL);
902 window->width=MaxIconSize;
903 window->height=MaxIconSize;
904 icon_size=(XIconSize *) NULL;
906 root_window=XRootWindow(display,window->screen);
907 if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
908 if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
910 if (icon_size == (XIconSize *) NULL)
913 Window manager does not restrict icon size.
915 icon_size=XAllocIconSize();
916 if (icon_size == (XIconSize *) NULL)
918 ThrowXWindowFatalException(ResourceLimitError,
919 "MemoryAllocationFailed",image->filename);
922 icon_size->min_width=1;
923 icon_size->max_width=MaxIconSize;
924 icon_size->min_height=1;
925 icon_size->max_height=MaxIconSize;
926 icon_size->width_inc=1;
927 icon_size->height_inc=1;
930 Determine aspect ratio of image.
932 width=(unsigned int) image->columns;
933 height=(unsigned int) image->rows;
935 if (window->crop_geometry)
936 (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
938 Look for an icon size that maintains the aspect ratio of image.
940 scale_factor=(MagickRealType) icon_size->max_width/width;
941 if (scale_factor > ((MagickRealType) icon_size->max_height/height))
942 scale_factor=(MagickRealType) icon_size->max_height/height;
943 icon_width=(unsigned int) icon_size->min_width;
944 while ((int) icon_width < icon_size->max_width)
946 if (icon_width >= (unsigned int) (scale_factor*width+0.5))
948 icon_width+=icon_size->width_inc;
950 icon_height=(unsigned int) icon_size->min_height;
951 while ((int) icon_height < icon_size->max_height)
953 if (icon_height >= (unsigned int) (scale_factor*height+0.5))
955 icon_height+=icon_size->height_inc;
957 (void) XFree((void *) icon_size);
958 window->width=icon_width;
959 window->height=icon_height;
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 % X B e s t P i x e l %
971 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 % XBestPixel() returns a pixel from an array of pixels that is closest to the
974 % requested color. If the color array is NULL, the colors are obtained from
977 % The format of the XBestPixel method is:
979 % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
980 % unsigned int number_colors,XColor *color)
982 % A description of each parameter follows:
984 % o pixel: XBestPixel returns the pixel value closest to the requested
987 % o display: Specifies a connection to an X server; returned from
990 % o colormap: Specifies the ID of the X server colormap.
992 % o colors: Specifies an array of XColor structures.
994 % o number_colors: Specifies the number of XColor structures in the
995 % color definition array.
997 % o color: Specifies the desired RGB value to find in the colors array.
1000 MagickExport void XBestPixel(Display *display,const Colormap colormap,
1001 XColor *colors,unsigned int number_colors,XColor *color)
1012 register MagickRealType
1023 Find closest representation for the requested RGB color.
1025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1026 assert(display != (Display *) NULL);
1027 assert(color != (XColor *) NULL);
1028 status=XAllocColor(display,colormap,color);
1029 if (status != False)
1031 query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
1032 if (query_server != MagickFalse)
1035 Read X server colormap.
1037 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
1038 if (colors == (XColor *) NULL)
1040 ThrowXWindowFatalException(ResourceLimitError,
1041 "MemoryAllocationFailed","...");
1044 for (i=0; i < (int) number_colors; i++)
1045 colors[i].pixel=(unsigned long) i;
1046 if (number_colors > 256)
1048 (void) XQueryColors(display,colormap,colors,(int) number_colors);
1050 min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
1053 for (i=0; i < (int) number_colors; i++)
1055 pixel.red=colors[i].red-(MagickRealType) color->red;
1056 distance=pixel.red*pixel.red;
1057 if (distance > min_distance)
1059 pixel.green=colors[i].green-(MagickRealType) color->green;
1060 distance+=pixel.green*pixel.green;
1061 if (distance > min_distance)
1063 pixel.blue=colors[i].blue-(MagickRealType) color->blue;
1064 distance+=pixel.blue*pixel.blue;
1065 if (distance > min_distance)
1067 min_distance=distance;
1068 color->pixel=colors[i].pixel;
1071 (void) XAllocColor(display,colormap,&colors[j]);
1072 if (query_server != MagickFalse)
1073 colors=(XColor *) RelinquishMagickMemory(colors);
1077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1081 % X B e s t V i s u a l I n f o %
1085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1087 % XBestVisualInfo() returns visual information for a visual that is the "best"
1088 % the server supports. "Best" is defined as:
1090 % 1. Restrict the visual list to those supported by the default screen.
1092 % 2. If a visual type is specified, restrict the visual list to those of
1095 % 3. If a map type is specified, choose the visual that matches the id
1096 % specified by the Standard Colormap.
1098 % 4 From the list of visuals, choose one that can display the most
1099 % simultaneous colors. If more than one visual can display the same
1100 % number of simultaneous colors, one is chosen based on a rank.
1102 % The format of the XBestVisualInfo method is:
1104 % XVisualInfo *XBestVisualInfo(Display *display,
1105 % XStandardColormap *map_info,XResourceInfo *resource_info)
1107 % A description of each parameter follows:
1109 % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
1112 % o display: Specifies a connection to an X server; returned from
1115 % o map_info: If map_type is specified, this structure is initialized
1116 % with info from the Standard Colormap.
1118 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1122 static inline int MagickMax(const int x,const int y)
1129 static inline unsigned long MagickMin(const unsigned int x,
1130 const unsigned int y)
1137 MagickExport XVisualInfo *XBestVisualInfo(Display *display,
1138 XStandardColormap *map_info,XResourceInfo *resource_info)
1140 #define MaxStandardColormaps 7
1141 #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
1142 (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
1143 visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1144 (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
1167 Restrict visual search by screen number.
1169 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1170 assert(display != (Display *) NULL);
1171 assert(map_info != (XStandardColormap *) NULL);
1172 assert(resource_info != (XResourceInfo *) NULL);
1173 map_type=resource_info->map_type;
1174 visual_type=resource_info->visual_type;
1175 visual_mask=VisualScreenMask;
1176 visual_template.screen=XDefaultScreen(display);
1177 visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
1178 if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
1179 if (resource_info->colors <= (1UL << (unsigned long) visual_template.depth))
1180 visual_mask|=VisualDepthMask;
1181 if (visual_type != (char *) NULL)
1184 Restrict visual search by class or visual id.
1186 if (LocaleCompare("staticgray",visual_type) == 0)
1188 visual_mask|=VisualClassMask;
1189 visual_template.klass=StaticGray;
1192 if (LocaleCompare("grayscale",visual_type) == 0)
1194 visual_mask|=VisualClassMask;
1195 visual_template.klass=GrayScale;
1198 if (LocaleCompare("staticcolor",visual_type) == 0)
1200 visual_mask|=VisualClassMask;
1201 visual_template.klass=StaticColor;
1204 if (LocaleCompare("pseudocolor",visual_type) == 0)
1206 visual_mask|=VisualClassMask;
1207 visual_template.klass=PseudoColor;
1210 if (LocaleCompare("truecolor",visual_type) == 0)
1212 visual_mask|=VisualClassMask;
1213 visual_template.klass=TrueColor;
1216 if (LocaleCompare("directcolor",visual_type) == 0)
1218 visual_mask|=VisualClassMask;
1219 visual_template.klass=DirectColor;
1222 if (LocaleCompare("default",visual_type) == 0)
1224 visual_mask|=VisualIDMask;
1225 visual_template.visualid=XVisualIDFromVisual(
1226 XDefaultVisual(display,XDefaultScreen(display)));
1229 if (isdigit((int) ((unsigned char) *visual_type)) != 0)
1231 visual_mask|=VisualIDMask;
1232 visual_template.visualid=
1233 strtol(visual_type,(char **) NULL,0);
1236 ThrowXWindowFatalException(XServerError,
1237 "UnrecognizedVisualSpecifier",visual_type);
1240 Get all visuals that meet our criteria so far.
1243 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1245 visual_mask=VisualScreenMask | VisualIDMask;
1246 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1249 Failed to get visual; try using the default visual.
1251 ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
1253 visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
1254 XDefaultScreen(display)));
1255 visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
1257 if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
1258 return((XVisualInfo *) NULL);
1259 ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
1260 XVisualClassName(visual_list->klass));
1262 resource_info->color_recovery=MagickFalse;
1263 if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
1269 map_name[MaxTextExtent];
1285 Choose a visual associated with a standard colormap.
1287 root_window=XRootWindow(display,XDefaultScreen(display));
1289 if (LocaleCompare(map_type,"list") != 0)
1292 User specified Standard Colormap.
1294 (void) FormatMagickString((char *) map_name,MaxTextExtent,
1295 "RGB_%s_MAP",map_type);
1296 LocaleUpper(map_name);
1297 map_property=XInternAtom(display,(char *) map_name,MagickTrue);
1298 if (map_property != (Atom) NULL)
1299 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1305 *colormap[MaxStandardColormaps]=
1307 "_HP_RGB_SMOOTH_MAP_LIST",
1317 Choose a standard colormap from a list.
1319 for (i=0; i < MaxStandardColormaps; i++)
1321 map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
1322 if (map_property == (Atom) NULL)
1324 status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
1326 if (status != False)
1329 resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
1331 if (status == False)
1333 ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
1335 return((XVisualInfo *) NULL);
1338 Search all Standard Colormaps and visuals for ids that match.
1340 *map_info=map_list[0];
1341 #if !defined(PRE_R4_ICCCM)
1342 visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
1343 for (i=0; i < number_maps; i++)
1344 for (j=0; j < number_visuals; j++)
1345 if (map_list[i].visualid ==
1346 XVisualIDFromVisual(visual_list[j].visual))
1348 *map_info=map_list[i];
1349 visual_template.visualid=XVisualIDFromVisual(
1350 visual_list[j].visual);
1353 if (map_info->visualid != visual_template.visualid)
1355 ThrowXWindowFatalException(XServerError,
1356 "UnableToMatchVisualToStandardColormap",map_type);
1357 return((XVisualInfo *) NULL);
1360 if (map_info->colormap == (Colormap) NULL)
1362 ThrowXWindowFatalException(XServerError,
1363 "StandardColormapIsNotInitialized",map_type);
1364 return((XVisualInfo *) NULL);
1366 (void) XFree((void *) map_list);
1370 static const unsigned int
1385 Pick one visual that displays the most simultaneous colors.
1387 visual_info=visual_list;
1389 for (i=1; i < number_visuals; i++)
1392 if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
1395 if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
1396 if (rank[p->klass] > rank[visual_info->klass])
1399 visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
1401 (void) XFree((void *) visual_list);
1403 Retrieve only one visual by its screen & id number.
1405 visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
1407 if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
1408 return((XVisualInfo *) NULL);
1409 return(visual_info);
1413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1417 % X C h e c k D e f i n e C u r s o r %
1421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1423 % XCheckDefineCursor() prevents cursor changes on the root window.
1425 % The format of the XXCheckDefineCursor method is:
1427 % XCheckDefineCursor(display,window,cursor)
1429 % A description of each parameter follows:
1431 % o display: Specifies a connection to an X server; returned from
1434 % o window: the window.
1436 % o cursor: the cursor.
1439 MagickExport int XCheckDefineCursor(Display *display,Window window,
1442 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1443 assert(display != (Display *) NULL);
1444 if (window == XRootWindow(display,XDefaultScreen(display)))
1446 return(XDefineCursor(display,window,cursor));
1450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1454 % X C h e c k R e f r e s h W i n d o w s %
1458 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1460 % XCheckRefreshWindows() checks the X server for exposure events for a
1461 % particular window and updates the areassociated with the exposure event.
1463 % The format of the XCheckRefreshWindows method is:
1465 % void XCheckRefreshWindows(Display *display,XWindows *windows)
1467 % A description of each parameter follows:
1469 % o display: Specifies a connection to an X server; returned from
1472 % o windows: Specifies a pointer to a XWindows structure.
1475 MagickExport void XCheckRefreshWindows(Display *display,XWindows *windows)
1483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1484 assert(display != (Display *) NULL);
1485 assert(windows != (XWindows *) NULL);
1486 XDelay(display,SuspendTime);
1487 id=windows->command.id;
1488 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1489 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1490 id=windows->image.id;
1491 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1492 XRefreshWindow(display,&windows->image,&event);
1493 XDelay(display,SuspendTime << 1);
1494 id=windows->command.id;
1495 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1496 (void) XCommandWidget(display,windows,(char const **) NULL,&event);
1497 id=windows->image.id;
1498 while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
1499 XRefreshWindow(display,&windows->image,&event);
1503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1507 % X C l i e n t M e s s a g e %
1511 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513 % XClientMessage() sends a reason to a window with XSendEvent. The reason is
1514 % initialized with a particular protocol type and atom.
1516 % The format of the XClientMessage function is:
1518 % XClientMessage(display,window,protocol,reason,timestamp)
1520 % A description of each parameter follows:
1522 % o display: Specifies a pointer to the Display structure; returned from
1525 % o window: Specifies a pointer to a Window structure.
1527 % o protocol: Specifies an atom value.
1529 % o reason: Specifies an atom value which is the reason to send.
1531 % o timestamp: Specifies a value of type Time.
1534 MagickExport void XClientMessage(Display *display,const Window window,
1535 const Atom protocol,const Atom reason,const Time timestamp)
1540 assert(display != (Display *) NULL);
1541 client_event.type=ClientMessage;
1542 client_event.window=window;
1543 client_event.message_type=protocol;
1544 client_event.format=32;
1545 client_event.data.l[0]=(long) reason;
1546 client_event.data.l[1]=(long) timestamp;
1547 (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555 + X C l i e n t W i n d o w %
1559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1561 % XClientWindow() finds a window, at or below the specified window, which has
1562 % a WM_STATE property. If such a window is found, it is returned, otherwise
1563 % the argument window is returned.
1565 % The format of the XClientWindow function is:
1567 % client_window=XClientWindow(display,target_window)
1569 % A description of each parameter follows:
1571 % o client_window: XClientWindow returns a window, at or below the specified
1572 % window, which has a WM_STATE property otherwise the argument
1573 % target_window is returned.
1575 % o display: Specifies a pointer to the Display structure; returned from
1578 % o target_window: Specifies the window to find a WM_STATE property.
1582 static Window XClientWindow(Display *display,Window target_window)
1604 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1605 assert(display != (Display *) NULL);
1606 state=XInternAtom(display,"WM_STATE",MagickTrue);
1607 if (state == (Atom) NULL)
1608 return(target_window);
1610 status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
1611 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
1612 if ((status == Success) && (type != (Atom) NULL))
1613 return(target_window);
1614 client_window=XWindowByProperty(display,target_window,state);
1615 if (client_window == (Window) NULL)
1616 return(target_window);
1617 return(client_window);
1621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625 % X C o n f i g u r e I m a g e C o l o r m a p %
1629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1631 % XConfigureImageColormap() creates a new X colormap.
1633 % The format of the XConfigureImageColormap method is:
1635 % void XConfigureImageColormap(Display *display,
1636 % XResourceInfo *resource_info,XWindows *windows,Image *image)
1638 % A description of each parameter follows:
1640 % o display: Specifies a connection to an X server; returned from
1643 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1645 % o windows: Specifies a pointer to a XWindows structure.
1647 % o image: the image.
1650 MagickExport void XConfigureImageColormap(Display *display,
1651 XResourceInfo *resource_info,XWindows *windows,Image *image)
1657 Make standard colormap.
1659 XSetCursorState(display,windows,MagickTrue);
1660 XCheckRefreshWindows(display,windows);
1661 XMakeStandardColormap(display,windows->visual_info,resource_info,image,
1662 windows->map_info,windows->pixel_info);
1663 colormap=windows->map_info->colormap;
1664 (void) XSetWindowColormap(display,windows->image.id,colormap);
1665 (void) XSetWindowColormap(display,windows->command.id,colormap);
1666 (void) XSetWindowColormap(display,windows->widget.id,colormap);
1667 if (windows->magnify.mapped != MagickFalse)
1668 (void) XSetWindowColormap(display,windows->magnify.id,colormap);
1669 if (windows->pan.mapped != MagickFalse)
1670 (void) XSetWindowColormap(display,windows->pan.id,colormap);
1671 XSetCursorState(display,windows,MagickFalse);
1672 XClientMessage(display,windows->image.id,windows->im_protocols,
1673 windows->im_update_colormap,CurrentTime);
1677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1681 % X C o n s t r a i n W i n d o w P o s i t i o n %
1685 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1687 % XConstrainWindowPosition() assures a window is positioned within the X
1688 % server boundaries.
1690 % The format of the XConstrainWindowPosition method is:
1692 % void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
1694 % A description of each parameter follows:
1696 % o display: Specifies a pointer to the Display structure; returned from
1699 % o window_info: Specifies a pointer to a XWindowInfo structure.
1702 MagickExport void XConstrainWindowPosition(Display *display,
1703 XWindowInfo *window_info)
1708 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1709 assert(display != (Display *) NULL);
1710 assert(window_info != (XWindowInfo *) NULL);
1711 limit=XDisplayWidth(display,window_info->screen)-window_info->width;
1712 if (window_info->x < 0)
1715 if (window_info->x > (int) limit)
1716 window_info->x=(int) limit;
1717 limit=XDisplayHeight(display,window_info->screen)-window_info->height;
1718 if (window_info->y < 0)
1721 if (window_info->y > limit)
1722 window_info->y=limit;
1726 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1734 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1736 % XDelay() suspends program execution for the number of milliseconds
1739 % The format of the Delay method is:
1741 % void XDelay(Display *display,const unsigned long milliseconds)
1743 % A description of each parameter follows:
1745 % o display: Specifies a pointer to the Display structure; returned from
1748 % o milliseconds: Specifies the number of milliseconds to delay before
1752 MagickExport void XDelay(Display *display,const unsigned long milliseconds)
1754 assert(display != (Display *) NULL);
1755 (void) XFlush(display);
1756 if (milliseconds == 0)
1758 #if defined(__WINDOWS__)
1759 Sleep(milliseconds);
1765 timer=milliseconds/1000.0;
1768 #elif defined(MAGICKCORE_HAVE_USLEEP)
1769 usleep(1000*milliseconds);
1770 #elif defined(MAGICKCORE_HAVE_SELECT)
1775 timer.tv_sec=(long) milliseconds/1000;
1776 timer.tv_usec=(long) (milliseconds % 1000)*1000;
1777 (void) select(0,(XFD_SET *) NULL,(XFD_SET *) NULL,(XFD_SET *) NULL,&timer);
1779 #elif defined(MAGICKCORE_HAVE_POLL)
1780 (void) poll((struct pollfd *) NULL,0,(int) milliseconds);
1781 #elif defined(__BEOS__)
1782 snooze(1000*milliseconds);
1784 # error "Time delay method not defined."
1789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1793 % X D e s t r o y R e s o u r c e I n f o %
1797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1799 % XDestroyResourceInfo() frees memory associated with the XResourceInfo
1802 % The format of the XDestroyResourceInfo method is:
1804 % void XDestroyResourceInfo(XResourceInfo *resource_info)
1806 % A description of each parameter follows:
1808 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1811 MagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
1813 if (resource_info->image_geometry != (char *) NULL)
1814 resource_info->image_geometry=(char *)
1815 RelinquishMagickMemory(resource_info->image_geometry);
1816 if (resource_info->quantize_info != (QuantizeInfo *) NULL)
1817 resource_info->quantize_info=DestroyQuantizeInfo(
1818 resource_info->quantize_info);
1819 if (resource_info->client_name != (char *) NULL)
1820 resource_info->client_name=(char *)
1821 RelinquishMagickMemory(resource_info->client_name);
1822 if (resource_info->name != (char *) NULL)
1823 resource_info->name=DestroyString(resource_info->name);
1824 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
1828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1832 % X D e s t r o y W i n d o w C o l o r s %
1836 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1838 % XDestroyWindowColors() frees X11 color resources previously saved on a
1839 % window by XRetainWindowColors or programs like xsetroot.
1841 % The format of the XDestroyWindowColors method is:
1843 % void XDestroyWindowColors(Display *display,Window window)
1845 % A description of each parameter follows:
1847 % o display: Specifies a connection to an X server; returned from
1850 % o window: Specifies a pointer to a Window structure.
1853 MagickExport void XDestroyWindowColors(Display *display,Window window)
1873 If there are previous resources on the root window, destroy them.
1875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1876 assert(display != (Display *) NULL);
1877 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
1878 if (property == (Atom) NULL)
1880 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
1884 status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
1885 (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
1886 if (status != Success)
1888 if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
1890 (void) XKillClient(display,(XID) (*((Pixmap *) data)));
1891 (void) XDeleteProperty(display,window,property);
1894 (void) XFree((void *) data);
1898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1902 % X D i s p l a y I m a g e I n f o %
1906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1908 % XDisplayImageInfo() displays information about an X image.
1910 % The format of the XDisplayImageInfo method is:
1912 % void XDisplayImageInfo(Display *display,
1913 % const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1916 % A description of each parameter follows:
1918 % o display: Specifies a connection to an X server; returned from
1921 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
1923 % o windows: Specifies a pointer to a XWindows structure.
1925 % o undo_image: the undo image.
1927 % o image: the image.
1930 MagickExport void XDisplayImageInfo(Display *display,
1931 const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
1935 filename[MaxTextExtent],
1958 Write info about the X server to a file.
1960 assert(display != (Display *) NULL);
1961 assert(resource_info != (XResourceInfo *) NULL);
1962 assert(windows != (XWindows *) NULL);
1963 assert(image != (Image *) NULL);
1965 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1967 unique_file=AcquireUniqueFileResource(filename);
1968 if (unique_file != -1)
1969 file=fdopen(unique_file,"w");
1970 if ((unique_file == -1) || (file == (FILE *) NULL))
1972 XNoticeWidget(display,windows,"Unable to display image info",filename);
1975 if (resource_info->gamma_correct != MagickFalse)
1976 if (resource_info->display_gamma != (char *) NULL)
1977 (void) fprintf(file,"Display\n gamma: %s\n\n",
1978 resource_info->display_gamma);
1980 Write info about the X image to a file.
1982 (void) fprintf(file,"X\n visual: %s\n",
1983 XVisualClassName((int) windows->image.storage_class));
1984 (void) fprintf(file," depth: %d\n",windows->image.ximage->depth);
1985 if (windows->visual_info->colormap_size != 0)
1986 (void) fprintf(file," colormap size: %d\n",
1987 windows->visual_info->colormap_size);
1988 if (resource_info->colormap== SharedColormap)
1989 (void) fprintf(file," colormap type: Shared\n");
1991 (void) fprintf(file," colormap type: Private\n");
1992 (void) fprintf(file," geometry: %dx%d\n",windows->image.ximage->width,
1993 windows->image.ximage->height);
1994 if (windows->image.crop_geometry != (char *) NULL)
1995 (void) fprintf(file," crop geometry: %s\n",windows->image.crop_geometry);
1996 if (windows->image.pixmap == (Pixmap) NULL)
1997 (void) fprintf(file," type: X Image\n");
1999 (void) fprintf(file," type: Pixmap\n");
2000 if (windows->image.shape != MagickFalse)
2001 (void) fprintf(file," non-rectangular shape: True\n");
2003 (void) fprintf(file," non-rectangular shape: False\n");
2004 if (windows->image.shared_memory != MagickFalse)
2005 (void) fprintf(file," shared memory: True\n");
2007 (void) fprintf(file," shared memory: False\n");
2008 (void) fprintf(file,"\n");
2009 if (resource_info->font != (char *) NULL)
2010 (void) fprintf(file,"Font: %s\n\n",resource_info->font);
2011 if (resource_info->text_font != (char *) NULL)
2012 (void) fprintf(file,"Text font: %s\n\n",resource_info->text_font);
2014 Write info about the undo cache to a file.
2017 for (levels=0; undo_image != (Image *) NULL; levels++)
2019 number_pixels=undo_image->list->columns*undo_image->list->rows;
2020 bytes+=number_pixels*sizeof(PixelPacket);
2021 undo_image=GetPreviousImageInList(undo_image);
2023 (void) fprintf(file,"Undo Edit Cache\n levels: %u\n",levels);
2024 (void) fprintf(file," bytes: %lumb\n",(unsigned long)
2025 (bytes+(1 << 19)) >> 20);
2026 (void) fprintf(file," limit: %lumb\n\n",resource_info->undo_cache);
2028 Write info about the image to a file.
2030 (void) IdentifyImage(image,file,MagickTrue);
2031 (void) fclose(file);
2032 text=FileToString(filename,~0,&image->exception);
2033 (void) RelinquishUniqueFileResource(filename);
2034 if (text == (char *) NULL)
2036 XNoticeWidget(display,windows,"MemoryAllocationFailed",
2037 "UnableToDisplayImageInfo");
2040 textlist=StringToList(text);
2041 if (textlist != (char **) NULL)
2044 title[MaxTextExtent];
2047 Display information about the image in the Text View widget.
2049 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2050 (void) FormatMagickString(title,MaxTextExtent,"Image Info: %s",
2052 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
2053 (char const **) textlist);
2054 for (i=0; textlist[i] != (char *) NULL; i++)
2055 textlist[i]=DestroyString(textlist[i]);
2056 textlist=(char **) RelinquishMagickMemory(textlist);
2058 text=DestroyString(text);
2062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2066 + X D i t h e r I m a g e %
2070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2072 % XDitherImage() dithers the reference image as required by the HP Color
2073 % Recovery algorithm. The color values are quantized to 3 bits of red and
2074 % green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
2075 % standard colormap.
2077 % The format of the XDitherImage method is:
2079 % void XDitherImage(Image *image,XImage *ximage)
2081 % A description of each parameter follows:
2083 % o image: the image.
2085 % o ximage: Specifies a pointer to a XImage structure; returned from
2090 static void XDitherImage(Image *image,XImage *ximage)
2092 static const short int
2095 {-16, 4, -1, 11,-14, 6, -3, 9,-15, 5, -2, 10,-13, 7, -4, 8},
2096 { 15, -5, 0,-12, 13, -7, 2,-10, 14, -6, 1,-11, 12, -8, 3, -9}
2098 dither_green[2][16]=
2100 { 11,-15, 7, -3, 8,-14, 4, -2, 10,-16, 6, -4, 9,-13, 5, -1},
2101 {-12, 14, -8, 2, -9, 13, -5, 1,-11, 15, -7, 3,-10, 12, -6, 0}
2105 { -3, 9,-13, 7, -1, 11,-15, 5, -4, 8,-14, 6, -2, 10,-16, 4},
2106 { 2,-10, 12, -8, 0,-12, 14, -6, 3, -9, 13, -7, 1,-11, 15, -5}
2121 register const PixelPacket
2132 register unsigned long
2141 Allocate and initialize dither maps.
2143 for (i=0; i < 2; i++)
2144 for (j=0; j < 16; j++)
2146 red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2148 green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2149 sizeof(*green_map));
2150 blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
2152 if ((red_map[i][j] == (unsigned char *) NULL) ||
2153 (green_map[i][j] == (unsigned char *) NULL) ||
2154 (blue_map[i][j] == (unsigned char *) NULL))
2156 ThrowXWindowFatalException(ResourceLimitError,
2157 "MemoryAllocationFailed",image->filename);
2162 Initialize dither tables.
2164 for (i=0; i < 2; i++)
2165 for (j=0; j < 16; j++)
2166 for (x=0; x < 256; x++)
2171 value+=dither_red[i][j];
2172 red_map[i][j][x]=(unsigned char)
2173 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2177 value+=dither_green[i][j];
2178 green_map[i][j][x]=(unsigned char)
2179 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2183 value+=((unsigned long) dither_blue[i][j] << 1);
2184 blue_map[i][j][x]=(unsigned char)
2185 ((value < 0) ? 0 : (value > 255) ? 255 : value);
2190 scanline_pad=(unsigned int) (ximage->bytes_per_line-
2191 ((unsigned long) (ximage->width*ximage->bits_per_pixel) >> 3));
2195 for (y=0; y < (int) image->rows; y++)
2197 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
2198 if (p == (const PixelPacket *) NULL)
2200 for (x=0; x < (int) image->columns; x++)
2202 color.red=RoundToQuantum((MagickRealType) (red_map[i][j][(int)
2203 ScaleQuantumToChar(p->red)] << 8));
2204 color.green=RoundToQuantum((MagickRealType) (green_map[i][j][(int)
2205 ScaleQuantumToChar(p->green)] << 8));
2206 color.blue=RoundToQuantum((MagickRealType) (blue_map[i][j][(int)
2207 ScaleQuantumToChar(p->blue)] << 8));
2208 pixel=(unsigned long) (((unsigned long) color.red & 0xe0) |
2209 (((unsigned long) color.green & 0xe0) >> 3) |
2210 (((unsigned long) color.blue & 0xc0) >> 6));
2223 Free allocated memory.
2225 for (i=0; i < 2; i++)
2226 for (j=0; j < 16; j++)
2228 green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
2229 blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
2230 red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
2235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2239 % X D r a w I m a g e %
2243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2245 % XDrawImage() draws a line on the image.
2247 % The format of the XDrawImage method is:
2249 % MagickBooleanType XDrawImage(display,pixel,draw_info,image)
2251 % A description of each parameter follows:
2253 % o display: Specifies a connection to an X server; returned from
2256 % o pixel: Specifies a pointer to a XPixelInfo structure.
2258 % o draw_info: Specifies a pointer to a XDrawInfo structure.
2260 % o image: the image.
2263 MagickExport MagickBooleanType XDrawImage(Display *display,
2264 const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image)
2300 Initialize drawd image.
2302 assert(display != (Display *) NULL);
2303 assert(pixel != (XPixelInfo *) NULL);
2304 assert(draw_info != (XDrawInfo *) NULL);
2305 assert(image != (Image *) NULL);
2306 if (image->debug != MagickFalse)
2307 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2309 Initialize drawd pixmap.
2311 root_window=XRootWindow(display,XDefaultScreen(display));
2312 depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
2313 draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
2314 draw_info->height,depth);
2315 if (draw_pixmap == (Pixmap) NULL)
2316 return(MagickFalse);
2318 Initialize graphics info.
2320 context_values.background=(unsigned long) (~0);
2321 context_values.foreground=0;
2322 context_values.line_width=(int) draw_info->line_width;
2323 draw_context=XCreateGC(display,root_window,(unsigned long)
2324 (GCBackground | GCForeground | GCLineWidth),&context_values);
2325 if (draw_context == (GC) NULL)
2326 return(MagickFalse);
2330 (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
2333 Draw line to pixmap.
2335 (void) XSetBackground(display,draw_context,0);
2336 (void) XSetForeground(display,draw_context,(unsigned long) (~0));
2337 (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2338 (void) XSetStipple(display,draw_context,draw_info->stipple);
2339 switch (draw_info->element)
2344 (void) XDrawLines(display,draw_pixmap,draw_context,
2345 draw_info->coordinate_info,(int) draw_info->number_coordinates,
2351 (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
2352 draw_info->line_info.y1,draw_info->line_info.x2,
2353 draw_info->line_info.y2);
2356 case RectangleElement:
2358 (void) XDrawRectangle(display,draw_pixmap,draw_context,
2359 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2360 (unsigned int) draw_info->rectangle_info.width,
2361 (unsigned int) draw_info->rectangle_info.height);
2364 case FillRectangleElement:
2366 (void) XFillRectangle(display,draw_pixmap,draw_context,
2367 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2368 (unsigned int) draw_info->rectangle_info.width,
2369 (unsigned int) draw_info->rectangle_info.height);
2373 case EllipseElement:
2375 (void) XDrawArc(display,draw_pixmap,draw_context,
2376 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2377 (unsigned int) draw_info->rectangle_info.width,
2378 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2381 case FillCircleElement:
2382 case FillEllipseElement:
2384 (void) XFillArc(display,draw_pixmap,draw_context,
2385 (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
2386 (unsigned int) draw_info->rectangle_info.width,
2387 (unsigned int) draw_info->rectangle_info.height,0,360*64);
2390 case PolygonElement:
2395 coordinate_info=draw_info->coordinate_info;
2396 (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
2397 (int) draw_info->number_coordinates,CoordModeOrigin);
2398 (void) XDrawLine(display,draw_pixmap,draw_context,
2399 coordinate_info[draw_info->number_coordinates-1].x,
2400 coordinate_info[draw_info->number_coordinates-1].y,
2401 coordinate_info[0].x,coordinate_info[0].y);
2404 case FillPolygonElement:
2406 (void) XFillPolygon(display,draw_pixmap,draw_context,
2407 draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
2412 (void) XFreeGC(display,draw_context);
2416 draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
2417 draw_info->height,AllPlanes,ZPixmap);
2418 if (draw_ximage == (XImage *) NULL)
2419 return(MagickFalse);
2420 (void) XFreePixmap(display,draw_pixmap);
2422 Initialize draw image.
2424 draw_image=AcquireImage((ImageInfo *) NULL);
2425 if (draw_image == (Image *) NULL)
2426 return(MagickFalse);
2427 draw_image->columns=draw_info->width;
2428 draw_image->rows=draw_info->height;
2430 Transfer drawn X image to image.
2432 width=(unsigned int) image->columns;
2433 height=(unsigned int) image->rows;
2436 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2437 (void) GetOneVirtualPixel(image,x,y,&draw_image->background_color,
2439 if (SetImageStorageClass(draw_image,DirectClass) == MagickFalse)
2440 return(MagickFalse);
2441 draw_image->matte=MagickTrue;
2442 exception=(&image->exception);
2443 for (y=0; y < (int) draw_image->rows; y++)
2448 register PixelPacket
2451 q=QueueAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2452 if (q == (PixelPacket *) NULL)
2454 for (x=0; x < (long) draw_image->columns; x++)
2456 if (XGetPixel(draw_ximage,x,y) == 0)
2459 Set this pixel to the background color.
2461 *q=draw_image->background_color;
2462 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2463 TransparentOpacity : OpaqueOpacity);
2468 Set this pixel to the pen color.
2470 q->red=ScaleShortToQuantum(pixel->pen_color.red);
2471 q->green=ScaleShortToQuantum(pixel->pen_color.green);
2472 q->blue=ScaleShortToQuantum(pixel->pen_color.blue);
2473 q->opacity=(Quantum) (draw_info->stencil == OpaqueStencil ?
2474 OpaqueOpacity : TransparentOpacity);
2478 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2481 XDestroyImage(draw_ximage);
2483 Determine draw geometry.
2485 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2486 if ((width != (unsigned int) draw_image->columns) ||
2487 (height != (unsigned int) draw_image->rows))
2490 image_geometry[MaxTextExtent];
2495 (void) FormatMagickString(image_geometry,MaxTextExtent,"%ux%u",
2497 (void) TransformImage(&draw_image,(char *) NULL,image_geometry);
2499 if (draw_info->degrees != 0.0)
2513 rotate_image=RotateImage(draw_image,draw_info->degrees,&image->exception);
2514 if (rotate_image == (Image *) NULL)
2515 return(MagickFalse);
2516 draw_image=DestroyImage(draw_image);
2517 draw_image=rotate_image;
2519 Annotation is relative to the degree of rotation.
2521 normalized_degrees=draw_info->degrees;
2522 while (normalized_degrees < -45.0)
2523 normalized_degrees+=360.0;
2524 for (rotations=0; normalized_degrees > 45.0; rotations++)
2525 normalized_degrees-=90.0;
2526 switch (rotations % 4)
2536 x=x-(int) draw_image->columns/2;
2537 y=y+(int) draw_image->columns/2;
2545 x=x-(int) draw_image->columns;
2553 x=x-(int) draw_image->columns/2;
2554 y=y-(int) (draw_image->rows-(draw_image->columns/2));
2560 Composite text onto the image.
2562 for (y=0; y < (int) draw_image->rows; y++)
2567 register PixelPacket
2570 q=GetAuthenticPixels(draw_image,0,y,draw_image->columns,1,exception);
2571 if (q == (PixelPacket *) NULL)
2573 for (x=0; x < (long) draw_image->columns; x++)
2575 if (q->opacity != (Quantum) TransparentOpacity)
2576 q->opacity=OpaqueOpacity;
2579 if (SyncAuthenticPixels(draw_image,exception) == MagickFalse)
2582 (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2583 if (draw_info->stencil == TransparentStencil)
2584 (void) CompositeImage(image,CopyOpacityCompositeOp,draw_image,x,y);
2588 (void) CompositeImage(image,OverCompositeOp,draw_image,x,y);
2591 draw_image=DestroyImage(draw_image);
2596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2606 % XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
2607 % and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2608 % for XQueryColor. It returns MagickFalse in those cases. Otherwise it returns
2611 % The format of the XError function is:
2613 % XError(display,error)
2615 % A description of each parameter follows:
2617 % o display: Specifies a pointer to the Display structure; returned from
2620 % o error: Specifies the error event.
2624 #if defined(__cplusplus) || defined(c_plusplus)
2628 MagickExport int XError(Display *display,XErrorEvent *error)
2630 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2631 assert(display != (Display *) NULL);
2632 assert(error != (XErrorEvent *) NULL);
2633 xerror_alert=MagickTrue;
2634 switch (error->request_code)
2638 if ((int) error->error_code == BadDrawable)
2639 return(MagickFalse);
2642 case X_GetWindowAttributes:
2645 if ((int) error->error_code == BadWindow)
2646 return(MagickFalse);
2651 if ((int) error->error_code == BadValue)
2652 return(MagickFalse);
2659 #if defined(__cplusplus) || defined(c_plusplus)
2664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2668 % X F r e e R e s o u r c e s %
2672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2674 % XFreeResources() frees X11 resources.
2676 % The format of the XFreeResources method is:
2678 % void XFreeResources(Display *display,XVisualInfo *visual_info,
2679 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2680 % XResourceInfo *resource_info,XWindowInfo *window_info)
2681 % resource_info,window_info)
2683 % A description of each parameter follows:
2685 % o display: Specifies a connection to an X server; returned from
2688 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2689 % returned from XGetVisualInfo.
2691 % o map_info: If map_type is specified, this structure is initialized
2692 % with info from the Standard Colormap.
2694 % o pixel: Specifies a pointer to a XPixelInfo structure.
2696 % o font_info: Specifies a pointer to a XFontStruct structure.
2698 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2700 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
2703 MagickExport void XFreeResources(Display *display,XVisualInfo *visual_info,
2704 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
2705 XResourceInfo *resource_info,XWindowInfo *window_info)
2707 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2708 assert(display != (Display *) NULL);
2709 assert(resource_info != (XResourceInfo *) NULL);
2710 if (window_info != (XWindowInfo *) NULL)
2715 if (window_info->ximage != (XImage *) NULL)
2716 XDestroyImage(window_info->ximage);
2717 if (window_info->id != (Window) NULL)
2720 Free destroy window and free cursors.
2722 if (window_info->id != XRootWindow(display,visual_info->screen))
2723 (void) XDestroyWindow(display,window_info->id);
2724 if (window_info->annotate_context != (GC) NULL)
2725 (void) XFreeGC(display,window_info->annotate_context);
2726 if (window_info->highlight_context != (GC) NULL)
2727 (void) XFreeGC(display,window_info->highlight_context);
2728 if (window_info->widget_context != (GC) NULL)
2729 (void) XFreeGC(display,window_info->widget_context);
2730 if (window_info->cursor != (Cursor) NULL)
2731 (void) XFreeCursor(display,window_info->cursor);
2732 window_info->cursor=(Cursor) NULL;
2733 if (window_info->busy_cursor != (Cursor) NULL)
2734 (void) XFreeCursor(display,window_info->busy_cursor);
2735 window_info->busy_cursor=(Cursor) NULL;
2741 if (font_info != (XFontStruct *) NULL)
2742 (void) XFreeFont(display,font_info);
2743 if (map_info != (XStandardColormap *) NULL)
2746 Free X Standard Colormap.
2748 if (resource_info->map_type == (char *) NULL)
2749 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
2750 (void) XFree((void *) map_info);
2755 if (visual_info != (XVisualInfo *) NULL)
2756 (void) XFree((void *) visual_info);
2757 if (resource_info->close_server != MagickFalse)
2758 (void) XCloseDisplay(display);
2762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2766 % X F r e e S t a n d a r d C o l o r m a p %
2770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2772 % XFreeStandardColormap() frees an X11 colormap.
2774 % The format of the XFreeStandardColormap method is:
2776 % void XFreeStandardColormap(Display *display,
2777 % const XVisualInfo *visual_info,XStandardColormap *map_info,
2778 % XPixelInfo *pixel)
2780 % A description of each parameter follows:
2782 % o display: Specifies a connection to an X server; returned from
2785 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2786 % returned from XGetVisualInfo.
2788 % o map_info: If map_type is specified, this structure is initialized
2789 % with info from the Standard Colormap.
2791 % o pixel: Specifies a pointer to a XPixelInfo structure.
2794 MagickExport void XFreeStandardColormap(Display *display,
2795 const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
2800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2801 assert(display != (Display *) NULL);
2802 assert(visual_info != (XVisualInfo *) NULL);
2803 assert(map_info != (XStandardColormap *) NULL);
2804 (void) XFlush(display);
2805 if (map_info->colormap != (Colormap) NULL)
2807 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
2808 (void) XFreeColormap(display,map_info->colormap);
2810 if (pixel != (XPixelInfo *) NULL)
2811 if ((visual_info->klass != TrueColor) &&
2812 (visual_info->klass != DirectColor))
2813 (void) XFreeColors(display,map_info->colormap,pixel->pixels,
2814 (int) pixel->colors,0);
2816 map_info->colormap=(Colormap) NULL;
2817 if (pixel != (XPixelInfo *) NULL)
2819 if (pixel->pixels != (unsigned long *) NULL)
2820 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2821 pixel->pixels=(unsigned long *) NULL;
2826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2830 % X G e t A n n o t a t e I n f o %
2834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2836 % XGetAnnotateInfo() initializes the AnnotateInfo structure.
2838 % The format of the XGetAnnotateInfo method is:
2840 % void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2842 % A description of each parameter follows:
2844 % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
2847 MagickExport void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
2850 Initialize annotate structure.
2852 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2853 assert(annotate_info != (XAnnotateInfo *) NULL);
2856 annotate_info->width=0;
2857 annotate_info->height=0;
2858 annotate_info->stencil=ForegroundStencil;
2859 annotate_info->degrees=0.0;
2860 annotate_info->font_info=(XFontStruct *) NULL;
2861 annotate_info->text=(char *) NULL;
2862 *annotate_info->geometry='\0';
2863 annotate_info->previous=(XAnnotateInfo *) NULL;
2864 annotate_info->next=(XAnnotateInfo *) NULL;
2865 (void) XSupportsLocale();
2866 (void) XSetLocaleModifiers("");
2870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2874 % X G e t M a p I n f o %
2878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2880 % XGetMapInfo() initializes the XStandardColormap structure.
2882 % The format of the XStandardColormap method is:
2884 % void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
2885 % XStandardColormap *map_info)
2887 % A description of each parameter follows:
2889 % o colormap: Specifies the ID of the X server colormap.
2891 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2892 % returned from XGetVisualInfo.
2894 % o map_info: Specifies a pointer to a X11 XStandardColormap structure.
2897 MagickExport void XGetMapInfo(const XVisualInfo *visual_info,
2898 const Colormap colormap,XStandardColormap *map_info)
2901 Initialize map info.
2903 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2904 assert(visual_info != (XVisualInfo *) NULL);
2905 assert(map_info != (XStandardColormap *) NULL);
2906 map_info->colormap=colormap;
2907 map_info->red_max=visual_info->red_mask;
2908 map_info->red_mult=(unsigned long) (map_info->red_max != 0 ? 1 : 0);
2909 if (map_info->red_max != 0)
2910 while ((map_info->red_max & 0x01) == 0)
2912 map_info->red_max>>=1;
2913 map_info->red_mult<<=1;
2915 map_info->green_max=visual_info->green_mask;
2916 map_info->green_mult=(unsigned long) (map_info->green_max != 0 ? 1 : 0);
2917 if (map_info->green_max != 0)
2918 while ((map_info->green_max & 0x01) == 0)
2920 map_info->green_max>>=1;
2921 map_info->green_mult<<=1;
2923 map_info->blue_max=visual_info->blue_mask;
2924 map_info->blue_mult=(unsigned long) (map_info->blue_max != 0 ? 1 : 0);
2925 if (map_info->blue_max != 0)
2926 while ((map_info->blue_max & 0x01) == 0)
2928 map_info->blue_max>>=1;
2929 map_info->blue_mult<<=1;
2931 map_info->base_pixel=0;
2935 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2939 % X G e t P i x e l I n f o %
2943 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945 % XGetPixelPacket() initializes the PixelPacket structure.
2947 % The format of the XGetPixelPacket method is:
2949 % void XGetPixelPacket(Display *display,const XVisualInfo *visual_info,
2950 % const XStandardColormap *map_info,const XResourceInfo *resource_info,
2951 % Image *image,XPixelInfo *pixel)
2954 % A description of each parameter follows:
2956 % o display: Specifies a connection to an X server; returned from
2959 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
2960 % returned from XGetVisualInfo.
2962 % o map_info: If map_type is specified, this structure is initialized
2963 % with info from the Standard Colormap.
2965 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
2967 % o image: the image.
2969 % o pixel: Specifies a pointer to a XPixelInfo structure.
2972 MagickExport void XGetPixelPacket(Display *display,
2973 const XVisualInfo *visual_info,const XStandardColormap *map_info,
2974 const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
2977 *PenColors[MaxNumberPens]=
2979 "#000000000000", /* black */
2980 "#00000000ffff", /* blue */
2981 "#0000ffffffff", /* cyan */
2982 "#0000ffff0000", /* green */
2983 "#bdbdbdbdbdbd", /* gray */
2984 "#ffff00000000", /* red */
2985 "#ffff0000ffff", /* magenta */
2986 "#ffffffff0000", /* yellow */
2987 "#ffffffffffff", /* white */
2988 "#bdbdbdbdbdbd", /* gray */
2989 "#bdbdbdbdbdbd" /* gray */
3005 Initialize pixel info.
3007 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3008 assert(display != (Display *) NULL);
3009 assert(visual_info != (XVisualInfo *) NULL);
3010 assert(map_info != (XStandardColormap *) NULL);
3011 assert(resource_info != (XResourceInfo *) NULL);
3012 assert(pixel != (XPixelInfo *) NULL);
3014 if (image != (Image *) NULL)
3015 if (image->storage_class == PseudoClass)
3016 pixel->colors=image->colors;
3017 packets=(unsigned int)
3018 MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3019 if (pixel->pixels != (unsigned long *) NULL)
3020 pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3021 pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3022 sizeof(pixel->pixels));
3023 if (pixel->pixels == (unsigned long *) NULL)
3024 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
3027 Set foreground color.
3029 colormap=map_info->colormap;
3030 (void) XParseColor(display,colormap,(char *) ForegroundColor,
3031 &pixel->foreground_color);
3032 status=XParseColor(display,colormap,resource_info->foreground_color,
3033 &pixel->foreground_color);
3034 if (status == False)
3035 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3036 resource_info->foreground_color);
3037 pixel->foreground_color.pixel=
3038 XStandardPixel(map_info,&pixel->foreground_color);
3039 pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
3041 Set background color.
3043 (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
3044 status=XParseColor(display,colormap,resource_info->background_color,
3045 &pixel->background_color);
3046 if (status == False)
3047 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3048 resource_info->background_color);
3049 pixel->background_color.pixel=
3050 XStandardPixel(map_info,&pixel->background_color);
3051 pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
3055 (void) XParseColor(display,colormap,(char *) BorderColor,
3056 &pixel->border_color);
3057 status=XParseColor(display,colormap,resource_info->border_color,
3058 &pixel->border_color);
3059 if (status == False)
3060 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3061 resource_info->border_color);
3062 pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
3063 pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
3067 pixel->matte_color=pixel->background_color;
3068 if (resource_info->matte_color != (char *) NULL)
3071 Matte color is specified as a X resource or command line argument.
3073 status=XParseColor(display,colormap,resource_info->matte_color,
3074 &pixel->matte_color);
3075 if (status == False)
3076 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3077 resource_info->matte_color);
3078 pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
3079 pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
3082 Set highlight color.
3084 pixel->highlight_color.red=(unsigned short) ((
3085 pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
3086 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3087 pixel->highlight_color.green=(unsigned short) ((
3088 pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
3089 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3090 pixel->highlight_color.blue=(unsigned short) ((
3091 pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
3092 (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
3093 pixel->highlight_color.pixel=
3094 XStandardPixel(map_info,&pixel->highlight_color);
3095 pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
3099 pixel->shadow_color.red=(unsigned short) (((MagickRealType)
3100 pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3101 pixel->shadow_color.green=(unsigned short) (((MagickRealType)
3102 pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3103 pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
3104 pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
3105 pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
3106 pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
3110 pixel->depth_color.red=(unsigned short) (((MagickRealType)
3111 pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3112 pixel->depth_color.green=(unsigned short) (((MagickRealType)
3113 pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3114 pixel->depth_color.blue=(unsigned short) (((MagickRealType)
3115 pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
3116 pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
3117 pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
3121 pixel->trough_color.red=(unsigned short) (((MagickRealType)
3122 pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3123 pixel->trough_color.green=(unsigned short) (((MagickRealType)
3124 pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3125 pixel->trough_color.blue=(unsigned short) (((MagickRealType)
3126 pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
3127 pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
3128 pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
3132 for (i=0; i < MaxNumberPens; i++)
3134 (void) XParseColor(display,colormap,(char *) PenColors[i],
3135 &pixel->pen_colors[i]);
3136 status=XParseColor(display,colormap,resource_info->pen_colors[i],
3137 &pixel->pen_colors[i]);
3138 if (status == False)
3139 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
3140 resource_info->pen_colors[i]);
3141 pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
3142 pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
3144 pixel->box_color=pixel->background_color;
3145 pixel->pen_color=pixel->foreground_color;
3148 if (image != (Image *) NULL)
3150 if ((resource_info->gamma_correct != MagickFalse) &&
3151 (image->gamma != 0.0))
3160 Initialize map relative to display and image gamma.
3162 flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
3163 red_gamma=geometry_info.rho;
3164 green_gamma=geometry_info.sigma;
3165 if ((flags & SigmaValue) == 0)
3166 green_gamma=red_gamma;
3167 blue_gamma=geometry_info.xi;
3168 if ((flags & XiValue) == 0)
3169 blue_gamma=red_gamma;
3170 red_gamma*=image->gamma;
3171 green_gamma*=image->gamma;
3172 blue_gamma*=image->gamma;
3174 if (image->storage_class == PseudoClass)
3177 Initialize pixel array for images of type PseudoClass.
3179 for (i=0; i < (long) image->colors; i++)
3181 XGammaPixel(map_info,image->colormap+i);
3182 for (i=0; i < MaxNumberPens; i++)
3183 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
3184 pixel->colors+=MaxNumberPens;
3190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3194 % X G e t R e s o u r c e C l a s s %
3198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3200 % XGetResourceClass() queries the X server for the specified resource name or
3201 % class. If the resource name or class is not defined in the database, the
3202 % supplied default value is returned.
3204 % The format of the XGetResourceClass method is:
3206 % char *XGetResourceClass(XrmDatabase database,const char *client_name,
3207 % const char *keyword,char *resource_default)
3209 % A description of each parameter follows:
3211 % o database: Specifies a resource database; returned from
3212 % XrmGetStringDatabase.
3214 % o client_name: Specifies the application name used to retrieve resource
3215 % info from the X server database.
3217 % o keyword: Specifies the keyword of the value being retrieved.
3219 % o resource_default: Specifies the default value to return if the query
3220 % fails to find the specified keyword/class.
3223 MagickExport char *XGetResourceClass(XrmDatabase database,
3224 const char *client_name,const char *keyword,char *resource_default)
3227 resource_class[MaxTextExtent],
3228 resource_name[MaxTextExtent];
3239 if (database == (XrmDatabase) NULL)
3240 return(resource_default);
3241 *resource_name='\0';
3242 *resource_class='\0';
3243 if (keyword != (char *) NULL)
3250 Initialize resource keyword and class.
3252 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",
3253 client_name,keyword);
3254 c=(int) (*client_name);
3255 if ((c >= XK_a) && (c <= XK_z))
3258 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3259 c-=(XK_agrave-XK_Agrave);
3261 if ((c >= XK_oslash) && (c <= XK_thorn))
3262 c-=(XK_oslash-XK_Ooblique);
3264 if ((k >= XK_a) && (k <= XK_z))
3267 if ((k >= XK_agrave) && (k <= XK_odiaeresis))
3268 k-=(XK_agrave-XK_Agrave);
3270 if ((k >= XK_oslash) && (k <= XK_thorn))
3271 k-=(XK_oslash-XK_Ooblique);
3272 (void) FormatMagickString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
3273 client_name+1,k,keyword+1);
3275 status=XrmGetResource(database,resource_name,resource_class,&resource_type,
3277 if (status == False)
3278 return(resource_default);
3279 return(resource_value.addr);
3283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3287 % X G e t R e s o u r c e D a t a b a s e %
3291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3293 % XGetResourceDatabase() creates a new resource database and initializes it.
3295 % The format of the XGetResourceDatabase method is:
3297 % XrmDatabase XGetResourceDatabase(Display *display,
3298 % const char *client_name)
3300 % A description of each parameter follows:
3302 % o database: XGetResourceDatabase() returns the database after it is
3305 % o display: Specifies a connection to an X server; returned from
3308 % o client_name: Specifies the application name used to retrieve resource
3309 % info from the X server database.
3312 MagickExport XrmDatabase XGetResourceDatabase(Display *display,
3313 const char *client_name)
3316 filename[MaxTextExtent];
3328 if (display == (Display *) NULL)
3329 return((XrmDatabase) NULL);
3330 assert(client_name != (char *) NULL);
3332 Initialize resource database.
3335 (void) XGetDefault(display,(char *) client_name,"dummy");
3336 resource_database=XrmGetDatabase(display);
3338 Combine application database.
3340 if (client_name != (char *) NULL)
3343 Get basename of client.
3345 p=client_name+(strlen(client_name)-1);
3346 while ((p > client_name) && (*p != '/'))
3351 c=(int) (*client_name);
3352 if ((c >= XK_a) && (c <= XK_z))
3355 if ((c >= XK_agrave) && (c <= XK_odiaeresis))
3356 c-=(XK_agrave-XK_Agrave);
3358 if ((c >= XK_oslash) && (c <= XK_thorn))
3359 c-=(XK_oslash-XK_Ooblique);
3360 #if defined(X11_APPLICATION_PATH)
3361 (void) FormatMagickString(filename,MaxTextExtent,"%s%c%s",
3362 X11_APPLICATION_PATH,c,client_name+1);
3363 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3365 if (XResourceManagerString(display) != (char *) NULL)
3368 Combine server database.
3370 server_database=XrmGetStringDatabase(XResourceManagerString(display));
3371 XrmCombineDatabase(server_database,&resource_database,MagickFalse);
3374 Merge user preferences database.
3376 #if defined(X11_PREFERENCES_PATH)
3377 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
3378 X11_PREFERENCES_PATH,client_name);
3379 ExpandFilename(filename);
3380 (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
3382 return(resource_database);
3386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3390 % X G e t R e s o u r c e I n f o %
3394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3396 % XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
3398 % The format of the XGetResourceInfo method is:
3400 % void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
3401 % const char *client_name,XResourceInfo *resource_info)
3403 % A description of each parameter follows:
3405 % o image_info: the image info.
3407 % o database: Specifies a resource database; returned from
3408 % XrmGetStringDatabase.
3410 % o client_name: Specifies the application name used to retrieve
3411 % resource info from the X server database.
3413 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
3416 MagickExport void XGetResourceInfo(const ImageInfo *image_info,
3417 XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
3424 Initialize resource info fields.
3426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3427 assert(resource_info != (XResourceInfo *) NULL);
3428 (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
3429 resource_info->resource_database=database;
3430 resource_info->image_info=(ImageInfo *) image_info;
3431 (void) SetImageInfoProgressMonitor(resource_info->image_info,
3432 XMagickProgressMonitor,(void *) NULL);
3433 resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
3434 resource_info->close_server=MagickTrue;
3435 resource_info->client_name=AcquireString(client_name);
3436 resource_value=XGetResourceClass(database,client_name,"backdrop",
3438 resource_info->backdrop=IsMagickTrue(resource_value);
3439 resource_info->background_color=XGetResourceInstance(database,client_name,
3440 "background",(char *) "#d6d6d6d6d6d6");
3441 resource_info->border_color=XGetResourceInstance(database,client_name,
3442 "borderColor",BorderColor);
3443 resource_value=XGetResourceClass(database,client_name,"borderWidth",
3445 resource_info->border_width=(unsigned int) atoi(resource_value);
3446 resource_value=XGetResourceClass(database,client_name,"colormap",
3448 resource_info->colormap=UndefinedColormap;
3449 if (LocaleCompare("private",resource_value) == 0)
3450 resource_info->colormap=PrivateColormap;
3451 if (LocaleCompare("shared",resource_value) == 0)
3452 resource_info->colormap=SharedColormap;
3453 if (resource_info->colormap == UndefinedColormap)
3454 ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
3456 resource_value=XGetResourceClass(database,client_name,
3457 "colorRecovery",(char *) "False");
3458 resource_info->color_recovery=IsMagickTrue(resource_value);
3459 resource_value=XGetResourceClass(database,client_name,"confirmExit",
3461 resource_info->confirm_exit=IsMagickTrue(resource_value);
3462 resource_value=XGetResourceClass(database,client_name,"confirmEdit",
3464 resource_info->confirm_edit=IsMagickTrue(resource_value);
3465 resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3466 resource_info->delay=(unsigned int) atoi(resource_value);
3467 resource_info->display_gamma=XGetResourceClass(database,client_name,
3468 "displayGamma",(char *) "2.2");
3469 resource_value=XGetResourceClass(database,client_name,"displayWarnings",
3471 resource_info->display_warnings=IsMagickTrue(resource_value);
3472 resource_info->font=XGetResourceClass(database,client_name,"font",
3474 resource_info->font=XGetResourceClass(database,client_name,"fontList",
3475 resource_info->font);
3476 resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
3478 resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
3479 (char *) "variable");
3480 resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
3482 resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
3484 resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
3485 (char *) "7x13bold");
3486 resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
3487 (char *) "8x13bold");
3488 resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
3489 (char *) "9x15bold");
3490 resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
3492 resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
3494 resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
3496 resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
3498 resource_info->foreground_color=XGetResourceInstance(database,client_name,
3499 "foreground",ForegroundColor);
3500 resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
3502 resource_info->gamma_correct=IsMagickTrue(resource_value);
3503 resource_info->image_geometry=ConstantString(XGetResourceClass(database,
3504 client_name,"geometry",(char *) NULL));
3505 resource_value=XGetResourceClass(database,client_name,"gravity",
3507 resource_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3508 MagickFalse,resource_value);
3509 cwd=getcwd(resource_info->home_directory,MaxTextExtent);
3510 resource_info->icon_geometry=XGetResourceClass(database,client_name,
3511 "iconGeometry",(char *) NULL);
3512 resource_value=XGetResourceClass(database,client_name,"iconic",
3514 resource_info->iconic=IsMagickTrue(resource_value);
3515 resource_value=XGetResourceClass(database,client_name,"immutable",
3516 LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
3518 resource_info->immutable=IsMagickTrue(resource_value);
3519 resource_value=XGetResourceClass(database,client_name,"magnify",
3521 resource_info->magnify=(unsigned int) atoi(resource_value);
3522 resource_info->map_type=XGetResourceClass(database,client_name,"map",
3524 resource_info->matte_color=XGetResourceInstance(database,client_name,
3525 "mattecolor",(char *) NULL);
3526 resource_info->name=ConstantString(XGetResourceClass(database,client_name,
3527 "name",(char *) NULL));
3528 resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
3530 resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
3532 resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
3534 resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
3536 resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
3538 resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
3540 resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
3541 (char *) "magenta");
3542 resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
3544 resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
3546 resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
3548 resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
3550 resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3551 resource_info->pause=(unsigned int) atoi(resource_value);
3552 resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3553 resource_info->quantum=atoi(resource_value);
3554 resource_info->text_font=XGetResourceClass(database,client_name,(char *)
3555 "font",(char *) "fixed");
3556 resource_info->text_font=XGetResourceClass(database,client_name,
3557 "textFontList",resource_info->text_font);
3558 resource_info->title=XGetResourceClass(database,client_name,"title",
3560 resource_value=XGetResourceClass(database,client_name,"undoCache",
3562 resource_info->undo_cache=(unsigned int) atol(resource_value);
3563 resource_value=XGetResourceClass(database,client_name,"update",
3565 resource_info->update=IsMagickTrue(resource_value);
3566 resource_value=XGetResourceClass(database,client_name,"usePixmap",
3568 resource_info->use_pixmap=IsMagickTrue(resource_value);
3569 resource_value=XGetResourceClass(database,client_name,"sharedMemory",
3571 resource_info->use_shared_memory=IsMagickTrue(resource_value);
3572 resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
3574 resource_info->window_group=XGetResourceClass(database,client_name,
3575 "windowGroup",(char *) NULL);
3576 resource_info->window_id=XGetResourceClass(database,client_name,"window",
3578 resource_info->write_filename=XGetResourceClass(database,client_name,
3579 "writeFilename",(char *) NULL);
3583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3587 % X G e t R e s o u r c e I n s t a n c e %
3591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3593 % XGetResourceInstance() queries the X server for the specified resource name.
3594 % If the resource name is not defined in the database, the supplied default
3595 % value is returned.
3597 % The format of the XGetResourceInstance method is:
3599 % char *XGetResourceInstance(XrmDatabase database,const char *client_name,
3600 % const char *keyword,const char *resource_default)
3602 % A description of each parameter follows:
3604 % o database: Specifies a resource database; returned from
3605 % XrmGetStringDatabase.
3607 % o client_name: Specifies the application name used to retrieve
3608 % resource info from the X server database.
3610 % o keyword: Specifies the keyword of the value being retrieved.
3612 % o resource_default: Specifies the default value to return if the query
3613 % fails to find the specified keyword/class.
3616 MagickExport char *XGetResourceInstance(XrmDatabase database,
3617 const char *client_name,const char *keyword,const char *resource_default)
3621 resource_name[MaxTextExtent];
3629 if (database == (XrmDatabase) NULL)
3630 return((char *) resource_default);
3631 *resource_name='\0';
3632 if (keyword != (char *) NULL)
3633 (void) FormatMagickString(resource_name,MaxTextExtent,"%s.%s",client_name,
3635 status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
3637 if (status == False)
3638 return((char *) resource_default);
3639 return(resource_value.addr);
3643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3647 % X G e t S c r e e n D e n s i t y %
3651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3653 % XGetScreenDensity() returns the density of the X server screen in
3656 % The format of the XGetScreenDensity method is:
3658 % char *XGetScreenDensity(Display *display)
3660 % A description of each parameter follows:
3662 % o density: XGetScreenDensity() returns the density of the X screen in
3665 % o display: Specifies a connection to an X server; returned from
3669 MagickExport char *XGetScreenDensity(Display *display)
3672 density[MaxTextExtent];
3679 Set density as determined by screen size.
3681 x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
3682 ((double) DisplayWidthMM(display,XDefaultScreen(display))));
3683 y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
3684 ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3685 (void) FormatMagickString(density,MaxTextExtent,"%gx%g",x_density,y_density);
3686 return(GetPageGeometry(density));
3690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3694 + X G e t S u b w i n d o w %
3698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3700 % XGetSubwindow() returns the subwindow of a window chosen the user with the
3701 % pointer and a button press.
3703 % The format of the XGetSubwindow method is:
3705 % Window XGetSubwindow(Display *display,Window window,int x,int y)
3707 % A description of each parameter follows:
3709 % o subwindow: XGetSubwindow() returns NULL if no subwindow is found
3710 % otherwise the subwindow is returned.
3712 % o display: Specifies a connection to an X server; returned from
3715 % o window: Specifies a pointer to a Window.
3717 % o x: the x coordinate of the pointer relative to the origin of the
3720 % o y: the y coordinate of the pointer relative to the origin of the
3725 static Window XGetSubwindow(Display *display,Window window,int x,int y)
3738 assert(display != (Display *) NULL);
3739 source_window=XRootWindow(display,XDefaultScreen(display));
3740 if (window == (Window) NULL)
3741 return(source_window);
3742 target_window=window;
3745 status=XTranslateCoordinates(display,source_window,window,x,y,
3746 &x_offset,&y_offset,&target_window);
3749 if (target_window == (Window) NULL)
3751 source_window=window;
3752 window=target_window;
3756 if (target_window == (Window) NULL)
3757 target_window=window;
3758 return(target_window);
3762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3766 % X G e t W i n d o w C o l o r %
3770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3772 % XGetWindowColor() returns the color of a pixel interactively chosen from the
3775 % The format of the XGetWindowColor method is:
3777 % MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
3780 % A description of each parameter follows:
3782 % o display: Specifies a connection to an X server; returned from
3785 % o windows: Specifies a pointer to a XWindows structure.
3787 % o name: the name of the color if found in the X Color Database is
3788 % returned in this character string.
3791 MagickExport MagickBooleanType XGetWindowColor(Display *display,
3792 XWindows *windows,char *name)
3823 Choose a pixel from the X server.
3825 assert(display != (Display *) NULL);
3826 assert(name != (char *) NULL);
3827 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
3829 target_window=XSelectWindow(display,&crop_info);
3830 if (target_window == (Window) NULL)
3831 return(MagickFalse);
3832 root_window=XRootWindow(display,XDefaultScreen(display));
3833 client_window=target_window;
3834 if (target_window != root_window)
3842 status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
3843 if (status != False)
3845 client_window=XClientWindow(display,target_window);
3846 target_window=client_window;
3850 Verify window is viewable.
3852 status=XGetWindowAttributes(display,target_window,&window_attributes);
3853 if ((status == False) || (window_attributes.map_state != IsViewable))
3854 return(MagickFalse);
3858 (void) XTranslateCoordinates(display,root_window,target_window,
3859 (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
3860 ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
3861 if (ximage == (XImage *) NULL)
3862 return(MagickFalse);
3863 color.pixel=XGetPixel(ximage,0,0);
3864 XDestroyImage(ximage);
3866 Match color against the color database.
3868 (void) XQueryColor(display,window_attributes.colormap,&color);
3869 pixel.red=ScaleShortToQuantum(color.red);
3870 pixel.green=ScaleShortToQuantum(color.green);
3871 pixel.blue=ScaleShortToQuantum(color.blue);
3872 pixel.opacity=OpaqueOpacity;
3873 (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
3874 &windows->image.image->exception);
3879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3883 + X G e t W i n d o w I m a g e %
3887 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3889 % XGetWindowImage() reads an image from the target X window and returns it.
3890 % XGetWindowImage() optionally descends the window hierarchy and overlays the
3891 % target image with each child image in an optimized fashion. Any child
3892 % window that have the same visual, colormap, and are contained by its parent
3895 % The format of the XGetWindowImage method is:
3897 % Image *XGetWindowImage(Display *display,const Window window,
3898 % const unsigned int borders,const unsigned int level)
3900 % A description of each parameter follows:
3902 % o display: Specifies a connection to an X server; returned from
3905 % o window: Specifies the window to obtain the image from.
3907 % o borders: Specifies whether borders pixels are to be saved with
3910 % o level: Specifies an unsigned integer representing the level of
3911 % decent in the window hierarchy. This value must be zero or one on
3912 % the initial call to XGetWindowImage. A value of zero returns after
3913 % one call. A value of one causes the function to descend the window
3914 % hierarchy and overlay the target image with each subwindow image.
3918 static Image *XGetWindowImage(Display *display,const Window window,
3919 const unsigned int borders,const unsigned int level)
3921 typedef struct _ColormapInfo
3929 struct _ColormapInfo
3933 typedef struct _WindowInfo
3965 register IndexPacket
3972 *colormap_info = (ColormapInfo *) NULL;
3992 Verify window is viewable.
3994 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3995 assert(display != (Display *) NULL);
3996 status=XGetWindowAttributes(display,window,&window_attributes);
3997 if ((status == False) || (window_attributes.map_state != IsViewable))
3998 return((Image *) NULL);
4000 Cropping rectangle is relative to root window.
4002 root_window=XRootWindow(display,XDefaultScreen(display));
4003 (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
4005 crop_info.x=(long) x_offset;
4006 crop_info.y=(long) y_offset;
4007 crop_info.width=(unsigned long) window_attributes.width;
4008 crop_info.height=(unsigned long) window_attributes.height;
4009 if (borders != MagickFalse)
4012 Include border in image.
4014 crop_info.x-=(long) window_attributes.border_width;
4015 crop_info.y-=(long) window_attributes.border_width;
4016 crop_info.width+=(unsigned long) (window_attributes.border_width << 1);
4017 crop_info.height+=(unsigned long) (window_attributes.border_width << 1);
4020 Crop to root window.
4022 if (crop_info.x < 0)
4024 crop_info.width+=crop_info.x;
4027 if (crop_info.y < 0)
4029 crop_info.height+=crop_info.y;
4032 display_width=XDisplayWidth(display,XDefaultScreen(display));
4033 if ((int) (crop_info.x+crop_info.width) > display_width)
4034 crop_info.width=(unsigned long) (display_width-crop_info.x);
4035 display_height=XDisplayHeight(display,XDefaultScreen(display));
4036 if ((int) (crop_info.y+crop_info.height) > display_height)
4037 crop_info.height=(unsigned long) (display_height-crop_info.y);
4039 Initialize window info attributes.
4041 if (number_windows >= max_windows)
4044 Allocate or resize window info buffer.
4047 if (window_info == (WindowInfo *) NULL)
4048 window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
4049 sizeof(*window_info));
4051 window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
4052 max_windows,sizeof(*window_info));
4054 if (window_info == (WindowInfo *) NULL)
4056 ThrowXWindowFatalException(ResourceLimitError,
4057 "MemoryAllocationFailed","...");
4058 return((Image *) NULL);
4060 id=number_windows++;
4061 window_info[id].window=window;
4062 window_info[id].visual=window_attributes.visual;
4063 window_info[id].colormap=window_attributes.colormap;
4064 window_info[id].bounds.x1=(short) crop_info.x;
4065 window_info[id].bounds.y1=(short) crop_info.y;
4066 window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
4067 window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
4068 crop_info.x-=x_offset;
4069 crop_info.y-=y_offset;
4070 window_info[id].crop_info=crop_info;
4080 Descend the window hierarchy.
4082 status=XQueryTree(display,window,&root_window,&window_info[id].parent,
4083 &children,&number_children);
4084 for (i=0; i < id; i++)
4085 if ((window_info[i].window == window_info[id].parent) &&
4086 (window_info[i].visual == window_info[id].visual) &&
4087 (window_info[i].colormap == window_info[id].colormap))
4089 if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
4090 (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
4091 (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
4092 (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
4095 Eliminate windows not circumscribed by their parent.
4101 if ((status == True) && (number_children != 0))
4103 for (i=0; i < (int) number_children; i++)
4104 (void) XGetWindowImage(display,children[i],MagickFalse,level+1);
4105 (void) XFree((void *) children);
4130 register PixelPacket
4133 register unsigned long
4146 Get X image for each window in the list.
4148 image=NewImageList();
4149 for (id=0; id < number_windows; id++)
4152 Does target window intersect top level window?
4155 ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
4156 (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
4157 (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
4158 (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
4159 MagickTrue : MagickFalse;
4161 Is target window contained by another window with the same colormap?
4163 for (j=0; j < id; j++)
4164 if ((window_info[id].visual == window_info[j].visual) &&
4165 (window_info[id].colormap == window_info[j].colormap))
4167 if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
4168 (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
4169 (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
4170 (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
4174 if ((window_info[id].visual != window_info[j].visual) ||
4175 (window_info[id].colormap != window_info[j].colormap))
4177 if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
4178 (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
4179 (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
4180 (window_info[id].bounds.y1 < window_info[j].bounds.y2))
4183 if (import == MagickFalse)
4188 ximage=XGetImage(display,window_info[id].window,(int)
4189 window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
4190 (unsigned int) window_info[id].crop_info.width,(unsigned int)
4191 window_info[id].crop_info.height,AllPlanes,ZPixmap);
4192 if (ximage == (XImage *) NULL)
4195 Initialize window colormap.
4198 colors=(XColor *) NULL;
4199 if (window_info[id].colormap != (Colormap) NULL)
4205 Search colormap list for window colormap.
4207 number_colors=(unsigned int) window_info[id].visual->map_entries;
4208 for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
4209 if (p->colormap == window_info[id].colormap)
4211 if (p == (ColormapInfo *) NULL)
4214 Get the window colormap.
4216 colors=(XColor *) AcquireQuantumMemory(number_colors,
4218 if (colors == (XColor *) NULL)
4220 XDestroyImage(ximage);
4221 return((Image *) NULL);
4223 if ((window_info[id].visual->klass != DirectColor) &&
4224 (window_info[id].visual->klass != TrueColor))
4225 for (i=0; i < (int) number_colors; i++)
4227 colors[i].pixel=(unsigned long) i;
4241 DirectColor or TrueColor visual.
4246 red_bit=window_info[id].visual->red_mask &
4247 (~(window_info[id].visual->red_mask)+1);
4248 green_bit=window_info[id].visual->green_mask &
4249 (~(window_info[id].visual->green_mask)+1);
4250 blue_bit=window_info[id].visual->blue_mask &
4251 (~(window_info[id].visual->blue_mask)+1);
4252 for (i=0; i < (int) number_colors; i++)
4254 colors[i].pixel=red | green | blue;
4257 if (red > window_info[id].visual->red_mask)
4260 if (green > window_info[id].visual->green_mask)
4263 if (blue > window_info[id].visual->blue_mask)
4267 (void) XQueryColors(display,window_info[id].colormap,colors,
4268 (int) number_colors);
4270 Append colormap to colormap list.
4272 p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
4273 if (p == (ColormapInfo *) NULL)
4274 return((Image *) NULL);
4275 p->colormap=window_info[id].colormap;
4277 p->next=colormap_info;
4283 Allocate image structure.
4285 composite_image=AcquireImage((ImageInfo *) NULL);
4286 if (composite_image == (Image *) NULL)
4288 XDestroyImage(ximage);
4289 return((Image *) NULL);
4292 Convert X image to MIFF format.
4294 if ((window_info[id].visual->klass != TrueColor) &&
4295 (window_info[id].visual->klass != DirectColor))
4296 composite_image->storage_class=PseudoClass;
4297 composite_image->columns=(unsigned long) ximage->width;
4298 composite_image->rows=(unsigned long) ximage->height;
4299 exception=(&composite_image->exception);
4300 switch (composite_image->storage_class)
4305 register unsigned long
4318 Determine shift and mask for red, green, and blue.
4320 red_mask=window_info[id].visual->red_mask;
4322 while ((red_mask != 0) && ((red_mask & 0x01) == 0))
4327 green_mask=window_info[id].visual->green_mask;
4329 while ((green_mask != 0) && ((green_mask & 0x01) == 0))
4334 blue_mask=window_info[id].visual->blue_mask;
4336 while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
4342 Convert X image to DirectClass packets.
4344 if ((number_colors != 0) &&
4345 (window_info[id].visual->klass == DirectColor))
4346 for (y=0; y < (int) composite_image->rows; y++)
4348 q=QueueAuthenticPixels(composite_image,0,y,
4349 composite_image->columns,1,exception);
4350 if (q == (PixelPacket *) NULL)
4352 for (x=0; x < (int) composite_image->columns; x++)
4354 pixel=XGetPixel(ximage,x,y);
4355 index=(pixel >> red_shift) & red_mask;
4356 q->red=ScaleShortToQuantum(colors[index].red);
4357 index=(pixel >> green_shift) & green_mask;
4358 q->green=ScaleShortToQuantum(colors[index].green);
4359 index=(pixel >> blue_shift) & blue_mask;
4360 q->blue=ScaleShortToQuantum(colors[index].blue);
4363 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4367 for (y=0; y < (int) composite_image->rows; y++)
4369 q=QueueAuthenticPixels(composite_image,0,y,
4370 composite_image->columns,1,exception);
4371 if (q == (PixelPacket *) NULL)
4373 for (x=0; x < (int) composite_image->columns; x++)
4375 pixel=XGetPixel(ximage,x,y);
4376 color=(pixel >> red_shift) & red_mask;
4377 color=(65535UL*color)/red_mask;
4378 q->red=ScaleShortToQuantum((unsigned short) color);
4379 color=(pixel >> green_shift) & green_mask;
4380 color=(65535UL*color)/green_mask;
4381 q->green=ScaleShortToQuantum((unsigned short) color);
4382 color=(pixel >> blue_shift) & blue_mask;
4383 color=(65535UL*color)/blue_mask;
4384 q->blue=ScaleShortToQuantum((unsigned short) color);
4387 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4397 if (AcquireImageColormap(composite_image,number_colors) == MagickFalse)
4399 XDestroyImage(ximage);
4400 composite_image=DestroyImage(composite_image);
4401 return((Image *) NULL);
4403 for (i=0; i < (int) composite_image->colors; i++)
4405 composite_image->colormap[colors[i].pixel].red=
4406 ScaleShortToQuantum(colors[i].red);
4407 composite_image->colormap[colors[i].pixel].green=
4408 ScaleShortToQuantum(colors[i].green);
4409 composite_image->colormap[colors[i].pixel].blue=
4410 ScaleShortToQuantum(colors[i].blue);
4413 Convert X image to PseudoClass packets.
4415 for (y=0; y < (int) composite_image->rows; y++)
4417 q=QueueAuthenticPixels(composite_image,0,y,composite_image->columns,1,exception);
4418 if (q == (PixelPacket *) NULL)
4420 indexes=GetAuthenticIndexQueue(composite_image);
4421 for (x=0; x < (int) composite_image->columns; x++)
4423 index=(IndexPacket) XGetPixel(ximage,x,y);
4425 *q++=composite_image->colormap[(long) index];
4427 if (SyncAuthenticPixels(composite_image,exception) == MagickFalse)
4433 XDestroyImage(ximage);
4434 if (image == (Image *) NULL)
4436 image=composite_image;
4440 Composite any children in back-to-front order.
4442 (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
4443 &x_offset,&y_offset,&child);
4444 x_offset-=(int) crop_info.x;
4447 y_offset-=(int) crop_info.y;
4450 (void) CompositeImage(image,CopyCompositeOp,composite_image,x_offset,
4454 Relinquish resources.
4456 while (colormap_info != (ColormapInfo *) NULL)
4458 next=colormap_info->next;
4459 colormap_info->colors=(XColor *)
4460 RelinquishMagickMemory(colormap_info->colors);
4461 colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
4465 Relinquish resources and restore initial state.
4467 window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
4470 colormap_info=(ColormapInfo *) NULL;
4473 return((Image *) NULL);
4477 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4481 % X G e t W i n d o w I n f o %
4485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4487 % XGetWindowInfo() initializes the XWindowInfo structure.
4489 % The format of the XGetWindowInfo method is:
4491 % void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4492 % XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4493 % XResourceInfo *resource_info,XWindowInfo *window)
4494 % resource_info,window)
4496 % A description of each parameter follows:
4498 % o display: Specifies a connection to an X server; returned from
4501 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
4502 % returned from XGetVisualInfo.
4504 % o map_info: If map_type is specified, this structure is initialized
4505 % with info from the Standard Colormap.
4507 % o pixel: Specifies a pointer to a XPixelInfo structure.
4509 % o font_info: Specifies a pointer to a XFontStruct structure.
4511 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
4514 MagickExport void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
4515 XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
4516 XResourceInfo *resource_info,XWindowInfo *window)
4519 Initialize window info.
4521 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4522 assert(display != (Display *) NULL);
4523 assert(visual_info != (XVisualInfo *) NULL);
4524 assert(map_info != (XStandardColormap *) NULL);
4525 assert(pixel != (XPixelInfo *) NULL);
4526 assert(resource_info != (XResourceInfo *) NULL);
4527 assert(window != (XWindowInfo *) NULL);
4528 if (window->id != (Window) NULL)
4530 if (window->cursor != (Cursor) NULL)
4531 (void) XFreeCursor(display,window->cursor);
4532 if (window->busy_cursor != (Cursor) NULL)
4533 (void) XFreeCursor(display,window->busy_cursor);
4534 if (window->highlight_stipple != (Pixmap) NULL)
4535 (void) XFreePixmap(display,window->highlight_stipple);
4536 if (window->shadow_stipple != (Pixmap) NULL)
4537 (void) XFreePixmap(display,window->shadow_stipple);
4538 if (window->name == (char *) NULL)
4539 window->name=AcquireString("");
4540 if (window->icon_name == (char *) NULL)
4541 window->icon_name=AcquireString("");
4546 Initialize these attributes just once.
4548 window->id=(Window) NULL;
4549 if (window->name == (char *) NULL)
4550 window->name=AcquireString("");
4551 if (window->icon_name == (char *) NULL)
4552 window->icon_name=AcquireString("");
4553 window->x=XDisplayWidth(display,visual_info->screen) >> 1;
4554 window->y=XDisplayWidth(display,visual_info->screen) >> 1;
4555 window->ximage=(XImage *) NULL;
4556 window->matte_image=(XImage *) NULL;
4557 window->pixmap=(Pixmap) NULL;
4558 window->matte_pixmap=(Pixmap) NULL;
4559 window->mapped=MagickFalse;
4560 window->stasis=MagickFalse;
4561 window->shared_memory=MagickTrue;
4562 window->segment_info=(void *) NULL;
4563 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
4568 if (window->segment_info == (void *) NULL)
4569 window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
4570 segment_info=(XShmSegmentInfo *) window->segment_info;
4571 segment_info[0].shmid=(-1);
4572 segment_info[0].shmaddr=(char *) NULL;
4573 segment_info[1].shmid=(-1);
4574 segment_info[1].shmaddr=(char *) NULL;
4579 Initialize these attributes every time function is called.
4581 window->screen=visual_info->screen;
4582 window->root=XRootWindow(display,visual_info->screen);
4583 window->visual=visual_info->visual;
4584 window->storage_class=(unsigned int) visual_info->klass;
4585 window->depth=(unsigned int) visual_info->depth;
4586 window->visual_info=visual_info;
4587 window->map_info=map_info;
4588 window->pixel_info=pixel;
4589 window->font_info=font_info;
4590 window->cursor=XCreateFontCursor(display,XC_left_ptr);
4591 window->busy_cursor=XCreateFontCursor(display,XC_watch);
4592 window->geometry=(char *) NULL;
4593 window->icon_geometry=(char *) NULL;
4594 if (resource_info->icon_geometry != (char *) NULL)
4595 (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
4596 window->crop_geometry=(char *) NULL;
4597 window->flags=(unsigned long) PSize;
4600 window->min_width=1;
4601 window->min_height=1;
4602 window->width_inc=1;
4603 window->height_inc=1;
4604 window->border_width=resource_info->border_width;
4605 window->annotate_context=pixel->annotate_context;
4606 window->highlight_context=pixel->highlight_context;
4607 window->widget_context=pixel->widget_context;
4608 window->shadow_stipple=(Pixmap) NULL;
4609 window->highlight_stipple=(Pixmap) NULL;
4610 window->use_pixmap=MagickTrue;
4611 window->immutable=MagickFalse;
4612 window->shape=MagickFalse;
4614 window->mask=(unsigned long) (CWBackingStore | CWBackPixel | CWBackPixmap |
4615 CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
4616 CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
4617 window->attributes.background_pixel=pixel->background_color.pixel;
4618 window->attributes.background_pixmap=(Pixmap) NULL;
4619 window->attributes.bit_gravity=ForgetGravity;
4620 window->attributes.backing_store=WhenMapped;
4621 window->attributes.save_under=MagickTrue;
4622 window->attributes.border_pixel=pixel->border_color.pixel;
4623 window->attributes.colormap=map_info->colormap;
4624 window->attributes.cursor=window->cursor;
4625 window->attributes.do_not_propagate_mask=NoEventMask;
4626 window->attributes.event_mask=NoEventMask;
4627 window->attributes.override_redirect=MagickFalse;
4628 window->attributes.win_gravity=NorthWestGravity;
4629 window->orphan=MagickFalse;
4633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4637 % X H i g h l i g h t E l l i p s e %
4641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4643 % XHighlightEllipse() puts a border on the X server around a region defined by
4646 % The format of the XHighlightEllipse method is:
4648 % void XHighlightEllipse(Display *display,Window window,
4649 % GC annotate_context,const RectangleInfo *highlight_info)
4651 % A description of each parameter follows:
4653 % o display: Specifies a connection to an X server; returned from
4656 % o window: Specifies a pointer to a Window structure.
4658 % o annotate_context: Specifies a pointer to a GC structure.
4660 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4661 % contains the extents of any highlighting rectangle.
4664 MagickExport void XHighlightEllipse(Display *display,Window window,
4665 GC annotate_context,const RectangleInfo *highlight_info)
4667 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4668 assert(display != (Display *) NULL);
4669 assert(window != (Window) NULL);
4670 assert(annotate_context != (GC) NULL);
4671 assert(highlight_info != (RectangleInfo *) NULL);
4672 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4674 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
4675 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4676 (unsigned int) highlight_info->height-1,0,360*64);
4677 (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
4678 (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4679 (unsigned int) highlight_info->height-3,0,360*64);
4683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4687 % X H i g h l i g h t L i n e %
4691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4693 % XHighlightLine() puts a border on the X server around a region defined by
4696 % The format of the XHighlightLine method is:
4698 % void XHighlightLine(Display *display,Window window,GC annotate_context,
4699 % const XSegment *highlight_info)
4701 % A description of each parameter follows:
4703 % o display: Specifies a connection to an X server; returned from
4706 % o window: Specifies a pointer to a Window structure.
4708 % o annotate_context: Specifies a pointer to a GC structure.
4710 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4711 % contains the extents of any highlighting rectangle.
4714 MagickExport void XHighlightLine(Display *display,Window window,
4715 GC annotate_context,const XSegment *highlight_info)
4717 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4718 assert(display != (Display *) NULL);
4719 assert(window != (Window) NULL);
4720 assert(annotate_context != (GC) NULL);
4721 assert(highlight_info != (XSegment *) NULL);
4722 (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
4723 highlight_info->y1,highlight_info->x2,highlight_info->y2);
4727 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4731 % X H i g h l i g h t R e c t a n g l e %
4735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4737 % XHighlightRectangle() puts a border on the X server around a region defined
4738 % by highlight_info.
4740 % The format of the XHighlightRectangle method is:
4742 % void XHighlightRectangle(Display *display,Window window,
4743 % GC annotate_context,const RectangleInfo *highlight_info)
4745 % A description of each parameter follows:
4747 % o display: Specifies a connection to an X server; returned from
4750 % o window: Specifies a pointer to a Window structure.
4752 % o annotate_context: Specifies a pointer to a GC structure.
4754 % o highlight_info: Specifies a pointer to a RectangleInfo structure. It
4755 % contains the extents of any highlighting rectangle.
4758 MagickExport void XHighlightRectangle(Display *display,Window window,
4759 GC annotate_context,const RectangleInfo *highlight_info)
4761 assert(display != (Display *) NULL);
4762 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4763 assert(window != (Window) NULL);
4764 assert(annotate_context != (GC) NULL);
4765 assert(highlight_info != (RectangleInfo *) NULL);
4766 if ((highlight_info->width < 4) || (highlight_info->height < 4))
4768 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
4769 (int) highlight_info->y,(unsigned int) highlight_info->width-1,
4770 (unsigned int) highlight_info->height-1);
4771 (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
4772 1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
4773 (unsigned int) highlight_info->height-3);
4777 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4781 % X I m p o r t I m a g e %
4785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4787 % XImportImage() reads an image from an X window.
4789 % The format of the XImportImage method is:
4791 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
4793 % A description of each parameter follows:
4795 % o image_info: the image info.
4797 % o ximage_info: Specifies a pointer to an XImportInfo structure.
4800 MagickExport Image *XImportImage(const ImageInfo *image_info,
4801 XImportInfo *ximage_info)
4834 Open X server connection.
4836 assert(image_info != (const ImageInfo *) NULL);
4837 assert(image_info->signature == MagickSignature);
4838 if (image_info->debug != MagickFalse)
4839 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4840 image_info->filename);
4841 assert(ximage_info != (XImportInfo *) NULL);
4842 display=XOpenDisplay(image_info->server_name);
4843 if (display == (Display *) NULL)
4845 ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
4846 XDisplayName(image_info->server_name));
4847 return((Image *) NULL);
4850 Set our forgiving exception handler.
4852 (void) XSetErrorHandler(XError);
4854 Select target window.
4860 root=XRootWindow(display,XDefaultScreen(display));
4861 target=(Window) NULL;
4862 if ((image_info->filename != (char *) NULL) &&
4863 (*image_info->filename != '\0'))
4865 if (LocaleCompare(image_info->filename,"root") == 0)
4870 Select window by ID or name.
4872 if (isdigit((unsigned char) *image_info->filename) != 0)
4873 target=XWindowByID(display,root,(Window)
4874 strtol(image_info->filename,(char **) NULL,0));
4875 if (target == (Window) NULL)
4876 target=XWindowByName(display,root,image_info->filename);
4877 if (target == (Window) NULL)
4878 ThrowXWindowFatalException(XServerError,
4879 "NoWindowWithSpecifiedIDExists",image_info->filename);
4883 If target window is not defined, interactively select one.
4885 prior_target=target;
4886 if (target == (Window) NULL)
4887 target=XSelectWindow(display,&crop_info);
4888 if (target == (Window) NULL)
4889 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4890 image_info->filename);
4891 client=target; /* obsolete */
4897 status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
4898 if (status != False)
4906 Find window manager frame.
4908 status=XQueryTree(display,target,&root,&parent,&children,&d);
4909 if ((status != False) && (children != (Window *) NULL))
4910 (void) XFree((char *) children);
4911 if ((status == False) || (parent == (Window) NULL) ||
4919 client=XClientWindow(display,target);
4920 if (ximage_info->frame == MagickFalse)
4922 if ((ximage_info->frame == MagickFalse) &&
4923 (prior_target != MagickFalse))
4924 target=prior_target;
4925 XDelay(display,SuspendTime << 4);
4928 if (ximage_info->screen)
4940 Obtain window image directly from screen.
4942 status=XGetWindowAttributes(display,target,&window_attributes);
4943 if (status == False)
4945 ThrowXWindowFatalException(XServerError,
4946 "UnableToReadXWindowAttributes",image_info->filename);
4947 (void) XCloseDisplay(display);
4948 return((Image *) NULL);
4950 (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
4953 crop_info.width=(unsigned long) window_attributes.width;
4954 crop_info.height=(unsigned long) window_attributes.height;
4955 if (ximage_info->borders)
4958 Include border in image.
4960 crop_info.x-=window_attributes.border_width;
4961 crop_info.y-=window_attributes.border_width;
4962 crop_info.width+=window_attributes.border_width << 1;
4963 crop_info.height+=window_attributes.border_width << 1;
4968 If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
4971 status=XGetWMColormapWindows(display,target,&children,&number_windows);
4972 if ((status == True) && (number_windows > 0))
4974 ximage_info->descend=MagickTrue;
4975 (void) XFree ((char *) children);
4977 colormaps=XListInstalledColormaps(display,target,&number_colormaps);
4978 if (number_colormaps > 0)
4980 if (number_colormaps > 1)
4981 ximage_info->descend=MagickTrue;
4982 (void) XFree((char *) colormaps);
4985 Alert the user not to alter the screen.
4987 if (ximage_info->silent == MagickFalse)
4988 (void) XBell(display,0);
4990 Get image by window id.
4992 (void) XGrabServer(display);
4993 image=XGetWindowImage(display,target,ximage_info->borders,
4994 ximage_info->descend ? 1U : 0U);
4995 (void) XUngrabServer(display);
4996 if (image == (Image *) NULL)
4997 ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
4998 image_info->filename)
5001 (void) CopyMagickString(image->filename,image_info->filename,
5003 if ((crop_info.width != 0) && (crop_info.height != 0))
5010 Crop image as defined by the cropping rectangle.
5012 clone_image=CloneImage(image,0,0,MagickTrue,&image->exception);
5013 if (clone_image != (Image *) NULL)
5015 crop_image=CropImage(clone_image,&crop_info,&image->exception);
5016 if (crop_image != (Image *) NULL)
5018 image=DestroyImage(image);
5023 status=XGetWMName(display,target,&window_name);
5026 if ((image_info->filename != (char *) NULL) &&
5027 (*image_info->filename == '\0'))
5028 (void) CopyMagickString(image->filename,(char *) window_name.value,
5029 (size_t) window_name.nitems+1);
5030 (void) XFree((void *) window_name.value);
5033 if (ximage_info->silent == MagickFalse)
5036 Alert the user we're done.
5038 (void) XBell(display,0);
5039 (void) XBell(display,0);
5041 (void) XCloseDisplay(display);
5046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5050 % X I n i t i a l i z e W i n d o w s %
5054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5056 % XInitializeWindows() initializes the XWindows structure.
5058 % The format of the XInitializeWindows method is:
5060 % XWindows *XInitializeWindows(Display *display,
5061 % XResourceInfo *resource_info)
5063 % A description of each parameter follows:
5065 % o windows: XInitializeWindows returns a pointer to a XWindows structure.
5067 % o display: Specifies a connection to an X server; returned from
5070 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5073 MagickExport XWindows *XInitializeWindows(Display *display,
5074 XResourceInfo *resource_info)
5083 Allocate windows structure.
5085 windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
5086 if (windows == (XWindows *) NULL)
5088 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5090 return((XWindows *) NULL);
5092 (void) ResetMagickMemory(windows,0,sizeof(*windows));
5093 windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
5094 sizeof(*windows->pixel_info));
5095 windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
5096 sizeof(*windows->icon_pixel));
5097 windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
5098 sizeof(*windows->icon_resources));
5099 if ((windows->pixel_info == (XPixelInfo *) NULL) ||
5100 (windows->icon_pixel == (XPixelInfo *) NULL) ||
5101 (windows->icon_resources == (XResourceInfo *) NULL))
5103 ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
5105 return((XWindows *) NULL);
5108 Initialize windows structure.
5110 windows->display=display;
5111 windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
5112 windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
5113 windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
5114 windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
5115 windows->im_remote_command=
5116 XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
5117 windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
5118 windows->im_update_colormap=
5119 XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
5120 windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
5121 windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
5122 windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
5123 windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
5124 windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
5125 #if defined(__WINDOWS__)
5126 (void) XSynchronize(display,IsWindows95());
5128 if (IsEventLogging())
5130 (void) XSynchronize(display,MagickTrue);
5131 (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5132 GetMagickVersion((unsigned long *) NULL));
5133 (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
5134 (void) LogMagickEvent(X11Event,GetMagickModule(),
5135 " Window Manager: 0x%lx",windows->wm_protocols);
5136 (void) LogMagickEvent(X11Event,GetMagickModule(),
5137 " delete window: 0x%lx",windows->wm_delete_window);
5138 (void) LogMagickEvent(X11Event,GetMagickModule()," take focus: 0x%lx",
5139 windows->wm_take_focus);
5140 (void) LogMagickEvent(X11Event,GetMagickModule()," ImageMagick: 0x%lx",
5141 windows->im_protocols);
5142 (void) LogMagickEvent(X11Event,GetMagickModule(),
5143 " remote command: 0x%lx",windows->im_remote_command);
5144 (void) LogMagickEvent(X11Event,GetMagickModule(),
5145 " update widget: 0x%lx",windows->im_update_widget);
5146 (void) LogMagickEvent(X11Event,GetMagickModule(),
5147 " update colormap: 0x%lx",windows->im_update_colormap);
5148 (void) LogMagickEvent(X11Event,GetMagickModule(),
5149 " former image: 0x%lx",windows->im_former_image);
5150 (void) LogMagickEvent(X11Event,GetMagickModule()," next image: 0x%lx",
5151 windows->im_next_image);
5152 (void) LogMagickEvent(X11Event,GetMagickModule(),
5153 " retain colors: 0x%lx",windows->im_retain_colors);
5154 (void) LogMagickEvent(X11Event,GetMagickModule()," exit: 0x%lx",
5156 (void) LogMagickEvent(X11Event,GetMagickModule()," Drag and Drop: 0x%lx",
5157 windows->dnd_protocols);
5160 Allocate standard colormap.
5162 windows->map_info=XAllocStandardColormap();
5163 windows->icon_map=XAllocStandardColormap();
5164 if ((windows->map_info == (XStandardColormap *) NULL) ||
5165 (windows->icon_map == (XStandardColormap *) NULL))
5166 ThrowXWindowFatalException(ResourceLimitFatalError,
5167 "MemoryAllocationFailed","...");
5168 windows->map_info->colormap=(Colormap) NULL;
5169 windows->icon_map->colormap=(Colormap) NULL;
5170 windows->pixel_info->pixels=(unsigned long *) NULL;
5171 windows->pixel_info->annotate_context=(GC) NULL;
5172 windows->pixel_info->highlight_context=(GC) NULL;
5173 windows->pixel_info->widget_context=(GC) NULL;
5174 windows->font_info=(XFontStruct *) NULL;
5175 windows->icon_pixel->annotate_context=(GC) NULL;
5176 windows->icon_pixel->pixels=(unsigned long *) NULL;
5180 *windows->icon_resources=(*resource_info);
5181 windows->icon_resources->visual_type=(char *) "default";
5182 windows->icon_resources->colormap=SharedColormap;
5183 windows->visual_info=
5184 XBestVisualInfo(display,windows->map_info,resource_info);
5185 windows->icon_visual=
5186 XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
5187 if ((windows->visual_info == (XVisualInfo *) NULL) ||
5188 (windows->icon_visual == (XVisualInfo *) NULL))
5189 ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
5190 resource_info->visual_type);
5191 if (IsEventLogging())
5193 (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
5194 (void) LogMagickEvent(X11Event,GetMagickModule()," visual id: 0x%lx",
5195 windows->visual_info->visualid);
5196 (void) LogMagickEvent(X11Event,GetMagickModule()," class: %s",
5197 XVisualClassName(windows->visual_info->klass));
5198 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d planes",
5199 windows->visual_info->depth);
5200 (void) LogMagickEvent(X11Event,GetMagickModule(),
5201 " size of colormap: %d entries",windows->visual_info->colormap_size);
5202 (void) LogMagickEvent(X11Event,GetMagickModule(),
5203 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",
5204 windows->visual_info->red_mask,windows->visual_info->green_mask,
5205 windows->visual_info->blue_mask);
5206 (void) LogMagickEvent(X11Event,GetMagickModule(),
5207 " significant bits in color: %d bits",
5208 windows->visual_info->bits_per_rgb);
5211 Allocate class and manager hints.
5213 windows->class_hints=XAllocClassHint();
5214 windows->manager_hints=XAllocWMHints();
5215 if ((windows->class_hints == (XClassHint *) NULL) ||
5216 (windows->manager_hints == (XWMHints *) NULL))
5217 ThrowXWindowFatalException(ResourceLimitFatalError,
5218 "MemoryAllocationFailed","...");
5220 Determine group leader if we have one.
5222 root_window=XRootWindow(display,windows->visual_info->screen);
5223 windows->group_leader.id=(Window) NULL;
5224 if (resource_info->window_group != (char *) NULL)
5226 if (isdigit((unsigned char) *resource_info->window_group) != 0)
5227 windows->group_leader.id=XWindowByID(display,root_window,(Window)
5228 strtol((char *) resource_info->window_group,(char **) NULL,0));
5229 if (windows->group_leader.id == (Window) NULL)
5230 windows->group_leader.id=
5231 XWindowByName(display,root_window,resource_info->window_group);
5237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5241 % X M a k e C u r s o r %
5245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5247 % XMakeCursor() creates a crosshairs X11 cursor.
5249 % The format of the XMakeCursor method is:
5251 % Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
5252 % char *background_color,char *foreground_color)
5254 % A description of each parameter follows:
5256 % o display: Specifies a connection to an X server; returned from
5259 % o window: Specifies the ID of the window for which the cursor is
5262 % o colormap: Specifies the ID of the colormap from which the background
5263 % and foreground color will be retrieved.
5265 % o background_color: Specifies the color to use for the cursor background.
5267 % o foreground_color: Specifies the color to use for the cursor foreground.
5270 MagickExport Cursor XMakeCursor(Display *display,Window window,
5271 Colormap colormap,char *background_color,char *foreground_color)
5273 #define scope_height 17
5274 #define scope_x_hot 8
5275 #define scope_y_hot 8
5276 #define scope_width 17
5278 static const unsigned char
5281 0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5282 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
5283 0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
5284 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
5285 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
5289 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5290 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
5291 0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
5292 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
5293 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
5307 assert(display != (Display *) NULL);
5308 assert(window != (Window) NULL);
5309 assert(colormap != (Colormap) NULL);
5310 assert(background_color != (char *) NULL);
5311 assert(foreground_color != (char *) NULL);
5312 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
5313 source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
5315 mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
5316 scope_width,scope_height);
5317 if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
5319 ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
5320 return((Cursor) NULL);
5322 (void) XParseColor(display,colormap,background_color,&background);
5323 (void) XParseColor(display,colormap,foreground_color,&foreground);
5324 cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
5325 scope_x_hot,scope_y_hot);
5326 (void) XFreePixmap(display,source);
5327 (void) XFreePixmap(display,mask);
5332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5336 % X M a k e I m a g e %
5340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5342 % XMakeImage() creates an X11 image. If the image size differs from the X11
5343 % image size, the image is first resized.
5345 % The format of the XMakeImage method is:
5347 % MagickBooleanType XMakeImage(Display *display,
5348 % const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5349 % unsigned int width,unsigned int height)
5351 % A description of each parameter follows:
5353 % o display: Specifies a connection to an X server; returned from
5356 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5358 % o window: Specifies a pointer to a XWindowInfo structure.
5360 % o image: the image.
5362 % o width: Specifies the width in pixels of the rectangular area to
5365 % o height: Specifies the height in pixels of the rectangular area to
5369 MagickExport MagickBooleanType XMakeImage(Display *display,
5370 const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5371 unsigned int width,unsigned int height)
5373 #define CheckOverflowException(length,width,height) \
5374 (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
5387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5388 assert(display != (Display *) NULL);
5389 assert(resource_info != (XResourceInfo *) NULL);
5390 assert(window != (XWindowInfo *) NULL);
5392 assert(height != 0);
5393 if ((window->width == 0) || (window->height == 0))
5394 return(MagickFalse);
5396 Apply user transforms to the image.
5398 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
5399 (void) XFlush(display);
5400 depth=(int) window->depth;
5401 if (window->destroy)
5402 window->image=DestroyImage(window->image);
5403 window->image=image;
5404 window->destroy=MagickFalse;
5405 if (window->image != (Image *) NULL)
5407 if (window->crop_geometry != (char *) NULL)
5418 window->image->page.x=0;
5419 window->image->page.y=0;
5420 (void) ParsePageGeometry(window->image,window->crop_geometry,
5421 &crop_info,&image->exception);
5422 crop_image=CropImage(window->image,&crop_info,&image->exception);
5423 if (crop_image != (Image *) NULL)
5425 if (window->image != image)
5426 window->image=DestroyImage(window->image);
5427 window->image=crop_image;
5428 window->destroy=MagickTrue;
5431 if ((width != (unsigned int) window->image->columns) ||
5432 (height != (unsigned int) window->image->rows))
5440 resize_image=NewImageList();
5441 if (window->pixel_info->colors != 0)
5442 resize_image=SampleImage(window->image,width,height,
5445 resize_image=ThumbnailImage(window->image,width,height,
5447 if (resize_image != (Image *) NULL)
5449 if (window->image != image)
5450 window->image=DestroyImage(window->image);
5451 window->image=resize_image;
5452 window->destroy=MagickTrue;
5455 width=(unsigned int) window->image->columns;
5456 height=(unsigned int) window->image->rows;
5461 ximage=(XImage *) NULL;
5462 format=(depth == 1) ? XYBitmap : ZPixmap;
5463 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5464 if (window->shared_memory != MagickFalse)
5469 segment_info=(XShmSegmentInfo *) window->segment_info;
5470 segment_info[1].shmid=(-1);
5471 segment_info[1].shmaddr=(char *) NULL;
5472 ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
5473 (char *) NULL,&segment_info[1],width,height);
5474 if (ximage == (XImage *) NULL)
5475 window->shared_memory=MagickFalse;
5476 length=(size_t) ximage->bytes_per_line*ximage->height;
5477 if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
5478 window->shared_memory=MagickFalse;
5479 if (window->shared_memory != MagickFalse)
5480 segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
5481 if (window->shared_memory != MagickFalse)
5482 segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
5483 if (segment_info[1].shmid < 0)
5484 window->shared_memory=MagickFalse;
5485 if (window->shared_memory != MagickFalse)
5486 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5489 if (ximage != (XImage *) NULL)
5490 XDestroyImage(ximage);
5491 ximage=(XImage *) NULL;
5492 if (segment_info[1].shmaddr)
5494 (void) shmdt(segment_info[1].shmaddr);
5495 segment_info[1].shmaddr=(char *) NULL;
5497 if (segment_info[1].shmid >= 0)
5499 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5500 segment_info[1].shmid=(-1);
5506 Allocate X image pixel data.
5508 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5509 if (window->shared_memory)
5517 (void) XSync(display,MagickFalse);
5518 xerror_alert=MagickFalse;
5519 segment_info=(XShmSegmentInfo *) window->segment_info;
5520 ximage->data=segment_info[1].shmaddr;
5521 segment_info[1].readOnly=MagickFalse;
5522 status=XShmAttach(display,&segment_info[1]);
5523 if (status != False)
5524 (void) XSync(display,MagickFalse);
5525 if ((status == False) || (xerror_alert != MagickFalse))
5527 window->shared_memory=MagickFalse;
5528 if (status != False)
5529 XShmDetach(display,&segment_info[1]);
5530 if (ximage != (XImage *) NULL)
5533 XDestroyImage(ximage);
5534 ximage=(XImage *) NULL;
5536 if (segment_info[1].shmid >= 0)
5538 if (segment_info[1].shmaddr != NULL)
5539 (void) shmdt(segment_info[1].shmaddr);
5540 (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
5541 segment_info[1].shmid=(-1);
5542 segment_info[1].shmaddr=(char *) NULL;
5547 if (window->shared_memory == MagickFalse)
5548 ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
5549 (char *) NULL,width,height,XBitmapPad(display),0);
5550 if (ximage == (XImage *) NULL)
5553 Unable to create X image.
5555 (void) XCheckDefineCursor(display,window->id,window->cursor);
5556 return(MagickFalse);
5558 length=(size_t) ximage->bytes_per_line*ximage->height;
5559 if (IsEventLogging())
5561 (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
5562 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %dx%d",
5563 ximage->width,ximage->height);
5564 (void) LogMagickEvent(X11Event,GetMagickModule()," format: %d",
5566 (void) LogMagickEvent(X11Event,GetMagickModule()," byte order: %d",
5567 ximage->byte_order);
5568 (void) LogMagickEvent(X11Event,GetMagickModule(),
5569 " bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
5570 ximage->bitmap_bit_order,ximage->bitmap_pad);
5571 (void) LogMagickEvent(X11Event,GetMagickModule()," depth: %d",
5573 (void) LogMagickEvent(X11Event,GetMagickModule()," bytes per line: %d",
5574 ximage->bytes_per_line);
5575 (void) LogMagickEvent(X11Event,GetMagickModule()," bits per pixel: %d",
5576 ximage->bits_per_pixel);
5577 (void) LogMagickEvent(X11Event,GetMagickModule(),
5578 " red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
5579 ximage->green_mask,ximage->blue_mask);
5581 if (window->shared_memory == MagickFalse)
5583 if (ximage->format != XYBitmap)
5584 ximage->data=(char *) AcquireQuantumMemory((size_t)
5585 ximage->bytes_per_line,(size_t) ximage->height);
5587 ximage->data=(char *) AcquireQuantumMemory((size_t)
5588 ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
5590 if (ximage->data == (char *) NULL)
5593 Unable to allocate pixel data.
5595 XDestroyImage(ximage);
5596 ximage=(XImage *) NULL;
5597 (void) XCheckDefineCursor(display,window->id,window->cursor);
5598 return(MagickFalse);
5600 if (window->ximage != (XImage *) NULL)
5603 Destroy previous X image.
5605 length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
5606 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5607 if (window->segment_info != (XShmSegmentInfo *) NULL)
5612 segment_info=(XShmSegmentInfo *) window->segment_info;
5613 if (segment_info[0].shmid >= 0)
5615 (void) XSync(display,MagickFalse);
5616 (void) XShmDetach(display,&segment_info[0]);
5617 (void) XSync(display,MagickFalse);
5618 if (segment_info[0].shmaddr != (char *) NULL)
5619 (void) shmdt(segment_info[0].shmaddr);
5620 (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
5621 segment_info[0].shmid=(-1);
5622 segment_info[0].shmaddr=(char *) NULL;
5623 window->ximage->data=(char *) NULL;
5627 if (window->ximage->data != (char *) NULL)
5628 free(window->ximage->data);
5629 window->ximage->data=(char *) NULL;
5630 XDestroyImage(window->ximage);
5631 window->ximage=(XImage *) NULL;
5633 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
5634 if (window->segment_info != (XShmSegmentInfo *) NULL)
5639 segment_info=(XShmSegmentInfo *) window->segment_info;
5640 segment_info[0]=segment_info[1];
5643 window->ximage=ximage;
5644 matte_image=(XImage *) NULL;
5645 if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
5646 if ((window->image->matte != MagickFalse) &&
5647 ((long) width <= XDisplayWidth(display,window->screen)) &&
5648 ((long) height <= XDisplayHeight(display,window->screen)))
5653 matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
5654 (char *) NULL,width,height,XBitmapPad(display),0);
5655 if (IsEventLogging())
5657 (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
5658 (void) LogMagickEvent(X11Event,GetMagickModule(),
5659 " width, height: %dx%d",matte_image->width,matte_image->height);
5661 if (matte_image != (XImage *) NULL)
5664 Allocate matte image pixel data.
5666 matte_image->data=(char *) AcquireQuantumMemory((size_t)
5667 matte_image->bytes_per_line*matte_image->depth,
5668 (size_t) matte_image->height);
5669 if (matte_image->data == (char *) NULL)
5671 XDestroyImage(matte_image);
5672 matte_image=(XImage *) NULL;
5676 if (window->matte_image != (XImage *) NULL)
5681 if (window->matte_image->data != (char *) NULL)
5682 free(window->matte_image->data);
5683 window->matte_image->data=(char *) NULL;
5684 XDestroyImage(window->matte_image);
5685 window->matte_image=(XImage *) NULL;
5687 window->matte_image=matte_image;
5688 if (window->matte_pixmap != (Pixmap) NULL)
5690 (void) XFreePixmap(display,window->matte_pixmap);
5691 window->matte_pixmap=(Pixmap) NULL;
5692 #if defined(MAGICKCORE_HAVE_SHAPE)
5693 if (window->shape != MagickFalse)
5694 XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
5697 window->stasis=MagickFalse;
5699 Convert pixels to X image data.
5701 if (window->image != (Image *) NULL)
5703 if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
5704 (ximage->bitmap_bit_order == LSBFirst)))
5705 XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5708 XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5711 if (window->matte_image != (XImage *) NULL)
5714 Create matte pixmap.
5716 window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
5717 if (window->matte_pixmap != (Pixmap) NULL)
5726 Copy matte image to matte pixmap.
5728 context_values.background=1;
5729 context_values.foreground=0;
5730 graphics_context=XCreateGC(display,window->matte_pixmap,
5731 (unsigned long) (GCBackground | GCForeground),&context_values);
5732 (void) XPutImage(display,window->matte_pixmap,graphics_context,
5733 window->matte_image,0,0,0,0,width,height);
5734 (void) XFreeGC(display,graphics_context);
5735 #if defined(MAGICKCORE_HAVE_SHAPE)
5736 if (window->shape != MagickFalse)
5737 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
5738 window->matte_pixmap,ShapeSet);
5742 (void) XMakePixmap(display,resource_info,window);
5746 (void) XCheckDefineCursor(display,window->id,window->cursor);
5751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5755 + X M a k e I m a g e L S B F i r s t %
5759 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5761 % XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
5762 % pixels are copied in least-significant bit and byte first order. The
5763 % server's scanline pad is respected. Rather than using one or two general
5764 % cases, many special cases are found here to help speed up the image
5767 % The format of the XMakeImageLSBFirst method is:
5769 % void XMakeImageLSBFirst(Display *display,XWindows *windows)
5771 % A description of each parameter follows:
5773 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
5775 % o window: Specifies a pointer to a XWindowInfo structure.
5777 % o image: the image.
5779 % o ximage: Specifies a pointer to a XImage structure; returned from
5782 % o matte_image: Specifies a pointer to a XImage structure; returned from
5786 static void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5787 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
5795 register const IndexPacket
5798 register const PixelPacket
5804 register unsigned char
5821 assert(resource_info != (XResourceInfo *) NULL);
5822 assert(window != (XWindowInfo *) NULL);
5823 assert(image != (Image *) NULL);
5824 if (image->debug != MagickFalse)
5825 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5827 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
5830 size[MaxTextExtent];
5838 image_info=AcquireImageInfo();
5839 (void) CopyMagickString(image_info->filename,
5840 resource_info->image_info->texture != (char *) NULL ?
5841 resource_info->image_info->texture : "pattern:checkerboard",
5843 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
5845 image_info->size=ConstantString(size);
5846 pattern=ReadImage(image_info,&image->exception);
5847 image_info=DestroyImageInfo(image_info);
5848 if (pattern != (Image *) NULL)
5850 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
5851 if (canvas != (Image *) NULL)
5852 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
5853 pattern=DestroyImage(pattern);
5856 scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
5857 ximage->bits_per_pixel) >> 3));
5858 map_info=window->map_info;
5859 pixels=window->pixel_info->pixels;
5860 q=(unsigned char *) ximage->data;
5862 if (ximage->format == XYBitmap)
5864 register unsigned short
5872 Convert canvas to big-endian bitmap.
5874 background=(unsigned char)
5875 (XPixelIntensity(&window->pixel_info->foreground_color) <
5876 XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
5877 foreground=(unsigned char)
5878 (XPixelIntensity(&window->pixel_info->background_color) <
5879 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5880 polarity=(unsigned short) ((PixelIntensityToQuantum(
5881 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
5882 if (canvas->colors == 2)
5883 polarity=PixelIntensity(&canvas->colormap[0]) <
5884 PixelIntensity(&canvas->colormap[1]);
5885 for (y=0; y < (int) canvas->rows; y++)
5887 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5888 if (p == (const PixelPacket *) NULL)
5890 indexes=GetVirtualIndexQueue(canvas);
5893 for (x=0; x < (int) canvas->columns; x++)
5896 if (indexes[x] == (IndexPacket) polarity)
5914 if (window->pixel_info->colors != 0)
5915 switch (ximage->bits_per_pixel)
5919 register unsigned int
5923 Convert to 2 bit color-mapped X canvas.
5925 for (y=0; y < (int) canvas->rows; y++)
5927 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5928 if (p == (const PixelPacket *) NULL)
5930 indexes=GetVirtualIndexQueue(canvas);
5932 for (x=0; x < (int) canvas->columns; x++)
5934 pixel=pixels[(long) indexes[x]] & 0x0f;
5939 *q=(unsigned char) pixel;
5945 *q|=(unsigned char) (pixel << 2);
5951 *q|=(unsigned char) (pixel << 4);
5957 *q|=(unsigned char) (pixel << 6);
5970 register unsigned int
5974 Convert to 4 bit color-mapped X canvas.
5976 for (y=0; y < (int) canvas->rows; y++)
5978 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
5979 if (p == (const PixelPacket *) NULL)
5981 indexes=GetVirtualIndexQueue(canvas);
5983 for (x=0; x < (int) canvas->columns; x++)
5985 pixel=pixels[(long) indexes[x]] & 0xf;
5990 *q=(unsigned char) pixel;
5996 *q|=(unsigned char) (pixel << 4);
6011 Convert to 8 bit color-mapped X canvas.
6013 if (resource_info->color_recovery &&
6014 resource_info->quantize_info->dither)
6016 XDitherImage(canvas,ximage);
6019 for (y=0; y < (int) canvas->rows; y++)
6021 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6022 if (p == (const PixelPacket *) NULL)
6024 indexes=GetVirtualIndexQueue(canvas);
6025 for (x=0; x < (int) canvas->columns; x++)
6027 pixel=pixels[(long) indexes[x]];
6028 *q++=(unsigned char) pixel;
6039 register unsigned int
6043 channel[sizeof(unsigned long)];
6046 Convert to multi-byte color-mapped X canvas.
6048 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6049 for (y=0; y < (int) canvas->rows; y++)
6051 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6052 if (p == (const PixelPacket *) NULL)
6054 indexes=GetVirtualIndexQueue(canvas);
6055 for (x=0; x < (int) canvas->columns; x++)
6057 pixel=pixels[(long) indexes[x]];
6058 for (k=0; k < (int) bytes_per_pixel; k++)
6060 channel[k]=(unsigned char) pixel;
6063 for (k=0; k < (int) bytes_per_pixel; k++)
6072 switch (ximage->bits_per_pixel)
6076 register unsigned int
6080 Convert to contiguous 2 bit continuous-tone X canvas.
6082 for (y=0; y < (int) canvas->rows; y++)
6085 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6086 if (p == (const PixelPacket *) NULL)
6088 for (x=0; x < (int) canvas->columns; x++)
6090 pixel=XGammaPixel(map_info,p);
6096 *q=(unsigned char) pixel;
6102 *q|=(unsigned char) (pixel << 2);
6108 *q|=(unsigned char) (pixel << 4);
6114 *q|=(unsigned char) (pixel << 6);
6128 register unsigned int
6132 Convert to contiguous 4 bit continuous-tone X canvas.
6134 for (y=0; y < (int) canvas->rows; y++)
6136 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6137 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 << 4);
6170 Convert to contiguous 8 bit continuous-tone X canvas.
6172 if (resource_info->color_recovery &&
6173 resource_info->quantize_info->dither)
6175 XDitherImage(canvas,ximage);
6178 for (y=0; y < (int) canvas->rows; y++)
6180 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6181 if (p == (const PixelPacket *) NULL)
6183 for (x=0; x < (int) canvas->columns; x++)
6185 pixel=XGammaPixel(map_info,p);
6186 *q++=(unsigned char) pixel;
6195 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6196 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6197 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6198 (map_info->blue_mult == 1))
6201 Convert to 32 bit continuous-tone X canvas.
6203 for (y=0; y < (int) canvas->rows; y++)
6205 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6206 &canvas->exception);
6207 if (p == (const PixelPacket *) NULL)
6209 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6210 (blue_gamma != 1.0))
6213 Gamma correct canvas.
6215 for (x=(int) canvas->columns-1; x >= 0; x--)
6217 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6218 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6219 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6225 for (x=(int) canvas->columns-1; x >= 0; x--)
6227 *q++=ScaleQuantumToChar((Quantum) p->blue);
6228 *q++=ScaleQuantumToChar((Quantum) p->green);
6229 *q++=ScaleQuantumToChar((Quantum) p->red);
6236 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6237 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6238 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6239 (map_info->blue_mult == 65536L))
6242 Convert to 32 bit continuous-tone X canvas.
6244 for (y=0; y < (int) canvas->rows; y++)
6246 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6247 &canvas->exception);
6248 if (p == (const PixelPacket *) NULL)
6250 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6251 (blue_gamma != 1.0))
6254 Gamma correct canvas.
6256 for (x=(int) canvas->columns-1; x >= 0; x--)
6258 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6259 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6260 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6266 for (x=(int) canvas->columns-1; x >= 0; x--)
6268 *q++=ScaleQuantumToChar((Quantum) p->red);
6269 *q++=ScaleQuantumToChar((Quantum) p->green);
6270 *q++=ScaleQuantumToChar((Quantum) p->blue);
6281 register unsigned int
6285 channel[sizeof(unsigned long)];
6288 Convert to multi-byte continuous-tone X canvas.
6290 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6291 for (y=0; y < (int) canvas->rows; y++)
6293 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6294 &canvas->exception);
6295 if (p == (PixelPacket *) NULL)
6297 for (x=0; x < (long) canvas->columns; x++)
6299 pixel=XGammaPixel(map_info,p);
6300 for (k=0; k < (int) bytes_per_pixel; k++)
6302 channel[k]=(unsigned char) pixel;
6305 for (k=0; k < (int) bytes_per_pixel; k++)
6315 if (matte_image != (XImage *) NULL)
6318 Initialize matte canvas.
6320 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6321 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6322 q=(unsigned char *) matte_image->data;
6323 for (y=0; y < (int) canvas->rows; y++)
6325 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6326 if (p == (const PixelPacket *) NULL)
6330 for (x=(int) canvas->columns-1; x >= 0; x--)
6333 if (p->opacity > (long) (QuantumRange/2))
6349 if (canvas != image)
6350 canvas=DestroyImage(canvas);
6354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6358 + X M a k e I m a g e M S B F i r s t %
6362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6364 % XMakeImageMSBFirst() initializes the pixel data of an X11 Image. The X
6365 % image pixels are copied in most-significant bit and byte first order. The
6366 % server's scanline pad is also respected. Rather than using one or two
6367 % general cases, many special cases are found here to help speed up the image
6370 % The format of the XMakeImageMSBFirst method is:
6372 % XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image)
6374 % A description of each parameter follows:
6376 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
6378 % o window: Specifies a pointer to a XWindowInfo structure.
6380 % o image: the image.
6382 % o ximage: Specifies a pointer to a XImage structure; returned from
6385 % o matte_image: Specifies a pointer to a XImage structure; returned from
6390 static void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6391 const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image)
6402 register const IndexPacket
6405 register const PixelPacket
6408 register unsigned char
6425 assert(resource_info != (XResourceInfo *) NULL);
6426 assert(window != (XWindowInfo *) NULL);
6427 assert(image != (Image *) NULL);
6428 if (image->debug != MagickFalse)
6429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
6431 if ((image->storage_class == DirectClass) && (image->matte != MagickFalse))
6434 size[MaxTextExtent];
6442 image_info=AcquireImageInfo();
6443 (void) CopyMagickString(image_info->filename,
6444 resource_info->image_info->texture != (char *) NULL ?
6445 resource_info->image_info->texture : "pattern:checkerboard",
6447 (void) FormatMagickString(size,MaxTextExtent,"%lux%lu",image->columns,
6449 image_info->size=ConstantString(size);
6450 pattern=ReadImage(image_info,&image->exception);
6451 image_info=DestroyImageInfo(image_info);
6452 if (pattern != (Image *) NULL)
6454 canvas=CloneImage(image,0,0,MagickTrue,&image->exception);
6455 if (canvas != (Image *) NULL)
6456 (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0);
6457 pattern=DestroyImage(pattern);
6460 scanline_pad=(unsigned int) (ximage->bytes_per_line-
6461 ((ximage->width*ximage->bits_per_pixel) >> 3));
6462 map_info=window->map_info;
6463 pixels=window->pixel_info->pixels;
6464 q=(unsigned char *) ximage->data;
6466 if (ximage->format == XYBitmap)
6468 register unsigned short
6476 Convert canvas to big-endian bitmap.
6478 background=(unsigned char)
6479 (XPixelIntensity(&window->pixel_info->foreground_color) <
6480 XPixelIntensity(&window->pixel_info->background_color) ? 0x01 : 0x00);
6481 foreground=(unsigned char)
6482 (XPixelIntensity(&window->pixel_info->background_color) <
6483 XPixelIntensity(&window->pixel_info->foreground_color) ? 0x01 : 0x00);
6484 polarity=(unsigned short) ((PixelIntensityToQuantum(
6485 &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
6486 if (canvas->colors == 2)
6487 polarity=PixelIntensity(&canvas->colormap[0]) <
6488 PixelIntensity(&canvas->colormap[1]);
6489 for (y=0; y < (int) canvas->rows; y++)
6491 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6492 if (p == (const PixelPacket *) NULL)
6494 indexes=GetVirtualIndexQueue(canvas);
6497 for (x=(int) canvas->columns-1; x >= 0; x--)
6500 if (indexes[x] == (IndexPacket) polarity)
6518 if (window->pixel_info->colors != 0)
6519 switch (ximage->bits_per_pixel)
6523 register unsigned int
6527 Convert to 2 bit color-mapped X canvas.
6529 for (y=0; y < (int) canvas->rows; y++)
6531 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6532 if (p == (const PixelPacket *) NULL)
6534 indexes=GetVirtualIndexQueue(canvas);
6536 for (x=0; x < (int) canvas->columns; x++)
6538 pixel=pixels[(long) indexes[x]] & 0xf;
6543 *q=(unsigned char) (pixel << 6);
6549 *q|=(unsigned char) (pixel << 4);
6555 *q|=(unsigned char) (pixel << 2);
6561 *q|=(unsigned char) pixel;
6574 register unsigned int
6578 Convert to 4 bit color-mapped X canvas.
6580 for (y=0; y < (int) canvas->rows; y++)
6582 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6583 if (p == (const PixelPacket *) NULL)
6585 indexes=GetVirtualIndexQueue(canvas);
6587 for (x=0; x < (int) canvas->columns; x++)
6589 pixel=pixels[(long) indexes[x]] & 0xf;
6594 *q=(unsigned char) (pixel << 4);
6600 *q|=(unsigned char) pixel;
6615 Convert to 8 bit color-mapped X canvas.
6617 if (resource_info->color_recovery &&
6618 resource_info->quantize_info->dither)
6620 XDitherImage(canvas,ximage);
6623 for (y=0; y < (int) canvas->rows; y++)
6625 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6626 if (p == (const PixelPacket *) NULL)
6628 indexes=GetVirtualIndexQueue(canvas);
6629 for (x=0; x < (int) canvas->columns; x++)
6631 pixel=pixels[(long) indexes[x]];
6632 *q++=(unsigned char) pixel;
6643 register unsigned int
6647 channel[sizeof(unsigned long)];
6650 Convert to 8 bit color-mapped X canvas.
6652 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6653 for (y=0; y < (int) canvas->rows; y++)
6655 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6656 if (p == (const PixelPacket *) NULL)
6658 indexes=GetVirtualIndexQueue(canvas);
6659 for (x=0; x < (int) canvas->columns; x++)
6661 pixel=pixels[(long) indexes[x]];
6662 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6664 channel[k]=(unsigned char) pixel;
6667 for (k=0; k < (int) bytes_per_pixel; k++)
6676 switch (ximage->bits_per_pixel)
6680 register unsigned int
6684 Convert to 4 bit continuous-tone X canvas.
6686 for (y=0; y < (int) canvas->rows; y++)
6688 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6689 if (p == (const PixelPacket *) NULL)
6692 for (x=(int) canvas->columns-1; x >= 0; x--)
6694 pixel=XGammaPixel(map_info,p);
6700 *q=(unsigned char) (pixel << 6);
6706 *q|=(unsigned char) (pixel << 4);
6712 *q|=(unsigned char) (pixel << 2);
6718 *q|=(unsigned char) pixel;
6732 register unsigned int
6736 Convert to 4 bit continuous-tone X canvas.
6738 for (y=0; y < (int) canvas->rows; y++)
6740 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6741 if (p == (const PixelPacket *) NULL)
6744 for (x=(int) canvas->columns-1; x >= 0; x--)
6746 pixel=XGammaPixel(map_info,p);
6752 *q=(unsigned char) (pixel << 4);
6758 *q|=(unsigned char) pixel;
6774 Convert to 8 bit continuous-tone X canvas.
6776 if (resource_info->color_recovery &&
6777 resource_info->quantize_info->dither)
6779 XDitherImage(canvas,ximage);
6782 for (y=0; y < (int) canvas->rows; y++)
6784 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6785 if (p == (const PixelPacket *) NULL)
6787 for (x=(int) canvas->columns-1; x >= 0; x--)
6789 pixel=XGammaPixel(map_info,p);
6790 *q++=(unsigned char) pixel;
6799 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6800 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6801 (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
6802 (map_info->blue_mult == 1))
6805 Convert to 32 bit continuous-tone X canvas.
6807 for (y=0; y < (int) canvas->rows; y++)
6809 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6810 &canvas->exception);
6811 if (p == (const PixelPacket *) NULL)
6813 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6814 (blue_gamma != 1.0))
6817 Gamma correct canvas.
6819 for (x=(int) canvas->columns-1; x >= 0; x--)
6822 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6823 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6824 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6829 for (x=(int) canvas->columns-1; x >= 0; x--)
6832 *q++=ScaleQuantumToChar((Quantum) p->red);
6833 *q++=ScaleQuantumToChar((Quantum) p->green);
6834 *q++=ScaleQuantumToChar((Quantum) p->blue);
6840 if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
6841 (map_info->green_max == 255) && (map_info->blue_max == 255) &&
6842 (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
6843 (map_info->blue_mult == 65536L))
6846 Convert to 32 bit continuous-tone X canvas.
6848 for (y=0; y < (int) canvas->rows; y++)
6850 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6851 &canvas->exception);
6852 if (p == (const PixelPacket *) NULL)
6854 if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
6855 (blue_gamma != 1.0))
6858 Gamma correct canvas.
6860 for (x=(int) canvas->columns-1; x >= 0; x--)
6863 *q++=ScaleQuantumToChar(XBlueGamma(p->blue));
6864 *q++=ScaleQuantumToChar(XGreenGamma(p->green));
6865 *q++=ScaleQuantumToChar(XRedGamma(p->red));
6870 for (x=(int) canvas->columns-1; x >= 0; x--)
6873 *q++=ScaleQuantumToChar((Quantum) p->blue);
6874 *q++=ScaleQuantumToChar((Quantum) p->green);
6875 *q++=ScaleQuantumToChar((Quantum) p->red);
6885 register unsigned int
6889 channel[sizeof(unsigned long)];
6892 Convert to multi-byte continuous-tone X canvas.
6894 bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
6895 for (y=0; y < (int) canvas->rows; y++)
6897 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,
6898 &canvas->exception);
6899 if (p == (const PixelPacket *) NULL)
6901 for (x=(int) canvas->columns-1; x >= 0; x--)
6903 pixel=XGammaPixel(map_info,p);
6904 for (k=(int) bytes_per_pixel-1; k >= 0; k--)
6906 channel[k]=(unsigned char) pixel;
6909 for (k=0; k < (int) bytes_per_pixel; k++)
6919 if (matte_image != (XImage *) NULL)
6922 Initialize matte canvas.
6924 scanline_pad=(unsigned int) (matte_image->bytes_per_line-
6925 ((matte_image->width*matte_image->bits_per_pixel) >> 3));
6926 q=(unsigned char *) matte_image->data;
6927 for (y=0; y < (int) canvas->rows; y++)
6929 p=GetVirtualPixels(canvas,0,y,canvas->columns,1,&canvas->exception);
6930 if (p == (const PixelPacket *) NULL)
6934 for (x=(int) canvas->columns-1; x >= 0; x--)
6937 if (p->opacity > (long) (QuantumRange/2))
6953 if (canvas != image)
6954 canvas=DestroyImage(canvas);
6958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6962 % X M a k e M a g n i f y I m a g e %
6966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6968 % XMakeMagnifyImage() magnifies a region of an X image and displays it.
6970 % The format of the XMakeMagnifyImage method is:
6972 % void XMakeMagnifyImage(display,windows)
6974 % A description of each parameter follows:
6976 % o display: Specifies a connection to an X server; returned from
6979 % o windows: Specifies a pointer to a XWindows structure.
6982 MagickExport void XMakeMagnifyImage(Display *display,XWindows *windows)
6985 tuple[MaxTextExtent];
7002 register unsigned char
7007 previous_magnify = 0;
7025 Check boundary conditions.
7027 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7028 assert(display != (Display *) NULL);
7029 assert(windows != (XWindows *) NULL);
7031 for (n=1; n < (long) windows->magnify.data; n++)
7033 while ((magnify*windows->image.ximage->width) < windows->magnify.width)
7035 while ((magnify*windows->image.ximage->height) < windows->magnify.height)
7037 while (magnify > windows->magnify.width)
7039 while (magnify > windows->magnify.height)
7041 if (magnify != previous_magnify)
7050 New magnify factor: update magnify window name.
7053 while ((1 << i) <= (int) magnify)
7055 (void) FormatMagickString(windows->magnify.name,MaxTextExtent,
7057 status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
7058 if (status != False)
7060 XSetWMName(display,windows->magnify.id,&window_name);
7061 XSetWMIconName(display,windows->magnify.id,&window_name);
7062 (void) XFree((void *) window_name.value);
7065 previous_magnify=magnify;
7066 ximage=windows->image.ximage;
7067 width=(unsigned int) windows->magnify.ximage->width;
7068 height=(unsigned int) windows->magnify.ximage->height;
7069 if ((windows->magnify.x < 0) ||
7070 (windows->magnify.x >= windows->image.ximage->width))
7071 windows->magnify.x=windows->image.ximage->width >> 1;
7072 x=windows->magnify.x-((width/magnify) >> 1);
7076 if (x > (int) (ximage->width-(width/magnify)))
7077 x=ximage->width-width/magnify;
7078 if ((windows->magnify.y < 0) ||
7079 (windows->magnify.y >= windows->image.ximage->height))
7080 windows->magnify.y=windows->image.ximage->height >> 1;
7081 y=windows->magnify.y-((height/magnify) >> 1);
7085 if (y > (int) (ximage->height-(height/magnify)))
7086 y=ximage->height-height/magnify;
7087 q=(unsigned char *) windows->magnify.ximage->data;
7088 scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
7089 ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
7090 if (ximage->bits_per_pixel < 8)
7092 register unsigned char
7099 register unsigned int
7105 pixel_info=windows->magnify.pixel_info;
7106 switch (ximage->bitmap_bit_order)
7111 Magnify little-endian bitmap.
7115 if (ximage->format == XYBitmap)
7117 background=(unsigned char)
7118 (XPixelIntensity(&pixel_info->foreground_color) <
7119 XPixelIntensity(&pixel_info->background_color) ? 0x80 : 0x00);
7120 foreground=(unsigned char)
7121 (XPixelIntensity(&pixel_info->background_color) <
7122 XPixelIntensity(&pixel_info->foreground_color) ? 0x80 : 0x00);
7123 if (windows->magnify.depth > 1)
7124 Swap(background,foreground);
7126 for (i=0; i < (long) height; i+=magnify)
7129 Propogate pixel magnify rows.
7131 for (j=0; j < magnify; j++)
7133 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7134 ((x*ximage->bits_per_pixel) >> 3);
7135 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7138 for (k=0; k < width; k+=magnify)
7141 Propogate pixel magnify columns.
7143 for (l=0; l < magnify; l++)
7146 Propogate each bit plane.
7148 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7151 if (*p & (0x01 << (p_bit+plane)))
7164 p_bit+=ximage->bits_per_pixel;
7171 *q=byte >> (8-q_bit);
7183 Magnify big-endian bitmap.
7187 if (ximage->format == XYBitmap)
7189 background=(unsigned char)
7190 (XPixelIntensity(&pixel_info->foreground_color) <
7191 XPixelIntensity(&pixel_info->background_color) ? 0x01 : 0x00);
7192 foreground=(unsigned char)
7193 (XPixelIntensity(&pixel_info->background_color) <
7194 XPixelIntensity(&pixel_info->foreground_color) ? 0x01 : 0x00);
7195 if (windows->magnify.depth > 1)
7196 Swap(background,foreground);
7198 for (i=0; i < (long) height; i+=magnify)
7201 Propogate pixel magnify rows.
7203 for (j=0; j < magnify; j++)
7205 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7206 ((x*ximage->bits_per_pixel) >> 3);
7207 p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
7210 for (k=0; k < width; k+=magnify)
7213 Propogate pixel magnify columns.
7215 for (l=0; l < magnify; l++)
7218 Propogate each bit plane.
7220 for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
7223 if (*p & (0x80 >> (p_bit+plane)))
7236 p_bit+=ximage->bits_per_pixel;
7243 *q=byte << (8-q_bit);
7254 switch (ximage->bits_per_pixel)
7260 Magnify 8 bit X image.
7262 for (i=0; i < (long) height; i+=magnify)
7265 Propogate pixel magnify rows.
7267 for (j=0; j < magnify; j++)
7269 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7270 ((x*ximage->bits_per_pixel) >> 3);
7271 for (k=0; k < width; k+=magnify)
7274 Propogate pixel magnify columns.
7276 for (l=0; l < magnify; l++)
7288 register unsigned int
7293 Magnify multi-byte X image.
7295 bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7296 for (i=0; i < (long) height; i+=magnify)
7299 Propogate pixel magnify rows.
7301 for (j=0; j < magnify; j++)
7303 p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
7304 ((x*ximage->bits_per_pixel) >> 3);
7305 for (k=0; k < width; k+=magnify)
7308 Propogate pixel magnify columns.
7310 for (l=0; l < magnify; l++)
7311 for (m=0; m < bytes_per_pixel; m++)
7323 Copy X image to magnify pixmap.
7325 x=windows->magnify.x-((width/magnify) >> 1);
7327 x=(int) ((width >> 1)-windows->magnify.x*magnify);
7329 if (x > (int) (ximage->width-(width/magnify)))
7330 x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
7333 y=windows->magnify.y-((height/magnify) >> 1);
7335 y=(int) ((height >> 1)-windows->magnify.y*magnify);
7337 if (y > (int) (ximage->height-(height/magnify)))
7338 y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
7341 if ((x != 0) || (y != 0))
7342 (void) XFillRectangle(display,windows->magnify.pixmap,
7343 windows->magnify.annotate_context,0,0,width,height);
7344 (void) XPutImage(display,windows->magnify.pixmap,
7345 windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
7347 if ((magnify > 1) && ((magnify <= (width >> 1)) &&
7348 (magnify <= (height >> 1))))
7354 Highlight center pixel.
7356 highlight_info.x=(long) windows->magnify.width >> 1;
7357 highlight_info.y=(long) windows->magnify.height >> 1;
7358 highlight_info.width=magnify;
7359 highlight_info.height=magnify;
7360 (void) XDrawRectangle(display,windows->magnify.pixmap,
7361 windows->magnify.highlight_context,(int) highlight_info.x,
7362 (int) highlight_info.y,(unsigned int) highlight_info.width-1,
7363 (unsigned int) highlight_info.height-1);
7365 (void) XDrawRectangle(display,windows->magnify.pixmap,
7366 windows->magnify.annotate_context,(int) highlight_info.x+1,
7367 (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
7368 (unsigned int) highlight_info.height-3);
7371 Show center pixel color.
7373 (void) GetOneVirtualMagickPixel(windows->image.image,windows->magnify.x,
7374 windows->magnify.y,&pixel,&windows->image.image->exception);
7375 (void) FormatMagickString(tuple,MaxTextExtent,"%d,%d: ",
7376 windows->magnify.x,windows->magnify.y);
7377 (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7378 ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
7379 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7380 ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
7381 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7382 ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
7383 if (pixel.colorspace == CMYKColorspace)
7385 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7386 ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
7388 if (pixel.matte != MagickFalse)
7390 (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7391 ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
7393 (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
7394 height=(unsigned int) windows->magnify.font_info->ascent+
7395 windows->magnify.font_info->descent;
7396 x=windows->magnify.font_info->max_bounds.width >> 1;
7397 y=windows->magnify.font_info->ascent+(height >> 2);
7398 (void) XDrawImageString(display,windows->magnify.pixmap,
7399 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7400 GetColorTuple(&pixel,MagickTrue,tuple);
7402 (void) XDrawImageString(display,windows->magnify.pixmap,
7403 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7404 (void) QueryMagickColorname(windows->image.image,&pixel,SVGCompliance,tuple,
7405 &windows->image.image->exception);
7407 (void) XDrawImageString(display,windows->magnify.pixmap,
7408 windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7410 Refresh magnify window.
7412 magnify_window=windows->magnify;
7415 XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
7419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7423 % X M a k e P i x m a p %
7427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7429 % XMakePixmap() creates an X11 pixmap.
7431 % The format of the XMakePixmap method is:
7433 % void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
7434 % XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
7435 % XPixelInfo *pixel)
7437 % A description of each parameter follows:
7439 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7441 % o display: Specifies a connection to an X server; returned from
7444 % o window: Specifies a pointer to a XWindowInfo structure.
7448 static MagickBooleanType XMakePixmap(Display *display,
7449 const XResourceInfo *resource_info,XWindowInfo *window)
7455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7456 assert(display != (Display *) NULL);
7457 assert(resource_info != (XResourceInfo *) NULL);
7458 assert(window != (XWindowInfo *) NULL);
7459 if (window->pixmap != (Pixmap) NULL)
7462 Destroy previous X pixmap.
7464 (void) XFreePixmap(display,window->pixmap);
7465 window->pixmap=(Pixmap) NULL;
7467 if (window->use_pixmap == MagickFalse)
7468 return(MagickFalse);
7469 if (window->ximage == (XImage *) NULL)
7470 return(MagickFalse);
7472 Display busy cursor.
7474 (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
7475 (void) XFlush(display);
7479 width=(unsigned int) window->ximage->width;
7480 height=(unsigned int) window->ximage->height;
7481 window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
7482 if (window->pixmap == (Pixmap) NULL)
7485 Unable to allocate pixmap.
7487 (void) XCheckDefineCursor(display,window->id,window->cursor);
7488 return(MagickFalse);
7491 Copy X image to pixmap.
7493 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
7494 if (window->shared_memory)
7495 (void) XShmPutImage(display,window->pixmap,window->annotate_context,
7496 window->ximage,0,0,0,0,width,height,MagickTrue);
7498 if (window->shared_memory == MagickFalse)
7499 (void) XPutImage(display,window->pixmap,window->annotate_context,
7500 window->ximage,0,0,0,0,width,height);
7501 if (IsEventLogging())
7503 (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
7504 (void) LogMagickEvent(X11Event,GetMagickModule()," width, height: %ux%u",
7510 (void) XCheckDefineCursor(display,window->id,window->cursor);
7515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7519 % X M a k e S t a n d a r d C o l o r m a p %
7523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7525 % XMakeStandardColormap() creates an X11 Standard Colormap.
7527 % The format of the XMakeStandardColormap method is:
7529 % XMakeStandardColormap(display,visual_info,resource_info,image,
7532 % A description of each parameter follows:
7534 % o display: Specifies a connection to an X server; returned from
7537 % o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
7538 % returned from XGetVisualInfo.
7540 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7542 % o image: the image.
7544 % o map_info: If a Standard Colormap type is specified, this structure is
7545 % initialized with info from the Standard Colormap.
7547 % o pixel: Specifies a pointer to a XPixelInfo structure.
7552 #if defined(__cplusplus) || defined(c_plusplus)
7556 static inline MagickRealType DiversityPixelIntensity(
7557 const DiversityPacket *pixel)
7562 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
7566 static int IntensityCompare(const void *x,const void *y)
7575 color_1=(DiversityPacket *) x;
7576 color_2=(DiversityPacket *) y;
7577 diversity=(int) (DiversityPixelIntensity(color_2)-
7578 DiversityPixelIntensity(color_1));
7582 static int PopularityCompare(const void *x,const void *y)
7588 color_1=(DiversityPacket *) x;
7589 color_2=(DiversityPacket *) y;
7590 return((int) color_2->count-(int) color_1->count);
7593 #if defined(__cplusplus) || defined(c_plusplus)
7597 static inline Quantum ScaleXToQuantum(const unsigned long x,
7598 const unsigned long scale)
7600 return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
7603 MagickExport void XMakeStandardColormap(Display *display,
7604 XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
7605 XStandardColormap *map_info,XPixelInfo *pixel)
7613 register IndexPacket
7634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
7635 assert(display != (Display *) NULL);
7636 assert(visual_info != (XVisualInfo *) NULL);
7637 assert(map_info != (XStandardColormap *) NULL);
7638 assert(resource_info != (XResourceInfo *) NULL);
7639 assert(pixel != (XPixelInfo *) NULL);
7640 exception=(&image->exception);
7641 if (resource_info->map_type != (char *) NULL)
7644 Standard Colormap is already defined (i.e. xstdcmap).
7646 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7648 number_colors=(unsigned int) (map_info->base_pixel+
7649 (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
7650 if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
7651 if ((image->matte == MagickFalse) &&
7652 (resource_info->color_recovery == MagickFalse) &&
7653 resource_info->quantize_info->dither &&
7654 (number_colors < MaxColormapSize))
7659 register PixelPacket
7663 Improve image appearance with error diffusion.
7665 affinity_image=AcquireImage((ImageInfo *) NULL);
7666 if (affinity_image == (Image *) NULL)
7667 ThrowXWindowFatalException(ResourceLimitFatalError,
7668 "UnableToDitherImage",image->filename);
7669 affinity_image->columns=number_colors;
7670 affinity_image->rows=1;
7672 Initialize colormap image.
7674 q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
7676 if (q != (PixelPacket *) NULL)
7678 for (i=0; i < (long) number_colors; i++)
7681 if (map_info->red_max != 0)
7682 q->red=ScaleXToQuantum((unsigned long) (i/
7683 map_info->red_mult),map_info->red_max);
7684 q->green=(Quantum) 0;
7685 if (map_info->green_max != 0)
7686 q->green=ScaleXToQuantum((unsigned long) ((i/
7687 map_info->green_mult) % (map_info->green_max+1)),
7688 map_info->green_max);
7689 q->blue=(Quantum) 0;
7690 if (map_info->blue_max != 0)
7691 q->blue=ScaleXToQuantum((unsigned long) (i %
7692 map_info->green_mult),map_info->blue_max);
7693 q->opacity=(Quantum) TransparentOpacity;
7696 (void) SyncAuthenticPixels(affinity_image,exception);
7697 (void) RemapImage(resource_info->quantize_info,image,
7700 XGetPixelPacket(display,visual_info,map_info,resource_info,image,
7702 (void) SetImageStorageClass(image,DirectClass);
7703 affinity_image=DestroyImage(affinity_image);
7705 if (IsEventLogging())
7707 (void) LogMagickEvent(X11Event,GetMagickModule(),
7708 "Standard Colormap:");
7709 (void) LogMagickEvent(X11Event,GetMagickModule(),
7710 " colormap id: 0x%lx",map_info->colormap);
7711 (void) LogMagickEvent(X11Event,GetMagickModule(),
7712 " red, green, blue max: %lu %lu %lu",map_info->red_max,
7713 map_info->green_max,map_info->blue_max);
7714 (void) LogMagickEvent(X11Event,GetMagickModule(),
7715 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
7716 map_info->green_mult,map_info->blue_mult);
7720 if ((visual_info->klass != DirectColor) &&
7721 (visual_info->klass != TrueColor))
7722 if ((image->storage_class == DirectClass) ||
7723 ((int) image->colors > visual_info->colormap_size))
7729 Image has more colors than the visual supports.
7731 quantize_info=(*resource_info->quantize_info);
7732 quantize_info.number_colors=(unsigned long) visual_info->colormap_size;
7733 (void) QuantizeImage(&quantize_info,image);
7736 Free previous and create new colormap.
7738 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
7739 colormap=XDefaultColormap(display,visual_info->screen);
7740 if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
7741 colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
7742 visual_info->visual,visual_info->klass == DirectColor ?
7743 AllocAll : AllocNone);
7744 if (colormap == (Colormap) NULL)
7745 ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
7748 Initialize the map and pixel info structures.
7750 XGetMapInfo(visual_info,colormap,map_info);
7751 XGetPixelPacket(display,visual_info,map_info,resource_info,image,pixel);
7753 Allocating colors in server colormap is based on visual class.
7755 switch (visual_info->klass)
7761 Define Standard Colormap for StaticGray or StaticColor visual.
7763 number_colors=image->colors;
7764 colors=(XColor *) AcquireQuantumMemory((size_t)
7765 visual_info->colormap_size,sizeof(*colors));
7766 if (colors == (XColor *) NULL)
7767 ThrowXWindowFatalException(ResourceLimitFatalError,
7768 "UnableToCreateColormap",image->filename);
7770 color.flags=(char) (DoRed | DoGreen | DoBlue);
7771 for (i=0; i < (long) image->colors; i++)
7773 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
7774 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
7775 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
7776 if (visual_info->klass != StaticColor)
7778 gray_value=(unsigned short) XPixelIntensity(&color);
7779 color.red=gray_value;
7780 color.green=gray_value;
7781 color.blue=gray_value;
7783 status=XAllocColor(display,colormap,&color);
7784 if (status == False)
7786 colormap=XCopyColormapAndFree(display,colormap);
7787 (void) XAllocColor(display,colormap,&color);
7789 pixel->pixels[i]=color.pixel;
7801 Define Standard Colormap for GrayScale or PseudoColor visual.
7803 number_colors=image->colors;
7804 colors=(XColor *) AcquireQuantumMemory((size_t)
7805 visual_info->colormap_size,sizeof(*colors));
7806 if (colors == (XColor *) NULL)
7807 ThrowXWindowFatalException(ResourceLimitFatalError,
7808 "UnableToCreateColormap",image->filename);
7810 Preallocate our GUI colors.
7812 (void) XAllocColor(display,colormap,&pixel->foreground_color);
7813 (void) XAllocColor(display,colormap,&pixel->background_color);
7814 (void) XAllocColor(display,colormap,&pixel->border_color);
7815 (void) XAllocColor(display,colormap,&pixel->matte_color);
7816 (void) XAllocColor(display,colormap,&pixel->highlight_color);
7817 (void) XAllocColor(display,colormap,&pixel->shadow_color);
7818 (void) XAllocColor(display,colormap,&pixel->depth_color);
7819 (void) XAllocColor(display,colormap,&pixel->trough_color);
7820 for (i=0; i < MaxNumberPens; i++)
7821 (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
7823 Determine if image colors will "fit" into X server colormap.
7825 colormap_type=resource_info->colormap;
7826 status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
7827 NULL,0,pixel->pixels,(unsigned int) image->colors);
7828 if (status != False)
7829 colormap_type=PrivateColormap;
7830 if (colormap_type == SharedColormap)
7848 Define Standard colormap for shared GrayScale or PseudoColor visual.
7850 diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
7851 sizeof(*diversity));
7852 if (diversity == (DiversityPacket *) NULL)
7853 ThrowXWindowFatalException(ResourceLimitFatalError,
7854 "UnableToCreateColormap",image->filename);
7855 for (i=0; i < (long) image->colors; i++)
7857 diversity[i].red=image->colormap[i].red;
7858 diversity[i].green=image->colormap[i].green;
7859 diversity[i].blue=image->colormap[i].blue;
7860 diversity[i].index=(unsigned short) i;
7861 diversity[i].count=0;
7863 for (y=0; y < (int) image->rows; y++)
7868 register PixelPacket
7871 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
7872 if (q == (PixelPacket *) NULL)
7874 indexes=GetAuthenticIndexQueue(image);
7875 for (x=(long) image->columns-1; x >= 0; x--)
7876 diversity[(long) indexes[x]].count++;
7879 Sort colors by decreasing intensity.
7881 qsort((void *) diversity,image->colors,sizeof(*diversity),
7883 for (i=0; i < (long) image->colors; )
7885 diversity[i].count<<=4; /* increase this colors popularity */
7886 i+=MagickMax((long) (image->colors >> 4),2);
7888 diversity[image->colors-1].count<<=4;
7889 qsort((void *) diversity,image->colors,sizeof(*diversity),
7895 color.flags=(char) (DoRed | DoGreen | DoBlue);
7896 for (i=0; i < (long) image->colors; i++)
7898 index=diversity[i].index;
7900 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7902 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7904 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7905 if (visual_info->klass != PseudoColor)
7907 gray_value=(unsigned short) XPixelIntensity(&color);
7908 color.red=gray_value;
7909 color.green=gray_value;
7910 color.blue=gray_value;
7912 status=XAllocColor(display,colormap,&color);
7913 if (status == False)
7915 pixel->pixels[index]=color.pixel;
7919 Read X server colormap.
7921 server_colors=(XColor *) AcquireQuantumMemory((size_t)
7922 visual_info->colormap_size,sizeof(*server_colors));
7923 if (server_colors == (XColor *) NULL)
7924 ThrowXWindowFatalException(ResourceLimitFatalError,
7925 "UnableToCreateColormap",image->filename);
7926 for (x=visual_info->colormap_size-1; x >= 0; x--)
7927 server_colors[x].pixel=(unsigned long) x;
7928 (void) XQueryColors(display,colormap,server_colors,
7929 (int) MagickMin((unsigned int) visual_info->colormap_size,256));
7931 Select remaining colors from X server colormap.
7933 for (; i < (long) image->colors; i++)
7935 index=diversity[i].index;
7937 ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
7939 ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
7941 ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
7942 if (visual_info->klass != PseudoColor)
7944 gray_value=(unsigned short) XPixelIntensity(&color);
7945 color.red=gray_value;
7946 color.green=gray_value;
7947 color.blue=gray_value;
7949 XBestPixel(display,colormap,server_colors,(unsigned int)
7950 visual_info->colormap_size,&color);
7951 pixel->pixels[index]=color.pixel;
7954 if ((int) image->colors < visual_info->colormap_size)
7957 Fill up colors array-- more choices for pen colors.
7959 retain_colors=MagickMin((unsigned int)
7960 (visual_info->colormap_size-image->colors),256);
7961 for (i=0; i < (long) retain_colors; i++)
7962 *p++=server_colors[i];
7963 number_colors+=retain_colors;
7965 server_colors=(XColor *) RelinquishMagickMemory(server_colors);
7966 diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
7970 Define Standard colormap for private GrayScale or PseudoColor visual.
7972 if (status == False)
7975 Not enough colormap entries in the colormap-- Create a new colormap.
7977 colormap=XCreateColormap(display,
7978 XRootWindow(display,visual_info->screen),visual_info->visual,
7980 if (colormap == (Colormap) NULL)
7981 ThrowXWindowFatalException(ResourceLimitFatalError,
7982 "UnableToCreateColormap",image->filename);
7983 map_info->colormap=colormap;
7984 if ((int) image->colors < visual_info->colormap_size)
7987 Retain colors from the default colormap to help lessens the
7988 effects of colormap flashing.
7990 retain_colors=MagickMin((unsigned int)
7991 (visual_info->colormap_size-image->colors),256);
7992 p=colors+image->colors;
7993 for (i=0; i < (long) retain_colors; i++)
7995 p->pixel=(unsigned long) i;
7998 (void) XQueryColors(display,
7999 XDefaultColormap(display,visual_info->screen),
8000 colors+image->colors,(int) retain_colors);
8002 Transfer colors from default to private colormap.
8004 (void) XAllocColorCells(display,colormap,MagickFalse,
8005 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8007 p=colors+image->colors;
8008 for (i=0; i < (long) retain_colors; i++)
8010 p->pixel=pixel->pixels[i];
8013 (void) XStoreColors(display,colormap,colors+image->colors,
8014 (int) retain_colors);
8015 number_colors+=retain_colors;
8017 (void) XAllocColorCells(display,colormap,MagickFalse,
8018 (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
8022 Store the image colormap.
8025 color.flags=(char) (DoRed | DoGreen | DoBlue);
8026 for (i=0; i < (long) image->colors; i++)
8028 color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
8029 color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
8030 color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
8031 if (visual_info->klass != PseudoColor)
8033 gray_value=(unsigned short) XPixelIntensity(&color);
8034 color.red=gray_value;
8035 color.green=gray_value;
8036 color.blue=gray_value;
8038 color.pixel=pixel->pixels[i];
8041 (void) XStoreColors(display,colormap,colors,(int) image->colors);
8052 Define Standard Colormap for TrueColor or DirectColor visual.
8054 number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
8055 (map_info->green_max*map_info->green_mult)+
8056 (map_info->blue_max*map_info->blue_mult)+1);
8057 linear_colormap=(number_colors > 4096) ||
8058 (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
8059 ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
8060 ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
8061 MagickTrue : MagickFalse;
8062 if (linear_colormap != MagickFalse)
8063 number_colors=(unsigned long) visual_info->colormap_size;
8065 Allocate color array.
8067 colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
8068 if (colors == (XColor *) NULL)
8069 ThrowXWindowFatalException(ResourceLimitFatalError,
8070 "UnableToCreateColormap",image->filename);
8072 Initialize linear color ramp.
8075 color.flags=(char) (DoRed | DoGreen | DoBlue);
8076 if (linear_colormap != MagickFalse)
8077 for (i=0; i < (long) number_colors; i++)
8079 color.blue=(unsigned short) 0;
8080 if (map_info->blue_max != 0)
8081 color.blue=(unsigned short) ((unsigned long)
8082 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8083 color.green=color.blue;
8084 color.red=color.blue;
8085 color.pixel=XStandardPixel(map_info,&color);
8089 for (i=0; i < (long) number_colors; i++)
8091 color.red=(unsigned short) 0;
8092 if (map_info->red_max != 0)
8093 color.red=(unsigned short) ((unsigned long)
8094 ((65535L*(i/map_info->red_mult))/map_info->red_max));
8095 color.green=(unsigned int) 0;
8096 if (map_info->green_max != 0)
8097 color.green=(unsigned short) ((unsigned long)
8098 ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
8099 map_info->green_max));
8100 color.blue=(unsigned short) 0;
8101 if (map_info->blue_max != 0)
8102 color.blue=(unsigned short) ((unsigned long)
8103 ((65535L*(i % map_info->green_mult))/map_info->blue_max));
8104 color.pixel=XStandardPixel(map_info,&color);
8107 if ((visual_info->klass == DirectColor) &&
8108 (colormap != XDefaultColormap(display,visual_info->screen)))
8109 (void) XStoreColors(display,colormap,colors,(int) number_colors);
8111 for (i=0; i < (long) number_colors; i++)
8112 (void) XAllocColor(display,colormap,&colors[i]);
8116 if ((visual_info->klass != DirectColor) &&
8117 (visual_info->klass != TrueColor))
8120 Set foreground, background, border, etc. pixels.
8122 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8123 &pixel->foreground_color);
8124 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8125 &pixel->background_color);
8126 if (pixel->background_color.pixel == pixel->foreground_color.pixel)
8129 Foreground and background colors must differ.
8131 pixel->background_color.red=(~pixel->foreground_color.red);
8132 pixel->background_color.green=
8133 (~pixel->foreground_color.green);
8134 pixel->background_color.blue=
8135 (~pixel->foreground_color.blue);
8136 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8137 &pixel->background_color);
8139 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8140 &pixel->border_color);
8141 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8142 &pixel->matte_color);
8143 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8144 &pixel->highlight_color);
8145 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8146 &pixel->shadow_color);
8147 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8148 &pixel->depth_color);
8149 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8150 &pixel->trough_color);
8151 for (i=0; i < MaxNumberPens; i++)
8153 XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8154 &pixel->pen_colors[i]);
8155 pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
8157 pixel->colors=image->colors+MaxNumberPens;
8159 colors=(XColor *) RelinquishMagickMemory(colors);
8160 if (IsEventLogging())
8162 (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
8163 (void) LogMagickEvent(X11Event,GetMagickModule()," colormap id: 0x%lx",
8164 map_info->colormap);
8165 (void) LogMagickEvent(X11Event,GetMagickModule(),
8166 " red, green, blue max: %lu %lu %lu",map_info->red_max,
8167 map_info->green_max,map_info->blue_max);
8168 (void) LogMagickEvent(X11Event,GetMagickModule(),
8169 " red, green, blue mult: %lu %lu %lu",map_info->red_mult,
8170 map_info->green_mult,map_info->blue_mult);
8175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8179 % X M a k e W i n d o w %
8183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8185 % XMakeWindow() creates an X11 window.
8187 % The format of the XMakeWindow method is:
8189 % void XMakeWindow(Display *display,Window parent,char **argv,int argc,
8190 % XClassHint *class_hint,XWMHints *manager_hints,
8191 % XWindowInfo *window_info)
8193 % A description of each parameter follows:
8195 % o display: Specifies a connection to an X server; returned from
8198 % o parent: Specifies the parent window_info.
8200 % o argv: Specifies the application's argument list.
8202 % o argc: Specifies the number of arguments.
8204 % o class_hint: Specifies a pointer to a X11 XClassHint structure.
8206 % o manager_hints: Specifies a pointer to a X11 XWMHints structure.
8208 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
8211 MagickExport void XMakeWindow(Display *display,Window parent,char **argv,
8212 int argc,XClassHint *class_hint,XWMHints *manager_hints,
8213 XWindowInfo *window_info)
8215 #define MinWindowSize 64
8223 static XTextProperty
8234 Set window info hints.
8236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8237 assert(display != (Display *) NULL);
8238 assert(window_info != (XWindowInfo *) NULL);
8239 size_hints=XAllocSizeHints();
8240 if (size_hints == (XSizeHints *) NULL)
8241 ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8242 size_hints->flags=(long) window_info->flags;
8243 size_hints->x=window_info->x;
8244 size_hints->y=window_info->y;
8245 size_hints->width=(int) window_info->width;
8246 size_hints->height=(int) window_info->height;
8247 if (window_info->immutable != MagickFalse)
8250 Window size cannot be changed.
8252 size_hints->min_width=size_hints->width;
8253 size_hints->min_height=size_hints->height;
8254 size_hints->max_width=size_hints->width;
8255 size_hints->max_height=size_hints->height;
8256 size_hints->flags|=PMinSize;
8257 size_hints->flags|=PMaxSize;
8262 Window size can be changed.
8264 size_hints->min_width=(int) window_info->min_width;
8265 size_hints->min_height=(int) window_info->min_height;
8266 size_hints->flags|=PResizeInc;
8267 size_hints->width_inc=(int) window_info->width_inc;
8268 size_hints->height_inc=(int) window_info->height_inc;
8269 #if !defined(PRE_R4_ICCCM)
8270 size_hints->flags|=PBaseSize;
8271 size_hints->base_width=size_hints->width_inc;
8272 size_hints->base_height=size_hints->height_inc;
8275 gravity=NorthWestGravity;
8276 if (window_info->geometry != (char *) NULL)
8279 default_geometry[MaxTextExtent],
8280 geometry[MaxTextExtent];
8289 User specified geometry.
8291 (void) FormatMagickString(default_geometry,MaxTextExtent,"%dx%d",
8292 size_hints->width,size_hints->height);
8293 (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
8295 while (strlen(p) != 0)
8297 if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
8300 (void) CopyMagickString(p,p+1,MaxTextExtent);
8302 flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
8303 window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
8304 &size_hints->width,&size_hints->height,&gravity);
8305 if ((flags & WidthValue) && (flags & HeightValue))
8306 size_hints->flags|=USSize;
8307 if ((flags & XValue) && (flags & YValue))
8309 size_hints->flags|=USPosition;
8310 window_info->x=size_hints->x;
8311 window_info->y=size_hints->y;
8314 #if !defined(PRE_R4_ICCCM)
8315 size_hints->win_gravity=gravity;
8316 size_hints->flags|=PWinGravity;
8318 if (window_info->id == (Window) NULL)
8319 window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
8320 (unsigned int) size_hints->width,(unsigned int) size_hints->height,
8321 window_info->border_width,(int) window_info->depth,InputOutput,
8322 window_info->visual,window_info->mask,&window_info->attributes);
8335 Window already exists; change relevant attributes.
8337 (void) XChangeWindowAttributes(display,window_info->id,window_info->mask,
8338 &window_info->attributes);
8339 mask=ConfigureNotify;
8340 while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
8341 window_changes.x=window_info->x;
8342 window_changes.y=window_info->y;
8343 window_changes.width=(int) window_info->width;
8344 window_changes.height=(int) window_info->height;
8345 mask=(MagickStatusType) (CWWidth | CWHeight);
8346 if (window_info->flags & USPosition)
8348 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
8349 mask,&window_changes);
8351 if (window_info->id == (Window) NULL)
8352 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
8354 status=XStringListToTextProperty(&window_info->name,1,&window_name);
8355 if (status == False)
8356 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8358 status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
8359 if (status == False)
8360 ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
8361 window_info->icon_name);
8362 if (window_info->icon_geometry != (char *) NULL)
8370 User specified icon geometry.
8372 size_hints->flags|=USPosition;
8373 flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
8374 (char *) NULL,0,size_hints,&manager_hints->icon_x,
8375 &manager_hints->icon_y,&width,&height,&gravity);
8376 if ((flags & XValue) && (flags & YValue))
8377 manager_hints->flags|=IconPositionHint;
8379 XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
8380 size_hints,manager_hints,class_hint);
8381 if (window_name.value != (void *) NULL)
8383 (void) XFree((void *) window_name.value);
8384 window_name.value=(unsigned char *) NULL;
8385 window_name.nitems=0;
8387 if (icon_name.value != (void *) NULL)
8389 (void) XFree((void *) icon_name.value);
8390 icon_name.value=(unsigned char *) NULL;
8393 atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
8394 atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
8395 (void) XSetWMProtocols(display,window_info->id,atom_list,2);
8396 (void) XFree((void *) size_hints);
8397 if (window_info->shape != MagickFalse)
8399 #if defined(MAGICKCORE_HAVE_SHAPE)
8405 Can we apply a non-rectangular shaping mask?
8409 if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
8410 window_info->shape=MagickFalse;
8412 window_info->shape=MagickFalse;
8415 if (window_info->shared_memory)
8417 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8419 Can we use shared memory with this window?
8421 if (XShmQueryExtension(display) == 0)
8422 window_info->shared_memory=MagickFalse;
8424 window_info->shared_memory=MagickFalse;
8427 window_info->image=NewImageList();
8428 window_info->destroy=MagickFalse;
8432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8436 % X M a g i c k P r o g r e s s M o n i t o r %
8440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8442 % XMagickProgressMonitor() displays the progress a task is making in
8443 % completing a task.
8445 % The format of the XMagickProgressMonitor method is:
8447 % void XMagickProgressMonitor(const char *task,
8448 % const MagickOffsetType quantum,const MagickSizeType span,
8449 % void *client_data)
8451 % A description of each parameter follows:
8453 % o task: Identifies the task in progress.
8455 % o quantum: Specifies the quantum position within the span which represents
8456 % how much progress has been made in completing a task.
8458 % o span: Specifies the span relative to completing a task.
8460 % o client_data: Pointer to any client data.
8464 static const char *GetLocaleMonitorMessage(const char *text)
8467 message[MaxTextExtent],
8476 (void) CopyMagickMemory(tag,text,MaxTextExtent);
8478 if (p != (char *) NULL)
8480 (void) FormatMagickString(message,MaxTextExtent,"Monitor/%s",tag);
8481 locale_message=GetLocaleMessage(message);
8482 if (locale_message == message)
8484 return(locale_message);
8487 MagickExport MagickBooleanType XMagickProgressMonitor(const char *tag,
8488 const MagickOffsetType quantum,const MagickSizeType span,
8489 void *magick_unused(client_data))
8494 windows=XSetWindows((XWindows *) ~0);
8495 if (windows == (XWindows *) NULL)
8497 if (windows->info.mapped != MagickFalse)
8498 XProgressMonitorWidget(windows->display,windows,
8499 GetLocaleMonitorMessage(tag),quantum,span);
8504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8508 % X Q u e r y C o l o r D a t a b a s e %
8512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8514 % XQueryColorDatabase() looks up a RGB values for a color given in the target
8517 % The format of the XQueryColorDatabase method is:
8519 % MagickBooleanType XQueryColorDatabase(const char *target,XColor *color)
8521 % A description of each parameter follows:
8523 % o target: Specifies the color to lookup in the X color database.
8525 % o color: A pointer to an PixelPacket structure. The RGB value of the target
8526 % color is returned as this value.
8529 MagickExport MagickBooleanType XQueryColorDatabase(const char *target,
8536 *display = (Display *) NULL;
8545 Initialize color return value.
8547 assert(color != (XColor *) NULL);
8551 color->flags=(char) (DoRed | DoGreen | DoBlue);
8552 if ((target == (char *) NULL) || (*target == '\0'))
8553 target="#ffffffffffff";
8555 Let the X server define the color for us.
8557 if (display == (Display *) NULL)
8558 display=XOpenDisplay((char *) NULL);
8559 if (display == (Display *) NULL)
8561 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
8562 return(MagickFalse);
8564 colormap=XDefaultColormap(display,XDefaultScreen(display));
8565 status=XParseColor(display,colormap,(char *) target,&xcolor);
8566 if (status == False)
8567 ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
8570 color->red=xcolor.red;
8571 color->green=xcolor.green;
8572 color->blue=xcolor.blue;
8573 color->flags=xcolor.flags;
8575 return(status != False ? MagickTrue : MagickFalse);
8579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8583 % X Q u e r y P o s i t i o n %
8587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8589 % XQueryPosition() gets the pointer coordinates relative to a window.
8591 % The format of the XQueryPosition method is:
8593 % void XQueryPosition(Display *display,const Window window,int *x,int *y)
8595 % A description of each parameter follows:
8597 % o display: Specifies a connection to an X server; returned from
8600 % o window: Specifies a pointer to a Window.
8602 % o x: Return the x coordinate of the pointer relative to the origin of the
8605 % o y: Return the y coordinate of the pointer relative to the origin of the
8609 MagickExport void XQueryPosition(Display *display,const Window window,int *x,int *y)
8621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8622 assert(display != (Display *) NULL);
8623 assert(window != (Window) NULL);
8624 assert(x != (int *) NULL);
8625 assert(y != (int *) NULL);
8626 (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
8631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8635 % X R e f r e s h W i n d o w %
8639 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8641 % XRefreshWindow() refreshes an image in a X window.
8643 % The format of the XRefreshWindow method is:
8645 % void XRefreshWindow(Display *display,const XWindowInfo *window,
8646 % const XEvent *event)
8648 % A description of each parameter follows:
8650 % o display: Specifies a connection to an X server; returned from
8653 % o window: Specifies a pointer to a XWindowInfo structure.
8655 % o event: Specifies a pointer to a XEvent structure. If it is NULL,
8656 % the entire image is refreshed.
8659 MagickExport void XRefreshWindow(Display *display,const XWindowInfo *window,
8660 const XEvent *event)
8670 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8671 assert(display != (Display *) NULL);
8672 assert(window != (XWindowInfo *) NULL);
8673 if (window->ximage == (XImage *) NULL)
8675 if (event != (XEvent *) NULL)
8678 Determine geometry from expose event.
8682 width=(unsigned int) event->xexpose.width;
8683 height=(unsigned int) event->xexpose.height;
8691 Refresh entire window; discard outstanding expose events.
8695 width=window->width;
8696 height=window->height;
8697 while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8700 Check boundary conditions.
8702 if ((window->ximage->width-(x+window->x)) < (int) width)
8703 width=(unsigned int) (window->ximage->width-(x+window->x));
8704 if ((window->ximage->height-(y+window->y)) < (int) height)
8705 height=(unsigned int) (window->ximage->height-(y+window->y));
8709 if (window->matte_pixmap != (Pixmap) NULL)
8711 #if defined(MAGICKCORE_HAVE_SHAPE)
8712 if (window->shape != MagickFalse)
8713 XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8714 window->matte_pixmap,ShapeSet);
8716 (void) XSetClipMask(display,window->annotate_context,
8717 window->matte_pixmap);
8719 if (window->pixmap != (Pixmap) NULL)
8721 if (window->depth > 1)
8722 (void) XCopyArea(display,window->pixmap,window->id,
8723 window->annotate_context,x+window->x,y+window->y,width,height,x,y);
8725 (void) XCopyPlane(display,window->pixmap,window->id,
8726 window->highlight_context,x+window->x,y+window->y,width,height,x,y,
8731 #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
8732 if (window->shared_memory)
8733 (void) XShmPutImage(display,window->id,window->annotate_context,
8734 window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
8736 if (window->shared_memory == MagickFalse)
8737 (void) XPutImage(display,window->id,window->annotate_context,
8738 window->ximage,x+window->x,y+window->y,x,y,width,height);
8740 if (window->matte_pixmap != (Pixmap) NULL)
8741 (void) XSetClipMask(display,window->annotate_context,None);
8742 (void) XFlush(display);
8746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8750 % X R e m o t e C o m m a n d %
8754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8756 % XRemoteCommand() forces a remote display(1) to display the specified
8759 % The format of the XRemoteCommand method is:
8761 % MagickBooleanType XRemoteCommand(Display *display,const char *window,
8762 % const char *filename)
8764 % A description of each parameter follows:
8766 % o display: Specifies a connection to an X server; returned from
8769 % o window: Specifies the name or id of an X window.
8771 % o filename: the name of the image filename to display.
8774 MagickExport MagickBooleanType XRemoteCommand(Display *display,
8775 const char *window,const char *filename)
8784 assert(filename != (char *) NULL);
8785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
8786 if (display == (Display *) NULL)
8787 display=XOpenDisplay((char *) NULL);
8788 if (display == (Display *) NULL)
8790 ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
8791 return(MagickFalse);
8793 remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
8794 remote_window=(Window) NULL;
8795 root_window=XRootWindow(display,XDefaultScreen(display));
8796 if (window != (char *) NULL)
8799 Search window hierarchy and identify any clients by name or ID.
8801 if (isdigit((unsigned char) *window) != 0)
8802 remote_window=XWindowByID(display,root_window,(Window)
8803 strtol((char *) window,(char **) NULL,0));
8804 if (remote_window == (Window) NULL)
8805 remote_window=XWindowByName(display,root_window,window);
8807 if (remote_window == (Window) NULL)
8808 remote_window=XWindowByProperty(display,root_window,remote_atom);
8809 if (remote_window == (Window) NULL)
8811 ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
8813 return(MagickFalse);
8816 Send remote command.
8818 remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
8819 (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
8820 PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
8821 (void) XSync(display,MagickFalse);
8826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8830 % X R e t a i n W i n d o w C o l o r s %
8834 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8836 % XRetainWindowColors() sets X11 color resources on a window. This preserves
8837 % the colors associated with an image displayed on the window.
8839 % The format of the XRetainWindowColors method is:
8841 % void XRetainWindowColors(Display *display,const Window window)
8843 % A description of each parameter follows:
8845 % o display: Specifies a connection to an X server; returned from
8848 % o window: Specifies a pointer to a XWindowInfo structure.
8851 MagickExport void XRetainWindowColors(Display *display,const Window window)
8860 Put property on the window.
8862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8863 assert(display != (Display *) NULL);
8864 assert(window != (Window) NULL);
8865 property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
8866 if (property == (Atom) NULL)
8868 ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
8872 pixmap=XCreatePixmap(display,window,1,1,1);
8873 if (pixmap == (Pixmap) NULL)
8875 ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
8878 (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
8879 (unsigned char *) &pixmap,1);
8880 (void) XSetCloseDownMode(display,RetainPermanent);
8884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8888 % X S e l e c t W i n d o w %
8892 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8894 % XSelectWindow() allows a user to select a window using the mouse. If the
8895 % mouse moves, a cropping rectangle is drawn and the extents of the rectangle
8896 % is returned in the crop_info structure.
8898 % The format of the XSelectWindow function is:
8900 % target_window=XSelectWindow(display,crop_info)
8902 % A description of each parameter follows:
8904 % o window: XSelectWindow returns the window id.
8906 % o display: Specifies a pointer to the Display structure; returned from
8909 % o crop_info: Specifies a pointer to a RectangleInfo structure. It
8910 % contains the extents of any cropping rectangle.
8914 static Window XSelectWindow(Display *display,RectangleInfo *crop_info)
8916 #define MinimumCropArea (unsigned int) 9
8943 Initialize graphic context.
8945 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8946 assert(display != (Display *) NULL);
8947 assert(crop_info != (RectangleInfo *) NULL);
8948 root_window=XRootWindow(display,XDefaultScreen(display));
8949 context_values.background=XBlackPixel(display,XDefaultScreen(display));
8950 context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
8951 context_values.function=GXinvert;
8952 context_values.plane_mask=
8953 context_values.background ^ context_values.foreground;
8954 context_values.subwindow_mode=IncludeInferiors;
8955 annotate_context=XCreateGC(display,root_window,(unsigned long) (GCBackground |
8956 GCForeground | GCFunction | GCSubwindowMode),&context_values);
8957 if (annotate_context == (GC) NULL)
8958 return(MagickFalse);
8960 Grab the pointer using target cursor.
8962 target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
8963 XDefaultScreen(display)),(char * ) "white",(char * ) "black");
8964 status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
8965 (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
8966 GrabModeAsync,root_window,target_cursor,CurrentTime);
8967 if (status != GrabSuccess)
8969 ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
8970 return((Window) NULL);
8976 crop_info->height=0;
8978 target_window=(Window) NULL;
8983 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
8984 (void) XDrawRectangle(display,root_window,annotate_context,
8985 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
8986 (unsigned int) crop_info->height-1);
8988 Allow another event.
8990 (void) XAllowEvents(display,SyncPointer,CurrentTime);
8991 (void) XWindowEvent(display,root_window,ButtonPressMask |
8992 ButtonReleaseMask | ButtonMotionMask,&event);
8993 if ((crop_info->width*crop_info->height) >= MinimumCropArea)
8994 (void) XDrawRectangle(display,root_window,annotate_context,
8995 (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
8996 (unsigned int) crop_info->height-1);
9001 target_window=XGetSubwindow(display,event.xbutton.subwindow,
9002 event.xbutton.x,event.xbutton.y);
9003 if (target_window == (Window) NULL)
9004 target_window=root_window;
9005 x_offset=event.xbutton.x_root;
9006 y_offset=event.xbutton.y_root;
9007 crop_info->x=x_offset;
9008 crop_info->y=y_offset;
9010 crop_info->height=0;
9022 Discard pending button motion events.
9024 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9025 crop_info->x=event.xmotion.x;
9026 crop_info->y=event.xmotion.y;
9028 Check boundary conditions.
9030 if ((int) crop_info->x < x_offset)
9031 crop_info->width=(unsigned int) (x_offset-crop_info->x);
9034 crop_info->width=(unsigned int) (crop_info->x-x_offset);
9035 crop_info->x=x_offset;
9037 if ((int) crop_info->y < y_offset)
9038 crop_info->height=(unsigned int) (y_offset-crop_info->y);
9041 crop_info->height=(unsigned int) (crop_info->y-y_offset);
9042 crop_info->y=y_offset;
9048 } while ((target_window == (Window) NULL) || (presses > 0));
9049 (void) XUngrabPointer(display,CurrentTime);
9050 (void) XFreeCursor(display,target_cursor);
9051 (void) XFreeGC(display,annotate_context);
9052 if ((crop_info->width*crop_info->height) < MinimumCropArea)
9055 crop_info->height=0;
9057 if ((crop_info->width != 0) && (crop_info->height != 0))
9058 target_window=root_window;
9059 return(target_window);
9063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9067 % X S e t C u r s o r S t a t e %
9071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9073 % XSetCursorState() sets the cursor state to busy, otherwise the cursor are
9074 % reset to their default.
9076 % The format of the XXSetCursorState method is:
9078 % XSetCursorState(display,windows,const MagickStatusType state)
9080 % A description of each parameter follows:
9082 % o display: Specifies a connection to an X server; returned from
9085 % o windows: Specifies a pointer to a XWindows structure.
9087 % o state: An unsigned integer greater than 0 sets the cursor state
9088 % to busy, otherwise the cursor are reset to their default.
9091 MagickExport void XSetCursorState(Display *display,XWindows *windows,
9092 const MagickStatusType state)
9094 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9095 assert(display != (Display *) NULL);
9096 assert(windows != (XWindows *) NULL);
9099 (void) XCheckDefineCursor(display,windows->image.id,
9100 windows->image.busy_cursor);
9101 (void) XCheckDefineCursor(display,windows->pan.id,
9102 windows->pan.busy_cursor);
9103 (void) XCheckDefineCursor(display,windows->magnify.id,
9104 windows->magnify.busy_cursor);
9105 (void) XCheckDefineCursor(display,windows->command.id,
9106 windows->command.busy_cursor);
9110 (void) XCheckDefineCursor(display,windows->image.id,
9111 windows->image.cursor);
9112 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
9113 (void) XCheckDefineCursor(display,windows->magnify.id,
9114 windows->magnify.cursor);
9115 (void) XCheckDefineCursor(display,windows->command.id,
9116 windows->command.cursor);
9117 (void) XCheckDefineCursor(display,windows->command.id,
9118 windows->widget.cursor);
9119 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9121 windows->info.mapped=MagickFalse;
9125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9129 % X S e t W i n d o w s %
9133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9135 % XSetWindows() sets the X windows structure if the windows info is specified.
9136 % Otherwise the current windows structure is returned.
9138 % The format of the XSetWindows method is:
9140 % XWindows *XSetWindows(XWindows *windows_info)
9142 % A description of each parameter follows:
9144 % o windows_info: Initialize the Windows structure with this information.
9147 MagickExport XWindows *XSetWindows(XWindows *windows_info)
9150 *windows = (XWindows *) NULL;
9152 if (windows_info != (XWindows *) ~0)
9154 windows=(XWindows *) RelinquishMagickMemory(windows);
9155 windows=windows_info;
9160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9164 % X U s e r P r e f e r e n c e s %
9168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9170 % XUserPreferences() saves the preferences in a configuration file in the
9171 % users' home directory.
9173 % The format of the XUserPreferences method is:
9175 % void XUserPreferences(XResourceInfo *resource_info)
9177 % A description of each parameter follows:
9179 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
9182 MagickExport void XUserPreferences(XResourceInfo *resource_info)
9184 #if defined(X11_PREFERENCES_PATH)
9186 cache[MaxTextExtent],
9187 filename[MaxTextExtent],
9188 specifier[MaxTextExtent];
9194 preferences_database;
9197 Save user preferences to the client configuration file.
9199 assert(resource_info != (XResourceInfo *) NULL);
9200 preferences_database=XrmGetStringDatabase("");
9201 (void) FormatMagickString(specifier,MaxTextExtent,"%s.backdrop",
9203 value=resource_info->backdrop ? "True" : "False";
9204 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9205 (void) FormatMagickString(specifier,MaxTextExtent,"%s.colormap",
9207 value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
9208 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9209 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmExit",
9211 value=resource_info->confirm_exit ? "True" : "False";
9212 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9213 (void) FormatMagickString(specifier,MaxTextExtent,"%s.confirmEdit",
9215 value=resource_info->confirm_edit ? "True" : "False";
9216 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9217 (void) FormatMagickString(specifier,MaxTextExtent,"%s.displayWarnings",
9219 value=resource_info->display_warnings ? "True" : "False";
9220 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9221 (void) FormatMagickString(specifier,MaxTextExtent,"%s.dither",
9223 value=resource_info->quantize_info->dither ? "True" : "False";
9224 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9225 (void) FormatMagickString(specifier,MaxTextExtent,"%s.gammaCorrect",
9227 value=resource_info->gamma_correct ? "True" : "False";
9228 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9229 (void) FormatMagickString(specifier,MaxTextExtent,"%s.undoCache",
9231 (void) FormatMagickString(cache,MaxTextExtent,"%lu",
9232 resource_info->undo_cache);
9233 XrmPutStringResource(&preferences_database,specifier,cache);
9234 (void) FormatMagickString(specifier,MaxTextExtent,"%s.usePixmap",
9236 value=resource_info->use_pixmap ? "True" : "False";
9237 XrmPutStringResource(&preferences_database,specifier,(char *) value);
9238 (void) FormatMagickString(filename,MaxTextExtent,"%s%src",
9239 X11_PREFERENCES_PATH,GetClientName());
9240 ExpandFilename(filename);
9241 XrmPutFileDatabase(preferences_database,filename);
9246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9250 % X V i s u a l C l a s s N a m e %
9254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9256 % XVisualClassName() returns the visual class name as a character string.
9258 % The format of the XVisualClassName method is:
9260 % char *XVisualClassName(const int visual_class)
9262 % A description of each parameter follows:
9264 % o visual_type: XVisualClassName returns the visual class as a character
9267 % o class: Specifies the visual class.
9271 static const char *XVisualClassName(const int visual_class)
9273 switch (visual_class)
9275 case StaticGray: return("StaticGray");
9276 case GrayScale: return("GrayScale");
9277 case StaticColor: return("StaticColor");
9278 case PseudoColor: return("PseudoColor");
9279 case TrueColor: return("TrueColor");
9280 case DirectColor: return("DirectColor");
9282 return("unknown visual class");
9286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9296 % XWarning() displays a warning reason in a Notice widget.
9298 % The format of the XWarning method is:
9300 % void XWarning(const unsigned int warning,const char *reason,
9301 % const char *description)
9303 % A description of each parameter follows:
9305 % o warning: Specifies the numeric warning category.
9307 % o reason: Specifies the reason to display before terminating the
9310 % o description: Specifies any description to the reason.
9313 MagickExport void XWarning(const ExceptionType magick_unused(warning),
9314 const char *reason,const char *description)
9317 text[MaxTextExtent];
9322 if (reason == (char *) NULL)
9324 (void) CopyMagickString(text,reason,MaxTextExtent);
9325 (void) ConcatenateMagickString(text,":",MaxTextExtent);
9326 windows=XSetWindows((XWindows *) ~0);
9327 XNoticeWidget(windows->display,windows,text,(char *) description);
9331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9335 % X W i n d o w B y I D %
9339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9341 % XWindowByID() locates a child window with a given ID. If not window with
9342 % the given name is found, 0 is returned. Only the window specified and its
9343 % subwindows are searched.
9345 % The format of the XWindowByID function is:
9347 % child=XWindowByID(display,window,id)
9349 % A description of each parameter follows:
9351 % o child: XWindowByID returns the window with the specified
9352 % id. If no windows are found, XWindowByID returns 0.
9354 % o display: Specifies a pointer to the Display structure; returned from
9357 % o id: Specifies the id of the window to locate.
9360 MagickExport Window XWindowByID(Display *display,const Window root_window,
9361 const unsigned long id)
9380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9381 assert(display != (Display *) NULL);
9382 assert(root_window != (Window) NULL);
9384 return(XSelectWindow(display,&rectangle_info));
9385 if (root_window == id)
9387 status=XQueryTree(display,root_window,&child,&child,&children,
9389 if (status == False)
9390 return((Window) NULL);
9391 window=(Window) NULL;
9392 for (i=0; i < (int) number_children; i++)
9395 Search each child and their children.
9397 window=XWindowByID(display,children[i],id);
9398 if (window != (Window) NULL)
9401 if (children != (Window *) NULL)
9402 (void) XFree((void *) children);
9407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9411 % X W i n d o w B y N a m e %
9415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9417 % XWindowByName() locates a window with a given name on a display. If no
9418 % window with the given name is found, 0 is returned. If more than one window
9419 % has the given name, the first one is returned. Only root and its children
9422 % The format of the XWindowByName function is:
9424 % window=XWindowByName(display,root_window,name)
9426 % A description of each parameter follows:
9428 % o window: XWindowByName returns the window id.
9430 % o display: Specifies a pointer to the Display structure; returned from
9433 % o root_window: Specifies the id of the root window.
9435 % o name: Specifies the name of the window to locate.
9438 MagickExport Window XWindowByName(Display *display,const Window root_window,
9458 assert(display != (Display *) NULL);
9459 assert(root_window != (Window) NULL);
9460 assert(name != (char *) NULL);
9461 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
9462 if (XGetWMName(display,root_window,&window_name) != 0)
9463 if (LocaleCompare((char *) window_name.value,name) == 0)
9464 return(root_window);
9465 status=XQueryTree(display,root_window,&child,&child,&children,
9467 if (status == False)
9468 return((Window) NULL);
9469 window=(Window) NULL;
9470 for (i=0; i < (int) number_children; i++)
9473 Search each child and their children.
9475 window=XWindowByName(display,children[i],name);
9476 if (window != (Window) NULL)
9479 if (children != (Window *) NULL)
9480 (void) XFree((void *) children);
9485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9489 % X W i n d o w B y P r o p e r y %
9493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9495 % XWindowByProperty() locates a child window with a given property. If not
9496 % window with the given name is found, 0 is returned. If more than one window
9497 % has the given property, the first one is returned. Only the window
9498 % specified and its subwindows are searched.
9500 % The format of the XWindowByProperty function is:
9502 % child=XWindowByProperty(display,window,property)
9504 % A description of each parameter follows:
9506 % o child: XWindowByProperty returns the window id with the specified
9507 % property. If no windows are found, XWindowByProperty returns 0.
9509 % o display: Specifies a pointer to the Display structure; returned from
9512 % o property: Specifies the property of the window to locate.
9515 MagickExport Window XWindowByProperty(Display *display,const Window window,
9516 const Atom property)
9544 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9545 assert(display != (Display *) NULL);
9546 assert(window != (Window) NULL);
9547 assert(property != (Atom) NULL);
9548 status=XQueryTree(display,window,&root,&parent,&children,&number_children);
9549 if (status == False)
9550 return((Window) NULL);
9552 child=(Window) NULL;
9553 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9555 status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
9556 (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
9558 (void) XFree((void *) data);
9559 if ((status == Success) && (type != (Atom) NULL))
9562 for (i=0; (i < number_children) && (child == (Window) NULL); i++)
9563 child=XWindowByProperty(display,children[i],property);
9564 if (children != (Window *) NULL)
9565 (void) XFree((void *) children);
9571 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9575 % X I m p o r t I m a g e %
9579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9581 % XImportImage() reads an image from an X window.
9583 % The format of the XImportImage method is:
9585 % Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info)
9587 % A description of each parameter follows:
9589 % o image_info: the image info..
9591 % o ximage_info: Specifies a pointer to an XImportInfo structure.
9594 MagickExport Image *XImportImage(const ImageInfo *image_info,
9595 XImportInfo *ximage_info)
9597 assert(image_info != (const ImageInfo *) NULL);
9598 assert(image_info->signature == MagickSignature);
9599 if (image_info->debug != MagickFalse)
9600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
9601 image_info->filename);
9602 assert(ximage_info != (XImportInfo *) NULL);
9603 return((Image *) NULL);
9608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9612 % X G e t I m p o r t I n f o %
9616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9618 % XGetImportInfo() initializes the XImportInfo structure.
9620 % The format of the XGetImportInfo method is:
9622 % void XGetImportInfo(XImportInfo *ximage_info)
9624 % A description of each parameter follows:
9626 % o ximage_info: Specifies a pointer to an ImageInfo structure.
9629 MagickExport void XGetImportInfo(XImportInfo *ximage_info)
9631 assert(ximage_info != (XImportInfo *) NULL);
9632 ximage_info->frame=MagickFalse;
9633 ximage_info->borders=MagickFalse;
9634 ximage_info->screen=MagickFalse;
9635 ximage_info->descend=MagickTrue;
9636 ximage_info->silent=MagickFalse;